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, $require_quit);
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,
16 'require-quit|Q' => \$require_quit,
19 my $interesting_fuzz = $minor_updates ? '\d' : '[2-9]';
21 chdir('patches') if -d 'patches';
23 if (!-f 'verify-patches') {
25 Please run this script from the root of the rsync dir or
26 from inside the patches subdir.
33 my($has_dependencies, @new, @rejects);
37 system "rsync -a --del cvsdir/ workdir/" if -d 'cvsdir';
41 open(IN, '../CVS/Root') or die $!;
45 mkdir('tmp', 0777) unless -d 'tmp';
46 chdir('tmp') or die "Unable to chdir to 'tmp'";
48 mkdir('workdir') unless -d 'workdir';
49 open(OUT, '>exclude') or die $!;
50 print OUT join("\n", 'CVS', @generated_files), "\n";
54 print "Using CVS to update the tmp/cvsdir copy of the source.\n";
55 system qq|cvs -qd "$root" co -P -d cvsdir rsync|;
58 @ARGV = glob('../*.diff') unless @ARGV;
61 foreach my $diff (@ARGV) {
62 next unless $diff =~ /\.diff$/;
63 next if $diff =~ /gzip-rsyncable[-_a-z]*\.diff$/;
64 $diff =~ s#^(patches|\.\.)/##;
67 open(IN, "../$diff") or die $!;
70 if (/^Depends-On-Patch: (\S+.diff)$/) {
72 $has_dependencies = 1;
73 print "\nApplying dependency patch $dep...\n";
74 if (system("patch -d cvsdir -p1 -b -Vt <../$dep") != 0) {
75 print "Unable to cleanly apply dependency patch -- skipping $diff\n";
76 system "rm -f cvsdir/*.rej cvsdir/*/*.rej";
80 sleep(1) if $prepare_source; # Ensure later diffs get later times.
82 if (!defined($conf_opts) && m#^\s*\./configure( .+)#) {
84 $conf_opts =~ s/\s+\(.*?\)//;
88 $conf_opts = '' unless defined $conf_opts;
90 my $default = apply_patch($diff);
92 if ($prepare_source) {
93 print "\nPreparing the source...\n";
94 chdir('workdir') or die $!;
95 system "./prepare-source";
96 chdir('..') or die $!;
99 if ($default =~ s/^D,// || $default eq 'N') {
100 my $def = generate_new_patch($diff);
101 $default = 'U,N' if $default eq 'N' && $def eq 'E';
102 $default = 'N' if !$minor_updates && $default eq 'U,N';
107 print "\n----------- $diff ------------\n",
108 "\nFix rejects, Diff create, Edit both diffs, Update patch,\n",
109 "Apply patch again, !(CMD), Build rsync, Next, Quit: [$default] ";
112 $ans = $default if $ans eq '';
113 while ($ans =~ s/^\s*(!|\w)((?<!!)[^;,]*|[^;]*)[;,]?//) {
116 $cmd = $2 || $ENV{'SHELL'};
117 chdir('workdir') or die $!;
119 chdir('..') or die $!;
124 $default = apply_patch($diff);
128 chdir('workdir') or die $!;
129 system "./prepare-source && ./configure $CONF_OPTS $conf_opts && make";
130 chdir('..') or die $!;
131 $default = '!make test';
135 $default = generate_new_patch($diff);
139 chdir('workdir') or die $!;
140 system "vim -d ../../$diff ../new.patch";
141 chdir('..') or die $!;
146 chdir('workdir') or die $!;
147 system "vim @rejects";
148 chdir('..') or die $!;
159 system "cp -p new.patch ../$diff";
160 print "\nUpdated $diff from new.patch\n";
170 while ($require_quit) {
171 print "\nType 'Q' to quit: ";
184 system "rsync -a --delete --exclude='*~' cvsdir/ workdir/";
185 print "\nApplying patch $diff...\n";
187 my($saw_failure, $saw_offset, $saw_fuzz);
188 open(IN, "patch -d workdir -p1 --no-backup-if-mismatch <../$diff |") or die $!;
192 if (s/^patching file //) {
193 push(@new, $_) unless -f "cvsdir/$_";
194 } elsif (s/.* saving rejects to file //) {
196 } elsif (/^Hunk #\d+ FAILED/) {
198 } elsif (/^Hunk #\d+ succeeded at \d+( with fuzz $interesting_fuzz)?/o) {
199 $saw_fuzz ||= defined $1;
204 return 'F,D,E' if $saw_failure;
205 return 'D,E' if $saw_fuzz && !$failures_only;
206 return 'D,U,N' if $saw_offset && !$failures_only;
213 open(IN, '-|', $cmd) or die $!;
215 next if /^(diff -|Index: |Only in )/;
216 s#^\Q--- cvsdir/\E([^\t]+).*#--- old/$1#;
217 s#^\Q+++ workdir/\E([^\t]+).*#+++ new/$1#;
223 sub generate_new_patch
228 system "touch -r workdir/$_ cvsdir/$_";
230 open(IN, "../$diff") or die $!;
231 open(OUT, '>new.patch') or die $!;
237 &filter_diff('diff --exclude-from=exclude -upr cvsdir workdir');
238 if ($prepare_source) {
239 # These are not included in the diff above so that patch will give
240 # generated files a later timestamp than the source files.
241 foreach my $fn (@generated_files) {
242 &filter_diff("diff -up cvsdir/$fn workdir");
249 print "\nDiffing... ";
250 if (system("diff ../$diff new.patch >/dev/null") == 0) {
251 print "new patch is identical to old.\n";
254 print "New patch DIFFERS from old.\n";
260 return unless $has_dependencies;
261 $has_dependencies = 0;
263 chdir('cvsdir') or die $!;
264 foreach (glob('*.~[1-9]~'), glob('*/*.~[1-9]~')) {
266 ($fn = $_) =~ s/\.~1~$//;
276 chdir('..') or die $!;
282 Usage: $0 [OPTS] [DIFF-FILE...]
283 -f, --failures-only Suggest skipping patches that don't have failing hunks
284 -Q, --require-quit Don't auto-exit at the end of the list
285 -n, --no-cvs Don't update tmp/cvsdir at the start of the run
286 -p, --prepare-source Run ./prepare-source and include generated files in diff
287 -u, --minor-updates Suggest 'U' for even minor changes in the diff