summaryrefslogtreecommitdiff
path: root/git-add--interactive.perl
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2018-03-16 10:13:46 +0000
committerJunio C Hamano <gitster@pobox.com>2018-03-16 12:08:32 -0700
commit05f700ef262d1d318a45dd0ce299bbd076d95963 (patch)
treef89c8fd25e9e89bc236769754e88029ff72a3b3f /git-add--interactive.perl
parent4fa64a54f4c6dd3e1ec05b95e40823d081e2d238 (diff)
downloadgit-pw/add-p-select.tar.gz
add -p: optimize line selection for short hunkspw/add-p-select
If there are fewer than ten changes in a hunk then make spaces optional when selecting individual lines. This means that for short hunks one can just type 1-357 to stage lines 1, 2, 3, 5 & 7. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-xgit-add--interactive.perl26
1 files changed, 26 insertions, 0 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 8bc0626f0e..86e373a101 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1082,6 +1082,29 @@ sub check_hunk_label {
return 1;
}
+sub split_hunk_selection {
+ local $_;
+ my @fields = @_;
+ my @ret;
+ for (@fields) {
+ while ($_ ne '') {
+ if (/^[0-9]-$/) {
+ push @ret, $_;
+ last;
+ } elsif (/^([0-9](?:-[0-9])?)(.*)/) {
+ push @ret, $1;
+ $_ = $2;
+ } else {
+ error_msg sprintf
+ __("invalid hunk line '%s'\n"),
+ substr($_, 0, 1);
+ return ();
+ }
+ }
+ }
+ return @ret;
+}
+
sub parse_hunk_selection {
local $_;
my ($hunk, $line) = @_;
@@ -1100,6 +1123,9 @@ sub parse_hunk_selection {
}
}
}
+ if ($max_label < 10) {
+ @fields = split_hunk_selection(@fields) or return undef;
+ }
for (@fields) {
if (my ($lo, $hi) = /^([0-9]+)-([0-9]*)$/) {
if ($hi eq '') {