6 my @generated_files = qw( proto.h configure config.h.in rsync.1 rsyncd.conf.5 );
8 my($no_cvs, $failures_only, $minor_updates, $prepare_source);
10 &Getopt::Long::Configure('bundling');
12 'no-cvs|n' => \$no_cvs,
13 'failures-only|f' => \$failures_only,
14 'minor-updates|u' => \$minor_updates,
15 'prepare-source|p' => \$prepare_source,
18 my $interesting_fuzz = $minor_updates ? '\d' : '[2-9]';
20 chdir('patches') if -d 'patches';
22 if (!-f 'verify-patches') {
24 Please run this script from the root of the rsync dir or
25 from inside the patches subdir.
32 my($has_dependencies, @new, @rejects);
36 system "rsync -a --del cvsdir/ workdir/" if -d 'cvsdir';
40 open(IN, '../CVS/Root') or die $!;
44 mkdir('tmp', 0777) unless -d 'tmp';
45 chdir('tmp') or die "Unable to chdir to 'tmp'";
47 mkdir('workdir') unless -d 'workdir';
48 open(OUT, '>exclude') or die $!;
49 print OUT join("\n", 'CVS', @generated_files), "\n";
53 print "Using CVS to update the tmp/cvsdir copy of the source.\n";
54 system qq|cvs -qd "$root" co -P -d cvsdir rsync|;
57 @ARGV = glob('../*.diff') unless @ARGV;
60 foreach my $diff (@ARGV) {
61 next unless $diff =~ /\.diff$/;
62 next if $diff =~ /gzip-rsyncable[-_a-z]*\.diff$/;
63 $diff =~ s#^(patches|\.\.)/##;
66 open(IN, "../$diff") or die $!;
69 if (/^Depends-On-Patch: (\S+.diff)$/) {
71 $has_dependencies = 1;
72 print "\nApplying dependency patch $dep...\n";
73 if (system("patch -d cvsdir -p1 -b -Vt <../$dep") != 0) {
74 print "Unable to cleanly apply dependency patch -- skipping $diff\n";
75 system "rm -f cvsdir/*.rej cvsdir/*/*.rej";
79 sleep(1) if $prepare_source; # Ensure later diffs get later times.
81 if (!defined($conf_opts) && m#^\s*\./configure( .+)#) {
83 $conf_opts =~ s/\s+\(.*?\)//;
87 $conf_opts = '' unless defined $conf_opts;
89 my $default = apply_patch($diff);
91 if ($prepare_source) {
92 print "\nPreparing the source...\n";
93 chdir('workdir') or die $!;
94 system "./prepare-source";
95 chdir('..') or die $!;
98 if ($default =~ s/^D,// || $default eq 'N') {
99 my $def = generate_new_patch($diff);
100 $default = 'U,N' if $default eq 'N' && $def eq 'E';
101 $default = 'N' if !$minor_updates && $default eq 'U,N';
106 print "\n----------- $diff ------------\n",
107 "\nFix rejects, Diff create, Edit both diffs, Update patch,\n",
108 "Apply patch again, !(CMD), Build rsync, Next, Quit: [$default] ";
111 $ans = $default if $ans eq '';
112 while ($ans =~ s/^\s*(!|\w)((?<!!)[^;,]*|[^;]*)[;,]?//) {
115 $cmd = $2 || $ENV{'SHELL'};
116 chdir('workdir') or die $!;
118 chdir('..') or die $!;
123 $default = apply_patch($diff);
127 chdir('workdir') or die $!;
128 system "./prepare-source && ./configure $CONF_OPTS $conf_opts && make";
129 chdir('..') or die $!;
130 $default = '!make test';
134 $default = generate_new_patch($diff);
138 chdir('workdir') or die $!;
139 system "vim -d ../../$diff ../new.patch";
140 chdir('..') or die $!;
145 chdir('workdir') or die $!;
146 system "vim @rejects";
147 chdir('..') or die $!;
158 system "cp -p new.patch ../$diff";
159 print "\nUpdated $diff from new.patch\n";
177 system "rsync -a --delete --exclude='*~' cvsdir/ workdir/";
178 print "\nApplying patch $diff...\n";
180 my($saw_failure, $saw_offset, $saw_fuzz);
181 open(IN, "patch -d workdir -p1 --no-backup-if-mismatch <../$diff |") or die $!;
185 if (s/^patching file //) {
186 push(@new, $_) unless -f "cvsdir/$_";
187 } elsif (s/.* saving rejects to file //) {
189 } elsif (/^Hunk #\d+ FAILED/) {
191 } elsif (/^Hunk #\d+ succeeded at \d+( with fuzz $interesting_fuzz)?/o) {
192 $saw_fuzz ||= defined $1;
197 return 'F,D,E' if $saw_failure;
198 return 'D,E' if $saw_fuzz && !$failures_only;
199 return 'D,U,N' if $saw_offset && !$failures_only;
206 open(IN, '-|', $cmd) or die $!;
208 next if /^(diff -|Index: |Only in )/;
209 s#^\Q--- cvsdir/\E([^\t]+).*#--- old/$1#;
210 s#^\Q+++ workdir/\E([^\t]+).*#+++ new/$1#;
216 sub generate_new_patch
221 system "touch -r workdir/$_ cvsdir/$_";
223 open(IN, "../$diff") or die $!;
224 open(OUT, '>new.patch') or die $!;
230 &filter_diff('diff --exclude-from=exclude -upr cvsdir workdir');
231 if ($prepare_source) {
232 # These are not included in the diff above so that patch will give
233 # generated files a later timestamp than the source files.
234 foreach my $fn (@generated_files) {
235 &filter_diff("diff -up cvsdir/$fn workdir");
242 print "\nDiffing... ";
243 if (system("diff ../$diff new.patch >/dev/null") == 0) {
244 print "new patch is identical to old.\n";
247 print "New patch DIFFERS from old.\n";
253 return unless $has_dependencies;
254 $has_dependencies = 0;
256 chdir('cvsdir') or die $!;
257 foreach (glob('*.~[1-9]~'), glob('*/*.~[1-9]~')) {
259 ($fn = $_) =~ s/\.~1~$//;
269 chdir('..') or die $!;
275 Usage: $0 [OPTS] [DIFF-FILE...]
276 -f, --failures-only Suggest skipping patches that don't have failing hunks
277 -n, --no-cvs Don't update tmp/cvsdir at the start of the run
278 -p, --prepare-source Run ./prepare-source and include generated files in diff
279 -u, --minor-updates Suggest 'U' for even minor changes in the diff