Merge branch 'mm/add-p-quit'
* mm/add-p-quit: Update git-add.txt according to the new possibilities of 'git add -p'. add-interactive: refactor mode hunk handling git add -p: new "quit" command at the prompt.
This commit is contained in:
commit
66aae6c1ba
@ -245,8 +245,11 @@ patch::
|
|||||||
|
|
||||||
y - stage this hunk
|
y - stage this hunk
|
||||||
n - do not stage this hunk
|
n - do not stage this hunk
|
||||||
|
q - quit, do not stage this hunk nor any of the remaining ones
|
||||||
a - stage this and all the remaining hunks in the file
|
a - stage this and all the remaining hunks in the file
|
||||||
d - do not stage this hunk nor any of the remaining hunks in the file
|
d - do not stage this hunk nor any of the remaining hunks in the file
|
||||||
|
g - select a hunk to go to
|
||||||
|
/ - search for a hunk matching the given regex
|
||||||
j - leave this hunk undecided, see next undecided hunk
|
j - leave this hunk undecided, see next undecided hunk
|
||||||
J - leave this hunk undecided, see next hunk
|
J - leave this hunk undecided, see next hunk
|
||||||
k - leave this hunk undecided, see previous undecided hunk
|
k - leave this hunk undecided, see previous undecided hunk
|
||||||
|
@ -620,11 +620,12 @@ sub parse_diff {
|
|||||||
if ($diff_use_color) {
|
if ($diff_use_color) {
|
||||||
@colored = run_cmd_pipe(qw(git diff-files -p --color --), $path);
|
@colored = run_cmd_pipe(qw(git diff-files -p --color --), $path);
|
||||||
}
|
}
|
||||||
my (@hunk) = { TEXT => [], DISPLAY => [] };
|
my (@hunk) = { TEXT => [], DISPLAY => [], TYPE => 'header' };
|
||||||
|
|
||||||
for (my $i = 0; $i < @diff; $i++) {
|
for (my $i = 0; $i < @diff; $i++) {
|
||||||
if ($diff[$i] =~ /^@@ /) {
|
if ($diff[$i] =~ /^@@ /) {
|
||||||
push @hunk, { TEXT => [], DISPLAY => [] };
|
push @hunk, { TEXT => [], DISPLAY => [],
|
||||||
|
TYPE => 'hunk' };
|
||||||
}
|
}
|
||||||
push @{$hunk[-1]{TEXT}}, $diff[$i];
|
push @{$hunk[-1]{TEXT}}, $diff[$i];
|
||||||
push @{$hunk[-1]{DISPLAY}},
|
push @{$hunk[-1]{DISPLAY}},
|
||||||
@ -636,8 +637,8 @@ sub parse_diff {
|
|||||||
sub parse_diff_header {
|
sub parse_diff_header {
|
||||||
my $src = shift;
|
my $src = shift;
|
||||||
|
|
||||||
my $head = { TEXT => [], DISPLAY => [] };
|
my $head = { TEXT => [], DISPLAY => [], TYPE => 'header' };
|
||||||
my $mode = { TEXT => [], DISPLAY => [] };
|
my $mode = { TEXT => [], DISPLAY => [], TYPE => 'mode' };
|
||||||
|
|
||||||
for (my $i = 0; $i < @{$src->{TEXT}}; $i++) {
|
for (my $i = 0; $i < @{$src->{TEXT}}; $i++) {
|
||||||
my $dest = $src->{TEXT}->[$i] =~ /^(old|new) mode (\d+)$/ ?
|
my $dest = $src->{TEXT}->[$i] =~ /^(old|new) mode (\d+)$/ ?
|
||||||
@ -684,6 +685,7 @@ sub split_hunk {
|
|||||||
my $this = +{
|
my $this = +{
|
||||||
TEXT => [],
|
TEXT => [],
|
||||||
DISPLAY => [],
|
DISPLAY => [],
|
||||||
|
TYPE => 'hunk',
|
||||||
OLD => $o_ofs,
|
OLD => $o_ofs,
|
||||||
NEW => $n_ofs,
|
NEW => $n_ofs,
|
||||||
OCNT => 0,
|
OCNT => 0,
|
||||||
@ -873,7 +875,11 @@ sub edit_hunk_loop {
|
|||||||
if (!defined $text) {
|
if (!defined $text) {
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
my $newhunk = { TEXT => $text, USE => 1 };
|
my $newhunk = {
|
||||||
|
TEXT => $text,
|
||||||
|
TYPE => $hunk->[$ix]->{TYPE},
|
||||||
|
USE => 1
|
||||||
|
};
|
||||||
if (diff_applies($head,
|
if (diff_applies($head,
|
||||||
@{$hunk}[0..$ix-1],
|
@{$hunk}[0..$ix-1],
|
||||||
$newhunk,
|
$newhunk,
|
||||||
@ -894,6 +900,7 @@ sub help_patch_cmd {
|
|||||||
print colored $help_color, <<\EOF ;
|
print colored $help_color, <<\EOF ;
|
||||||
y - stage this hunk
|
y - stage this hunk
|
||||||
n - do not stage this hunk
|
n - do not stage this hunk
|
||||||
|
q - quit, do not stage this hunk nor any of the remaining ones
|
||||||
a - stage this and all the remaining hunks in the file
|
a - stage this and all the remaining hunks in the file
|
||||||
d - do not stage this hunk nor any of the remaining hunks in the file
|
d - do not stage this hunk nor any of the remaining hunks in the file
|
||||||
g - select a hunk to go to
|
g - select a hunk to go to
|
||||||
@ -930,7 +937,7 @@ sub patch_update_cmd {
|
|||||||
@mods);
|
@mods);
|
||||||
}
|
}
|
||||||
for (@them) {
|
for (@them) {
|
||||||
patch_update_file($_->{VALUE});
|
return 0 if patch_update_file($_->{VALUE});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -976,6 +983,7 @@ sub display_hunks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub patch_update_file {
|
sub patch_update_file {
|
||||||
|
my $quit = 0;
|
||||||
my ($ix, $num);
|
my ($ix, $num);
|
||||||
my $path = shift;
|
my $path = shift;
|
||||||
my ($head, @hunk) = parse_diff($path);
|
my ($head, @hunk) = parse_diff($path);
|
||||||
@ -985,32 +993,7 @@ sub patch_update_file {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (@{$mode->{TEXT}}) {
|
if (@{$mode->{TEXT}}) {
|
||||||
while (1) {
|
unshift @hunk, $mode;
|
||||||
print @{$mode->{DISPLAY}};
|
|
||||||
print colored $prompt_color,
|
|
||||||
"Stage mode change [y/n/a/d/?]? ";
|
|
||||||
my $line = prompt_single_character;
|
|
||||||
if ($line =~ /^y/i) {
|
|
||||||
$mode->{USE} = 1;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
elsif ($line =~ /^n/i) {
|
|
||||||
$mode->{USE} = 0;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
elsif ($line =~ /^a/i) {
|
|
||||||
$_->{USE} = 1 foreach ($mode, @hunk);
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
elsif ($line =~ /^d/i) {
|
|
||||||
$_->{USE} = 0 foreach ($mode, @hunk);
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
help_patch_cmd('');
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$num = scalar @hunk;
|
$num = scalar @hunk;
|
||||||
@ -1054,14 +1037,19 @@ sub patch_update_file {
|
|||||||
}
|
}
|
||||||
last if (!$undecided);
|
last if (!$undecided);
|
||||||
|
|
||||||
if (hunk_splittable($hunk[$ix]{TEXT})) {
|
if ($hunk[$ix]{TYPE} eq 'hunk' &&
|
||||||
|
hunk_splittable($hunk[$ix]{TEXT})) {
|
||||||
$other .= ',s';
|
$other .= ',s';
|
||||||
}
|
}
|
||||||
|
if ($hunk[$ix]{TYPE} eq 'hunk') {
|
||||||
$other .= ',e';
|
$other .= ',e';
|
||||||
|
}
|
||||||
for (@{$hunk[$ix]{DISPLAY}}) {
|
for (@{$hunk[$ix]{DISPLAY}}) {
|
||||||
print;
|
print;
|
||||||
}
|
}
|
||||||
print colored $prompt_color, "Stage this hunk [y,n,a,d,/$other,?]? ";
|
print colored $prompt_color, 'Stage ',
|
||||||
|
($hunk[$ix]{TYPE} eq 'mode' ? 'mode change' : 'this hunk'),
|
||||||
|
" [y,n,a,d,/$other,?]? ";
|
||||||
my $line = prompt_single_character;
|
my $line = prompt_single_character;
|
||||||
if ($line) {
|
if ($line) {
|
||||||
if ($line =~ /^y/i) {
|
if ($line =~ /^y/i) {
|
||||||
@ -1113,6 +1101,16 @@ sub patch_update_file {
|
|||||||
}
|
}
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
elsif ($line =~ /^q/i) {
|
||||||
|
while ($ix < $num) {
|
||||||
|
if (!defined $hunk[$ix]{USE}) {
|
||||||
|
$hunk[$ix]{USE} = 0;
|
||||||
|
}
|
||||||
|
$ix++;
|
||||||
|
}
|
||||||
|
$quit = 1;
|
||||||
|
next;
|
||||||
|
}
|
||||||
elsif ($line =~ m|^/(.*)|) {
|
elsif ($line =~ m|^/(.*)|) {
|
||||||
my $regex = $1;
|
my $regex = $1;
|
||||||
if ($1 eq "") {
|
if ($1 eq "") {
|
||||||
@ -1193,7 +1191,7 @@ sub patch_update_file {
|
|||||||
$num = scalar @hunk;
|
$num = scalar @hunk;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
elsif ($line =~ /^e/) {
|
elsif ($other =~ /e/ && $line =~ /^e/) {
|
||||||
my $newhunk = edit_hunk_loop($head, \@hunk, $ix);
|
my $newhunk = edit_hunk_loop($head, \@hunk, $ix);
|
||||||
if (defined $newhunk) {
|
if (defined $newhunk) {
|
||||||
splice @hunk, $ix, 1, $newhunk;
|
splice @hunk, $ix, 1, $newhunk;
|
||||||
@ -1214,9 +1212,6 @@ sub patch_update_file {
|
|||||||
|
|
||||||
my $n_lofs = 0;
|
my $n_lofs = 0;
|
||||||
my @result = ();
|
my @result = ();
|
||||||
if ($mode->{USE}) {
|
|
||||||
push @result, @{$mode->{TEXT}};
|
|
||||||
}
|
|
||||||
for (@hunk) {
|
for (@hunk) {
|
||||||
if ($_->{USE}) {
|
if ($_->{USE}) {
|
||||||
push @result, @{$_->{TEXT}};
|
push @result, @{$_->{TEXT}};
|
||||||
@ -1239,6 +1234,7 @@ sub patch_update_file {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print "\n";
|
print "\n";
|
||||||
|
return $quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub diff_cmd {
|
sub diff_cmd {
|
||||||
|
Loading…
Reference in New Issue
Block a user