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);
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 'auto-cmd|a=s' => sub { push(@auto_cmds, $_[1]) },
21 my $auto_regex = @auto_cmds ? qr/^(@auto_cmds)$/i : qr/^never$/;
22 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.
34 $ENV{'LC_COLLATE'} = 'C';
38 my($has_dependencies, @new, @rejects);
42 system "rsync -a --del cvsdir/ workdir/" if -d 'cvsdir';
46 open(IN, '../CVS/Root') or die $!;
50 mkdir('tmp', 0777) unless -d 'tmp';
51 chdir('tmp') or die "Unable to chdir to 'tmp'";
53 mkdir('workdir') unless -d 'workdir';
54 open(OUT, '>exclude') or die $!;
55 print OUT join("\n", 'CVS', @generated_files), "\n";
59 print "Using CVS to update the tmp/cvsdir copy of the source.\n";
60 system qq|cvs -qd "$root" co -P -d cvsdir rsync|;
63 @ARGV = glob('../*.diff') unless @ARGV;
66 foreach my $diff (@ARGV) {
67 next unless $diff =~ /\.diff$/;
68 next if $diff =~ /gzip-rsyncable[-_a-z]*\.diff$/;
69 $diff =~ s#^(patches|\.\.)/##;
72 open(IN, "../$diff") or die $!;
75 if (/^Depends-On-Patch: (\S+.diff)$/) {
77 $has_dependencies = 1;
78 print "\nApplying dependency patch $dep...\n";
79 if (system("patch -d cvsdir -p1 -b -Vt <../$dep") != 0) {
80 print "Unable to cleanly apply dependency patch -- skipping $diff\n";
81 system "rm -f cvsdir/*.rej cvsdir/*/*.rej";
85 sleep(1) if $prepare_source; # Ensure later diffs get later times.
87 if (!defined($conf_opts) && s#^\s+\./configure\s+##) {
88 chomp($conf_opts = $_);
89 $conf_opts =~ s/\s*\(.*?\)//;
93 $conf_opts = '' unless defined $conf_opts;
95 my $default = apply_patch($diff);
97 if ($prepare_source) {
98 print "\nPreparing the source...\n";
99 chdir('workdir') or die $!;
100 system "./prepare-source";
101 chdir('..') or die $!;
104 if ($default =~ s/^D,// || $default eq 'N') {
105 my $def = generate_new_patch($diff);
106 $default = 'U,N' if $default eq 'N' && $def eq 'E';
107 $default = 'N' if !$minor_updates && $default eq 'U,N';
113 print "\n----------- $diff ------------\n",
114 "\nFix rejects, Diff create, Edit both diffs, Update patch,\n",
115 "Apply patch again, !(CMD), Build rsync, Next, Quit: [$default] ";
117 if ($first_time && $default =~ /$auto_regex/) {
118 print $default, "\n";
122 if ($input =~ s/^(-a|--auto-cmd=?)\s*//) {
123 push(@auto_cmds, $input eq '' ? $default : $input);
125 $auto_regex = qr/^(@auto_cmds)$/i;
129 $ans = $input if $input ne '';
132 while ($ans =~ s/^\s*(!|\w)((?<!!)[^;,]*|[^;]*)[;,]?//) {
135 $cmd = $2 || $ENV{'SHELL'};
136 chdir('workdir') or die $!;
138 chdir('..') or die $!;
143 $default = apply_patch($diff);
147 chdir('workdir') or die $!;
148 my $cmd = "./prepare-source && ./configure $CONF_OPTS $conf_opts && make";
149 print "Running: $cmd\n";
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_offset, $saw_fuzz);
203 open(IN, "patch -d workdir -p1 --no-backup-if-mismatch <../$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+ succeeded at \d+( with fuzz $interesting_fuzz)?/o) {
212 $saw_fuzz ||= defined $1;
217 return 'F,D,E' if @rejects;
218 return 'D,E' if $saw_fuzz && !$failures_only;
219 return 'D,U,N' if $saw_offset && !$failures_only;
226 open(IN, '-|', $cmd) or die $!;
228 next if /^(diff -|Index: |Only in )/;
229 s#^\Q--- cvsdir/\E([^\t]+).*#--- old/$1#;
230 s#^\Q+++ workdir/\E([^\t]+).*#+++ new/$1#;
236 sub generate_new_patch
241 system "touch -r workdir/$_ cvsdir/$_";
243 open(IN, "../$diff") or die $!;
244 open(OUT, '>new.patch') or die $!;
250 &filter_diff('diff --exclude-from=exclude -upr cvsdir workdir');
251 if ($prepare_source) {
252 # These are not included in the diff above so that patch will give
253 # generated files a later timestamp than the source files.
254 foreach my $fn (@generated_files) {
255 &filter_diff("diff -up cvsdir/$fn workdir");
262 print "\nDiffing... ";
263 if (system("diff ../$diff new.patch >/dev/null") == 0) {
264 print "new patch is identical to old.\n";
267 print "New patch DIFFERS from old.\n";
273 return unless $has_dependencies;
274 $has_dependencies = 0;
276 chdir('cvsdir') or die $!;
277 foreach (glob('*.~[1-9]~'), glob('*/*.~[1-9]~')) {
279 ($fn = $_) =~ s/\.~1~$//;
289 chdir('..') or die $!;
295 Usage: $0 [OPTS] [DIFF-FILE...]
296 -a, --auto-cmd=REGEX If default_cmd =~ /^(REGEX)\$/, enter it automatically
297 -f, --failures-only Suggest skipping patches that don't have failing hunks
298 -n, --no-cvs Don't update tmp/cvsdir at the start of the run
299 -p, --prepare-source Run ./prepare-source and include generated files in diff
300 -u, --minor-updates Suggest 'U' for even minor changes in the diff