rev-parse: --abbrev-ref option to shorten ref name
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
2bb98169be
commit
a45d34691e
|
@ -84,6 +84,11 @@ OPTIONS
|
||||||
unfortunately named tag "master"), and show them as full
|
unfortunately named tag "master"), and show them as full
|
||||||
refnames (e.g. "refs/heads/master").
|
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::
|
--all::
|
||||||
Show all refs found in `$GIT_DIR/refs`.
|
Show all refs found in `$GIT_DIR/refs`.
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ static int show_type = NORMAL;
|
||||||
#define SHOW_SYMBOLIC_FULL 2
|
#define SHOW_SYMBOLIC_FULL 2
|
||||||
static int symbolic;
|
static int symbolic;
|
||||||
static int abbrev;
|
static int abbrev;
|
||||||
|
static int abbrev_ref;
|
||||||
|
static int abbrev_ref_strict;
|
||||||
static int output_sq;
|
static int output_sq;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -109,8 +111,8 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
|
||||||
return;
|
return;
|
||||||
def = NULL;
|
def = NULL;
|
||||||
|
|
||||||
if (symbolic && name) {
|
if ((symbolic || abbrev_ref) && name) {
|
||||||
if (symbolic == SHOW_SYMBOLIC_FULL) {
|
if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) {
|
||||||
unsigned char discard[20];
|
unsigned char discard[20];
|
||||||
char *full;
|
char *full;
|
||||||
|
|
||||||
|
@ -125,6 +127,9 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
|
||||||
*/
|
*/
|
||||||
break;
|
break;
|
||||||
case 1: /* happy */
|
case 1: /* happy */
|
||||||
|
if (abbrev_ref)
|
||||||
|
full = shorten_unambiguous_ref(full,
|
||||||
|
abbrev_ref_strict);
|
||||||
show_with_type(type, full);
|
show_with_type(type, full);
|
||||||
break;
|
break;
|
||||||
default: /* ambiguous */
|
default: /* ambiguous */
|
||||||
|
@ -506,6 +511,20 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
|
||||||
symbolic = SHOW_SYMBOLIC_FULL;
|
symbolic = SHOW_SYMBOLIC_FULL;
|
||||||
continue;
|
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")) {
|
if (!strcmp(arg, "--all")) {
|
||||||
for_each_ref(show_reference, NULL);
|
for_each_ref(show_reference, NULL);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue