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';
14 open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
20 @extra_files = split(' ', $_);
26 my $incl_generated_files = shift if @ARGV && $ARGV[0] eq '--gen';
28 system "git checkout master" and exit 1;
29 if ($incl_generated_files) {
30 die "'a' must not exist in the current directory.\n" if -e 'a';
31 die "'b' must not exist in the current directory.\n" if -e 'b';
32 system "make gen && rsync -a @extra_files a/" and exit 1;
34 my $last_touch = time;
36 my(@patches, %local_patch);
39 s{^(patches|patch|origin/patch)/} {};
43 open(PIPE, '-|', 'git', 'branch', '-l') or die $!;
45 open(PIPE, '-|', 'git', 'branch', '-a') or die $!;
48 if (m# origin/patch/(.*)#) {
50 } elsif (m# patch/(.*)#) {
56 my(%parent, %description);
57 foreach my $patch (@patches) {
58 my $branch = ($local_patch{$patch} ? '' : 'origin/') . "patch/$patch";
60 open(PIPE, '-|', 'git', 'diff', '-U1000', "master...$branch", '--', "PATCH.$patch") or die $!;
62 next if m{^\Q+++\E b/PATCH};
63 next unless s/^[ +]//;
64 if (m#patch -p1 <patches/(\S+)\.diff# && $1 ne $patch) {
69 $description{$patch} = $desc;
73 foreach my $patch (@patches) {
74 next if $completed{$patch}++;
78 if ($incl_generated_files) {
82 sleep 1 if $last_touch == time;
83 system "git checkout master";
92 my $parent = $parent{$patch};
93 if (defined $parent) {
94 unless ($completed{$parent}++) {
95 update_patch($parent);
97 $parent = "patch/$parent";
102 print "======== $patch ========\n";
104 sleep 1 if $incl_generated_files && $last_touch == time;
105 if ($local_patch{$patch}) {
106 system "git checkout patch/$patch" and exit 1;
108 system "git checkout --track -b patch/$patch origin/patch/$patch" and exit 1;
111 open(OUT, '>', "patches/$patch.diff") or die $!;
112 print OUT $description{$patch}, "\n";
114 if (system("git rebase -m $parent") != 0) {
115 print qq|"git rebase -m $parent" incomplete -- please fix.\n|;
116 $ENV{PS1} = "[$parent] patch/$patch: ";
117 system $ENV{SHELL} and exit 1;
120 if ($incl_generated_files) {
121 system "make gen && rsync -a @extra_files b/" and exit 1;
125 open(PIPE, '-|', 'git', 'diff', $parent) or die $!;
126 DIFF: while (<PIPE>) {
127 while (m{^diff --git a/PATCH}) {
129 last if m{^diff --git a/};
131 last DIFF if !defined $_;
138 if ($incl_generated_files) {
139 open(PIPE, '-|', 'diff', '-up', 'a', 'b') or die $!;
141 s/^((?:---|\+\+\+) [^\t]+)\t.*/$1/;