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

[PATCH 1/6] git-describe: really prefer tags only.

From
Junio C Hamano <junkio@cox.net>
Date
Dec 28, 2005, 00:42 UTC
Message-ID
<7v1wzy3vdl.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0512241409300.14098@g5.osdl.org>

Often there are references other than annotated tags under refs/tags hierarchy that are used to "keep things just in case". default to use annotated tags only, still leaving the option to use any ref with --all flag.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 Linus Torvalds <torvalds@osdl.org> writes:
 > On Sat, 24 Dec 2005, Linus Torvalds wrote:
 >> 
 >> This is useful for two things:
 >> 
 >>  - automatic version naming in Makefiles, for example. We could use it in 
 >>    git itself: when doing "git --version", we could use this to give a 
 >>    much more useful description of exactly what version was installed.
 >
 > This trivial patch fails to do that correctly, but maybe somebody could 
 > fix it. 
 Here is a 6-patch series towards that.  Will be in the proposed
 updates later tonight.
 describe.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
170c7e67e7792e0d5ce2328c1d7b8d4139a7c7e7
diff --git a/describe.c b/describe.c
index ebfa429..e1b6588 100644
--- a/describe.c
+++ b/describe.c
@@ -1,12 +1,13 @@
 #include "cache.h"
 #include "commit.h"
+#include "tag.h"
 #include "refs.h"
 
 #define SEEN (1u << 0)
 
 static const char describe_usage[] = "git-describe [--all] <committish>*";
 
-static int all = 0;	/* Default to tags only */
+static int all = 0;	/* Default to annotated tags only */
 
 static int names = 0, allocs = 0;
 static struct commit_name {
@@ -49,9 +50,15 @@ static int get_name(const char *path, co
 	struct commit *commit = lookup_commit_reference_gently(sha1, 1);
 	if (!commit)
 		return 0;
-	if (!all && strncmp(path, "refs/tags/", 10))
-		return 0;
-	add_to_known_names(path, commit);
+	if (!all) {
+		struct object *object;
+		if (strncmp(path, "refs/tags/", 10))
+			return 0;
+		object = parse_object(sha1);
+		if (object->type != tag_type)
+			return 0;
+	}
+	add_to_known_names(all ? path : path + 10, commit);
 	return 0;
 }
 
-- 
1.0.5-geb9d
Previous: Johannes SchindelinNext: Junio C Hamano
Message 6 of 14 in “Add a "git-describe" command”
  1. Linus TorvaldsDec 24, 2005
  2. Linus TorvaldsDec 24, 2005
  3. M_Dec 25, 2005
  4. Junio C HamanoDec 28, 2005
  5. Johannes SchindelinDec 28, 2005
  6. 1/6 git-describe: really prefer tags only.Junio C Hamano, Dec 28, 2005
  7. 2/6 git-describe: use find_unique_abbrev()Junio C Hamano, Dec 28, 2005
  8. 3/6 git-describe: --tags and --abbrevJunio C Hamano, Dec 28, 2005
  9. 4/6 git-describe: still prefer annotated tag under --all and --tagsJunio C Hamano, Dec 28, 2005
  10. 5/6 git-describe: documentation.Junio C Hamano, Dec 28, 2005
  11. 6/6 Makefile: use git-describe to mark the git version.Junio C Hamano, Dec 28, 2005
  12. Junio C HamanoDec 25, 2005
  13. Linus TorvaldsDec 25, 2005
  14. Junio C HamanoDec 25, 2005

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.