From 58a28a53892a910428c7a1315f9dc4ecbf6a9252 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Wed, 23 Nov 2011 22:51:13 +0100 Subject: [PATCH] In bisect-runner.pl, only shell out to patch from apply_patch(). Previously the system's patch binary was invoked from 3 places. Refactoring the code to only call it from one place will make it easier to work around ancient versions of patch that some vendors still supply. --- Porting/bisect-runner.pl | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Porting/bisect-runner.pl b/Porting/bisect-runner.pl index 711a14a..a1e5a02 100755 --- a/Porting/bisect-runner.pl +++ b/Porting/bisect-runner.pl @@ -531,28 +531,37 @@ sub edit_file { } sub apply_patch { - my $patch = shift; - - my ($file) = $patch =~ qr!^--- a/(\S+)\n\+\+\+ b/\1!sm; + my ($patch, $what, $files) = @_; + $what = 'patch' unless defined $what; + unless (defined $files) { + $patch =~ m!^--- a/(\S+)\n\+\+\+ b/\1!sm; + $files = " $1"; + } open my $fh, '|-', 'patch', '-p1' or die "Can't run patch: $!"; print $fh $patch; return if close $fh; print STDERR "Patch is <<'EOPATCH'\n${patch}EOPATCH\n"; - die "Can't patch $file: $?, $!"; + die "Can't $what$files: $?, $!"; } sub apply_commit { my ($commit, @files) = @_; - return unless system "git show $commit @files | patch -p1"; - die "Can't apply commit $commit to @files" if @files; - die "Can't apply commit $commit"; + my $patch = `git show $commit @files`; + if (!defined $patch) { + die "Can't get commit $commit for @files: $?" if @files; + die "Can't get commit $commit: $?"; + } + apply_patch($patch, "patch $commit", @files ? " for @files" : ''); } sub revert_commit { my ($commit, @files) = @_; - return unless system "git show -R $commit @files | patch -p1"; - die "Can't apply revert $commit from @files" if @files; - die "Can't apply revert $commit"; + my $patch = `git show -R $commit @files`; + if (!defined $patch) { + die "Can't get revert commit $commit for @files: $?" if @files; + die "Can't get revert commit $commit: $?"; + } + apply_patch($patch, "revert $commit", @files ? " for @files" : ''); } sub checkout_file { -- 2.7.4