X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/blobdiff_plain/64efc51eb1db9487252eae268597651db34ece65..59d64e0ba3e9b104bed3cb7c99e23066676be9d5:/verify-patches diff --git a/verify-patches b/verify-patches index 28d37b9..807c584 100755 --- a/verify-patches +++ b/verify-patches @@ -3,16 +3,24 @@ use strict; use Getopt::Long; -my($no_cvs, $failures_only, $minor_updates); +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'; @@ -23,15 +31,15 @@ from inside the patches subdir. EOT } +$ENV{'LC_COLLATE'} = 'C'; $| = 1; -$ENV{'TZ'} = 'UTC'; 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; @@ -44,19 +52,12 @@ chdir('tmp') or die "Unable to chdir to 'tmp'"; mkdir('workdir') unless -d 'workdir'; open(OUT, '>exclude') or die $!; -print OUT <) { last if /^--- /; @@ -74,31 +76,59 @@ foreach my $diff (@ARGV) { my $dep = $1; $has_dependencies = 1; print "\nApplying dependency patch $dep...\n"; - if (system("patch -d cvsdir -p0 -b -Vt -Zf <../$dep") != 0) { + 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 ''; + 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; + } + $ans = $input if $input ne ''; + } + $first_time = 0; while ($ans =~ s/^\s*(!|\w)((?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 $need_autoconf; - my $conf_opts; - open(IN, "../$diff") or die $!; - while () { - if (!defined $conf_opts) { - $conf_opts = '' if /^---/; - if (m#^\s*\./configure( .+)#) { - $conf_opts = $1; - } - } - if (m#^--- orig/(configure\.in|/aclocal\.m4)#) { - $need_autoconf = 1; - last; - } - } - close IN; chdir('workdir') or die $!; - system "autoconf; autoheader" if $need_autoconf; - system "make proto; ./configure $CONF_OPTS $conf_opts; make"; + my $cmd = "./prepare-source && ./configure $CONF_OPTS $conf_opts && make"; + print "Running: $cmd\n"; + system $cmd; chdir('..') or die $!; $default = '!make test'; next; @@ -199,8 +199,8 @@ sub apply_patch system "rsync -a --delete --exclude='*~' cvsdir/ workdir/"; print "\nApplying patch $diff...\n"; undef @rejects; - my($saw_failure, $saw_offset, $saw_fuzz); - open(IN, "patch -d workdir -p0 --no-backup-if-mismatch -Zf <../$diff |") or die $!; + my($saw_offset, $saw_fuzz); + open(IN, "patch -d workdir -p1 --no-backup-if-mismatch <../$diff |") or die $!; while () { print $_; chomp; @@ -208,20 +208,31 @@ sub apply_patch push(@new, $_) unless -f "cvsdir/$_"; } elsif (s/.* saving rejects to file //) { push(@rejects, $_); - } elsif (/^Hunk #\d+ FAILED/) { - $saw_failure = 1; } elsif (/^Hunk #\d+ succeeded at \d+( with fuzz $interesting_fuzz)?/o) { $saw_fuzz ||= defined $1; $saw_offset = 1; } } close IN; - return 'F,D,E' if $saw_failure; + 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 $_; + } + close IN; +} + sub generate_new_patch { my($diff) = @_; @@ -236,15 +247,14 @@ 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#(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)(\.\d\d\d\d\d\d\d\d\d)? \+0000$#$1#; - 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/$_"); @@ -283,7 +293,10 @@ sub usage { die <