* [RFC PATCH] git add -p: new "quit" command at the prompt. @ 2009-04-10 14:57 Matthieu Moy 2009-04-11 19:22 ` Junio C Hamano 0 siblings, 1 reply; 15+ messages in thread From: Matthieu Moy @ 2009-04-10 14:57 UTC (permalink / raw) To: git; +Cc: Matthieu Moy There's already 'd' to stop staging hunks in a file, but no command to stop the interactive staging (for the current files and the remaining ones). This patch implements this functionality, and binds it to 'q'. --- I'm not familiar at all with the code in git-add--interactive.perl, so my code is mostly cut-and-pasted+adapted from the 'd' command. Probably suboptimal. git-add--interactive.perl | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index def062a..210d230 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -894,6 +894,7 @@ sub help_patch_cmd { print colored $help_color, <<\EOF ; y - 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 d - do not stage this hunk nor any of the remaining hunks in the file g - select a hunk to go to @@ -930,7 +931,7 @@ sub patch_update_cmd { @mods); } for (@them) { - patch_update_file($_->{VALUE}); + return 0 if patch_update_file($_->{VALUE}); } } @@ -976,6 +977,7 @@ sub display_hunks { } sub patch_update_file { + my $quit = 0; my ($ix, $num); my $path = shift; my ($head, @hunk) = parse_diff($path); @@ -1006,6 +1008,11 @@ sub patch_update_file { $_->{USE} = 0 foreach ($mode, @hunk); last; } + elsif ($line =~ /^q/i) { + $_->{USE} = 0 foreach ($mode, @hunk); + $quit = 1; + last; + } else { help_patch_cmd(''); next; @@ -1113,6 +1120,16 @@ sub patch_update_file { } next; } + elsif ($line =~ /^q/i) { + while ($ix < $num) { + if (!defined $hunk[$ix]{USE}) { + $hunk[$ix]{USE} = 0; + } + $ix++; + } + $quit = 1; + next; + } elsif ($line =~ m|^/(.*)|) { my $regex = $1; if ($1 eq "") { @@ -1239,6 +1256,7 @@ sub patch_update_file { } print "\n"; + return $quit; } sub diff_cmd { -- 1.6.2.2.449.g92961.dirty ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-10 14:57 [RFC PATCH] git add -p: new "quit" command at the prompt Matthieu Moy @ 2009-04-11 19:22 ` Junio C Hamano 2009-04-12 12:45 ` Matthieu Moy 0 siblings, 1 reply; 15+ messages in thread From: Junio C Hamano @ 2009-04-11 19:22 UTC (permalink / raw) To: Matthieu Moy; +Cc: git Matthieu Moy <Matthieu.Moy@imag.fr> writes: > There's already 'd' to stop staging hunks in a file, but no command to > stop the interactive staging (for the current files and the remaining > ones). This patch implements this functionality, and binds it to 'q'. > --- > > I'm not familiar at all with the code in git-add--interactive.perl, so > my code is mostly cut-and-pasted+adapted from the 'd' command. You can say 'd' and then ^C, I think. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-11 19:22 ` Junio C Hamano @ 2009-04-12 12:45 ` Matthieu Moy 2009-04-12 12:54 ` Sverre Rabbelier ` (3 more replies) 0 siblings, 4 replies; 15+ messages in thread From: Matthieu Moy @ 2009-04-12 12:45 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Junio C Hamano <gitster@pobox.com> writes: > Matthieu Moy <Matthieu.Moy@imag.fr> writes: > >> There's already 'd' to stop staging hunks in a file, but no command to >> stop the interactive staging (for the current files and the remaining >> ones). This patch implements this functionality, and binds it to 'q'. >> --- >> >> I'm not familiar at all with the code in git-add--interactive.perl, so >> my code is mostly cut-and-pasted+adapted from the 'd' command. > > You can say 'd' and then ^C, I think. Yes, you /can/, and that's what I'm doing right now in this situation. But that's undocumented, not so intuitive (I found out I could do that after trying ^C alone, which doesn't work, staged content is recorded on disk at the end of the file only, not after each prompt), ... I thought the situation was common enough to deserve an explicit command. The 'd' command is natural for "git add -i" + patch subcommand, but for "git add -p", I found 'd' mostly useless, and I really want a "quit" command. Sure, I can live without it, but if other people would like to have it, please speak now ;-). -- Matthieu ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-12 12:45 ` Matthieu Moy @ 2009-04-12 12:54 ` Sverre Rabbelier 2009-04-13 1:39 ` Miles Bader 2009-04-12 17:29 ` [RFC PATCH] " Nicolas Sebrecht ` (2 subsequent siblings) 3 siblings, 1 reply; 15+ messages in thread From: Sverre Rabbelier @ 2009-04-12 12:54 UTC (permalink / raw) To: Matthieu Moy; +Cc: Junio C Hamano, git Heya, On Sunday, April 12, 2009, Matthieu Moy <Matthieu.Moy@imag.fr> wrote: > Sure, I can live without it, but if other people would like to have > it, please speak now ;-). Yes please, I would like a q command to git add -p too! -- Cheers, Sverre Rabbelier -- Cheers, Sverre Rabbelier ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-12 12:54 ` Sverre Rabbelier @ 2009-04-13 1:39 ` Miles Bader 0 siblings, 0 replies; 15+ messages in thread From: Miles Bader @ 2009-04-13 1:39 UTC (permalink / raw) To: Sverre Rabbelier; +Cc: Matthieu Moy, Junio C Hamano, git Sverre Rabbelier <srabbelier@gmail.com> writes: > Yes please, I would like a q command to git add -p too! Me too. Even though I've used add -p a lot, I _still_ find myself looking for a quit sub-command sometimes and being momentarily confused because there isn't one... it just seems such a natural thing... -Miles -- Would you like fries with that? ^ permalink raw reply [flat|nested] 15+ messages in thread
* [RFC PATCH] Re: git add -p: new "quit" command at the prompt. 2009-04-12 12:45 ` Matthieu Moy 2009-04-12 12:54 ` Sverre Rabbelier @ 2009-04-12 17:29 ` Nicolas Sebrecht 2009-04-13 16:38 ` [RFC PATCH] " Wincent Colaiuta 2009-04-14 20:44 ` Matthieu Moy 3 siblings, 0 replies; 15+ messages in thread From: Nicolas Sebrecht @ 2009-04-12 17:29 UTC (permalink / raw) To: Matthieu Moy; +Cc: Junio C Hamano, git On Sun, Apr 12, 2009 at 02:45:23PM +0200, Matthieu Moy wrote: > I thought the situation was common enough to deserve an explicit > command. The 'd' command is natural for "git add -i" + patch > subcommand, but for "git add -p", I found 'd' mostly useless, and I > really want a "quit" command. > > Sure, I can live without it, but if other people would like to have > it, please speak now ;-). Acked-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net> -- Nicolas Sebrecht ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-12 12:45 ` Matthieu Moy 2009-04-12 12:54 ` Sverre Rabbelier 2009-04-12 17:29 ` [RFC PATCH] " Nicolas Sebrecht @ 2009-04-13 16:38 ` Wincent Colaiuta 2009-04-14 20:44 ` Matthieu Moy 3 siblings, 0 replies; 15+ messages in thread From: Wincent Colaiuta @ 2009-04-13 16:38 UTC (permalink / raw) To: Matthieu Moy; +Cc: Junio C Hamano, git El 12/4/2009, a las 14:45, Matthieu Moy escribió: > Junio C Hamano <gitster@pobox.com> writes: > >> You can say 'd' and then ^C, I think. > > Yes, you /can/, and that's what I'm doing right now in this situation. > But that's undocumented, not so intuitive (I found out I could do that > after trying ^C alone, which doesn't work, staged content is recorded > on disk at the end of the file only, not after each prompt), ... > > I thought the situation was common enough to deserve an explicit > command. The 'd' command is natural for "git add -i" + patch > subcommand, but for "git add -p", I found 'd' mostly useless, and I > really want a "quit" command. > > Sure, I can live without it, but if other people would like to have > it, please speak now ;-). Yes, I'd like it too. I've been using ^C a lot, but I'd never noticed that changes weren't staged except at the end of each file. Thanks for bringing it up; you might have saved some people (including me) from being bitten by it at some point. Wincent ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-12 12:45 ` Matthieu Moy ` (2 preceding siblings ...) 2009-04-13 16:38 ` [RFC PATCH] " Wincent Colaiuta @ 2009-04-14 20:44 ` Matthieu Moy 2009-04-15 23:25 ` Junio C Hamano 3 siblings, 1 reply; 15+ messages in thread From: Matthieu Moy @ 2009-04-14 20:44 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Matthieu Moy <Matthieu.Moy@imag.fr> writes: > Junio C Hamano <gitster@pobox.com> writes: > >> Matthieu Moy <Matthieu.Moy@imag.fr> writes: >> >>> There's already 'd' to stop staging hunks in a file, but no command to >>> stop the interactive staging (for the current files and the remaining >>> ones). This patch implements this functionality, and binds it to 'q'. >>> --- >>> >>> I'm not familiar at all with the code in git-add--interactive.perl, so >>> my code is mostly cut-and-pasted+adapted from the 'd' command. >> >> You can say 'd' and then ^C, I think. > > Yes, you /can/, and that's what I'm doing right now in this situation. > But that's undocumented, not so intuitive (I found out I could do that > after trying ^C alone, which doesn't work, staged content is recorded > on disk at the end of the file only, not after each prompt), ... > > I thought the situation was common enough to deserve an explicit > command. The 'd' command is natural for "git add -i" + patch > subcommand, but for "git add -p", I found 'd' mostly useless, and I > really want a "quit" command. > > Sure, I can live without it, but if other people would like to have > it, please speak now ;-). I think everybody agree that the intention of the patch is good (well, several pro, and no real counter-argument). I'll send an updated version with documentation soon, but I'd appreciate review and comments on the code. I'm not really happy with the fact that I mainly cut-and-pasted code from the "d" command, but OTOH, that's already how the code is today (huge if/elsif/... with similar elsif blocks for each command). -- Matthieu ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-14 20:44 ` Matthieu Moy @ 2009-04-15 23:25 ` Junio C Hamano 2009-04-16 6:00 ` Jeff King 0 siblings, 1 reply; 15+ messages in thread From: Junio C Hamano @ 2009-04-15 23:25 UTC (permalink / raw) To: Matthieu Moy; +Cc: git, Jeff King Matthieu Moy <Matthieu.Moy@imag.fr> writes: > I think everybody agree that the intention of the patch is good (well, > several pro, and no real counter-argument). Oh, I think we have already passed that state long time ago. It's queued as c9cc8d9 ([NEEDS SIGN OFF, DOC, AND REVIEW] git add -p: new "quit" command at the prompt., 2009-04-10) in 'pu'. I agree that there is a "Huh?" factor in the repeated and similar hunks to patch_update_file, but the first hunk is dealing with the mode change and the second one is about the patch text. Currently parse_diff_header() returns the mode line into $mode and the main loop treats $mode differently from @hunk, which is an array of hunks parsed by parse_diff(). Treating $mode as a "fake hunk" by unshifting it at the beginning of @hunk array and teaching the main loop minor details such as $mode "fake hunk" cannot be edited nor split, I suspect we _could_ unify the two. ca72468 (add--interactive: allow user to choose mode update, 2008-03-27) introduced this duplication. Jeff, what do you think? I am not sure if it is worth it. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-15 23:25 ` Junio C Hamano @ 2009-04-16 6:00 ` Jeff King 2009-04-16 6:52 ` Jeff King 0 siblings, 1 reply; 15+ messages in thread From: Jeff King @ 2009-04-16 6:00 UTC (permalink / raw) To: Junio C Hamano; +Cc: Matthieu Moy, git On Wed, Apr 15, 2009 at 04:25:55PM -0700, Junio C Hamano wrote: > Currently parse_diff_header() returns the mode line into $mode and the > main loop treats $mode differently from @hunk, which is an array of hunks > parsed by parse_diff(). Treating $mode as a "fake hunk" by unshifting it > at the beginning of @hunk array and teaching the main loop minor details > such as $mode "fake hunk" cannot be edited nor split, I suspect we _could_ > unify the two. > > ca72468 (add--interactive: allow user to choose mode update, 2008-03-27) > introduced this duplication. Jeff, what do you think? I am not sure if > it is worth it. Yeah, at least at one point I thought that was possible: http://article.gmane.org/gmane.comp.version-control.git/78340 Let me see how painful it would be. -Peff ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-16 6:00 ` Jeff King @ 2009-04-16 6:52 ` Jeff King 2009-04-16 7:14 ` Jeff King 0 siblings, 1 reply; 15+ messages in thread From: Jeff King @ 2009-04-16 6:52 UTC (permalink / raw) To: Junio C Hamano; +Cc: Matthieu Moy, git On Thu, Apr 16, 2009 at 02:00:27AM -0400, Jeff King wrote: > > Currently parse_diff_header() returns the mode line into $mode and the > > main loop treats $mode differently from @hunk, which is an array of hunks > > parsed by parse_diff(). Treating $mode as a "fake hunk" by unshifting it > > at the beginning of @hunk array and teaching the main loop minor details > > such as $mode "fake hunk" cannot be edited nor split, I suspect we _could_ > > unify the two. > > Let me see how painful it would be. Not too painful at all. We can _almost_ get away with a really minimal "just unshift it" patch, but calling splittable_hunk() generates some perl warnings (because the hunk lacks @@ lines), and doing a hunk edit seems to confuse the code (it duplicates the "old mode" line for some reason). It is not worth trying to fix, though, as editing the mode hunk is not useful in practice (see the commit message below). It would also be possible to refactor the header parsing to just pull the mode lines out as we are parsing the hunks. However, it is probably not worth the added complexity: you have header lines, then some mode lines, then some more header lines, then some hunks. So you have to keep more state around to do a linear parse. Anyway, I think this is a nice improvement on its own, and it should make Matthieu's patch a little cleaner. -- >8 -- Subject: [PATCH] add-interactive: refactor mode hunk handling The original implementation considered the mode separately from the rest of the hunks, asking about it outside the main hunk-selection loop. This patch instead places a mode change as the first hunk in the loop. This has two advantages: 1. less duplicated code (since we use the main selection loop). This also cleans up an inconsistency, which is that the main selection loop separates options with a comma, whereas the mode prompt used slashes. 2. users can now skip the mode change and come back to it, search for it (via "/mode"), etc, as they can with other hunks. To facilitate this, each hunk is now marked with a "type". Mode hunks are not considered for splitting (which would make no sense, and also confuses the split_hunk function), nor are they editable. In theory, one could edit the mode lines and change to an entirely new mode. In practice, there are only two modes that git cares about (0644 and 0755), so either you want to move from one to the other or not (and you can do that by staging or not staging). Signed-off-by: Jeff King <peff@peff.net> --- git-add--interactive.perl | 59 ++++++++++++++++----------------------------- 1 files changed, 21 insertions(+), 38 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index def062a..b895e3b 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -620,11 +620,12 @@ sub parse_diff { if ($diff_use_color) { @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++) { if ($diff[$i] =~ /^@@ /) { - push @hunk, { TEXT => [], DISPLAY => [] }; + push @hunk, { TEXT => [], DISPLAY => [], + TYPE => 'hunk' }; } push @{$hunk[-1]{TEXT}}, $diff[$i]; push @{$hunk[-1]{DISPLAY}}, @@ -636,8 +637,8 @@ sub parse_diff { sub parse_diff_header { my $src = shift; - my $head = { TEXT => [], DISPLAY => [] }; - my $mode = { TEXT => [], DISPLAY => [] }; + my $head = { TEXT => [], DISPLAY => [], TYPE => 'header' }; + my $mode = { TEXT => [], DISPLAY => [], TYPE => 'mode' }; for (my $i = 0; $i < @{$src->{TEXT}}; $i++) { my $dest = $src->{TEXT}->[$i] =~ /^(old|new) mode (\d+)$/ ? @@ -684,6 +685,7 @@ sub split_hunk { my $this = +{ TEXT => [], DISPLAY => [], + TYPE => 'hunk', OLD => $o_ofs, NEW => $n_ofs, OCNT => 0, @@ -873,7 +875,11 @@ sub edit_hunk_loop { if (!defined $text) { return undef; } - my $newhunk = { TEXT => $text, USE => 1 }; + my $newhunk = { + TEXT => $text, + TYPE => $hunk->[$ix]->{TYPE}, + USE => 1 + }; if (diff_applies($head, @{$hunk}[0..$ix-1], $newhunk, @@ -985,32 +991,7 @@ sub patch_update_file { } if (@{$mode->{TEXT}}) { - while (1) { - 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; - } - } + unshift @hunk, $mode; } $num = scalar @hunk; @@ -1054,14 +1035,19 @@ sub patch_update_file { } last if (!$undecided); - if (hunk_splittable($hunk[$ix]{TEXT})) { + if ($hunk[$ix]{TYPE} eq 'hunk' && + hunk_splittable($hunk[$ix]{TEXT})) { $other .= ',s'; } - $other .= ',e'; + if ($hunk[$ix]{TYPE} eq 'hunk') { + $other .= ',e'; + } for (@{$hunk[$ix]{DISPLAY}}) { 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; if ($line) { if ($line =~ /^y/i) { @@ -1193,7 +1179,7 @@ sub patch_update_file { $num = scalar @hunk; next; } - elsif ($line =~ /^e/) { + elsif ($other =~ /e/ && $line =~ /^e/) { my $newhunk = edit_hunk_loop($head, \@hunk, $ix); if (defined $newhunk) { splice @hunk, $ix, 1, $newhunk; @@ -1214,9 +1200,6 @@ sub patch_update_file { my $n_lofs = 0; my @result = (); - if ($mode->{USE}) { - push @result, @{$mode->{TEXT}}; - } for (@hunk) { if ($_->{USE}) { push @result, @{$_->{TEXT}}; -- 1.6.3.rc0.157.g02b29.dirty ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-16 6:52 ` Jeff King @ 2009-04-16 7:14 ` Jeff King 2009-04-16 16:44 ` Matthieu Moy 0 siblings, 1 reply; 15+ messages in thread From: Jeff King @ 2009-04-16 7:14 UTC (permalink / raw) To: Junio C Hamano; +Cc: Matthieu Moy, git On Thu, Apr 16, 2009 at 02:52:23AM -0400, Jeff King wrote: > Anyway, I think this is a nice improvement on its own, and it should > make Matthieu's patch a little cleaner. Hmm, it looks like you just applied Matthieu's patch to next already. Here is the rebased version of mine (the conflict resolution was pretty trivial, though: just delete the newly added 'q' option from the mode loop, which no longer exists). -- >8 -- Subject: [PATCH] add-interactive: refactor mode hunk handling The original implementation considered the mode separately from the rest of the hunks, asking about it outside the main hunk-selection loop. This patch instead places a mode change as the first hunk in the loop. This has two advantages: 1. less duplicated code (since we use the main selection loop). This also cleans up an inconsistency, which is that the main selection loop separates options with a comma, whereas the mode prompt used slashes. 2. users can now skip the mode change and come back to it, search for it (via "/mode"), etc, as they can with other hunks. To facilitate this, each hunk is now marked with a "type". Mode hunks are not considered for splitting (which would make no sense, and also confuses the split_hunk function), nor are they editable. In theory, one could edit the mode lines and change to a new mode. In practice, there are only two modes that git cares about (0644 and 0755), so either you want to move from one to the other or not (and you can do that by staging or not staging). Signed-off-by: Jeff King <peff@peff.net> --- git-add--interactive.perl | 64 ++++++++++++++------------------------------ 1 files changed, 21 insertions(+), 43 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 210d230..60dd1b5 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -620,11 +620,12 @@ sub parse_diff { if ($diff_use_color) { @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++) { if ($diff[$i] =~ /^@@ /) { - push @hunk, { TEXT => [], DISPLAY => [] }; + push @hunk, { TEXT => [], DISPLAY => [], + TYPE => 'hunk' }; } push @{$hunk[-1]{TEXT}}, $diff[$i]; push @{$hunk[-1]{DISPLAY}}, @@ -636,8 +637,8 @@ sub parse_diff { sub parse_diff_header { my $src = shift; - my $head = { TEXT => [], DISPLAY => [] }; - my $mode = { TEXT => [], DISPLAY => [] }; + my $head = { TEXT => [], DISPLAY => [], TYPE => 'header' }; + my $mode = { TEXT => [], DISPLAY => [], TYPE => 'mode' }; for (my $i = 0; $i < @{$src->{TEXT}}; $i++) { my $dest = $src->{TEXT}->[$i] =~ /^(old|new) mode (\d+)$/ ? @@ -684,6 +685,7 @@ sub split_hunk { my $this = +{ TEXT => [], DISPLAY => [], + TYPE => 'hunk', OLD => $o_ofs, NEW => $n_ofs, OCNT => 0, @@ -873,7 +875,11 @@ sub edit_hunk_loop { if (!defined $text) { return undef; } - my $newhunk = { TEXT => $text, USE => 1 }; + my $newhunk = { + TEXT => $text, + TYPE => $hunk->[$ix]->{TYPE}, + USE => 1 + }; if (diff_applies($head, @{$hunk}[0..$ix-1], $newhunk, @@ -987,37 +993,7 @@ sub patch_update_file { } if (@{$mode->{TEXT}}) { - while (1) { - 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; - } - elsif ($line =~ /^q/i) { - $_->{USE} = 0 foreach ($mode, @hunk); - $quit = 1; - last; - } - else { - help_patch_cmd(''); - next; - } - } + unshift @hunk, $mode; } $num = scalar @hunk; @@ -1061,14 +1037,19 @@ sub patch_update_file { } last if (!$undecided); - if (hunk_splittable($hunk[$ix]{TEXT})) { + if ($hunk[$ix]{TYPE} eq 'hunk' && + hunk_splittable($hunk[$ix]{TEXT})) { $other .= ',s'; } - $other .= ',e'; + if ($hunk[$ix]{TYPE} eq 'hunk') { + $other .= ',e'; + } for (@{$hunk[$ix]{DISPLAY}}) { 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; if ($line) { if ($line =~ /^y/i) { @@ -1210,7 +1191,7 @@ sub patch_update_file { $num = scalar @hunk; next; } - elsif ($line =~ /^e/) { + elsif ($other =~ /e/ && $line =~ /^e/) { my $newhunk = edit_hunk_loop($head, \@hunk, $ix); if (defined $newhunk) { splice @hunk, $ix, 1, $newhunk; @@ -1231,9 +1212,6 @@ sub patch_update_file { my $n_lofs = 0; my @result = (); - if ($mode->{USE}) { - push @result, @{$mode->{TEXT}}; - } for (@hunk) { if ($_->{USE}) { push @result, @{$_->{TEXT}}; -- 1.6.3.rc0.204.g6bb2 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] git add -p: new "quit" command at the prompt. 2009-04-16 7:14 ` Jeff King @ 2009-04-16 16:44 ` Matthieu Moy 2009-04-16 16:46 ` [PATCH 1/2] " Matthieu Moy 0 siblings, 1 reply; 15+ messages in thread From: Matthieu Moy @ 2009-04-16 16:44 UTC (permalink / raw) To: Junio C Hamano; +Cc: Jeff King, git Jeff King <peff@peff.net> writes: > On Thu, Apr 16, 2009 at 02:52:23AM -0400, Jeff King wrote: > >> Anyway, I think this is a nice improvement on its own, and it should >> make Matthieu's patch a little cleaner. > > Hmm, it looks like you just applied Matthieu's patch to next > already. 2 things : my patch was lacking a Signed-off-by:, and your (Junio) modification to add the documentation has a typo (quite instead of quit). I'm resending the patch with a Signed-off-by, in case, and another patch fixes the typo (and updates the help with 'g' and '/'). -- Matthieu ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 1/2] git add -p: new "quit" command at the prompt. 2009-04-16 16:44 ` Matthieu Moy @ 2009-04-16 16:46 ` Matthieu Moy 2009-04-16 16:46 ` [PATCH 2/2] Update git-add.txt according to the new possibilities of 'git add -p' Matthieu Moy 0 siblings, 1 reply; 15+ messages in thread From: Matthieu Moy @ 2009-04-16 16:46 UTC (permalink / raw) To: gitster, git; +Cc: Matthieu Moy There's already 'd' to stop staging hunks in a file, but no explicit command to stop the interactive staging (for the current files and the remaining ones). Of course you can do 'd' and then ^C, but it would be more intuitive to allow 'quit' action. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com> --- Documentation/git-add.txt | 1 + git-add--interactive.perl | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index ce71838..709e04b 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -245,6 +245,7 @@ patch:: y - stage this hunk n - do not stage this hunk + q - quite, do not stage this hunk nor any of the remaining ones 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 j - leave this hunk undecided, see next undecided hunk diff --git a/git-add--interactive.perl b/git-add--interactive.perl index def062a..210d230 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -894,6 +894,7 @@ sub help_patch_cmd { print colored $help_color, <<\EOF ; y - 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 d - do not stage this hunk nor any of the remaining hunks in the file g - select a hunk to go to @@ -930,7 +931,7 @@ sub patch_update_cmd { @mods); } for (@them) { - patch_update_file($_->{VALUE}); + return 0 if patch_update_file($_->{VALUE}); } } @@ -976,6 +977,7 @@ sub display_hunks { } sub patch_update_file { + my $quit = 0; my ($ix, $num); my $path = shift; my ($head, @hunk) = parse_diff($path); @@ -1006,6 +1008,11 @@ sub patch_update_file { $_->{USE} = 0 foreach ($mode, @hunk); last; } + elsif ($line =~ /^q/i) { + $_->{USE} = 0 foreach ($mode, @hunk); + $quit = 1; + last; + } else { help_patch_cmd(''); next; @@ -1113,6 +1120,16 @@ sub patch_update_file { } next; } + elsif ($line =~ /^q/i) { + while ($ix < $num) { + if (!defined $hunk[$ix]{USE}) { + $hunk[$ix]{USE} = 0; + } + $ix++; + } + $quit = 1; + next; + } elsif ($line =~ m|^/(.*)|) { my $regex = $1; if ($1 eq "") { @@ -1239,6 +1256,7 @@ sub patch_update_file { } print "\n"; + return $quit; } sub diff_cmd { -- 1.6.2.2.449.g92961.dirty ^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 2/2] Update git-add.txt according to the new possibilities of 'git add -p'. 2009-04-16 16:46 ` [PATCH 1/2] " Matthieu Moy @ 2009-04-16 16:46 ` Matthieu Moy 0 siblings, 0 replies; 15+ messages in thread From: Matthieu Moy @ 2009-04-16 16:46 UTC (permalink / raw) To: gitster, git; +Cc: Matthieu Moy The text is merely cut-and-pasted from git-add--interactive.perl. The cut-and-paste also fixes a typo. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> --- Documentation/git-add.txt | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index 709e04b..d938b42 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -245,9 +245,11 @@ patch:: y - stage this hunk n - do not stage this hunk - q - quite, do not stage this hunk nor any of the remaining ones + q - quit, do not stage this hunk nor any of the remaining ones 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 + 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 hunk k - leave this hunk undecided, see previous undecided hunk -- 1.6.2.2.449.g92961.dirty ^ permalink raw reply related [flat|nested] 15+ messages in thread
end of thread, other threads:[~2009-04-16 16:53 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-04-10 14:57 [RFC PATCH] git add -p: new "quit" command at the prompt Matthieu Moy 2009-04-11 19:22 ` Junio C Hamano 2009-04-12 12:45 ` Matthieu Moy 2009-04-12 12:54 ` Sverre Rabbelier 2009-04-13 1:39 ` Miles Bader 2009-04-12 17:29 ` [RFC PATCH] " Nicolas Sebrecht 2009-04-13 16:38 ` [RFC PATCH] " Wincent Colaiuta 2009-04-14 20:44 ` Matthieu Moy 2009-04-15 23:25 ` Junio C Hamano 2009-04-16 6:00 ` Jeff King 2009-04-16 6:52 ` Jeff King 2009-04-16 7:14 ` Jeff King 2009-04-16 16:44 ` Matthieu Moy 2009-04-16 16:46 ` [PATCH 1/2] " Matthieu Moy 2009-04-16 16:46 ` [PATCH 2/2] Update git-add.txt according to the new possibilities of 'git add -p' Matthieu Moy
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).