Commit | Line | Data |
---|---|---|
3a849c85 WD |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | ||
5 | chdir('patches') if -d 'patches'; | |
6 | ||
7 | if (!-f 'verify-patches') { | |
8 | die <<EOT; | |
9 | Please run this script from the root of the rsync dir or | |
10 | from inside the patches subdir. | |
11 | EOT | |
12 | } | |
13 | ||
a978ee02 | 14 | $| = 1; |
b1a4cc32 WD |
15 | $ENV{'TZ'} = 'UTC'; |
16 | my $CONF_OPTS = '-C'; | |
3a849c85 | 17 | |
b1a4cc32 | 18 | my($has_dependencies, @new, @rejects); |
3a849c85 WD |
19 | |
20 | END { | |
21 | &restore_cvsdir; | |
b1a4cc32 | 22 | system "rsync -a --delete cvsdir/ workdir/" if -d 'cvsdir'; |
3a849c85 WD |
23 | }; |
24 | ||
25 | my $root; | |
26 | open(IN, '../CVS/Root') or die $!; | |
27 | chomp($root = <IN>); | |
28 | close IN; | |
29 | ||
b1a4cc32 WD |
30 | mkdir('tmp', 0777) unless -d 'tmp'; |
31 | chdir('tmp') or die "Unable to chdir to 'tmp'"; | |
3a849c85 WD |
32 | |
33 | mkdir('workdir') unless -d 'workdir'; | |
34 | open(OUT, '>exclude') or die $!; | |
35 | print OUT <<EOT; | |
b1a4cc32 | 36 | CVS |
3a849c85 WD |
37 | proto.h |
38 | configure | |
39 | config.h.in | |
40 | rsync.1 | |
41 | rsyncd.conf.5 | |
42 | EOT | |
43 | close OUT; | |
44 | ||
b1a4cc32 | 45 | print "Using CVS to update the tmp/cvsdir copy of the source.\n"; |
3a849c85 WD |
46 | system qq|cvs -d "$root" co -d cvsdir rsync|; |
47 | ||
48 | @ARGV = glob('../*.diff') unless @ARGV; | |
49 | ||
50 | DIFF: | |
51 | foreach my $diff (@ARGV) { | |
52 | next unless $diff =~ /\.diff$/; | |
53 | next if $diff =~ /gzip-rsyncable\.diff$/; | |
54 | $diff =~ s#^(patches|\.\.)/##; | |
55 | ||
56 | open(IN, "../$diff") or die $!; | |
57 | while (<IN>) { | |
58 | last if /^--- /; | |
59 | if (/^Depends-On-Patch: (\S+.diff)$/) { | |
60 | my $dep = $1; | |
61 | $has_dependencies = 1; | |
a978ee02 | 62 | print "\nApplying dependency patch $dep...\n"; |
b1a4cc32 | 63 | if (system("patch -d cvsdir -p0 -b -Vt -Zf <../$dep") != 0) { |
14191ec6 | 64 | print "Unable to cleanly apply dependency patch -- skipping $diff\n"; |
7c88f9bf | 65 | system "rm -f cvsdir/*.rej cvsdir/*/*.rej"; |
3a849c85 WD |
66 | &restore_cvsdir; |
67 | next DIFF; | |
68 | } | |
69 | } | |
70 | } | |
71 | close IN; | |
72 | ||
b1a4cc32 | 73 | my $default = apply_patch($diff); |
fcbecd85 | 74 | if ($default =~ s/^D,// || $default eq 'N') { |
14191ec6 WD |
75 | my $def = generate_new_patch($diff); |
76 | $default = 'U,N' if $default eq 'N' && $def eq 'E'; | |
a978ee02 | 77 | } |
b1a4cc32 | 78 | |
a978ee02 | 79 | PROMPT: |
3a849c85 | 80 | while (1) { |
b1a4cc32 WD |
81 | print "\n----------- $diff ------------\n", |
82 | "\nFix rejects, Diff create, Edit both diffs, Update patch,\n", | |
83 | "Apply patch again, !(CMD), Build rsync, Next, Quit: [$default] "; | |
3a849c85 WD |
84 | my $ans = <STDIN>; |
85 | chomp $ans; | |
b1a4cc32 | 86 | $ans = $default if $ans eq ''; |
a978ee02 WD |
87 | while ($ans =~ s/^\s*(!|\w)((?<!!)[^;,]*|[^;]*)[;,]?//) { |
88 | my $cmd = "\U$1\E"; | |
89 | if ($cmd eq '!') { | |
90 | $cmd = $2 || $ENV{'SHELL'}; | |
91 | chdir('workdir') or die $!; | |
92 | system $cmd; | |
93 | chdir('..') or die $!; | |
7c88f9bf | 94 | $default = 'D'; |
a978ee02 WD |
95 | next; |
96 | } | |
97 | if ($cmd eq 'A') { | |
98 | $default = apply_patch($diff); | |
99 | next; | |
100 | } | |
101 | if ($cmd eq 'B') { | |
102 | if (!-f 'workdir/Makefile') { | |
103 | open(IN, '../../Makefile') or die $!; | |
104 | open(OUT, '>workdir/Makefile') or die $!; | |
105 | print OUT "srcdir=.\n\n"; | |
106 | while (<IN>) { | |
107 | last if /^gen:/; | |
108 | } | |
b1a4cc32 | 109 | print OUT $_; |
a978ee02 WD |
110 | while (<IN>) { |
111 | last if /^clean:/; | |
112 | print OUT $_; | |
113 | } | |
114 | close IN; | |
115 | close OUT; | |
b1a4cc32 | 116 | } |
11360491 WD |
117 | my $need_autoconf; |
118 | my $conf_opts; | |
119 | open(IN, "../$diff") or die $!; | |
120 | while (<IN>) { | |
121 | if (!defined $conf_opts) { | |
122 | $conf_opts = '' if /^---/; | |
123 | if (m#^\s*\./configure( .+)#) { | |
124 | $conf_opts = $1; | |
125 | } | |
126 | } | |
127 | if (m#^--- orig/(configure\.in|/aclocal\.m4)#) { | |
128 | $need_autoconf = 1; | |
129 | last; | |
130 | } | |
131 | } | |
132 | close IN; | |
a978ee02 | 133 | chdir('workdir') or die $!; |
11360491 WD |
134 | system "autoconf; autoheader" if $need_autoconf; |
135 | system "make proto; ./configure $CONF_OPTS $conf_opts; make"; | |
a978ee02 WD |
136 | chdir('..') or die $!; |
137 | $default = '!make test'; | |
138 | next; | |
139 | } | |
140 | if ($cmd eq 'D') { | |
141 | $default = generate_new_patch($diff); | |
142 | next; | |
143 | } | |
144 | if ($cmd eq 'E') { | |
145 | chdir('workdir') or die $!; | |
146 | system "vim -d ../../$diff ../new.patch"; | |
147 | chdir('..') or die $!; | |
148 | $default = 'U,A,D'; | |
149 | next; | |
150 | } | |
151 | if ($cmd eq 'F') { | |
152 | chdir('workdir') or die $!; | |
153 | system "vim @rejects"; | |
154 | chdir('..') or die $!; | |
155 | $default = 'D,E'; | |
156 | next; | |
157 | } | |
158 | if ($cmd eq 'N') { | |
159 | last PROMPT; | |
160 | } | |
161 | if ($cmd eq 'Q') { | |
162 | exit; | |
163 | } | |
164 | if ($cmd eq 'U') { | |
165 | system "cp -p new.patch ../$diff"; | |
166 | print "\nUpdated $diff from new.patch\n"; | |
167 | $default = 'A'; | |
168 | next; | |
b1a4cc32 | 169 | } |
b1a4cc32 | 170 | } |
3a849c85 WD |
171 | } |
172 | ||
173 | &restore_cvsdir; | |
174 | } | |
175 | ||
176 | exit; | |
177 | ||
178 | ||
b1a4cc32 WD |
179 | sub apply_patch |
180 | { | |
181 | my($diff) = @_; | |
182 | ||
183 | undef @new; | |
a978ee02 WD |
184 | system "rsync -a --delete --exclude='*~' cvsdir/ workdir/"; |
185 | print "\nApplying patch $diff...\n"; | |
fcbecd85 | 186 | undef @rejects; |
14191ec6 | 187 | my($saw_failure, $saw_offset, $saw_fuzz); |
b1a4cc32 WD |
188 | open(IN, "patch -d workdir -p0 --no-backup-if-mismatch -Zf <../$diff |") or die $!; |
189 | while (<IN>) { | |
190 | print $_; | |
191 | chomp; | |
192 | if (s/^patching file //) { | |
193 | push(@new, $_) unless -f "cvsdir/$_"; | |
194 | } elsif (s/.* saving rejects to file //) { | |
195 | push(@rejects, $_); | |
196 | } elsif (/^Hunk #\d+ FAILED/) { | |
14191ec6 WD |
197 | $saw_failure = 1; |
198 | } elsif (/^Hunk #\d+ succeeded at \d+( with fuzz )?/) { | |
199 | $saw_fuzz ||= defined $1; | |
200 | $saw_offset = 1; | |
b1a4cc32 WD |
201 | } |
202 | } | |
203 | close IN; | |
14191ec6 WD |
204 | return 'F,D,E' if $saw_failure; |
205 | return 'D,E' if $saw_fuzz; | |
206 | return 'D,U,N' if $saw_offset; | |
207 | 'N'; | |
b1a4cc32 WD |
208 | } |
209 | ||
3a849c85 WD |
210 | sub generate_new_patch |
211 | { | |
212 | my($diff) = @_; | |
213 | ||
214 | foreach (@new) { | |
215 | system "touch -r workdir/$_ cvsdir/$_"; | |
216 | } | |
217 | open(IN, "../$diff") or die $!; | |
218 | open(OUT, '>new.patch') or die $!; | |
219 | while (<IN>) { | |
220 | last if /^--- /; | |
221 | print OUT $_; | |
222 | } | |
223 | close IN; | |
224 | open(IN, 'diff --exclude-from=exclude -upr cvsdir workdir |') or die $!; | |
225 | while (<IN>) { | |
226 | next if /^(diff -|Index: |Only in )/; | |
227 | s#^\Q--- cvsdir/\E#--- orig/#; | |
228 | s#^\Q+++ workdir/\E#+++ #; | |
229 | s#(\.000000000)? \+0000$##; | |
230 | print OUT $_; | |
231 | } | |
232 | close IN; | |
233 | close OUT; | |
234 | foreach (@new) { | |
235 | unlink("cvsdir/$_"); | |
236 | } | |
a978ee02 | 237 | print "\nDiffing... "; |
b1a4cc32 | 238 | if (system("diff ../$diff new.patch >/dev/null") == 0) { |
a978ee02 | 239 | print "new patch is identical to old.\n"; |
b1a4cc32 WD |
240 | return 'N'; |
241 | } | |
a978ee02 | 242 | print "New patch DIFFERS from old.\n"; |
b1a4cc32 | 243 | 'E'; |
3a849c85 WD |
244 | } |
245 | ||
246 | sub restore_cvsdir | |
247 | { | |
248 | return unless $has_dependencies; | |
249 | $has_dependencies = 0; | |
250 | ||
251 | foreach (glob('*.~[1-9]~'), glob('*/*.~[1-9]~')) { | |
252 | my $fn; | |
253 | ($fn = $_) =~ s/\.~1~$//; | |
254 | if ($fn eq $_) { | |
255 | unlink($_); | |
256 | } elsif (-r $fn) { | |
257 | rename($_, $fn); | |
258 | } else { | |
259 | unlink($_); | |
260 | unlink($fn); | |
261 | } | |
262 | } | |
263 | } |