Skip to content

Commit

Permalink
Merge branch 'sb/describe-long'
Browse files Browse the repository at this point in the history
* sb/describe-long:
  git-describe: --long shows the object name even for a tagged commit
  • Loading branch information
Junio C Hamano committed Mar 2, 2008
2 parents 7385a42 + 518120e commit c42f636
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Documentation/git-describe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ OPTIONS
being employed to standard error. The tag name will still
be printed to standard out.

--long::
Always output the long format (the tag, the number of commits
and the abbreviated commit name) even when it matches a tag.
This is useful when you want to see parts of the commit object name
in "describe" output, even when the commit in question happens to be
a tagged version. Instead of just emitting the tag name, it will
describe such a commit as v1.2-0-deadbeef (0th commit since tag v1.2
that points at object deadbeef....).

--match <pattern>::
Only consider tags matching the given pattern (can be used to avoid
leaking private tags made from the repository).
Expand Down
11 changes: 10 additions & 1 deletion builtin-describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static const char * const describe_usage[] = {
static int debug; /* Display lots of verbose info */
static int all; /* Default to annotated tags only */
static int tags; /* But allow any tags if --tags is specified */
static int longformat;
static int abbrev = DEFAULT_ABBREV;
static int max_candidates = 10;
const char *pattern = NULL;
Expand Down Expand Up @@ -170,7 +171,11 @@ static void describe(const char *arg, int last_one)

n = cmit->util;
if (n) {
printf("%s\n", n->path);
if (!longformat)
printf("%s\n", n->path);
else
printf("%s-0-g%s\n", n->path,
find_unique_abbrev(cmit->object.sha1, abbrev));
return;
}

Expand Down Expand Up @@ -271,6 +276,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
OPT_BOOLEAN(0, "debug", &debug, "debug search strategy on stderr"),
OPT_BOOLEAN(0, "all", &all, "use any ref in .git/refs"),
OPT_BOOLEAN(0, "tags", &tags, "use any tag in .git/refs/tags"),
OPT_BOOLEAN(0, "long", &longformat, "always use long format"),
OPT__ABBREV(&abbrev),
OPT_SET_INT(0, "exact-match", &max_candidates,
"only output exact matches", 0),
Expand All @@ -289,6 +295,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)

save_commit_buffer = 0;

if (longformat && abbrev == 0)
die("--long is incompatible with --abbrev=0");

if (contains) {
const char **args = xmalloc((6 + argc) * sizeof(char*));
int i = 0;
Expand Down
2 changes: 2 additions & 0 deletions t/t6120-describe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,6 @@ check_describe D-* --tags HEAD^^
check_describe A-* --tags HEAD^^2
check_describe B --tags HEAD^^2^

check_describe B-0-* --long HEAD^^2^

test_done

0 comments on commit c42f636

Please sign in to comment.