@matheusbsbs / matheus-bagliano / commits / feededd05b
Fork 0

Teach git-describe to use peeled ref information when scanning tags

By using the peeled ref information inside of the packed-refs file we can avoid opening tag objects to obtain the commits they reference. This speeds up git-describe when there are a large number of tags in the repository as we have less objects to parse before we can start commit matching. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Feb 24, 2008 at 03:07 UTC feededd05b551a02a95fe2a736e9d5f688b86119
1 file changed +17 -6
builtin-describe.c
+17 -6
@@ -46,19 +46,30 @@ static void add_to_known_names(const char *path,
46
47 static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
48 {
49 - struct commit *commit = lookup_commit_reference_gently(sha1, 1);
49 + struct commit *commit;
50 struct object *object;
51 - int prio;
51 + unsigned char peeled[20];
52 + int is_tag, prio;
53 +
54 + if (!peel_ref(path, peeled) && !is_null_sha1(peeled)) {
55 + commit = lookup_commit_reference_gently(peeled, 1);
56 + if (!commit)
57 + return 0;
58 + is_tag = !!hashcmp(sha1, commit->object.sha1);
59 + } else {
60 + commit = lookup_commit_reference_gently(sha1, 1);
61 + object = parse_object(sha1);
62 + if (!commit || !object)
63 + return 0;
64 + is_tag = object->type == OBJ_TAG;
65 + }
66
53 - if (!commit)
54 - return 0;
55 - object = parse_object(sha1);
67 /* If --all, then any refs are used.
68 * If --tags, then any tags are used.
69 * Otherwise only annotated tags are used.
70 */
71 if (!prefixcmp(path, "refs/tags/")) {
61 - if (object->type == OBJ_TAG) {
72 + if (is_tag) {
73 prio = 2;
74 if (pattern && fnmatch(pattern, path + 10, 0))
75 prio = 0;