[PATCH 2/2] Teach git-add--interactive to highlight untracked file prefixes
From: Wincent Colaiuta <hidden>
Date: 2016-06-15 22:43:55
Subsystem:
the rest · Maintainer:
Linus Torvalds
Tweak the list_and_choose function so that untracked files will use the automatic prefix detection machinery. This works because while previously we handled arrays (command menus), hashes (patch subcommand) now we explicitly handle strings (add untracked subcommand). Signed-off-by: Wincent Colaiuta <redacted> --- git-add--interactive.perl | 30 +++++++++++++++--------------- 1 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 0fb808f..a1aee21 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl@@ -256,21 +256,21 @@ sub list_and_choose { for ($i = 0; $i < @stuff; $i++) { my $chosen = $chosen[$i] ? '*' : ' '; my $print = $stuff[$i]; - if (ref $print) { - if ((ref $print) eq 'ARRAY') { - $print = @prefixes ? - highlight_prefix(@{$prefixes[$i]}) : - $print->[0]; - } - else { - my $value = @prefixes ? - highlight_prefix(@{$prefixes[$i]}) : - $print->{VALUE}; - $print = sprintf($status_fmt, - $print->{INDEX}, - $print->{FILE}, - $value); - } + my $ref = ref $print; + my $highlighted = highlight_prefix(@{$prefixes[$i]}) + if @prefixes; + if ($ref eq 'ARRAY') { + $print = $highlighted || $print->[0]; + } + elsif ($ref eq 'HASH') { + my $value = $highlighted || $print->{VALUE}; + $print = sprintf($status_fmt, + $print->{INDEX}, + $print->{FILE}, + $value); + } + else { + $print = $highlighted || $print; } printf("%s%2d: %s", $chosen, $i+1, $print); if (($opts->{LIST_FLAT}) &&
--
1.5.3.6.953.gdffc