From: Bert Wesarg <bert.wesarg@googlemail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Bert Wesarg <bert.wesarg@googlemail.com>,
Jeff King <peff@peff.net>,
git@vger.kernel.org
Subject: [RFC/PATCH 3/2] rev-parse: --abbrev-ref option to shorten ref name
Date: Mon, 13 Apr 2009 13:20:26 +0200 [thread overview]
Message-ID: <1239621626-26952-1-git-send-email-bert.wesarg@googlemail.com> (raw)
In-Reply-To: <1239618347-17158-1-git-send-email-bert.wesarg@googlemail.com>
This applies the shorten_unambiguous_ref function to the object name.
Default mode is controlled by core.warnAmbiguousRefs. Else it is given as
optional argument to --abbrev-ref={strict|loose}.
This should be faster than 'git for-each-ref --format="%(refname:short)" <ref>'
for single refs.
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
Cc: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Can someone check, if I need to alter the filter, thanks.
Regards,
Bert
Documentation/git-rev-parse.txt | 5 +++++
builtin-rev-parse.c | 23 +++++++++++++++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 5ed2bc8..fba30b1 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -84,6 +84,11 @@ OPTIONS
unfortunately named tag "master"), and show them as full
refnames (e.g. "refs/heads/master").
+--abbrev-ref[={strict|loose}]::
+ A non-ambiguous short name of the objects name.
+ The option core.warnAmbiguousRefs is used to select the strict
+ abbreviation mode.
+
--all::
Show all refs found in `$GIT_DIR/refs`.
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 81d5a6f..22c6d6a 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -26,6 +26,8 @@ static int show_type = NORMAL;
#define SHOW_SYMBOLIC_FULL 2
static int symbolic;
static int abbrev;
+static int abbrev_ref;
+static int abbrev_ref_strict;
static int output_sq;
/*
@@ -109,8 +111,8 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
return;
def = NULL;
- if (symbolic && name) {
- if (symbolic == SHOW_SYMBOLIC_FULL) {
+ if ((symbolic || abbrev_ref) && name) {
+ if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) {
unsigned char discard[20];
char *full;
@@ -125,6 +127,9 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
*/
break;
case 1: /* happy */
+ if (abbrev_ref)
+ full = shorten_unambiguous_ref(full,
+ abbrev_ref_strict);
show_with_type(type, full);
break;
default: /* ambiguous */
@@ -506,6 +511,20 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
symbolic = SHOW_SYMBOLIC_FULL;
continue;
}
+ if (!prefixcmp(arg, "--abbrev-ref") &&
+ (!arg[12] || arg[12] == '=')) {
+ abbrev_ref = 1;
+ abbrev_ref_strict = warn_ambiguous_refs;
+ if (arg[12] == '=') {
+ if (!strcmp(arg + 13, "strict"))
+ abbrev_ref_strict = 1;
+ else if (!strcmp(arg + 13, "loose"))
+ abbrev_ref_strict = 0;
+ else
+ die("unknown mode for %s", arg);
+ }
+ continue;
+ }
if (!strcmp(arg, "--all")) {
for_each_ref(show_reference, NULL);
continue;
--
tg: (5fec79c..) bw/rev-parse_--abbrev_ref (depends on: bw/utilize-it)
next prev parent reply other threads:[~2009-04-13 11:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-13 10:25 [PATCH 1/2] shorten_unambiguous_ref(): add strict mode Bert Wesarg
2009-04-13 10:25 ` [PATCH 2/2] for-each-ref: utilize core.warnAmbiguousRefs for :short-format Bert Wesarg
2009-04-13 11:20 ` Bert Wesarg [this message]
2009-04-13 16:43 ` [RFC/PATCH 3/2] rev-parse: --abbrev-ref option to shorten ref name Junio C Hamano
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=1239621626-26952-1-git-send-email-bert.wesarg@googlemail.com \
--to=bert.wesarg@googlemail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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).