2 # This script is used to turn one or more of the "patch/*" branches
3 # into one or more diffs in the "patches" directory. Pass the option
4 # --gen if you want generated files in the diffs. Pass the name of
5 # one or more diffs if you want to just update a subset of all the
10 die "No 'patches' directory present in the current dir.\n" unless -d 'patches';
11 die "No '.git' directory present in the current dir.\n" unless -d '.git';
13 open(IN, '<', 'prepare-source.mak') or die "Couldn't open prepare-source.mak: $!\n";
17 my @extra_files = m{\n([^\s:]+):.*\n\t\S}g;
18 my $incl_generated_files;
20 $incl_generated_files = shift if @ARGV && $ARGV[0] eq '--gen';
22 system "git-checkout master" and exit 1;
24 if ($incl_generated_files) {
25 die "'a' already exists.\n" if -e 'a';
26 die "'b' already exists.\n" if -e 'b';
27 system "./prepare-source && rsync -a @extra_files a/" and exit 1;
30 my(@patches, %local_patch);
33 s{^(patches|patch|origin/patch)/} {};
37 open(PIPE, '-|', 'git-branch', '-l') or die $!;
39 open(PIPE, '-|', 'git-branch', '-a') or die $!;
42 if (m# origin/patch/(.*)#) {
44 } elsif (m# patch/(.*)#) {
50 foreach my $patch (@patches) {
51 print "======== $patch ========\n";
52 if ($local_patch{$patch}) {
53 system "git-checkout patch/$patch" and exit 1;
55 system "git-checkout --track -b patch/$patch origin/patch/$patch" and exit 1;
57 my $parent = 'master';
58 open(IN, '<', 'PATCH') or next;
59 open(OUT, '>', "patches/$patch.diff") or die $!;
62 if (m#patch -p1 <patch/(\S+)\.diff# && $1 ne $patch) {
70 system "git-rebase -m $parent || $ENV{SHELL}";
72 open(PIPE, '-|', 'git-diff', 'master') or die $!;
74 last if m{^diff --git a/PATCH b/PATCH$};
78 last if m{^diff --git a/};
83 if ($incl_generated_files) {
84 system "./prepare-source && rsync -a @extra_files b/" and exit 1;
85 open(PIPE, '-|', 'diff', '-up', 'a', 'b') or die $!;
87 s/^((?:---|\+\+\+) [^\t]+)\t.*/$1/;
96 if ($incl_generated_files) {
100 print "-------- master --------\n";
101 system "git-checkout master && ./prepare-source";