6 my($no_cvs, $failures_only, $minor_updates);
8 &Getopt::Long::Configure('bundling');
10 'no-cvs|n' => \$no_cvs,
11 'failures-only|f' => \$failures_only,
12 'minor-updates|u' => \$minor_updates,
15 my $interesting_fuzz = $minor_updates ? '\d' : '[2-9]';
17 chdir('patches') if -d 'patches';
19 if (!-f 'verify-patches') {
21 Please run this script from the root of the rsync dir or
22 from inside the patches subdir.
30 my($has_dependencies, @new, @rejects);
34 system "rsync -a --delete cvsdir/ workdir/" if -d 'cvsdir';
38 open(IN, '../CVS/Root') or die $!;
42 mkdir('tmp', 0777) unless -d 'tmp';
43 chdir('tmp') or die "Unable to chdir to 'tmp'";
45 mkdir('workdir') unless -d 'workdir';
46 open(OUT, '>exclude') or die $!;
58 print "Using CVS to update the tmp/cvsdir copy of the source.\n";
59 system qq|cvs -d "$root" co -d cvsdir rsync|;
62 @ARGV = glob('../*.diff') unless @ARGV;
65 foreach my $diff (@ARGV) {
66 next unless $diff =~ /\.diff$/;
67 next if $diff =~ /gzip-rsyncable[-_a-z]*\.diff$/;
68 $diff =~ s#^(patches|\.\.)/##;
70 open(IN, "../$diff") or die $!;
73 if (/^Depends-On-Patch: (\S+.diff)$/) {
75 $has_dependencies = 1;
76 print "\nApplying dependency patch $dep...\n";
77 if (system("patch -d cvsdir -p0 -b -Vt -Zf <../$dep") != 0) {
78 print "Unable to cleanly apply dependency patch -- skipping $diff\n";
79 system "rm -f cvsdir/*.rej cvsdir/*/*.rej";
87 my $default = apply_patch($diff);
88 if ($default =~ s/^D,// || $default eq 'N') {
89 my $def = generate_new_patch($diff);
90 $default = 'U,N' if $default eq 'N' && $def eq 'E';
91 $default = 'N' if !$minor_updates && $default eq 'U,N';
96 print "\n----------- $diff ------------\n",
97 "\nFix rejects, Diff create, Edit both diffs, Update patch,\n",
98 "Apply patch again, !(CMD), Build rsync, Next, Quit: [$default] ";
101 $ans = $default if $ans eq '';
102 while ($ans =~ s/^\s*(!|\w)((?<!!)[^;,]*|[^;]*)[;,]?//) {
105 $cmd = $2 || $ENV{'SHELL'};
106 chdir('workdir') or die $!;
108 chdir('..') or die $!;
113 $default = apply_patch($diff);
117 if (!-f 'workdir/Makefile') {
118 open(IN, '../../Makefile') or die $!;
119 open(OUT, '>workdir/Makefile') or die $!;
120 print OUT "srcdir=.\n\n";
134 open(IN, "../$diff") or die $!;
136 if (!defined $conf_opts) {
137 $conf_opts = '' if /^---/;
138 if (m#^\s*\./configure( .+)#) {
142 if (m#^--- orig/(configure\.in|/aclocal\.m4)#) {
148 chdir('workdir') or die $!;
149 system "autoconf; autoheader" if $need_autoconf;
150 system "make proto; ./configure $CONF_OPTS $conf_opts; make";
151 chdir('..') or die $!;
152 $default = '!make test';
156 $default = generate_new_patch($diff);
160 chdir('workdir') or die $!;
161 system "vim -d ../../$diff ../new.patch";
162 chdir('..') or die $!;
167 chdir('workdir') or die $!;
168 system "vim @rejects";
169 chdir('..') or die $!;
180 system "cp -p new.patch ../$diff";
181 print "\nUpdated $diff from new.patch\n";
199 system "rsync -a --delete --exclude='*~' cvsdir/ workdir/";
200 print "\nApplying patch $diff...\n";
202 my($saw_failure, $saw_offset, $saw_fuzz);
203 open(IN, "patch -d workdir -p0 --no-backup-if-mismatch -Zf <../$diff |") or die $!;
207 if (s/^patching file //) {
208 push(@new, $_) unless -f "cvsdir/$_";
209 } elsif (s/.* saving rejects to file //) {
211 } elsif (/^Hunk #\d+ FAILED/) {
213 } elsif (/^Hunk #\d+ succeeded at \d+( with fuzz $interesting_fuzz)?/o) {
214 $saw_fuzz ||= defined $1;
219 return 'F,D,E' if $saw_failure;
220 return 'D,E' if $saw_fuzz && !$failures_only;
221 return 'D,U,N' if $saw_offset && !$failures_only;
225 sub generate_new_patch
230 system "touch -r workdir/$_ cvsdir/$_";
232 open(IN, "../$diff") or die $!;
233 open(OUT, '>new.patch') or die $!;
239 open(IN, 'diff --exclude-from=exclude -upr cvsdir workdir |') or die $!;
241 next if /^(diff -|Index: |Only in )/;
242 s#^\Q--- cvsdir/\E#--- orig/#;
243 s#^\Q+++ workdir/\E#+++ #;
244 s#(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)(\.\d\d\d\d\d\d\d\d\d)? \+0000$#$1#;
252 print "\nDiffing... ";
253 if (system("diff ../$diff new.patch >/dev/null") == 0) {
254 print "new patch is identical to old.\n";
257 print "New patch DIFFERS from old.\n";
263 return unless $has_dependencies;
264 $has_dependencies = 0;
266 chdir('cvsdir') or die $!;
267 foreach (glob('*.~[1-9]~'), glob('*/*.~[1-9]~')) {
269 ($fn = $_) =~ s/\.~1~$//;
279 chdir('..') or die $!;
285 Usage: $0 [OPTS] [DIFF-FILE...]
286 -n, --no-cvs Don't update tmp/cvsdir at the start of the run
287 -u, --minor-updates Suggest 'U' for even minor changes in the diff