add -p: allow line selection to be inverted
[gitweb.git] / git-add--interactive.perl
index d8131d9a0a20d7984256cbc463be948004879cac..8bc0626f0e29cc8a4ea3408352b5c867c34b0834 100755 (executable)
@@ -1085,9 +1085,21 @@ sub check_hunk_label {
 sub parse_hunk_selection {
        local $_;
        my ($hunk, $line) = @_;
-       my $max_label = $hunk->{MAX_LABEL};
+       my ($max_label, $invert) = ($hunk->{MAX_LABEL}, undef);
        my @selected = (0) x ($max_label + 1);
        my @fields = split(/[,\s]+/, $line);
+       if ($fields[0] =~ /^-(.*)/) {
+               $invert = 1;
+               if ($1 ne '') {
+                       $fields[0] = $1;
+               } else {
+                       shift @fields;
+                       unless (@fields) {
+                               error_msg __("no lines to invert\n");
+                               return undef;
+                       }
+               }
+       }
        for (@fields) {
                if (my ($lo, $hi) = /^([0-9]+)-([0-9]*)$/) {
                        if ($hi eq '') {
@@ -1107,6 +1119,9 @@ sub parse_hunk_selection {
                        return undef;
                }
        }
+       if ($invert) {
+               @selected = map { !$_ } @selected;
+       }
        return \@selected;
 }