git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Teach git-describe --long to output always the long format

From
SBSanti Béjar <sbejar@gmail.com>
Date
Feb 25, 2008, 09:43 UTC
Message-ID
<1203932613-7759-1-git-send-email-sbejar@gmail.com>
In-Reply-To
<1203864412-27977-1-git-send-email-sbejar@gmail.com>

This can be useful when more than one person can make "official" tags (or nobody), but you want unique identifiers with a descriptive name. Or when parsing git-describe output if you want to avoid hardcoding the information about the form of tags in a project (tags can, and sometimes do, contain '-').

Signed-off-by: Santi Béjar <sbejar@gmail.com>
---
Hi,
  this time with documentation and usecases (thanks Jakub)
Santi
 Documentation/git-describe.txt |    9 +++++++++
 builtin-describe.c             |   11 ++++++++++-
 t/t6120-describe.sh            |    2 ++
 3 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index 1c3dfb4..f46fbdd 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -51,6 +51,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 can be useful when more than one person can make "official" tags
+	(or nobody), but you want unique identifiers with a descriptive
+	name. Or when parsing git-describe output if you want to avoid
+	hardcoding the information about the form of tags in a project
+	(tags can, and sometimes do, contain '-').
+
 --match <pattern>::
 	Only consider tags matching the given pattern (can be used to avoid
 	leaking private tags made from the repository).
diff --git a/builtin-describe.c b/builtin-describe.c
index 3428483..3fd2e73 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -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;
@@ -155,7 +156,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;
 	}
 
@@ -254,6 +259,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_INTEGER(0, "candidates", &max_candidates,
 			    "consider <n> most recent tags (default: 10)"),
@@ -270,6 +276,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;
diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index ae8ee11..a7557bd 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -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
-- 
1.5.4.3.293.gac81
Previous: Jakub Narebski
Message 12 of 12 in “Teach git-describe --long to output always the long format”
  1. Teach git-describe --long to output always the long formatSanti Béjar, Feb 24, 2008
  2. Shawn O. PearceFeb 25, 2008
  3. Junio C HamanoFeb 25, 2008
  4. Santi BéjarFeb 25, 2008
  5. Junio C HamanoFeb 25, 2008
  6. Santi BéjarFeb 25, 2008
  7. Junio C HamanoFeb 25, 2008
  8. Santi BéjarFeb 25, 2008
  9. Junio C HamanoFeb 26, 2008
  10. Santi BéjarFeb 26, 2008
  11. Jakub NarebskiFeb 25, 2008
  12. Teach git-describe --long to output always the long formatSanti Béjar, Feb 25, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.