From: Wincent Colaiuta <win@wincent.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Wincent Colaiuta <win@wincent.com>
Subject: [PATCH] Fixes for automatic prefix highlighting
Date: Sun, 2 Dec 2007 14:44:11 +0100 [thread overview]
Message-ID: <1196603051-92641-1-git-send-email-win@wincent.com> (raw)
These changes make the automatic prefix highlighting work with the "Add
untracked" subcommand in git-add--interactive by explicitly handling
arrays, hashes and strings internally (previously only arrays and hashes
were handled).
In addition, prefixes which have special meaning for list_and_choose
(things like "*" for "all" and "-" for "deselect) are explicitly
excluded (highlighting these prefixes would be misleading).
Signed-off-by: Wincent Colaiuta <win@wincent.com>
---
El 1/12/2007, a las 19:04, Junio C Hamano escribió:
> I've locally munged and pushed out the results before sending the
> message you are responding to. Sorry, I should have been clearer (and
> this is the second time with you if I recall correctly).
Sorry, Junio. I do fetch, inspect and integrate changes fairly
regularly, but I missed that one.
This patch which I am sending now applies on top of "next" (as fetched a
few minutes ago).
git-add--interactive.perl | 47 ++++++++++++++++++++++++++++----------------
1 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 23fd2f7..32fb9ea 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -193,7 +193,7 @@ sub find_unique_prefixes {
if ((ref $print) eq 'ARRAY') {
$print = $print->[0];
}
- else {
+ elsif ((ref $print) eq 'HASH') {
$print = $print->{VALUE};
}
update_trie(\%trie, $print);
@@ -230,12 +230,25 @@ sub find_unique_prefixes {
return @return;
}
+# filters out prefixes which have special meaning to list_and_choose()
+sub is_valid_prefix {
+ my $prefix = shift;
+ return (defined $prefix) &&
+ !($prefix =~ /[\s,]/) && # separators
+ !($prefix =~ /^-/) && # deselection
+ !($prefix =~ /^\d+/) && # selection
+ ($prefix ne '*'); # "all" wildcard
+}
+
# given a prefix/remainder tuple return a string with the prefix highlighted
# for now use square brackets; later might use ANSI colors (underline, bold)
sub highlight_prefix {
my $prefix = shift;
my $remainder = shift;
- return (defined $prefix) ? "[$prefix]$remainder" : $remainder;
+ return $remainder unless defined $prefix;
+ return is_valid_prefix($prefix) ?
+ "[$prefix]$remainder" :
+ "$prefix$remainder";
}
sub list_and_choose {
@@ -257,21 +270,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-02 13:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1196603051-92641-1-git-send-email-win@wincent.com \
--to=win@wincent.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).