From 725135db120a3c371e1f58016db9b792eebcbed5 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 18 Apr 2011 02:56:13 -0700 Subject: [PATCH] [commit-patch] Use lsdiffs -s option to keep track of added, removed, and changed files in the patch so we can use them appropriately. --- commit-patch | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/commit-patch b/commit-patch index bf68f7a..25ed6f7 100755 --- a/commit-patch +++ b/commit-patch @@ -206,31 +206,34 @@ if ($vc{name} eq 'git') { } my ($lsdiff_out, $err); -run ["lsdiff", @{$vc{lsdiffarg}}, $patch], '|', ["sort"], '|', ["uniq"], \$lsdiff_out, \$err or die "lsdiff|sort|unique : $! ($err)"; -my @files = split(/\n/, $lsdiff_out); -die "No files in patch" unless scalar @files; +run ["lsdiff", '-s', @{$vc{lsdiffarg}}, $patch], '>', \$lsdiff_out, '2>', \$err or die "lsdiff|sort|unique : $! ($err)"; +my %lsdiff = map { /^([-+!])\s+(.*)$/ or die "bad lsdiff line: $_\nOut:\n$lsdiff_out"; ( $2 => $1 ) } split(/\n/, $lsdiff_out); +my @added = grep { $lsdiff{$_} eq '+' } keys %lsdiff; +my @removed = grep { $lsdiff{$_} eq '-' } keys %lsdiff; +my @changed = grep { $lsdiff{$_} eq '!' } keys %lsdiff; +die "No files in patch" unless scalar %lsdiff; #print "Found $vc{name} in $repo\n"; #printf("files: %s\n", join(",", @files)); -for my $f (@files) { +for my $f (@changed, @removed) { run ["cp", "-f", $f, "$f.orig.$$"] or die "couldn't make backup of $f: $!" if -f $f; $clean{"$f.orig.$$"} = $f; } $SIG{PIPE} = $SIG{INT} = $SIG{QUIT} = sub { print "Cleanly aborting..\n"; }; my ($out, $working_patch, $non_committed_patch); -run([split(/ /,$vc{diff}), @files], '>', \$working_patch, '2>', \$err);# CVS diff dies. Sigh. or die "$err\n"; +run([split(/ /,$vc{diff}), @changed, @removed], '>', \$working_patch, '2>', \$err);# CVS diff dies. Sigh. or die "$err\n"; unless ($working_patch =~ /^\s*$/s) { run(["interdiff", $vc{patcharg}, $patch, '-'], '<', \$working_patch, '>', \$non_committed_patch, '2>', \$err) or die "$err\n"; run(["patch", $vc{patcharg}, "-R"], '<', \$working_patch, '>', \$out, '2>', \$err) or die "$out\n$err\n"; } run(["patch", $vc{patcharg}], '<', $patch, '>', \$out, '2>', \$err) or die "$out\n$err\n"; -run([split(/ /,$vc{add}), @files], '>', \$out, '2>', \$err);# Expect these 2 to fail when -run([split(/ /,$vc{remove}), @files], '>', \$out, '2>', \$err);# there are no new files. +run([split(/ /,$vc{add}), @added], '>', \$out, '2>', \$err);# Expect these 2 to fail when +run([split(/ /,$vc{remove}), @removed], '>', \$out, '2>', \$err);# there are no new files. # Don't capture stdout or stderr because it can be interactive (cough cough darcs) -run([split(/ /,$vc_commit), @message_opt, @files],debug => 0) or die "commit failed.\n"; +run([split(/ /,$vc_commit), @message_opt, @added, @removed, @changed]) or die "commit failed.\n"; run(["patch", $vc{patcharg}], '<', \$non_committed_patch, '>', \$out, '2>', \$err) or die "$out\n$err\n"; END { -- 2.51.2