From: Wayne Davison Date: Sun, 4 Jul 2004 09:01:23 +0000 (+0000) Subject: A few more improvements including an ability to build the patched X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/commitdiff_plain/b1a4cc328a5c9cecd8e726869af006c789cdf9e8 A few more improvements including an ability to build the patched source and to spawn a shell or run a command. --- diff --git a/verify-patches b/verify-patches index 661f8a8..ea72381 100755 --- a/verify-patches +++ b/verify-patches @@ -11,12 +11,14 @@ from inside the patches subdir. EOT } -$ENV{'TZ'} = 'GMT'; +$ENV{'TZ'} = 'UTC'; +my $CONF_OPTS = '-C'; -my($has_dependencies, @new); +my($has_dependencies, @new, @rejects); END { &restore_cvsdir; + system "rsync -a --delete cvsdir/ workdir/" if -d 'cvsdir'; }; my $root; @@ -24,14 +26,13 @@ open(IN, '../CVS/Root') or die $!; chomp($root = ); close IN; -my $tmpdir = ',tmp-for-patch-tests'; - -mkdir($tmpdir, 0777) unless -d $tmpdir; -chdir($tmpdir) or die "Unable to chdir to $tmpdir"; +mkdir('tmp', 0777) unless -d 'tmp'; +chdir('tmp') or die "Unable to chdir to 'tmp'"; mkdir('workdir') unless -d 'workdir'; open(OUT, '>exclude') or die $!; print OUT <) { - print $_; - chomp; - if (s/^patching file //) { - push(@new, $_) unless -f "cvsdir/$_"; - } elsif (s/.* saving rejects to file //) { - push(@rejects, $_); - } elsif (/^Hunk #\d+ FAILED/) { - $default = 'F'; - } elsif (/^Hunk #\d+ succeeded/) { - $default = 'E' unless $default eq 'F'; - } - } - close IN; - if ($default eq 'N') { - generate_new_patch($diff); - if (system("diff ../$diff new.patch >/dev/null") == 0) { - print "\n(New patch is identical to old.)\n"; - } - } - $apply = 0; - } - print "\nFix rejects, Edit both diffs, Update patch,\n", - "Apply patch again, Next, Quit: [$default] "; + 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 unless $ans =~ s/^(\w)/$1/; - if ($ans =~ /E/i) { - generate_new_patch($diff); + $ans = $default if $ans eq ''; + if ($ans =~ /^!(.*)/) { + my $cmd = $1 || $ENV{'SHELL'}; chdir('workdir') or die $!; - system "vim -d ../../$diff ../new.patch"; + system $cmd; chdir('..') or die $!; - $default = 'U'; - } elsif ($ans =~ /F/i) { + $default = 'D,E'; + next; + } + if ($ans =~ /^\S*F/i) { chdir('workdir') or die $!; system "vim @rejects"; chdir('..') or die $!; - $default = 'E'; - } elsif ($ans =~ /U/i) { + $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'; - } elsif ($ans =~ /A/i) { - $apply = 1; - } elsif ($ans =~ /N/i) { - last; - } elsif ($ans =~ /Q/i) { + } + 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; + } + chdir('workdir') or die $!; + system "make gen; ./configure $CONF_OPTS; make"; + chdir('..') or die $!; + $default = '!make test'; + } + if ($ans =~ /^\S*Q/i) { exit; } + if ($ans =~ /^\S*N/i) { + last; + } } &restore_cvsdir; @@ -133,6 +143,35 @@ foreach my $diff (@ARGV) { exit; +sub apply_patch +{ + my($diff) = @_; + + undef @new; + my $def = 'N'; + system "rsync -a --delete cvsdir/ workdir/"; + print "\n"; + open(IN, "patch -d workdir -p0 --no-backup-if-mismatch -Zf <../$diff |") or die $!; + while () { + print $_; + chomp; + if (s/^patching file //) { + 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'; + } + } + close IN; + if ($def eq 'N') { + generate_new_patch($diff); + } + $def; +} + sub generate_new_patch { my($diff) = @_; @@ -160,6 +199,11 @@ sub generate_new_patch foreach (@new) { unlink("cvsdir/$_"); } + if (system("diff ../$diff new.patch >/dev/null") == 0) { + print "\n(New patch is identical to old.)\n"; + return 'N'; + } + 'E'; } sub restore_cvsdir