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);
9 my $auto_cmd = 'never';
11 &Getopt::Long::Configure('bundling');
13 'no-cvs|n' => \$no_cvs,
14 'failures-only|f' => \$failures_only,
15 'minor-updates|u' => \$minor_updates,
16 'prepare-source|p' => \$prepare_source,
17 'require-quit|Q' => \$require_quit,
18 'auto-cmd=s' => \$auto_cmd,
21 $auto_cmd = qr/^($auto_cmd)$/;
23 my $interesting_fuzz = $minor_updates ? '\d' : '[2-9]';
25 chdir('patches') if -d 'patches';
27 if (!-f 'verify-patches') {
29 Please run this script from the root of the rsync dir or
30 from inside the patches subdir.
37 my($has_dependencies, @new, @rejects);
41 system "rsync -a --del cvsdir/ workdir/" if -d 'cvsdir';
45 open(IN, '../CVS/Root') or die $!;
49 mkdir('tmp', 0777) unless -d 'tmp';
50 chdir('tmp') or die "Unable to chdir to 'tmp'";
52 mkdir('workdir') unless -d 'workdir';
53 open(OUT, '>exclude') or die $!;
54 print OUT join("\n", 'CVS', @generated_files), "\n";
58 print "Using CVS to update the tmp/cvsdir copy of the source.\n";
59 system qq|cvs -qd "$root" co -P -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|\.\.)/##;
71 open(IN, "../$diff") or die $!;
74 if (/^Depends-On-Patch: (\S+.diff)$/) {
76 $has_dependencies = 1;
77 print "\nApplying dependency patch $dep...\n";
78 if (system("patch -d cvsdir -p1 -b -Vt <../$dep") != 0) {
79 print "Unable to cleanly apply dependency patch -- skipping $diff\n";
80 system "rm -f cvsdir/*.rej cvsdir/*/*.rej";
84 sleep(1) if $prepare_source; # Ensure later diffs get later times.
86 if (!defined($conf_opts) && m#^\s*\./configure( .+)#) {
88 $conf_opts =~ s/\s+\(.*?\)//;
92 $conf_opts = '' unless defined $conf_opts;
94 my $default = apply_patch($diff);
96 if ($prepare_source) {
97 print "\nPreparing the source...\n";
98 chdir('workdir') or die $!;
99 system "./prepare-source";
100 chdir('..') or die $!;
103 if ($default =~ s/^D,// || $default eq 'N') {
104 my $def = generate_new_patch($diff);
105 $default = 'U,N' if $default eq 'N' && $def eq 'E';
106 $default = 'N' if !$minor_updates && $default eq 'U,N';
111 print "\n----------- $diff ------------\n",
112 "\nFix rejects, Diff create, Edit both diffs, Update patch,\n",
113 "Apply patch again, !(CMD), Build rsync, Next, Quit: [$default] ";
115 if ($default =~ /$auto_cmd/) {
116 print $default, "\n";
120 $ans = $input if $input ne '';
122 while ($ans =~ s/^\s*(!|\w)((?<!!)[^;,]*|[^;]*)[;,]?//) {
125 $cmd = $2 || $ENV{'SHELL'};
126 chdir('workdir') or die $!;
128 chdir('..') or die $!;
133 $default = apply_patch($diff);
137 chdir('workdir') or die $!;
138 system "./prepare-source && ./configure $CONF_OPTS $conf_opts && make";
139 chdir('..') or die $!;
140 $default = '!make test';
144 $default = generate_new_patch($diff);
148 chdir('workdir') or die $!;
149 system "vim -d ../../$diff ../new.patch";
150 chdir('..') or die $!;
155 chdir('workdir') or die $!;
156 system "vim @rejects";
157 chdir('..') or die $!;
168 system "cp -p new.patch ../$diff";
169 print "\nUpdated $diff from new.patch\n";
179 while ($require_quit) {
180 print "\nType 'Q' to quit: ";
193 system "rsync -a --delete --exclude='*~' cvsdir/ workdir/";
194 print "\nApplying patch $diff...\n";
196 my($saw_failure, $saw_offset, $saw_fuzz);
197 open(IN, "patch -d workdir -p1 --no-backup-if-mismatch <../$diff |") or die $!;
201 if (s/^patching file //) {
202 push(@new, $_) unless -f "cvsdir/$_";
203 } elsif (s/.* saving rejects to file //) {
205 } elsif (/^Hunk #\d+ FAILED/) {
207 } elsif (/^Hunk #\d+ succeeded at \d+( with fuzz $interesting_fuzz)?/o) {
208 $saw_fuzz ||= defined $1;
213 return 'F,D,E' if $saw_failure;
214 return 'D,E' if $saw_fuzz && !$failures_only;
215 return 'D,U,N' if $saw_offset && !$failures_only;
222 open(IN, '-|', $cmd) or die $!;
224 next if /^(diff -|Index: |Only in )/;
225 s#^\Q--- cvsdir/\E([^\t]+).*#--- old/$1#;
226 s#^\Q+++ workdir/\E([^\t]+).*#+++ new/$1#;
232 sub generate_new_patch
237 system "touch -r workdir/$_ cvsdir/$_";
239 open(IN, "../$diff") or die $!;
240 open(OUT, '>new.patch') or die $!;
246 &filter_diff('diff --exclude-from=exclude -upr cvsdir workdir');
247 if ($prepare_source) {
248 # These are not included in the diff above so that patch will give
249 # generated files a later timestamp than the source files.
250 foreach my $fn (@generated_files) {
251 &filter_diff("diff -up cvsdir/$fn workdir");
258 print "\nDiffing... ";
259 if (system("diff ../$diff new.patch >/dev/null") == 0) {
260 print "new patch is identical to old.\n";
263 print "New patch DIFFERS from old.\n";
269 return unless $has_dependencies;
270 $has_dependencies = 0;
272 chdir('cvsdir') or die $!;
273 foreach (glob('*.~[1-9]~'), glob('*/*.~[1-9]~')) {
275 ($fn = $_) =~ s/\.~1~$//;
285 chdir('..') or die $!;
291 Usage: $0 [OPTS] [DIFF-FILE...]
292 --auto-cmd=REGEX If default_cmd =~ /^(REGEX)\$/, enter it automatically
293 -f, --failures-only Suggest skipping patches that don't have failing hunks
294 -n, --no-cvs Don't update tmp/cvsdir at the start of the run
295 -p, --prepare-source Run ./prepare-source and include generated files in diff
296 -Q, --require-quit Don't auto-exit at the end of the list
297 -u, --minor-updates Suggest 'U' for even minor changes in the diff