@matheusbsbs / matheus-bagliano / commits / dd971cc9d6
Fork 0

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 <bill.pursell@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

William Pursell committed Nov 27, 2008 at 04:07 UTC dd971cc9d6588307447075b2352127a9e24dd3e1
1 file changed +27 -1
git-add--interactive.perl
+27 -1
@@ -801,6 +801,7 @@ n - do not stage this hunk
801 a - stage this and all the remaining hunks in the file
802 d - do not stage this hunk nor any of the remaining hunks in the file
803 g - select a hunk to go to
804 +/ - search for a hunk matching the given regex
805 j - leave this hunk undecided, see next undecided hunk
806 J - leave this hunk undecided, see next hunk
807 k - leave this hunk undecided, see previous undecided hunk
@@ -964,7 +965,7 @@ sub patch_update_file {
965 for (@{$hunk[$ix]{DISPLAY}}) {
966 print;
967 }
967 - print colored $prompt_color, "Stage this hunk [y,n,a,d$other,?]? ";
968 + print colored $prompt_color, "Stage this hunk [y,n,a,d,/$other,?]? ";
969 my $line = <STDIN>;
970 if ($line) {
971 if ($line =~ /^y/i) {
@@ -1013,6 +1014,31 @@ sub patch_update_file {
1014 }
1015 next;
1016 }
1017 + elsif ($line =~ m|^/(.*)|) {
1018 + my $search_string;
1019 + eval {
1020 + $search_string = qr{$1}m;
1021 + };
1022 + if ($@) {
1023 + my ($err,$exp) = ($@, $1);
1024 + $err =~ s/ at .*git-add--interactive line \d+, <STDIN> line \d+.*$//;
1025 + print STDERR "Malformed search regexp $exp: $err\n";
1026 + next;
1027 + }
1028 + my $iy = $ix;
1029 + while (1) {
1030 + my $text = join ("", @{$hunk[$iy]{TEXT}});
1031 + last if ($text =~ $search_string);
1032 + $iy++;
1033 + $iy = 0 if ($iy >= $num);
1034 + if ($ix == $iy) {
1035 + print STDERR "No hunk matches the given pattern\n";
1036 + last;
1037 + }
1038 + }
1039 + $ix = $iy;
1040 + next;
1041 + }
1042 elsif ($other =~ /K/ && $line =~ /^K/) {
1043 $ix--;
1044 next;