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';
36 my $CONF_OPTS = '--cache-file=../config.cache';
38 my($has_dependencies, @new, @rejects);
42 system "rsync -a --del cvsdir/ workdir/" if -d 'cvsdir';
43 my $pid = readlink('lock') || 0;
44 unlink('lock') if $pid == $$;
48 open(IN, '../CVS/Root') or die $!;
52 mkdir('tmp', 0777) unless -d 'tmp';
53 chdir('tmp') or die "Unable to chdir to 'tmp'";
54 symlink('..', 'patches') unless -d 'patches';
56 symlink($$, 'lock') or die "Unable to create lock file: $!\n";
58 mkdir('workdir') unless -d 'workdir';
59 open(OUT, '>exclude') or die $!;
60 print OUT join("\n", 'CVS', @generated_files), "\n";
64 print "Using CVS to update the tmp/cvsdir copy of the source.\n";
65 system qq|cvs -qd "$root" co -P -d cvsdir rsync|;
66 @_ = qw( configure configure.in config.h.in configure.in
67 rsync.1 rsync.yo rsyncd.conf.5 rsyncd.conf.yo );
69 my $gen = 'cvsdir/' . shift(@_);
70 my $src = 'cvsdir/' . shift(@_);
71 if ((-M $gen) > (-M $src)) {
77 @ARGV = glob('patches/*.diff') unless @ARGV;
80 foreach my $diff (@ARGV) {
81 next unless $diff =~ /\.diff$/;
82 next if $diff =~ /gzip-rsyncable[-_a-z]*\.diff$/;
83 $diff =~ s#^(patches|\.\.)/##;
86 open(IN, "patches/$diff") or die $!;
89 if (m#^\s+patch -p1 <patches/(\S+.diff)# && $1 ne $diff) {
91 $has_dependencies = 1;
92 print "\nApplying dependency patch $dep...\n";
93 if (system("patch -d cvsdir -p1 -b -Vt <patches/$dep") != 0) {
94 print "Unable to cleanly apply dependency patch -- skipping $diff\n";
95 system "rm -f cvsdir/*.rej cvsdir/*/*.rej";
99 sleep(1) if $prepare_source; # Ensure later diffs get later times.
101 if (!defined($conf_opts) && s#^\s+\./configure\s+##) {
102 chomp($conf_opts = $_);
103 $conf_opts =~ s/\s*\(.*?\)//;
107 $conf_opts = '' unless defined $conf_opts;
109 my $default = apply_patch($diff);
111 if ($prepare_source) {
112 print "\nPreparing the source...\n";
113 chdir('workdir') or die $!;
114 system "./prepare-source";
115 chdir('..') or die $!;
118 if ($default =~ s/^D,// || $default eq 'N') {
119 my $def = generate_new_patch($diff);
120 $default = 'U,N' if $default eq 'N' && $def eq 'E';
121 $default = 'N' if !$minor_updates && $default eq 'U,N';
127 print "\n----------- $diff ------------\n",
128 "\nFix rejects, Diff create, Edit both diffs, Update patch,\n",
129 "Apply patch again, !(CMD), Build rsync, Next, Quit: [$default] ";
131 if ($first_time && $default =~ /$auto_regex/) {
132 print $default, "\n";
136 if ($input =~ s/^(-a|--auto-cmd=?)\s*//) {
137 push(@auto_cmds, $input eq '' ? $default : $input);
139 $auto_regex = qr/^(@auto_cmds)$/i;
143 $ans = $input if $input ne '';
146 while ($ans =~ s/^\s*(!|\w)((?<!!)[^;,]*|[^;]*)[;,]?//) {
149 $cmd = $2 || $ENV{'SHELL'};
150 chdir('workdir') or die $!;
152 chdir('..') or die $!;
157 $default = apply_patch($diff);
161 chdir('workdir') or die $!;
162 my $cmd = "./prepare-source && ./configure $CONF_OPTS $conf_opts && make";
163 print "Running: $cmd\n";
165 chdir('..') or die $!;
166 $default = '!make test';
170 $default = generate_new_patch($diff);
174 chdir('workdir') or die $!;
175 system "vim -d ../patches/$diff ../new.patch";
176 chdir('..') or die $!;
181 chdir('workdir') or die $!;
182 system "vim @rejects";
183 chdir('..') or die $!;
194 system "cp -p new.patch patches/$diff";
195 print "\nUpdated $diff from new.patch\n";
213 system "rsync -a --delete --exclude='*~' cvsdir/ workdir/";
214 print "\nApplying patch $diff...\n";
216 my($saw_offset, $saw_fuzz);
217 open(IN, "patch -d workdir -p1 --no-backup-if-mismatch <patches/$diff |") or die $!;
221 if (s/^patching file //) {
222 push(@new, $_) unless -f "cvsdir/$_";
223 } elsif (s/.* saving rejects to file //) {
225 } elsif (/^Hunk #\d+ succeeded at \d+( with fuzz $interesting_fuzz)?/o) {
226 $saw_fuzz ||= defined $1;
231 return 'F,D,E' if @rejects;
232 return 'D,E' if $saw_fuzz && !$failures_only;
233 return 'D,U,N' if $saw_offset && !$failures_only;
240 open(IN, '-|', $cmd) or die $!;
242 next if /^(diff -|Index: |Only in )/;
243 s#^\Q--- cvsdir/\E([^\t]+).*#--- old/$1#;
244 s#^\Q+++ workdir/\E([^\t]+).*#+++ new/$1#;
250 sub generate_new_patch
255 system "touch -r workdir/$_ cvsdir/$_";
257 open(IN, "patches/$diff") or die $!;
258 open(OUT, '>new.patch') or die $!;
264 &filter_diff('diff --exclude-from=exclude -dupr cvsdir workdir');
265 if ($prepare_source) {
266 # These are not included in the diff above so that patch will give
267 # generated files a later timestamp than the source files.
268 foreach my $fn (@generated_files) {
269 &filter_diff("diff -dup cvsdir/$fn workdir");
276 print "\nDiffing... ";
277 if (system("diff patches/$diff new.patch >/dev/null") == 0) {
278 print "new patch is identical to old.\n";
281 print "New patch DIFFERS from old.\n";
287 return unless $has_dependencies;
288 $has_dependencies = 0;
290 chdir('cvsdir') or die $!;
291 foreach (glob('*.~[1-9]~'), glob('*/*.~[1-9]~')) {
293 ($fn = $_) =~ s/\.~1~$//;
303 chdir('..') or die $!;
309 Usage: $0 [OPTS] [DIFF-FILE...]
310 -a, --auto-cmd=REGEX If default_cmd =~ /^(REGEX)\$/, enter it automatically
311 -f, --failures-only Suggest skipping patches that don't have failing hunks
312 -n, --no-cvs Don't update tmp/cvsdir at the start of the run
313 -p, --prepare-source Run ./prepare-source and include generated files in diff
314 -u, --minor-updates Suggest 'U' for even minor changes in the diff