]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/describe.c
object-name.h: move declarations for object-name.c functions from cache.h
[thirdparty/git.git] / builtin / describe.c
index e912ba50d7bac4fbd562774e00cf454e17651baf..d360b1d12af935e6cfab9aed5a1049bb70037fba 100644 (file)
@@ -1,6 +1,9 @@
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
+#define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
+#include "environment.h"
+#include "gettext.h"
+#include "hex.h"
 #include "lockfile.h"
 #include "commit.h"
 #include "tag.h"
 #include "refs.h"
 #include "builtin.h"
 #include "exec-cmd.h"
+#include "object-name.h"
 #include "parse-options.h"
 #include "revision.h"
 #include "diff.h"
 #include "hashmap.h"
+#include "setup.h"
 #include "strvec.h"
 #include "run-command.h"
 #include "object-store.h"
@@ -23,8 +28,9 @@
 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"),
+       N_("git describe [--all] [--tags] [--contains] [--abbrev=<n>] [<commit-ish>...]"),
+       N_("git describe [--all] [--tags] [--contains] [--abbrev=<n>] --dirty[=<mark>]"),
+       N_("git describe <blob>"),
        NULL
 };
 
@@ -63,7 +69,7 @@ static const char *prio_names[] = {
        N_("head"), N_("lightweight"), N_("annotated"),
 };
 
-static int commit_name_neq(const void *unused_cmp_data,
+static int commit_name_neq(const void *cmp_data UNUSED,
                           const struct hashmap_entry *eptr,
                           const struct hashmap_entry *entry_or_key,
                           const void *peeled)
@@ -140,7 +146,8 @@ static void add_to_known_names(const char *path,
        }
 }
 
-static int get_name(const char *path, const struct object_id *oid, int flag, void *cb_data)
+static int get_name(const char *path, const struct object_id *oid,
+                   int flag UNUSED, void *cb_data UNUSED)
 {
        int is_tag = 0;
        struct object_id peeled;
@@ -259,7 +266,7 @@ static unsigned long finish_depth_computation(
                        best->depth++;
                while (parents) {
                        struct commit *p = parents->item;
-                       parse_commit(p);
+                       repo_parse_commit(the_repository, p);
                        if (!(p->object.flags & SEEN))
                                commit_list_insert_by_date(p, list);
                        p->object.flags |= c->object.flags;
@@ -296,7 +303,8 @@ static void append_name(struct commit_name *n, struct strbuf *dst)
 
 static void append_suffix(int depth, const struct object_id *oid, struct strbuf *dst)
 {
-       strbuf_addf(dst, "-%d-g%s", depth, find_unique_abbrev(oid, abbrev));
+       strbuf_addf(dst, "-%d-g%s", depth,
+                   repo_find_unique_abbrev(the_repository, oid, abbrev));
 }
 
 static void describe_commit(struct object_id *oid, struct strbuf *dst)
@@ -401,7 +409,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
                }
                while (parents) {
                        struct commit *p = parents->item;
-                       parse_commit(p);
+                       repo_parse_commit(the_repository, p);
                        if (!(p->object.flags & SEEN))
                                commit_list_insert_by_date(p, &list);
                        p->object.flags |= c->object.flags;
@@ -517,6 +525,7 @@ static void describe_blob(struct object_id oid, struct strbuf *dst)
 
        traverse_commit_list(&revs, process_commit, process_object, &pcd);
        reset_revision_walk();
+       release_revisions(&revs);
 }
 
 static void describe(const char *arg, int last_one)
@@ -528,7 +537,7 @@ static void describe(const char *arg, int last_one)
        if (debug)
                fprintf(stderr, _("describe %s\n"), arg);
 
-       if (get_oid(arg, &oid))
+       if (repo_get_oid(the_repository, arg, &oid))
                die(_("Not a valid object name %s"), arg);
        cmit = lookup_commit_reference_gently(the_repository, &oid, 1);
 
@@ -590,7 +599,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
        save_commit_buffer = 0;
 
        if (longformat && abbrev == 0)
-               die(_("--long is incompatible with --abbrev=0"));
+               die(_("options '%s' and '%s' cannot be used together"), "--long", "--abbrev=0");
 
        if (contains) {
                struct string_list_item *item;
@@ -650,10 +659,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                        int fd, result;
 
                        setup_work_tree();
-                       read_cache();
+                       repo_read_index(the_repository);
                        refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
                                      NULL, NULL, NULL);
-                       fd = hold_locked_index(&index_lock, 0);
+                       fd = repo_hold_locked_index(the_repository,
+                                                   &index_lock, 0);
                        if (0 <= fd)
                                repo_update_index_if_able(the_repository, &index_lock);
 
@@ -667,12 +677,13 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                                suffix = NULL;
                        else
                                suffix = dirty;
+                       release_revisions(&revs);
                }
                describe("HEAD", 1);
        } else if (dirty) {
-               die(_("--dirty is incompatible with commit-ishes"));
+               die(_("option '%s' and commit-ishes cannot be used together"), "--dirty");
        } else if (broken) {
-               die(_("--broken is incompatible with commit-ishes"));
+               die(_("option '%s' and commit-ishes cannot be used together"), "--broken");
        } else {
                while (argc-- > 0)
                        describe(*argv++, argc == 0);