aboutsummaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorAnton Berezin <tobez@FreeBSD.org>2005-04-12 10:56:08 +0000
committerAnton Berezin <tobez@FreeBSD.org>2005-04-12 10:56:08 +0000
commitbbd85008bd2069495542eb2f2f9216f405ebcafa (patch)
tree7962738e5ce68c86dcdf805a700d59d57aa74276 /Tools
parentb15acf8ca74f8ac50547c4e1e53bbf87a5e01e3f (diff)
downloadports-bbd85008bd2069495542eb2f2f9216f405ebcafa.tar.gz
ports-bbd85008bd2069495542eb2f2f9216f405ebcafa.zip
Notes
Diffstat (limited to 'Tools')
-rw-r--r--Tools/scripts/README2
-rwxr-xr-xTools/scripts/splitpatch.pl110
2 files changed, 112 insertions, 0 deletions
diff --git a/Tools/scripts/README b/Tools/scripts/README
index 200de58d33af..9dd53f2de754 100644
--- a/Tools/scripts/README
+++ b/Tools/scripts/README
@@ -33,6 +33,8 @@ prdone - checks in the port, attempting to fill out the commit message using
portsearch - A utility for searching the ports tree. It allows more detailed
search criteria than ``make search key=<string>'' and accepts
all perl(1) regular expressions.
+splitpatch.pl - A small script to convert multi-file patches to several
+ appropriately named single-file patches.
tindex - script used to build INDEXes for supported FreeBSD branches, which
are the source of the 'make fetchindex' INDEXes, and the build
failure reports on ports@FreeBSD.org
diff --git a/Tools/scripts/splitpatch.pl b/Tools/scripts/splitpatch.pl
new file mode 100755
index 000000000000..9b69c89fb003
--- /dev/null
+++ b/Tools/scripts/splitpatch.pl
@@ -0,0 +1,110 @@
+#! /usr/bin/perl -w
+# ----------------------------------------------------------------------------
+# "THE BEER-WARE LICENSE" (Revision 42)
+# <tobez@FreeBSD.org> wrote this file. As long as you retain this notice you
+# can do whatever you want with this stuff. If we meet some day, and you think
+# this stuff is worth it, you can buy me a beer in return. Anton Berezin
+# ----------------------------------------------------------------------------
+#
+# $FreeBSD$
+use strict;
+
+# good tests:
+# /usr/ports/archivers/zoo/files/patch-aa (context diff)
+# /usr/ports/astro/xplanet/files/patch-aa (unified with paths)
+
+my ($in,$fl,$abort,$state,$out);
+
+if (!@ARGV || $ARGV[0] =~ /^-/) {
+ print STDERR "Usage:
+ $0 patchfile ...
+"
+}
+
+while (@ARGV) {
+ $in = shift;
+ $state = \&nofile;
+ if (open IN, "< $in") {
+ $abort = 0;
+ $out = "";
+ $fl = "";
+ while (<IN>) {
+ $state->();
+ last if $abort;
+ }
+ close IN;
+ if ($out && !$abort) {
+ print "Wrote $out\n";
+ }
+ } else {
+ print STDERR "cannot open $in: $!\n";
+ }
+}
+
+sub nofile
+{
+ if (/^\*\*\*\s+/ && !/^\*\*\*\s+\d+,\d+\s+/) {
+ $state = \&cstart;
+ $fl = $_;
+ } elsif (/^---\s+/ && !/^---\s+\d+,\d+\s+/) {
+ $state = \&ustart;
+ $fl = $_;
+ }
+}
+
+sub cstart
+{
+ if (!/^---\s+\d+,\d+\s+/ && /^---\s+(\S+)\s+/) {
+ $state = \&body;
+ $out = $1;
+ $out =~ s|/|_|g;
+ $out = "patch-$out";
+ if (open OUT, "> $out") {
+ print OUT $fl;
+ print OUT $_;
+ } else {
+ print STDERR "Cannot create $out: $!, aborting\n";
+ $abort = 1;
+ }
+ } else {
+ print STDERR "Bad context diff in $in, aborting\n";
+ $abort = 1;
+ }
+}
+
+sub ustart
+{
+ if (/^\+\+\+\s+(\S+)\s+/) {
+ $state = \&body;
+ $out = $1;
+ $out =~ s|/|_|g;
+ $out = "patch-$out";
+ if (open OUT, "> $out") {
+ print OUT $fl;
+ print OUT $_;
+ } else {
+ print STDERR "Cannot create $out: $!, aborting\n";
+ $abort = 1;
+ }
+ } else {
+ print STDERR "Bad unified diff in $in, aborting\n";
+ $abort = 1;
+ }
+}
+
+sub body
+{
+ if (/^\*\*\*\s+/ && !/^\*\*\*\s+\d+,\d+\s+/) {
+ close OUT;
+ print "Wrote $out\n";
+ $state = \&cstart;
+ $fl = $_;
+ } elsif (/^---\s+/ && !/^---\s+\d+,\d+\s+/) {
+ close OUT;
+ print "Wrote $out\n";
+ $state = \&ustart;
+ $fl = $_;
+ } else {
+ print OUT $_;
+ }
+}