X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/blobdiff_plain/b1a4cc328a5c9cecd8e726869af006c789cdf9e8..59d64e0ba3e9b104bed3cb7c99e23066676be9d5:/verify-patches diff --git a/verify-patches b/verify-patches index ea72381..807c584 100755 --- a/verify-patches +++ b/verify-patches @@ -1,6 +1,26 @@ #!/usr/bin/perl use strict; +use Getopt::Long; + +my @generated_files = qw( proto.h configure config.h.in rsync.1 rsyncd.conf.5 ); + +my($no_cvs, $failures_only, $minor_updates, $prepare_source); +my @auto_cmds; + +&Getopt::Long::Configure('bundling'); +GetOptions( + 'no-cvs|n' => \$no_cvs, + 'failures-only|f' => \$failures_only, + 'minor-updates|u' => \$minor_updates, + 'prepare-source|p' => \$prepare_source, + 'auto-cmd|a=s' => sub { push(@auto_cmds, $_[1]) }, +) or &usage; + +$" = '|'; +my $auto_regex = @auto_cmds ? qr/^(@auto_cmds)$/i : qr/^never$/; +my $interesting_fuzz = $minor_updates ? '\d' : '[2-9]'; +$" = ' '; chdir('patches') if -d 'patches'; @@ -11,14 +31,15 @@ from inside the patches subdir. EOT } -$ENV{'TZ'} = 'UTC'; +$ENV{'LC_COLLATE'} = 'C'; +$| = 1; my $CONF_OPTS = '-C'; my($has_dependencies, @new, @rejects); END { &restore_cvsdir; - system "rsync -a --delete cvsdir/ workdir/" if -d 'cvsdir'; + system "rsync -a --del cvsdir/ workdir/" if -d 'cvsdir'; }; my $root; @@ -31,109 +52,136 @@ chdir('tmp') or die "Unable to chdir to 'tmp'"; mkdir('workdir') unless -d 'workdir'; open(OUT, '>exclude') or die $!; -print OUT <) { last if /^--- /; if (/^Depends-On-Patch: (\S+.diff)$/) { my $dep = $1; $has_dependencies = 1; - print "\nApplying dependency patch $dep\n"; - if (system("patch -d cvsdir -p0 -b -Vt -Zf <../$dep") != 0) { - print "Unable to cleanly apply depenency patch -- skipping $diff\n"; + print "\nApplying dependency patch $dep...\n"; + if (system("patch -d cvsdir -p1 -b -Vt <../$dep") != 0) { + print "Unable to cleanly apply dependency patch -- skipping $diff\n"; + system "rm -f cvsdir/*.rej cvsdir/*/*.rej"; &restore_cvsdir; next DIFF; } + sleep(1) if $prepare_source; # Ensure later diffs get later times. + } + if (!defined($conf_opts) && s#^\s+\./configure\s+##) { + chomp($conf_opts = $_); + $conf_opts =~ s/\s*\(.*?\)//; } } close IN; + $conf_opts = '' unless defined $conf_opts; my $default = apply_patch($diff); + if ($prepare_source) { + print "\nPreparing the source...\n"; + chdir('workdir') or die $!; + system "./prepare-source"; + chdir('..') or die $!; + } + + if ($default =~ s/^D,// || $default eq 'N') { + my $def = generate_new_patch($diff); + $default = 'U,N' if $default eq 'N' && $def eq 'E'; + $default = 'N' if !$minor_updates && $default eq 'U,N'; + } + + my $first_time = 1; + PROMPT: while (1) { print "\n----------- $diff ------------\n", "\nFix rejects, Diff create, Edit both diffs, Update patch,\n", "Apply patch again, !(CMD), Build rsync, Next, Quit: [$default] "; - my $ans = ; - chomp $ans; - $ans = $default if $ans eq ''; - if ($ans =~ /^!(.*)/) { - my $cmd = $1 || $ENV{'SHELL'}; - chdir('workdir') or die $!; - system $cmd; - chdir('..') or die $!; - $default = 'D,E'; - next; - } - if ($ans =~ /^\S*F/i) { - chdir('workdir') or die $!; - system "vim @rejects"; - chdir('..') or die $!; - $default = 'D,E'; - } - if ($ans =~ /^\S*D/i) { - $default = generate_new_patch($diff); - } - if ($ans =~ /^\S*E/i) { - chdir('workdir') or die $!; - system "vim -d ../../$diff ../new.patch"; - chdir('..') or die $!; - $default = 'U,A'; - } - if ($ans =~ /^\S*U/i) { - system "cp -p new.patch ../$diff"; - print "\nUpdated $diff from new.patch\n"; - $default = 'A'; - } - if ($ans =~ /^\S*A/i) { - $default = apply_patch($diff); - } - if ($ans =~ /^\S*B/i) { - if (!-f 'workdir/Makefile') { - open(IN, '../../Makefile') or die $!; - open(OUT, '>workdir/Makefile') or die $!; - print OUT "srcdir=.\n\n"; - while () { - last if /^gen:/; - } - print OUT $_; - while () { - last if /^clean:/; - print OUT $_; - } - close IN; - close OUT; + my $ans = $default; + if ($first_time && $default =~ /$auto_regex/) { + print $default, "\n"; + } else { + my $input = ; + chomp $input; + if ($input =~ s/^(-a|--auto-cmd=?)\s*//) { + push(@auto_cmds, $input eq '' ? $default : $input); + $" = '|'; + $auto_regex = qr/^(@auto_cmds)$/i; + $" = ' '; + next; } - chdir('workdir') or die $!; - system "make gen; ./configure $CONF_OPTS; make"; - chdir('..') or die $!; - $default = '!make test'; + $ans = $input if $input ne ''; } - if ($ans =~ /^\S*Q/i) { - exit; - } - if ($ans =~ /^\S*N/i) { - last; + $first_time = 0; + while ($ans =~ s/^\s*(!|\w)((?) { print $_; chomp; @@ -159,17 +208,29 @@ sub apply_patch push(@new, $_) unless -f "cvsdir/$_"; } elsif (s/.* saving rejects to file //) { push(@rejects, $_); - } elsif (/^Hunk #\d+ FAILED/) { - $def = 'F'; - } elsif (/^Hunk #\d+ succeeded/) { - $def = 'E' unless $def eq 'F,D,E'; + } elsif (/^Hunk #\d+ succeeded at \d+( with fuzz $interesting_fuzz)?/o) { + $saw_fuzz ||= defined $1; + $saw_offset = 1; } } close IN; - if ($def eq 'N') { - generate_new_patch($diff); + return 'F,D,E' if @rejects; + return 'D,E' if $saw_fuzz && !$failures_only; + return 'D,U,N' if $saw_offset && !$failures_only; + 'N'; +} + +sub filter_diff +{ + my($cmd) = @_; + open(IN, '-|', $cmd) or die $!; + while () { + next if /^(diff -|Index: |Only in )/; + s#^\Q--- cvsdir/\E([^\t]+).*#--- old/$1#; + s#^\Q+++ workdir/\E([^\t]+).*#+++ new/$1#; + print OUT $_; } - $def; + close IN; } sub generate_new_patch @@ -186,23 +247,24 @@ sub generate_new_patch print OUT $_; } close IN; - open(IN, 'diff --exclude-from=exclude -upr cvsdir workdir |') or die $!; - while () { - next if /^(diff -|Index: |Only in )/; - s#^\Q--- cvsdir/\E#--- orig/#; - s#^\Q+++ workdir/\E#+++ #; - s#(\.000000000)? \+0000$##; - print OUT $_; + &filter_diff('diff --exclude-from=exclude -upr cvsdir workdir'); + if ($prepare_source) { + # These are not included in the diff above so that patch will give + # generated files a later timestamp than the source files. + foreach my $fn (@generated_files) { + &filter_diff("diff -up cvsdir/$fn workdir"); + } } - close IN; close OUT; foreach (@new) { unlink("cvsdir/$_"); } + print "\nDiffing... "; if (system("diff ../$diff new.patch >/dev/null") == 0) { - print "\n(New patch is identical to old.)\n"; + print "new patch is identical to old.\n"; return 'N'; } + print "New patch DIFFERS from old.\n"; 'E'; } @@ -211,16 +273,30 @@ sub restore_cvsdir return unless $has_dependencies; $has_dependencies = 0; + chdir('cvsdir') or die $!; foreach (glob('*.~[1-9]~'), glob('*/*.~[1-9]~')) { my $fn; ($fn = $_) =~ s/\.~1~$//; if ($fn eq $_) { unlink($_); - } elsif (-r $fn) { - rename($_, $fn); + } elsif (-r $_) { + rename($_, $fn); } else { unlink($_); unlink($fn); } } + chdir('..') or die $!; +} + +sub usage +{ + die <