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

Re: git describe fails without tags

From
Junio C Hamano <junkio@cox.net>
Date
Jan 25, 2006, 09:52 UTC
Message-ID
<7vek2wws61.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20060125074725.GA2768@informatik.uni-freiburg.de>
Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de> writes:
Show 8 quoted lines
> I wonder if it would be sane to assume an implicit tag for the empty
> repository, s.t. git describe results in 
>
> 	<empty>-62ac6c16
>
> (whatever name is choosen for <empty>).
>
> Any opinions?

The value of 'describe' is not in the 62ac6c part, but in the tag part, which lets us find out that the rev in question is at least newer than that tag. If the reason you are doing "describe" is to find out an usable abbreviated name, you could feed the first few hexdigits to "git rev-parse --verify", lengthening the prefix longer by one until it says you have a unique prefix [*1*].

In other words, not particularly interested, although it is trivial to implement, like this:

diff --git a/describe.c b/describe.c
index 4866510..aeaf0fb 100644
--- a/describe.c
+++ b/describe.c
@@ -137,7 +137,7 @@ static void describe(char *arg, int last
 			return;
 		}
 	}
-	die("cannot describe '%s'", sha1_to_hex(cmit->object.sha1));
+	printf("%s\n", find_unique_abbrev(cmit->object.sha1, abbrev));
 }
 
 int main(int argc, char **argv)


[Footnote]

*1* If you do this often, we could introduce

	$ git rev-parse --abbrev=<n> HEAD

    that quacks like --verify (i.e. makes sure there is a single
    "extended SHA1 expression" that evaluates to a valid object
    name) but outputs the result abbreviated to at least <n>
    hexdigits.
    
    This has an added advantage that it would work on a
    non-commit object name.


-- >8 --
[PATCH] rev-parse: --abbrev option.

The new option behaves just like --verify, but outputs an
abbreviated object name that is unique within the repository.

Signed-off-by: Junio C Hamano <junkio@cox.net>

---

 rev-parse.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

3c7c31a913c3c4060e85f2919e2136412928dcec
diff --git a/rev-parse.c b/rev-parse.c
index 0c951af..c1646e4 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -20,6 +20,7 @@ static char *def = NULL;
 #define REVERSED 1
 static int show_type = NORMAL;
 static int symbolic = 0;
+static int abbrev = 0;
 static int output_sq = 0;
 
 static int revs_count = 0;
@@ -95,6 +96,8 @@ static void show_rev(int type, const uns
 		putchar('^');
 	if (symbolic && name)
 		show(name);
+	else if (abbrev)
+		show(find_unique_abbrev(sha1, abbrev));
 	else
 		show(sha1_to_hex(sha1));
 }
@@ -195,6 +198,17 @@ int main(int argc, char **argv)
 				verify = 1;
 				continue;
 			}
+			if (!strcmp(arg, "--abbrev") ||
+			    !strncmp(arg, "--abbrev=", 9)) {
+				filter &= ~(DO_FLAGS|DO_NOREV);
+				verify = 1;
+				abbrev = DEFAULT_ABBREV;
+				if (arg[8] == '=')
+					abbrev = strtoul(arg + 9, NULL, 10);
+				if (abbrev < 0 || 40 <= abbrev)
+					abbrev = DEFAULT_ABBREV;
+				continue;
+			}
 			if (!strcmp(arg, "--sq")) {
 				output_sq = 1;
 				continue;
-- 
1.1.4.g869a
Previous: Uwe ZeisbergerNext: Uwe Zeisberger
Message 2 of 7 in “git describe fails without tags”
  1. Uwe ZeisbergerJan 25, 2006
  2. Junio C HamanoJan 25, 2006
  3. Uwe ZeisbergerJan 26, 2006
  4. Junio C HamanoJan 26, 2006
  5. Uwe ZeisbergerJan 26, 2006
  6. Uwe ZeisbergerJan 26, 2006
  7. Junio C HamanoJan 26, 2006

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.