diff options
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-x | git-add--interactive.perl | 91 |
1 files changed, 57 insertions, 34 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl index f36c0078ac..8a72018712 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -714,7 +714,7 @@ sub parse_diff { if (defined $patch_mode_revision) { push @diff_cmd, get_diff_reference($patch_mode_revision); } - my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path); + my @diff = run_cmd_pipe("git", @diff_cmd, qw(--no-color --), $path); my @colored = (); if ($diff_use_color) { my @display_cmd = ("git", @diff_cmd, qw(--color --), $path); @@ -754,13 +754,16 @@ sub parse_diff_header { my $head = { TEXT => [], DISPLAY => [], TYPE => 'header' }; my $mode = { TEXT => [], DISPLAY => [], TYPE => 'mode' }; my $deletion = { TEXT => [], DISPLAY => [], TYPE => 'deletion' }; - my $addition = { TEXT => [], DISPLAY => [], TYPE => 'addition' }; + my $addition; for (my $i = 0; $i < @{$src->{TEXT}}; $i++) { + if ($src->{TEXT}->[$i] =~ /^new file/) { + $addition = 1; + $head->{TYPE} = 'addition'; + } my $dest = $src->{TEXT}->[$i] =~ /^(old|new) mode (\d+)$/ ? $mode : $src->{TEXT}->[$i] =~ /^deleted file/ ? $deletion : - $src->{TEXT}->[$i] =~ /^new file/ ? $addition : $head; push @{$dest->{TEXT}}, $src->{TEXT}->[$i]; push @{$dest->{DISPLAY}}, $src->{DISPLAY}->[$i]; @@ -1501,12 +1504,6 @@ sub patch_update_file { push @{$deletion->{DISPLAY}}, @{$hunk->{DISPLAY}}; } @hunk = ($deletion); - } elsif (@{$addition->{TEXT}}) { - foreach my $hunk (@hunk) { - push @{$addition->{TEXT}}, @{$hunk->{TEXT}}; - push @{$addition->{DISPLAY}}, @{$hunk->{DISPLAY}}; - } - @hunk = ($addition); } $num = scalar @hunk; @@ -1516,6 +1513,7 @@ sub patch_update_file { my ($prev, $next, $other, $undecided, $i); $other = ''; + last if ($ix and !$num); if ($num <= $ix) { $ix = 0; } @@ -1548,35 +1546,51 @@ sub patch_update_file { last; } } - last if (!$undecided); + last if (!$undecided && ($num || !$addition)); - if ($hunk[$ix]{TYPE} eq 'hunk' && - hunk_splittable($hunk[$ix]{TEXT})) { - $other .= ',s'; - } - if ($hunk[$ix]{TYPE} eq 'hunk') { - $other .= ',e'; - } - for (@{$hunk[$ix]{DISPLAY}}) { - print; + if ($num) { + if ($hunk[$ix]{TYPE} eq 'hunk' && + hunk_splittable($hunk[$ix]{TEXT})) { + $other .= ',s'; + } + if ($hunk[$ix]{TYPE} eq 'hunk') { + $other .= ',e'; + } + for (@{$hunk[$ix]{DISPLAY}}) { + print; + } } - print colored $prompt_color, "(", ($ix+1), "/$num) ", - sprintf(__($patch_update_prompt_modes{$patch_mode}{$hunk[$ix]{TYPE}}), $other); + my $type = $num ? $hunk[$ix]{TYPE} : $head->{TYPE}; + print colored $prompt_color, "(", ($ix+1), "/", ($num ? $num : 1), ") ", + sprintf(__($patch_update_prompt_modes{$patch_mode}{$type}), $other); my $line = prompt_single_character; last unless defined $line; if ($line) { if ($line =~ /^y/i) { - $hunk[$ix]{USE} = 1; + if ($num) { + $hunk[$ix]{USE} = 1; + } else { + $head->{USE} = 1; + } } elsif ($line =~ /^n/i) { - $hunk[$ix]{USE} = 0; + if ($num) { + $hunk[$ix]{USE} = 0; + } else { + $head->{USE} = 0; + } } elsif ($line =~ /^a/i) { - while ($ix < $num) { - if (!defined $hunk[$ix]{USE}) { - $hunk[$ix]{USE} = 1; + if ($num) { + while ($ix < $num) { + if (!defined $hunk[$ix]{USE}) { + $hunk[$ix]{USE} = 1; + } + $ix++; } + } else { + $head->{USE} = 1; $ix++; } next; @@ -1613,19 +1627,28 @@ sub patch_update_file { next; } elsif ($line =~ /^d/i) { - while ($ix < $num) { - if (!defined $hunk[$ix]{USE}) { - $hunk[$ix]{USE} = 0; + if ($num) { + while ($ix < $num) { + if (!defined $hunk[$ix]{USE}) { + $hunk[$ix]{USE} = 0; + } + $ix++; } + } else { + $head->{USE} = 0; $ix++; } next; } elsif ($line =~ /^q/i) { - for ($i = 0; $i < $num; $i++) { - if (!defined $hunk[$i]{USE}) { - $hunk[$i]{USE} = 0; + if ($num) { + for ($i = 0; $i < $num; $i++) { + if (!defined $hunk[$i]{USE}) { + $hunk[$i]{USE} = 0; + } } + } elsif (!defined $head->{USE}) { + $head->{USE} = 0; } $quit = 1; last; @@ -1743,7 +1766,7 @@ sub patch_update_file { } } - @hunk = coalesce_overlapping_hunks(@hunk); + @hunk = coalesce_overlapping_hunks(@hunk) if ($num); my $n_lofs = 0; my @result = (); @@ -1753,7 +1776,7 @@ sub patch_update_file { } } - if (@result) { + if (@result or $head->{USE}) { my @patch = reassemble_patch($head->{TEXT}, @result); my $apply_routine = $patch_mode_flavour{APPLY}; &$apply_routine(@patch); |