git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] Teach git-add--interactive to highlight untracked file prefixes

From
Wincent Colaiuta <win@wincent.com>
Date
Dec 1, 2007, 14:07 UTC
Message-ID
<1196518040-85584-2-git-send-email-win@wincent.com>
In-Reply-To
<1196518040-85584-1-git-send-email-win@wincent.com>

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 <win@wincent.com>
---
 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
Previous: Wincent ColaiutaNext: Wincent Colaiuta
Message 12 of 17 in “Highlight keyboard shortcuts in git-add--interactive”
  1. Highlight keyboard shortcuts in git-add--interactiveWincent Colaiuta, Nov 21, 2007
  2. Matthieu MoyNov 21, 2007
  3. Jeff KingNov 21, 2007
  4. Dan ZwellNov 21, 2007
  5. Junio C HamanoNov 28, 2007
  6. Wincent ColaiutaNov 29, 2007
  7. Highlight keyboard shortcuts in git-add--interactiveWincent Colaiuta, Nov 29, 2007
  8. Jeff KingNov 29, 2007
  9. Junio C HamanoDec 1, 2007
  10. Wincent ColaiutaDec 1, 2007
  11. 1/2 Highlight keyboard shortcuts in git-add--interactiveWincent Colaiuta, Dec 1, 2007
  12. 2/2 Teach git-add--interactive to highlight untracked file prefixesWincent Colaiuta, Dec 1, 2007
  13. Wincent ColaiutaDec 1, 2007
  14. Highlight keyboard shortcuts in git-add--interactiveWincent Colaiuta, Dec 1, 2007
  15. Wincent ColaiutaDec 2, 2007
  16. Junio C HamanoDec 2, 2007
  17. Wincent ColaiutaDec 3, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.