From 57886bc7fb9413becf4c240320d61bf641600762 Mon Sep 17 00:00:00 2001 From: William Pursell Date: Thu, 27 Nov 2008 04:07:52 +0000 Subject: [PATCH 1/5] git-add -i/-p: Change prompt separater from slash to comma Otherwise the find command '/' soon to be introduced will be hard to see. Signed-off-by: William Pursell Signed-off-by: Junio C Hamano --- git-add--interactive.perl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index ca60356d0..ca5036334 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -929,22 +929,22 @@ sub patch_update_file { for ($i = 0; $i < $ix; $i++) { if (!defined $hunk[$i]{USE}) { $prev = 1; - $other .= '/k'; + $other .= ',k'; last; } } if ($ix) { - $other .= '/K'; + $other .= ',K'; } for ($i = $ix + 1; $i < $num; $i++) { if (!defined $hunk[$i]{USE}) { $next = 1; - $other .= '/j'; + $other .= ',j'; last; } } if ($ix < $num - 1) { - $other .= '/J'; + $other .= ',J'; } if ($num > 1) { $other .= '/g'; @@ -958,13 +958,13 @@ sub patch_update_file { last if (!$undecided); if (hunk_splittable($hunk[$ix]{TEXT})) { - $other .= '/s'; + $other .= ',s'; } - $other .= '/e'; + $other .= ',e'; for (@{$hunk[$ix]{DISPLAY}}) { print; } - print colored $prompt_color, "Stage this hunk [y/n/a/d$other/?]? "; + print colored $prompt_color, "Stage this hunk [y,n,a,d$other,?]? "; my $line = ; if ($line) { if ($line =~ /^y/i) { From dd971cc9d6588307447075b2352127a9e24dd3e1 Mon Sep 17 00:00:00 2001 From: William Pursell Date: Thu, 27 Nov 2008 04:07:57 +0000 Subject: [PATCH 2/5] Add / command in add --patch This command allows the user to skip hunks that don't match the specified regex. Signed-off-by: William Pursell Signed-off-by: Junio C Hamano --- git-add--interactive.perl | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index ca5036334..64ad28998 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -801,6 +801,7 @@ sub help_patch_cmd { 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 @@ -964,7 +965,7 @@ sub patch_update_file { for (@{$hunk[$ix]{DISPLAY}}) { print; } - print colored $prompt_color, "Stage this hunk [y,n,a,d$other,?]? "; + print colored $prompt_color, "Stage this hunk [y,n,a,d,/$other,?]? "; my $line = ; if ($line) { if ($line =~ /^y/i) { @@ -1013,6 +1014,31 @@ sub patch_update_file { } next; } + elsif ($line =~ m|^/(.*)|) { + my $search_string; + eval { + $search_string = qr{$1}m; + }; + if ($@) { + my ($err,$exp) = ($@, $1); + $err =~ s/ at .*git-add--interactive line \d+, line \d+.*$//; + print STDERR "Malformed search regexp $exp: $err\n"; + next; + } + my $iy = $ix; + while (1) { + my $text = join ("", @{$hunk[$iy]{TEXT}}); + last if ($text =~ $search_string); + $iy++; + $iy = 0 if ($iy >= $num); + if ($ix == $iy) { + print STDERR "No hunk matches the given pattern\n"; + last; + } + } + $ix = $iy; + next; + } elsif ($other =~ /K/ && $line =~ /^K/) { $ix--; next; From ace30ba813ed723534c3b4d223db6eddea417de7 Mon Sep 17 00:00:00 2001 From: William Pursell Date: Thu, 27 Nov 2008 04:08:03 +0000 Subject: [PATCH 3/5] In add --patch, Handle K,k,J,j slightly more gracefully. Instead of printing the help menu, this will print "No next hunk" and then process the given hunk again. Signed-off-by: William Pursell Signed-off-by: Junio C Hamano --- git-add--interactive.perl | 43 +++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 64ad28998..30ddab293 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -1039,29 +1039,42 @@ sub patch_update_file { $ix = $iy; next; } - elsif ($other =~ /K/ && $line =~ /^K/) { - $ix--; + elsif ($line =~ /^K/) { + if ($other =~ /K/) { + $ix--; + } + else { + print STDERR "No previous hunk\n"; + } next; } - elsif ($other =~ /J/ && $line =~ /^J/) { - $ix++; + elsif ($line =~ /^J/) { + if ($other =~ /J/) { + $ix++; + } + else { + print STDERR "No next hunk\n"; + } next; } - elsif ($other =~ /k/ && $line =~ /^k/) { - while (1) { - $ix--; - last if (!$ix || - !defined $hunk[$ix]{USE}); + elsif ($line =~ /^k/) { + if ($other =~ /k/) { + while (1) { + $ix--; + last if (!$ix || + !defined $hunk[$ix]{USE}); + } + } + else { + print STDERR "No previous hunk\n"; } next; } - elsif ($other =~ /j/ && $line =~ /^j/) { - while (1) { - $ix++; - last if ($ix >= $num || - !defined $hunk[$ix]{USE}); + elsif ($line =~ /^j/) { + if ($other !~ /j/) { + print STDERR "No next hunk\n"; + next; } - next; } elsif ($other =~ /s/ && $line =~ /^s/) { my @split = split_hunk($hunk[$ix]{TEXT}, $hunk[$ix]{DISPLAY}); From 4404b2e39236e6f9c5bff121fc920d7ec17f7b6d Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Mon, 2 Feb 2009 22:46:28 +0100 Subject: [PATCH 4/5] add -p: change prompt separator for 'g' 57886bc (git-add -i/-p: Change prompt separater from slash to comma, 2008-11-27) changed the prompt separator to ',', but forgot to adapt the 'g' (goto) command. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- git-add--interactive.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 30ddab293..551b4475b 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -948,7 +948,7 @@ sub patch_update_file { $other .= ',J'; } if ($num > 1) { - $other .= '/g'; + $other .= ',g'; } for ($i = 0; $i < $num; $i++) { if (!defined $hunk[$i]{USE}) { From 68c02d7c462e1748578209346f050a587c040139 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Mon, 2 Feb 2009 22:46:29 +0100 Subject: [PATCH 5/5] add -p: trap Ctrl-D in 'goto' mode If the user hit Ctrl-D (EOF) while the script was in 'go to hunk?' mode, it threw an undefined variable error. Explicitly test for EOF and have it re-enter the goto prompt loop. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- git-add--interactive.perl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 551b4475b..3bf0cda4e 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -994,6 +994,9 @@ sub patch_update_file { } print "go to which hunk$extra? "; $response = ; + if (!defined $response) { + $response = ''; + } chomp $response; } if ($response !~ /^\s*\d+\s*$/) {