X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/blobdiff_plain/a978ee022780f351e4c20f30d82824c3448fee49..6240d1e484dd4e3cc4d0dad8d47d58193354784e:/verify-patches diff --git a/verify-patches b/verify-patches index 6b2cca9..64ae506 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,15 +31,17 @@ from inside the patches subdir. EOT } +$ENV{'LC_COLLATE'} = 'C'; $| = 1; -$ENV{'TZ'} = 'UTC'; -my $CONF_OPTS = '-C'; +my $CONF_OPTS = '--cache-file=../config.cache'; 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 $pid = readlink('lock') || 0; + unlink('lock') if $pid == $$; }; my $root; @@ -29,59 +51,98 @@ close IN; mkdir('tmp', 0777) unless -d 'tmp'; chdir('tmp') or die "Unable to chdir to 'tmp'"; +symlink('..', 'patches') unless -d 'patches'; + +symlink($$, 'lock') or die "Unable to create lock file: $!\n"; mkdir('workdir') unless -d 'workdir'; open(OUT, '>exclude') or die $!; -print OUT < (-M $src)) { + system "touch $gen"; + } + } +} -@ARGV = glob('../*.diff') unless @ARGV; +@ARGV = glob('patches/*.diff') unless @ARGV; DIFF: foreach my $diff (@ARGV) { next unless $diff =~ /\.diff$/; - next if $diff =~ /gzip-rsyncable\.diff$/; + next if $diff =~ /gzip-rsyncable[-_a-z]*\.diff$/; $diff =~ s#^(patches|\.\.)/##; - open(IN, "../$diff") or die $!; + my $conf_opts; + open(IN, "patches/$diff") or die $!; while () { last if /^--- /; - if (/^Depends-On-Patch: (\S+.diff)$/) { + if (m#^\s+patch -p1 ; - 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; - } chdir('workdir') or die $!; - system "make gen; ./configure $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; @@ -124,7 +172,7 @@ foreach my $diff (@ARGV) { } if ($cmd eq 'E') { chdir('workdir') or die $!; - system "vim -d ../../$diff ../new.patch"; + system "vim -d ../patches/$diff ../new.patch"; chdir('..') or die $!; $default = 'U,A,D'; next; @@ -143,7 +191,7 @@ foreach my $diff (@ARGV) { exit; } if ($cmd eq 'U') { - system "cp -p new.patch ../$diff"; + system "cp -p new.patch patches/$diff"; print "\nUpdated $diff from new.patch\n"; $default = 'A'; next; @@ -162,10 +210,11 @@ sub apply_patch my($diff) = @_; undef @new; - my $def = 'N'; - system "rsync -a --delete --exclude='*~' cvsdir/ workdir/"; + system "rsync -a --del --exclude='*~' cvsdir/ workdir/"; print "\nApplying patch $diff...\n"; - open(IN, "patch -d workdir -p0 --no-backup-if-mismatch -Zf <../$diff |") or die $!; + undef @rejects; + my($saw_offset, $saw_fuzz); + open(IN, "patch -f -d workdir -p1 --no-backup-if-mismatch ) { print $_; chomp; @@ -173,14 +222,31 @@ sub apply_patch push(@new, $_) unless -f "cvsdir/$_"; } elsif (s/.* saving rejects to file //) { push(@rejects, $_); - } elsif (/^Hunk #\d+ FAILED/) { - $def = 'F,D,E'; - } elsif (/^Hunk #\d+ succeeded/) { - $def = 'E' unless $def =~ /F/; + } elsif (/No file to patch\.\s+Skipping patch/) { + push(@rejects, 'skipped.file'); + } elsif (/^Hunk #\d+ succeeded at \d+( with fuzz $interesting_fuzz)?/o) { + $saw_fuzz ||= defined $1; + $saw_offset = 1; } } close IN; - $def; + 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 @@ -190,28 +256,27 @@ sub generate_new_patch foreach (@new) { system "touch -r workdir/$_ cvsdir/$_"; } - open(IN, "../$diff") or die $!; + open(IN, "patches/$diff") or die $!; open(OUT, '>new.patch') or die $!; while () { last if /^--- /; 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 -dupr 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 -dup cvsdir/$fn workdir"); + } } - close IN; close OUT; foreach (@new) { unlink("cvsdir/$_"); } print "\nDiffing... "; - if (system("diff ../$diff new.patch >/dev/null") == 0) { + if (system("diff patches/$diff new.patch >/dev/null") == 0) { print "new patch is identical to old.\n"; return 'N'; } @@ -224,16 +289,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 <