X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=git-add--interactive.perl;h=cd43c3491260cb2aa51f0d19fd18ab66e4ad8217;hb=72d9b222a940c93a8d915c26a4d5d077e23be871;hp=8ce1ec92c2b04e1271b3ee1a41a2ac60d2f8aad4;hpb=dda8f4bf2b159d6f8e6d816e35418708cc6f21a1;p=git.git diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 8ce1ec92c..21f1330a5 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -957,6 +957,28 @@ sub coalesce_overlapping_hunks { return @out; } +sub reassemble_patch { + my $head = shift; + my @patch; + + # Include everything in the header except the beginning of the diff. + push @patch, (grep { !/^[-+]{3}/ } @$head); + + # Then include any headers from the hunk lines, which must + # come before any actual hunk. + while (@_ && $_[0] !~ /^@/) { + push @patch, shift; + } + + # Then begin the diff. + push @patch, grep { /^[-+]{3}/ } @$head; + + # And then the actual hunks. + push @patch, @_; + + return @patch; +} + sub color_diff { return map { colored((/^@/ ? $fraginfo_color : @@ -990,8 +1012,7 @@ sub edit_hunk_manually { EOF close $fh; - my $editor = $ENV{GIT_EDITOR} || $repo->config("core.editor") - || $ENV{VISUAL} || $ENV{EDITOR} || "vi"; + chomp(my $editor = run_cmd_pipe(qw(git var GIT_EDITOR))); system('sh', '-c', $editor.' "$@"', $editor, $hunkfile); if ($? != 0) { @@ -1217,7 +1238,11 @@ sub patch_update_file { if (@{$mode->{TEXT}}) { unshift @hunk, $mode; } - if (@{$deletion->{TEXT}} && !@hunk) { + if (@{$deletion->{TEXT}}) { + foreach my $hunk (@hunk) { + push @{$deletion->{TEXT}}, @{$hunk->{TEXT}}; + push @{$deletion->{DISPLAY}}, @{$hunk->{DISPLAY}}; + } @hunk = ($deletion); } @@ -1450,7 +1475,7 @@ sub patch_update_file { if (@result) { my $fh; - my @patch = (@{$head->{TEXT}}, @result); + my @patch = reassemble_patch($head->{TEXT}, @result); my $apply_routine = $patch_mode_flavour{APPLY}; &$apply_routine(@patch); refresh();