X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/blobdiff_plain/efda4e563573bf4c01697d2a3576c9045a1125aa..6dca00254adc64ba87f07ff1c959766a67d764c7:/verify-patches diff --git a/verify-patches b/verify-patches index 7100d32..d6d7c3a 100755 --- a/verify-patches +++ b/verify-patches @@ -1,93 +1,322 @@ -#!/bin/sh - -[ -d patches ] && cd patches - -if [ ! -f verify-patches ]; then - echo "Please run this script from the root of the rsync dir" - echo "or from inside the patches subdir." - exit 1 -fi - -root=`cat ../CVS/Root` -tmpdir=,tmp-for-patch-tests - -[ -d $tmpdir ] || mkdir $tmpdir -cd $tmpdir || exit 1 - -[ -d workdir ] || mkdir workdir -echo "Using CVS to update the $tmpdir/cvsdir copy of the source." -cvs -d "$root" co -d cvsdir rsync - -cd workdir || exit 1 - -if [ -z "$1" ]; then - set -- ../../*.diff -fi - -for xx in "${@}"; do - case "$xx" in - *gzip-rsyncable.diff) continue ;; - patches/*) xx=`echo $xx | sed 's:patches:../..:'` ;; - */*.diff) ;; - *.diff) xx=../../$xx ;; - *) continue ;; - esac - apply=y - while : ; do - echo -e "\n----------- $xx ------------" - if [ $apply = y ]; then - rsync -a --delete ../cvsdir/ . - patch -p0 <$xx | tee ,patch.output - new='' - for nn in `sed -n 's/^patching file //p' ,patch.output`; do - [ -f ../cvsdir/$nn ] || new="$new $nn" - done - if grep "^Hunk #[0-9]* FAILED" ,patch.output >/dev/null; then - default=F - elif grep "^Hunk #[0-9]* succeeded" ,patch.output >/dev/null; then - default=E - else - default=N - fi - apply=n - fi - echo -e "\nFix rejects, Edit both diffs, Update patch," - echo -n "Apply patch again, Next, Quit: [$default] " - read ans - [ -z "$ans" ] && ans=$default - case "$ans" in - [Ee]*) - [ ! -z "$new" ] && cvs add $new - new='' - rm -f *.rej *.orig */*.rej */*.orig - sed '/^--- /,$ d' $xx >,new.patch - cvs diff -N | egrep -v '^(diff -|===============|RCS file: |retrieving revision |Index: )' >>,new.patch - vim -d $xx ,new.patch - default=U - ;; - [Ff]*) - vim `sed -ne 's/.* saving rejects to file //p' ,patch.output` - default=E - ;; - [Uu]*) - if [ -f ,new.patch ]; then - cp -p ,new.patch $xx - echo -e "\nCopied ,new.patch to $xx" - default=A - else - echo -e "\n*** Edit the diffs first. ***" - default=E - fi - ;; - [Aa]*) - apply=y - ;; - [Nn]*) - break - ;; - [Qq]*) - exit 0 - ;; - esac - done -done +#!/usr/bin/perl + +use strict; +use Getopt::Long; +use Cwd; + +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'; + +if (!-f 'verify-patches') { + die <); +close IN; + +mkdir('tmp', 0777) unless -d 'tmp'; +chdir('tmp') or die "Unable to chdir to 'tmp'"; +unlink('patches'); +symlink($patches_dir, 'patches'); + +symlink($$, 'lock') or die "Unable to create lock file: $!\n"; + +mkdir('workdir') unless -d 'workdir'; +open(OUT, '>exclude') or die $!; +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('patches/*.diff') unless @ARGV; + +DIFF: +foreach my $diff (@ARGV) { + next unless $diff =~ /\.diff$/; + next if $diff =~ /gzip-rsyncable[-_a-z]*\.diff$/; + $diff =~ s#^(patches|\.\.)/##; + + my $conf_opts; + open(IN, "patches/$diff") or die $!; + while () { + last if /^--- /; + if (m#^\s+patch -p1 ; + 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; + if (s/^patching file //) { + push(@new, $_) unless -f "cvsdir/$_"; + } elsif (s/.* saving rejects to file //) { + push(@rejects, $_); + } 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 @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) = @_; + + foreach (@new) { + system "touch -r workdir/$_ cvsdir/$_"; + } + open(IN, "patches/$diff") or die $!; + open(OUT, '>new.patch') or die $!; + while () { + last if /^--- /; + print OUT $_; + } + close IN; + &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 -dupW128 cvsdir/$fn workdir"); + } + } + close OUT; + foreach (@new) { + unlink("cvsdir/$_"); + } + print "\nDiffing... "; + if (system("diff patches/$diff new.patch >/dev/null") == 0) { + print "new patch is identical to old.\n"; + return 'N'; + } + print "New patch DIFFERS from old.\n"; + 'E'; +} + +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 $_) { + rename($_, $fn); + } else { + unlink($_); + unlink($fn); + } + } + chdir('..') or die $!; +} + +sub usage +{ + die <