File tree Expand file tree Collapse file tree 3 files changed +32
-5
lines changed Expand file tree Collapse file tree 3 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -340,10 +340,11 @@ patch::
340
340
If you press "l" then the hunk will be reprinted with each insertion or
341
341
deletion labelled with a number and you will be prompted to enter which
342
342
lines you wish to select. Individual line numbers should be separated by
343
- a space or comma, to specify a range of lines use a dash between
344
- them. If the upper bound of a range of lines is omitted it defaults to
345
- the last line. To invert the selection prefix it with "-" so "-3-5,8"
346
- will select everything except lines 3, 4, 5 and 8.
343
+ a space or comma (these can be omitted if there are fewer than ten
344
+ labelled lines), to specify a range of lines use a dash between them. If
345
+ the upper bound of a range of lines is omitted it defaults to the last
346
+ line. To invert the selection prefix it with "-" so "-3-5,8" will select
347
+ everything except lines 3, 4, 5 and 8.
347
348
+
348
349
After deciding the fate for all hunks, if there is any hunk
349
350
that was chosen, the index is updated with the selected hunks.
Original file line number Diff line number Diff line change @@ -1082,6 +1082,29 @@ sub check_hunk_label {
1082
1082
return 1;
1083
1083
}
1084
1084
1085
+ sub split_hunk_selection {
1086
+ local $_ ;
1087
+ my @fields = @_ ;
1088
+ my @ret ;
1089
+ for (@fields ) {
1090
+ while ($_ ne ' ' ) {
1091
+ if (/ ^[0-9]-$ / ) {
1092
+ push @ret , $_ ;
1093
+ last ;
1094
+ } elsif (/ ^([0-9](?:-[0-9])?)(.*)/ ) {
1095
+ push @ret , $1 ;
1096
+ $_ = $2 ;
1097
+ } else {
1098
+ error_msg sprintf
1099
+ __(" invalid hunk line '%s '\n " ),
1100
+ substr ($_ , 0, 1);
1101
+ return ();
1102
+ }
1103
+ }
1104
+ }
1105
+ return @ret ;
1106
+ }
1107
+
1085
1108
sub parse_hunk_selection {
1086
1109
local $_ ;
1087
1110
my ($hunk , $line ) = @_ ;
@@ -1100,6 +1123,9 @@ sub parse_hunk_selection {
1100
1123
}
1101
1124
}
1102
1125
}
1126
+ if ($max_label < 10) {
1127
+ @fields = split_hunk_selection(@fields ) or return undef ;
1128
+ }
1103
1129
for (@fields ) {
1104
1130
if (my ($lo , $hi ) = /^([0-9]+)-([0-9]*)$/ ) {
1105
1131
if ($hi eq ' ' ) {
Original file line number Diff line number Diff line change @@ -410,7 +410,7 @@ test_expect_success 'setup expected diff' '
410
410
'
411
411
412
412
test_expect_success ' can reset individual lines of patch' '
413
- printf "%s\n" l "-1 3" |
413
+ printf "%s\n" l -13 |
414
414
EDITOR=: git reset -p 2>error &&
415
415
test_must_be_empty error &&
416
416
git diff --cached HEAD >actual &&
You can’t perform that action at this time.
0 commit comments