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";
59 open(PIPE, '-|', 'git-diff', "master...$branch", '--', "PATCH.$patch") or die $!;
67 if (m#patch -p1 <patches/(\S+)\.diff# && $1 ne $patch) {
72 $description{$patch} = $desc;
76 foreach my $patch (@patches) {
77 next if $completed{$patch}++;
81 if ($incl_generated_files) {
85 sleep 1 if $last_touch == time;
86 system "git-checkout master";
95 my $parent = $parent{$patch};
96 if (defined $parent) {
97 unless ($completed{$parent}++) {
98 update_patch($parent);
100 $parent = "patch/$parent";
105 print "======== $patch ========\n";
107 sleep 1 if $incl_generated_files && $last_touch == time;
108 if ($local_patch{$patch}) {
109 system "git-checkout patch/$patch" and exit 1;
111 system "git-checkout --track -b patch/$patch origin/patch/$patch" and exit 1;
114 open(OUT, '>', "patches/$patch.diff") or die $!;
115 print OUT $description{$patch}, "\n";
117 if (system("git-rebase -m $parent") != 0) {
118 print qq|"git-rebase -m $parent" incomplete -- please fix.\n|;
119 $ENV{PS1} = "[$parent] patch/$patch: ";
120 system $ENV{SHELL} and exit 1;
123 if ($incl_generated_files) {
124 system "make gen && rsync -a @extra_files b/" and exit 1;
128 open(PIPE, '-|', 'git-diff', $parent) or die $!;
129 DIFF: while (<PIPE>) {
130 while (m{^diff --git a/PATCH}) {
132 last if m{^diff --git a/};
134 last DIFF if !defined $_;
140 if ($incl_generated_files) {
141 open(PIPE, '-|', 'diff', '-up', 'a', 'b') or die $!;
143 s/^((?:---|\+\+\+) [^\t]+)\t.*/$1/;