X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-add--interactive.perl;h=21f1330a5bf26c955051ce9cf263289d90c7667b;hb=97b03c353856602a3c30b01baae1efb8dfe4243e;hp=cd43c3491260cb2aa51f0d19fd18ab66e4ad8217;hpb=c214f2c80c70c2a3803bf1f3efc323cee5496024;p=git.git diff --git a/git-add--interactive.perl b/git-add--interactive.perl index cd43c3491..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 : @@ -1453,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();