public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Wincent Colaiuta <win@wincent•com>
To: git@vger•kernel.org
Cc: gitster@pobox•com, dzwell@gmail•com, peff@peff•net,
	Matthieu.Moy@imag•fr, Wincent Colaiuta <win@wincent•com>
Subject: [PATCH 2/2] Teach git-add--interactive to highlight untracked file prefixes
Date: Sat,  1 Dec 2007 15:07:20 +0100	[thread overview]
Message-ID: <1196518040-85584-2-git-send-email-win@wincent.com> (raw)
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

  reply	other threads:[~2007-12-01 14:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-21 14:27 [PATCH] Highlight keyboard shortcuts in git-add--interactive Wincent Colaiuta
2007-11-21 14:32 ` Matthieu Moy
2007-11-21 15:28 ` Jeff King
2007-11-21 23:00   ` Dan Zwell
2007-11-28 23:56 ` Junio C Hamano
2007-11-29  1:08   ` Wincent Colaiuta
2007-11-29 12:00   ` Wincent Colaiuta
2007-11-29 14:51     ` Jeff King
2007-12-01  2:36     ` Junio C Hamano
2007-12-01 13:58       ` Wincent Colaiuta
2007-12-01 14:07       ` [PATCH 1/2] " Wincent Colaiuta
2007-12-01 14:07         ` Wincent Colaiuta [this message]
2007-12-01 14:15         ` Wincent Colaiuta
2007-12-01 14:29           ` [REPLACEMENT PATCH] " Wincent Colaiuta
2007-12-02 14:11       ` [PATCH] " Wincent Colaiuta
2007-12-02 19:06         ` Junio C Hamano
2007-12-03  8:09           ` Wincent Colaiuta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1196518040-85584-2-git-send-email-win@wincent.com \
    --to=win@wincent$(echo .)com \
    --cc=Matthieu.Moy@imag$(echo .)fr \
    --cc=dzwell@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    --cc=peff@peff$(echo .)net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox