commit: add repository argument to lookup_commit_reference
[gitweb.git] / builtin / describe.c
index cf1ae77d7c705cdfb34bdb5403bad8db4148eccf..c8ff64766d04c9dad38dc8f2ccccb7c9ffecaa63 100644 (file)
 #include "hashmap.h"
 #include "argv-array.h"
 #include "run-command.h"
+#include "object-store.h"
 #include "revision.h"
 #include "list-objects.h"
+#include "commit-slab.h"
 
 #define MAX_TAGS       (FLAG_BITS - 1)
 
+define_commit_slab(commit_names, struct commit_name *);
+
 static const char * const describe_usage[] = {
        N_("git describe [<options>] [<commit-ish>...]"),
        N_("git describe [<options>] --dirty"),
@@ -37,6 +41,7 @@ static struct string_list patterns = STRING_LIST_INIT_NODUP;
 static struct string_list exclude_patterns = STRING_LIST_INIT_NODUP;
 static int always;
 static const char *suffix, *dirty, *broken;
+static struct commit_names commit_names;
 
 /* diff-index command arguments to check if working tree is dirty. */
 static const char *diff_index_args[] = {
@@ -298,7 +303,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
        unsigned long seen_commits = 0;
        unsigned int unannotated_cnt = 0;
 
-       cmit = lookup_commit_reference(oid);
+       cmit = lookup_commit_reference(the_repository, oid);
 
        n = find_commit_name(&cmit->object.oid);
        if (n && (tags || all || n->prio == 2)) {
@@ -321,11 +326,15 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
        if (!have_util) {
                struct hashmap_iter iter;
                struct commit *c;
-               struct commit_name *n = hashmap_iter_first(&names, &iter);
+               struct commit_name *n;
+
+               init_commit_names(&commit_names);
+               n = hashmap_iter_first(&names, &iter);
                for (; n; n = hashmap_iter_next(&iter)) {
-                       c = lookup_commit_reference_gently(&n->peeled, 1);
+                       c = lookup_commit_reference_gently(the_repository,
+                                                          &n->peeled, 1);
                        if (c)
-                               c->util = n;
+                               *commit_names_at(&commit_names, c) = n;
                }
                have_util = 1;
        }
@@ -336,8 +345,11 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
        while (list) {
                struct commit *c = pop_commit(&list);
                struct commit_list *parents = c->parents;
+               struct commit_name **slot;
+
                seen_commits++;
-               n = c->util;
+               slot = commit_names_peek(&commit_names, c);
+               n = slot ? *slot : NULL;
                if (n) {
                        if (!tags && !all && n->prio < 2) {
                                unannotated_cnt++;
@@ -498,7 +510,7 @@ static void describe(const char *arg, int last_one)
 
        if (get_oid(arg, &oid))
                die(_("Not a valid object name %s"), arg);
-       cmit = lookup_commit_reference_gently(&oid, 1);
+       cmit = lookup_commit_reference_gently(the_repository, &oid, 1);
 
        if (cmit)
                describe_commit(&oid, &sb);