X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/blobdiff_plain/4cb494cd4671e5aea0379f84c0480554fdf922bb..8e65e95897d45f2f9912349580c977c6e0a5cfc7:/verify-patches diff --git a/verify-patches b/verify-patches index 402224c..64ae506 100755 --- a/verify-patches +++ b/verify-patches @@ -3,15 +3,10 @@ use strict; use Getopt::Long; -my %generated_files = ( - 'proto.h' => qr#\.[ch]$#, - 'configure' => qr#^(configure\.in|aclocal\.m4)$#, - 'config.h.in' => qr#^(configure\.in|aclocal\.m4)$#, - 'rsync.1' => qr#^rsync\.yo$#, - 'rsyncd.conf.5' => qr#^rsyncd\.conf\.yo$#, -); +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( @@ -19,9 +14,13 @@ GetOptions( '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'; @@ -32,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; @@ -50,21 +51,30 @@ 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 "CVS\n"; -if (!$prepare_source) { - print OUT join("\n", sort keys %generated_files), "\n"; -} +print OUT join("\n", 'CVS', @generated_files), "\n"; close OUT; unless ($no_cvs) { print "Using CVS to update the tmp/cvsdir copy of the source.\n"; system qq|cvs -qd "$root" co -P -d cvsdir rsync|; + @_ = qw( configure configure.in config.h.in configure.in + rsync.1 rsync.yo rsyncd.conf.5 rsyncd.conf.yo ); + while (@_) { + my $gen = 'cvsdir/' . shift(@_); + my $src = 'cvsdir/' . shift(@_); + if ((-M $gen) > (-M $src)) { + system "touch $gen"; + } + } } -@ARGV = glob('../*.diff') unless @ARGV; +@ARGV = glob('patches/*.diff') unless @ARGV; DIFF: foreach my $diff (@ARGV) { @@ -72,57 +82,36 @@ foreach my $diff (@ARGV) { 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 ) { - if (!defined $conf_opts) { - if (m#^\s*\./configure( .+)#) { - $conf_opts = $1; - $conf_opts =~ s/\s+\(.*?\)//; - } elsif (/^--- /) { - $conf_opts = ''; - } - } - if (m#^--- orig/([^\t]+)#) { - my $patching = $1; - while (my($fn, $re) = each %generated_files) { - if ($patching =~ /$re/) { - $regenerate{$fn} = 1; - } - } + if (!defined($conf_opts) && s#^\s+\./configure\s+##) { + chomp($conf_opts = $_); + $conf_opts =~ s/\s*\(.*?\)//; } } close IN; - my @regenerate = sort keys %regenerate; + $conf_opts = '' unless defined $conf_opts; my $default = apply_patch($diff); - if (@regenerate) { + if ($prepare_source) { + print "\nPreparing the source...\n"; chdir('workdir') or die $!; - foreach (@regenerate) { - utime(111111111, 111111111, $_); - } - if ($prepare_source) { - print "\nRegenerating: @regenerate\n"; - system "make -f prepare-source.mak @regenerate"; - } + system "./prepare-source"; chdir('..') or die $!; } @@ -132,14 +121,28 @@ foreach my $diff (@ARGV) { $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)((?) { print $_; chomp; @@ -223,20 +222,33 @@ sub apply_patch push(@new, $_) unless -f "cvsdir/$_"; } elsif (s/.* saving rejects to file //) { push(@rejects, $_); - } elsif (/^Hunk #\d+ FAILED/) { - $saw_failure = 1; + } 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; - 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) = @_; @@ -244,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#(\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 -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'; } @@ -298,6 +309,7 @@ sub usage { die <