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 my $patches_dir = 'patches';
11 my $incl_generated_files;
13 if (@ARGV && $ARGV[0] =~ /^--gen(?:=(\S+))?$/) {
14 $patches_dir = $1 if defined $1;
15 $incl_generated_files = 1;
19 die "No '$patches_dir' directory was found.\n" unless -d
$patches_dir;
20 die "No '.git' directory present in the current dir.\n" unless -d
'.git';
23 open(IN
, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
29 @extra_files = split(' ', $_);
35 system "git checkout master" and exit 1;
36 if ($incl_generated_files) {
37 die "'a' must not exist in the current directory.\n" if -e
'a';
38 die "'b' must not exist in the current directory.\n" if -e
'b';
39 system "./config.status Makefile && make gen && rsync -a @extra_files a/" and exit 1;
41 my $last_touch = time;
43 my(@patches, %local_patch);
46 s{^(patches|patch|origin/patch)/} {};
50 open(PIPE
, '-|', 'git', 'branch', '-l') or die $!;
52 open(PIPE
, '-|', 'git', 'branch', '-a') or die $!;
55 if (m
# origin/patch/(.*)#) {
57 } elsif (m
# patch/(.*)#) {
63 my(%parent, %description);
64 foreach my $patch (@patches) {
65 my $branch = ($local_patch{$patch} ?
'' : 'origin/') . "patch/$patch";
67 open(PIPE
, '-|', 'git', 'diff', '-U1000', "master...$branch", '--', "PATCH.$patch") or die $!;
72 next unless s/^[ +]//;
73 if (m
#patch -p1 <patches/(\S+)\.diff# && $1 ne $patch) {
78 $description{$patch} = $desc;
82 foreach my $patch (@patches) {
83 next if $completed{$patch}++;
87 if ($incl_generated_files) {
91 sleep 1 if $last_touch == time;
92 system "git checkout master";
101 my $parent = $parent{$patch};
102 if (defined $parent) {
103 unless ($completed{$parent}++) {
104 update_patch
($parent);
106 $parent = "patch/$parent";
111 print "======== $patch ========\n";
113 sleep 1 if $incl_generated_files && $last_touch == time;
114 if ($local_patch{$patch}) {
115 system "git checkout patch/$patch" and exit 1;
117 system "git checkout --track -b patch/$patch origin/patch/$patch" and exit 1;
120 open(OUT
, '>', "$patches_dir/$patch.diff") or die $!;
121 print OUT
$description{$patch}, "\n";
123 if (system("git rebase -m $parent") != 0) {
124 print qq|"git rebase -m $parent" incomplete
-- please fix
.\n|;
125 $ENV{PS1
} = "[$parent] patch/$patch: ";
126 system $ENV{SHELL
} and exit 1;
129 if ($incl_generated_files) {
130 system "./config.status Makefile && make gen && rsync -a @extra_files b/" and exit 1;
134 open(PIPE
, '-|', 'git', 'diff', $parent) or die $!;
135 DIFF
: while (<PIPE
>) {
136 while (m{^diff --git a/PATCH}) {
138 last if m{^diff --git a/};
140 last DIFF
if !defined $_;
147 if ($incl_generated_files) {
148 open(PIPE
, '-|', 'diff', '-up', 'a', 'b') or die $!;
150 s/^((?:---|\+\+\+) [^\t]+)\t.*/$1/;