@@ -801,6 +801,7 @@ sub help_patch_cmd {
801
801
a - stage this and all the remaining hunks in the file
802
802
d - do not stage this hunk nor any of the remaining hunks in the file
803
803
g - select a hunk to go to
804
+ / - search for a hunk matching the given regex
804
805
j - leave this hunk undecided, see next undecided hunk
805
806
J - leave this hunk undecided, see next hunk
806
807
k - leave this hunk undecided, see previous undecided hunk
@@ -929,25 +930,25 @@ sub patch_update_file {
929
930
for ($i = 0; $i < $ix ; $i ++) {
930
931
if (!defined $hunk [$i ]{USE }) {
931
932
$prev = 1;
932
- $other .= ' / k' ;
933
+ $other .= ' , k' ;
933
934
last ;
934
935
}
935
936
}
936
937
if ($ix ) {
937
- $other .= ' / K' ;
938
+ $other .= ' , K' ;
938
939
}
939
940
for ($i = $ix + 1; $i < $num ; $i ++) {
940
941
if (!defined $hunk [$i ]{USE }) {
941
942
$next = 1;
942
- $other .= ' / j' ;
943
+ $other .= ' , j' ;
943
944
last ;
944
945
}
945
946
}
946
947
if ($ix < $num - 1) {
947
- $other .= ' / J' ;
948
+ $other .= ' , J' ;
948
949
}
949
950
if ($num > 1) {
950
- $other .= ' / g' ;
951
+ $other .= ' , g' ;
951
952
}
952
953
for ($i = 0; $i < $num ; $i ++) {
953
954
if (!defined $hunk [$i ]{USE }) {
@@ -958,13 +959,13 @@ sub patch_update_file {
958
959
last if (!$undecided );
959
960
960
961
if (hunk_splittable($hunk [$ix ]{TEXT })) {
961
- $other .= ' / s' ;
962
+ $other .= ' , s' ;
962
963
}
963
- $other .= ' / e' ;
964
+ $other .= ' , e' ;
964
965
for (@{$hunk [$ix ]{DISPLAY }}) {
965
966
print ;
966
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 , ?]? " ;
968
969
my $line = <STDIN >;
969
970
if ($line ) {
970
971
if ($line =~ / ^y/i ) {
@@ -993,6 +994,9 @@ sub patch_update_file {
993
994
}
994
995
print " go to which hunk$extra ? " ;
995
996
$response = <STDIN >;
997
+ if (!defined $response ) {
998
+ $response = ' ' ;
999
+ }
996
1000
chomp $response ;
997
1001
}
998
1002
if ($response !~ / ^\s *\d +\s *$ / ) {
@@ -1013,30 +1017,68 @@ sub patch_update_file {
1013
1017
}
1014
1018
next ;
1015
1019
}
1016
- elsif ($other =~ / K/ && $line =~ / ^K/ ) {
1017
- $ix --;
1018
- next ;
1019
- }
1020
- elsif ($other =~ / J/ && $line =~ / ^J/ ) {
1021
- $ix ++;
1020
+ elsif ($line =~ m | ^/(.*)| ) {
1021
+ my $search_string ;
1022
+ eval {
1023
+ $search_string = qr {$1 } m ;
1024
+ };
1025
+ if ($@ ) {
1026
+ my ($err ,$exp ) = ($@ , $1 );
1027
+ $err =~ s / at .*git-add--interactive line \d +, <STDIN> line \d +.*$// ;
1028
+ print STDERR " Malformed search regexp $exp : $err \n " ;
1029
+ next ;
1030
+ }
1031
+ my $iy = $ix ;
1032
+ while (1) {
1033
+ my $text = join (" " , @{$hunk [$iy ]{TEXT }});
1034
+ last if ($text =~ $search_string );
1035
+ $iy ++;
1036
+ $iy = 0 if ($iy >= $num );
1037
+ if ($ix == $iy ) {
1038
+ print STDERR " No hunk matches the given pattern\n " ;
1039
+ last ;
1040
+ }
1041
+ }
1042
+ $ix = $iy ;
1022
1043
next ;
1023
1044
}
1024
- elsif ($other =~ / k / && $ line =~ / ^k / ) {
1025
- while (1 ) {
1045
+ elsif ($line =~ / ^K / ) {
1046
+ if ( $other =~ / K / ) {
1026
1047
$ix --;
1027
- last if (!$ix ||
1028
- !defined $hunk [$ix ]{USE });
1048
+ }
1049
+ else {
1050
+ print STDERR " No previous hunk\n " ;
1029
1051
}
1030
1052
next ;
1031
1053
}
1032
- elsif ($other =~ / j / && $ line =~ / ^j / ) {
1033
- while (1 ) {
1054
+ elsif ($line =~ / ^J / ) {
1055
+ if ( $other =~ / J / ) {
1034
1056
$ix ++;
1035
- last if ($ix >= $num ||
1036
- !defined $hunk [$ix ]{USE });
1057
+ }
1058
+ else {
1059
+ print STDERR " No next hunk\n " ;
1060
+ }
1061
+ next ;
1062
+ }
1063
+ elsif ($line =~ / ^k/ ) {
1064
+ if ($other =~ / k/ ) {
1065
+ while (1) {
1066
+ $ix --;
1067
+ last if (!$ix ||
1068
+ !defined $hunk [$ix ]{USE });
1069
+ }
1070
+ }
1071
+ else {
1072
+ print STDERR " No previous hunk\n " ;
1037
1073
}
1038
1074
next ;
1039
1075
}
1076
+ elsif ($line =~ / ^j/ ) {
1077
+ if ($other !~ / j/ ) {
1078
+ print STDERR " No next hunk\n " ;
1079
+ next ;
1080
+ }
1081
+ }
1040
1082
elsif ($other =~ / s/ && $line =~ / ^s/ ) {
1041
1083
my @split = split_hunk($hunk [$ix ]{TEXT }, $hunk [$ix ]{DISPLAY });
1042
1084
if (1 < @split ) {
0 commit comments