]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/describe.c
Sync with maint
[thirdparty/git.git] / builtin / describe.c
index cf1ae77d7c705cdfb34bdb5403bad8db4148eccf..b6df81d8d0e80e9665ae8f8afcf3cb03d1ae688c 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "lockfile.h"
 #include "hashmap.h"
 #include "argv-array.h"
 #include "run-command.h"
-#include "revision.h"
+#include "object-store.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[] = {
@@ -57,20 +62,23 @@ static const char *prio_names[] = {
        N_("head"), N_("lightweight"), N_("annotated"),
 };
 
-static int commit_name_cmp(const void *unused_cmp_data,
-                          const void *entry,
-                          const void *entry_or_key,
+static int commit_name_neq(const void *unused_cmp_data,
+                          const struct hashmap_entry *eptr,
+                          const struct hashmap_entry *entry_or_key,
                           const void *peeled)
 {
-       const struct commit_name *cn1 = entry;
-       const struct commit_name *cn2 = entry_or_key;
+       const struct commit_name *cn1, *cn2;
+
+       cn1 = container_of(eptr, const struct commit_name, entry);
+       cn2 = container_of(entry_or_key, const struct commit_name, entry);
 
-       return oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);
+       return !oideq(&cn1->peeled, peeled ? peeled : &cn2->peeled);
 }
 
 static inline struct commit_name *find_commit_name(const struct object_id *peeled)
 {
-       return hashmap_get_from_hash(&names, sha1hash(peeled->hash), peeled->hash);
+       return hashmap_get_entry_from_hash(&names, oidhash(peeled), peeled,
+                                               struct commit_name, entry);
 }
 
 static int replace_name(struct commit_name *e,
@@ -88,13 +96,13 @@ static int replace_name(struct commit_name *e,
                struct tag *t;
 
                if (!e->tag) {
-                       t = lookup_tag(&e->oid);
+                       t = lookup_tag(the_repository, &e->oid);
                        if (!t || parse_tag(t))
                                return 1;
                        e->tag = t;
                }
 
-               t = lookup_tag(oid);
+               t = lookup_tag(the_repository, oid);
                if (!t || parse_tag(t))
                        return 0;
                *tag = t;
@@ -117,8 +125,8 @@ static void add_to_known_names(const char *path,
                if (!e) {
                        e = xmalloc(sizeof(struct commit_name));
                        oidcpy(&e->peeled, peeled);
-                       hashmap_entry_init(e, sha1hash(peeled->hash));
-                       hashmap_add(&names, e);
+                       hashmap_entry_init(&e->entry, oidhash(peeled));
+                       hashmap_add(&names, &e->entry);
                        e->path = NULL;
                }
                e->tag = tag;
@@ -185,7 +193,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
 
        /* Is it annotated? */
        if (!peel_ref(path, &peeled)) {
-               is_annotated = !!oidcmp(oid, &peeled);
+               is_annotated = !oideq(oid, &peeled);
        } else {
                oidcpy(&peeled, oid);
                is_annotated = 0;
@@ -262,7 +270,7 @@ static unsigned long finish_depth_computation(
 static void append_name(struct commit_name *n, struct strbuf *dst)
 {
        if (n->prio == 2 && !n->tag) {
-               n->tag = lookup_tag(&n->oid);
+               n->tag = lookup_tag(the_repository, &n->oid);
                if (!n->tag || parse_tag(n->tag))
                        die(_("annotated tag %s not available"), n->path);
        }
@@ -298,7 +306,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)) {
@@ -307,7 +315,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
                 */
                append_name(n, dst);
                if (longformat)
-                       append_suffix(0, n->tag ? &n->tag->tagged->oid : oid, dst);
+                       append_suffix(0, n->tag ? get_tagged_oid(n->tag) : oid, dst);
                if (suffix)
                        strbuf_addstr(dst, suffix);
                return;
@@ -321,11 +329,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);
-               for (; n; n = hashmap_iter_next(&iter)) {
-                       c = lookup_commit_reference_gently(&n->peeled, 1);
+               struct commit_name *n;
+
+               init_commit_names(&commit_names);
+               hashmap_for_each_entry(&names, &iter, n,
+                                       entry /* member name */) {
+                       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 +348,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++;
@@ -457,7 +472,7 @@ static void process_object(struct object *obj, const char *path, void *data)
 {
        struct process_commit_data *pcd = data;
 
-       if (!oidcmp(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {
+       if (oideq(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {
                reset_revision_walk();
                describe_commit(&pcd->current_commit, pcd->dst);
                strbuf_addf(pcd->dst, ":%s", path);
@@ -476,7 +491,7 @@ static void describe_blob(struct object_id oid, struct strbuf *dst)
                "--objects", "--in-commit-order", "--reverse", "HEAD",
                NULL);
 
-       init_revisions(&revs, NULL);
+       repo_init_revisions(the_repository, &revs, NULL);
        if (setup_revisions(args.argc, args.argv, &revs, NULL) > 1)
                BUG("setup_revisions could not handle all args?");
 
@@ -498,7 +513,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);
@@ -584,7 +599,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                return cmd_name_rev(args.argc, args.argv, prefix);
        }
 
-       hashmap_init(&names, commit_name_cmp, NULL, 0);
+       hashmap_init(&names, commit_name_neq, NULL, 0);
        for_each_rawref(get_name, NULL);
        if (!hashmap_get_size(&names) && !always)
                die(_("No names found, cannot describe anything."));
@@ -617,14 +632,15 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                        struct argv_array args = ARGV_ARRAY_INIT;
                        int fd, result;
 
-                       read_cache_preload(NULL);
+                       setup_work_tree();
+                       read_cache();
                        refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
                                      NULL, NULL, NULL);
                        fd = hold_locked_index(&index_lock, 0);
                        if (0 <= fd)
-                               update_index_if_able(&the_index, &index_lock);
+                               repo_update_index_if_able(the_repository, &index_lock);
 
-                       init_revisions(&revs, prefix);
+                       repo_init_revisions(the_repository, &revs, prefix);
                        argv_array_pushv(&args, diff_index_args);
                        if (setup_revisions(args.argc, args.argv, &revs, NULL) != 1)
                                BUG("malformed internal diff-index command line");