6 my($no_cvs, $minor_updates);
8 &Getopt::Long::Configure('bundling');
10 'no-cvs|n' => \$no_cvs,
11 'minor-updates|u' => \$minor_updates,
14 chdir('patches') if -d 'patches';
16 if (!-f 'verify-patches') {
18 Please run this script from the root of the rsync dir or
19 from inside the patches subdir.
27 my($has_dependencies, @new, @rejects);
31 system "rsync -a --delete cvsdir/ workdir/" if -d 'cvsdir';
35 open(IN, '../CVS/Root') or die $!;
39 mkdir('tmp', 0777) unless -d 'tmp';
40 chdir('tmp') or die "Unable to chdir to 'tmp'";
42 mkdir('workdir') unless -d 'workdir';
43 open(OUT, '>exclude') or die $!;
55 print "Using CVS to update the tmp/cvsdir copy of the source.\n";
56 system qq|cvs -d "$root" co -d cvsdir rsync|;
59 @ARGV = glob('../*.diff') unless @ARGV;
62 foreach my $diff (@ARGV) {
63 next unless $diff =~ /\.diff$/;
64 next if $diff =~ /gzip-rsyncable\.diff$/;
65 $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 -p0 -b -Vt -Zf <../$dep") != 0) {
75 print "Unable to cleanly apply dependency patch -- skipping $diff\n";
76 system "rm -f cvsdir/*.rej cvsdir/*/*.rej";
84 my $default = apply_patch($diff);
85 if ($default =~ s/^D,// || $default eq 'N') {
86 my $def = generate_new_patch($diff);
87 $default = 'U,N' if $default eq 'N' && $def eq 'E';
88 $default = 'N' if !$minor_updates && $default eq 'U,N';
93 print "\n----------- $diff ------------\n",
94 "\nFix rejects, Diff create, Edit both diffs, Update patch,\n",
95 "Apply patch again, !(CMD), Build rsync, Next, Quit: [$default] ";
98 $ans = $default if $ans eq '';
99 while ($ans =~ s/^\s*(!|\w)((?<!!)[^;,]*|[^;]*)[;,]?//) {
102 $cmd = $2 || $ENV{'SHELL'};
103 chdir('workdir') or die $!;
105 chdir('..') or die $!;
110 $default = apply_patch($diff);
114 if (!-f 'workdir/Makefile') {
115 open(IN, '../../Makefile') or die $!;
116 open(OUT, '>workdir/Makefile') or die $!;
117 print OUT "srcdir=.\n\n";
131 open(IN, "../$diff") or die $!;
133 if (!defined $conf_opts) {
134 $conf_opts = '' if /^---/;
135 if (m#^\s*\./configure( .+)#) {
139 if (m#^--- orig/(configure\.in|/aclocal\.m4)#) {
145 chdir('workdir') or die $!;
146 system "autoconf; autoheader" if $need_autoconf;
147 system "make proto; ./configure $CONF_OPTS $conf_opts; make";
148 chdir('..') or die $!;
149 $default = '!make test';
153 $default = generate_new_patch($diff);
157 chdir('workdir') or die $!;
158 system "vim -d ../../$diff ../new.patch";
159 chdir('..') or die $!;
164 chdir('workdir') or die $!;
165 system "vim @rejects";
166 chdir('..') or die $!;
177 system "cp -p new.patch ../$diff";
178 print "\nUpdated $diff from new.patch\n";
196 system "rsync -a --delete --exclude='*~' cvsdir/ workdir/";
197 print "\nApplying patch $diff...\n";
199 my($saw_failure, $saw_offset, $saw_fuzz);
200 open(IN, "patch -d workdir -p0 --no-backup-if-mismatch -Zf <../$diff |") or die $!;
204 if (s/^patching file //) {
205 push(@new, $_) unless -f "cvsdir/$_";
206 } elsif (s/.* saving rejects to file //) {
208 } elsif (/^Hunk #\d+ FAILED/) {
210 } elsif (/^Hunk #\d+ succeeded at \d+( with fuzz )?/) {
211 $saw_fuzz ||= defined $1;
216 return 'F,D,E' if $saw_failure;
217 return 'D,E' if $saw_fuzz;
218 return 'D,U,N' if $saw_offset;
222 sub generate_new_patch
227 system "touch -r workdir/$_ cvsdir/$_";
229 open(IN, "../$diff") or die $!;
230 open(OUT, '>new.patch') or die $!;
236 open(IN, 'diff --exclude-from=exclude -upr cvsdir workdir |') or die $!;
238 next if /^(diff -|Index: |Only in )/;
239 s#^\Q--- cvsdir/\E#--- orig/#;
240 s#^\Q+++ workdir/\E#+++ #;
241 s#(\.000000000)? \+0000$##;
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 foreach (glob('*.~[1-9]~'), glob('*/*.~[1-9]~')) {
265 ($fn = $_) =~ s/\.~1~$//;
280 Usage: $0 [OPTS] [DIFF-FILE...]
281 -n, --no-cvs Don't update tmp/cvsdir at the start of the run
282 -u, --minor-updates Suggest 'U' for even minor changes in the diff