@matheusbsbs / matheus-bagliano / commits / 518120e348
Fork 0

git-describe: --long shows the object name even for a tagged commit

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....). Signed-off-by: Santi Béjar <sbejar@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Santi Béjar committed Feb 25, 2008 at 10:43 UTC 518120e3487a00148f8001454f1e76e484442a22
3 files changed +21 -1
Documentation/git-describe.txt
+9
@@ -51,6 +51,15 @@ OPTIONS
51 being employed to standard error. The tag name will still
52 be printed to standard out.
53
54 +--long::
55 + Always output the long format (the tag, the number of commits
56 + and the abbreviated commit name) even when it matches a tag.
57 + This is useful when you want to see parts of the commit object name
58 + in "describe" output, even when the commit in question happens to be
59 + a tagged version. Instead of just emitting the tag name, it will
60 + describe such a commit as v1.2-0-deadbeef (0th commit since tag v1.2
61 + that points at object deadbeef....).
62 +
63 --match <pattern>::
64 Only consider tags matching the given pattern (can be used to avoid
65 leaking private tags made from the repository).
builtin-describe.c
+10 -1
@@ -17,6 +17,7 @@ static const char * const describe_usage[] = {
17 static int debug; /* Display lots of verbose info */
18 static int all; /* Default to annotated tags only */
19 static int tags; /* But allow any tags if --tags is specified */
20 +static int longformat;
21 static int abbrev = DEFAULT_ABBREV;
22 static int max_candidates = 10;
23 const char *pattern = NULL;
@@ -155,7 +156,11 @@ static void describe(const char *arg, int last_one)
156
157 n = cmit->util;
158 if (n) {
158 - printf("%s\n", n->path);
159 + if (!longformat)
160 + printf("%s\n", n->path);
161 + else
162 + printf("%s-0-g%s\n", n->path,
163 + find_unique_abbrev(cmit->object.sha1, abbrev));
164 return;
165 }
166
@@ -254,6 +259,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
259 OPT_BOOLEAN(0, "debug", &debug, "debug search strategy on stderr"),
260 OPT_BOOLEAN(0, "all", &all, "use any ref in .git/refs"),
261 OPT_BOOLEAN(0, "tags", &tags, "use any tag in .git/refs/tags"),
262 + OPT_BOOLEAN(0, "long", &longformat, "always use long format"),
263 OPT__ABBREV(&abbrev),
264 OPT_INTEGER(0, "candidates", &max_candidates,
265 "consider <n> most recent tags (default: 10)"),
@@ -270,6 +276,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
276
277 save_commit_buffer = 0;
278
279 + if (longformat && abbrev == 0)
280 + die("--long is incompatible with --abbrev=0");
281 +
282 if (contains) {
283 const char **args = xmalloc((6 + argc) * sizeof(char*));
284 int i = 0;
t/t6120-describe.sh
+2
@@ -94,4 +94,6 @@ check_describe D-* --tags HEAD^^
94 check_describe A-* --tags HEAD^^2
95 check_describe B --tags HEAD^^2^
96
97 +check_describe B-0-* --long HEAD^^2^
98 +
99 test_done