Commit | Line | Data |
---|---|---|
d26c7dfd WD |
1 | #!/usr/bin/perl -w |
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 | |
6 | # diffs. | |
7 | ||
8 | use strict; | |
9 | ||
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'; | |
12 | ||
67b9b26f WD |
13 | my @extra_files; |
14 | open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n"; | |
15 | while (<IN>) { | |
16 | if (s/^GENFILES=//) { | |
17 | while (s/\\$//) { | |
18 | $_ .= <IN>; | |
19 | } | |
20 | @extra_files = split(' ', $_); | |
21 | last; | |
22 | } | |
23 | } | |
d26c7dfd WD |
24 | close IN; |
25 | ||
49ebb358 | 26 | my $incl_generated_files = shift if @ARGV && $ARGV[0] eq '--gen'; |
d26c7dfd WD |
27 | |
28 | system "git-checkout master" and exit 1; | |
d26c7dfd | 29 | if ($incl_generated_files) { |
18fa9129 WD |
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'; | |
67b9b26f | 32 | system "make gen && rsync -a @extra_files a/" and exit 1; |
d26c7dfd | 33 | } |
49ebb358 | 34 | my $last_touch = time; |
d26c7dfd WD |
35 | |
36 | my(@patches, %local_patch); | |
37 | if (@ARGV) { | |
38 | foreach (@ARGV) { | |
39 | s{^(patches|patch|origin/patch)/} {}; | |
40 | s{\.diff$} {}; | |
41 | push(@patches, $_); | |
42 | } | |
43 | open(PIPE, '-|', 'git-branch', '-l') or die $!; | |
44 | } else { | |
45 | open(PIPE, '-|', 'git-branch', '-a') or die $!; | |
46 | } | |
47 | while (<PIPE>) { | |
48 | if (m# origin/patch/(.*)#) { | |
49 | push(@patches, $1); | |
50 | } elsif (m# patch/(.*)#) { | |
51 | $local_patch{$1} = 1; | |
52 | } | |
53 | } | |
54 | close PIPE; | |
55 | ||
97f04215 | 56 | my(%parent, %description); |
d26c7dfd | 57 | foreach my $patch (@patches) { |
97f04215 WD |
58 | my $branch = ($local_patch{$patch} ? '' : 'origin/') . "patch/$patch"; |
59 | open(PIPE, '-|', 'git-diff', "master...$branch", '--', "PATCH.$patch") or die $!; | |
60 | while (<PIPE>) { | |
61 | last if /^@@ /; | |
62 | } | |
63 | my $desc = ''; | |
64 | while (<PIPE>) { | |
65 | next if /^-/; # huh?? | |
66 | s/^.//; | |
67 | if (m#patch -p1 <patches/(\S+)\.diff# && $1 ne $patch) { | |
68 | $parent{$patch} = $1; | |
69 | } | |
70 | $desc .= $_; | |
71 | } | |
72 | $description{$patch} = $desc; | |
73 | } | |
74 | ||
75 | my %completed; | |
76 | foreach my $patch (@patches) { | |
77 | next if $completed{$patch}++; | |
78 | update_patch($patch); | |
79 | } | |
80 | ||
81 | if ($incl_generated_files) { | |
82 | system "rm -rf a b"; | |
83 | } | |
84 | ||
aa6865d7 WD |
85 | sleep 1 if $last_touch == time; |
86 | system "git-checkout master"; | |
87 | ||
97f04215 WD |
88 | exit; |
89 | ||
90 | ||
91 | sub update_patch | |
92 | { | |
93 | my($patch) = @_; | |
94 | ||
95 | my $parent = $parent{$patch}; | |
96 | if (defined $parent) { | |
97 | unless ($completed{$parent}++) { | |
98 | update_patch($parent); | |
99 | } | |
100 | $parent = "patch/$parent"; | |
101 | } else { | |
102 | $parent = 'master'; | |
103 | } | |
104 | ||
d26c7dfd | 105 | print "======== $patch ========\n"; |
97f04215 | 106 | |
18fa9129 | 107 | sleep 1 if $incl_generated_files && $last_touch == time; |
d26c7dfd WD |
108 | if ($local_patch{$patch}) { |
109 | system "git-checkout patch/$patch" and exit 1; | |
110 | } else { | |
111 | system "git-checkout --track -b patch/$patch origin/patch/$patch" and exit 1; | |
112 | } | |
18fa9129 | 113 | |
d26c7dfd | 114 | open(OUT, '>', "patches/$patch.diff") or die $!; |
97f04215 | 115 | print OUT $description{$patch}, "\n"; |
d26c7dfd | 116 | |
8d321144 WD |
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: "; | |
18fa9129 | 120 | system $ENV{SHELL} and exit 1; |
8d321144 | 121 | } |
d26c7dfd | 122 | |
49ebb358 | 123 | if ($incl_generated_files) { |
67b9b26f | 124 | system "make gen && rsync -a @extra_files b/" and exit 1; |
d26c7dfd | 125 | } |
49ebb358 WD |
126 | $last_touch = time; |
127 | ||
128 | open(PIPE, '-|', 'git-diff', $parent) or die $!; | |
129 | DIFF: while (<PIPE>) { | |
130 | while (m{^diff --git a/PATCH}) { | |
131 | while (<PIPE>) { | |
132 | last if m{^diff --git a/}; | |
133 | } | |
134 | last DIFF if !defined $_; | |
135 | } | |
136 | print OUT $_; | |
d26c7dfd | 137 | } |
d26c7dfd WD |
138 | close PIPE; |
139 | ||
140 | if ($incl_generated_files) { | |
d26c7dfd WD |
141 | open(PIPE, '-|', 'diff', '-up', 'a', 'b') or die $!; |
142 | while (<PIPE>) { | |
143 | s/^((?:---|\+\+\+) [^\t]+)\t.*/$1/; | |
144 | print OUT $_; | |
145 | } | |
146 | close PIPE; | |
147 | } | |
148 | ||
149 | close OUT; | |
150 | } |