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 $!;
65 next unless s/^[ +]//;
66 if (m#patch -p1 <patches/(\S+)\.diff# && $1 ne $patch) {
71 $description{$patch} = $desc;
75 foreach my $patch (@patches) {
76 next if $completed{$patch}++;
80 if ($incl_generated_files) {
84 sleep 1 if $last_touch == time;
85 system "git checkout master";
94 my $parent = $parent{$patch};
95 if (defined $parent) {
96 unless ($completed{$parent}++) {
97 update_patch($parent);
99 $parent = "patch/$parent";
104 print "======== $patch ========\n";
106 sleep 1 if $incl_generated_files && $last_touch == time;
107 if ($local_patch{$patch}) {
108 system "git checkout patch/$patch" and exit 1;
110 system "git checkout --track -b patch/$patch origin/patch/$patch" and exit 1;
113 open(OUT, '>', "patches/$patch.diff") or die $!;
114 print OUT $description{$patch}, "\n";
116 if (system("git rebase -m $parent") != 0) {
117 print qq|"git rebase -m $parent" incomplete -- please fix.\n|;
118 $ENV{PS1} = "[$parent] patch/$patch: ";
119 system $ENV{SHELL} and exit 1;
122 if ($incl_generated_files) {
123 system "make gen && rsync -a @extra_files b/" and exit 1;
127 open(PIPE, '-|', 'git', 'diff', $parent) or die $!;
128 DIFF: while (<PIPE>) {
129 while (m{^diff --git a/PATCH}) {
131 last if m{^diff --git a/};
133 last DIFF if !defined $_;
140 if ($incl_generated_files) {
141 open(PIPE, '-|', 'diff', '-up', 'a', 'b') or die $!;
143 s/^((?:---|\+\+\+) [^\t]+)\t.*/$1/;