git-describe: really prefer tags only.
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>
Junio C Hamano committed
Dec 27, 2005 at 14:36 UTC
635d413430d5419cfd0ac18e2318cf46c1984750
1 file changed
+11
-4
describe.c
+11
-4
@@ -1,12 +1,13 @@
1
#include "cache.h"
2
#include "commit.h"
3
+#include "tag.h"
4
#include "refs.h"
5
6
#define SEEN (1u << 0)
7
8
static const char describe_usage[] = "git-describe [--all] <committish>*";
9
9
-static int all = 0; /* Default to tags only */
10
+static int all = 0; /* Default to annotated tags only */
11
12
static int names = 0, allocs = 0;
13
static struct commit_name {
@@ -49,9 +50,15 @@ static int get_name(const char *path, const unsigned char *sha1)
50
struct commit *commit = lookup_commit_reference_gently(sha1, 1);
51
if (!commit)
52
return 0;
52
- if (!all && strncmp(path, "refs/tags/", 10))
53
- return 0;
54
- add_to_known_names(path, commit);
53
+ if (!all) {
54
+ struct object *object;
55
+ if (strncmp(path, "refs/tags/", 10))
56
+ return 0;
57
+ object = parse_object(sha1);
58
+ if (object->type != tag_type)
59
+ return 0;
60
+ }
61
+ add_to_known_names(all ? path : path + 10, commit);
62
return 0;
63
}
64