sha1-file.c: mark more strings for translation
[gitweb.git] / builtin / show-branch.c
index 7073a3eb9769cae1f00e714a93528b33ca651d9c..f2e985c00abd2e6f7aa1eaa1c9368f4c3ada60ab 100644 (file)
@@ -1,12 +1,13 @@
 #include "cache.h"
 #include "config.h"
-#include "commit.h"
+#include "pretty.h"
 #include "refs.h"
 #include "builtin.h"
 #include "color.h"
 #include "argv-array.h"
 #include "parse-options.h"
 #include "dir.h"
+#include "commit-slab.h"
 
 static const char* show_branch_usage[] = {
     N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
@@ -21,6 +22,11 @@ static int showbranch_use_color = -1;
 
 static struct argv_array default_args = ARGV_ARRAY_INIT;
 
+/*
+ * TODO: convert this use of commit->object.flags to commit-slab
+ * instead to store a pointer to ref name directly. Then use the same
+ * UNINTERESTING definition from revision.h here.
+ */
 #define UNINTERESTING  01
 
 #define REV_SHIFT       2
@@ -59,15 +65,27 @@ struct commit_name {
        int generation; /* how many parents away from head_name */
 };
 
+define_commit_slab(commit_name_slab, struct commit_name *);
+static struct commit_name_slab name_slab;
+
+static struct commit_name *commit_to_name(struct commit *commit)
+{
+       return *commit_name_slab_at(&name_slab, commit);
+}
+
+
 /* Name the commit as nth generation ancestor of head_name;
  * we count only the first-parent relationship for naming purposes.
  */
 static void name_commit(struct commit *commit, const char *head_name, int nth)
 {
        struct commit_name *name;
-       if (!commit->util)
-               commit->util = xmalloc(sizeof(struct commit_name));
-       name = commit->util;
+
+       name = *commit_name_slab_at(&name_slab, commit);
+       if (!name) {
+               name = xmalloc(sizeof(*name));
+               *commit_name_slab_at(&name_slab, commit) = name;
+       }
        name->head_name = head_name;
        name->generation = nth;
 }
@@ -79,8 +97,8 @@ static void name_commit(struct commit *commit, const char *head_name, int nth)
  */
 static void name_parent(struct commit *commit, struct commit *parent)
 {
-       struct commit_name *commit_name = commit->util;
-       struct commit_name *parent_name = parent->util;
+       struct commit_name *commit_name = commit_to_name(commit);
+       struct commit_name *parent_name = commit_to_name(parent);
        if (!commit_name)
                return;
        if (!parent_name ||
@@ -94,12 +112,12 @@ static int name_first_parent_chain(struct commit *c)
        int i = 0;
        while (c) {
                struct commit *p;
-               if (!c->util)
+               if (!commit_to_name(c))
                        break;
                if (!c->parents)
                        break;
                p = c->parents->item;
-               if (!p->util) {
+               if (!commit_to_name(p)) {
                        name_parent(c, p);
                        i++;
                }
@@ -122,7 +140,7 @@ static void name_commits(struct commit_list *list,
        /* First give names to the given heads */
        for (cl = list; cl; cl = cl->next) {
                c = cl->item;
-               if (c->util)
+               if (commit_to_name(c))
                        continue;
                for (i = 0; i < num_rev; i++) {
                        if (rev[i] == c) {
@@ -148,9 +166,9 @@ static void name_commits(struct commit_list *list,
                        struct commit_name *n;
                        int nth;
                        c = cl->item;
-                       if (!c->util)
+                       if (!commit_to_name(c))
                                continue;
-                       n = c->util;
+                       n = commit_to_name(c);
                        parents = c->parents;
                        nth = 0;
                        while (parents) {
@@ -158,7 +176,7 @@ static void name_commits(struct commit_list *list,
                                struct strbuf newname = STRBUF_INIT;
                                parents = parents->next;
                                nth++;
-                               if (p->util)
+                               if (commit_to_name(p))
                                        continue;
                                switch (n->generation) {
                                case 0:
@@ -271,7 +289,7 @@ static void show_one_commit(struct commit *commit, int no_name)
 {
        struct strbuf pretty = STRBUF_INIT;
        const char *pretty_str = "(unavailable)";
-       struct commit_name *name = commit->util;
+       struct commit_name *name = commit_to_name(commit);
 
        if (commit->object.parsed) {
                pp_commit_easy(CMIT_FMT_ONELINE, commit, &pretty);
@@ -292,7 +310,7 @@ static void show_one_commit(struct commit *commit, int no_name)
                }
                else
                        printf("[%s] ",
-                              find_unique_abbrev(commit->object.oid.hash,
+                              find_unique_abbrev(&commit->object.oid,
                                                  DEFAULT_ABBREV));
        }
        puts(pretty_str);
@@ -393,7 +411,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid,
        /* If both heads/foo and tags/foo exists, get_sha1 would
         * get confused.
         */
-       if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
+       if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
                ofs = 5;
        return append_ref(refname + ofs, oid, 0);
 }
@@ -408,7 +426,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid,
        /* If both heads/foo and tags/foo exists, get_sha1 would
         * get confused.
         */
-       if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
+       if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
                ofs = 5;
        return append_ref(refname + ofs, oid, 0);
 }
@@ -514,7 +532,7 @@ static int show_independent(struct commit **rev,
 static void append_one_rev(const char *av)
 {
        struct object_id revkey;
-       if (!get_sha1(av, revkey.hash)) {
+       if (!get_oid(av, &revkey)) {
                append_ref(av, &revkey, 0);
                return;
        }
@@ -660,6 +678,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                OPT_END()
        };
 
+       init_commit_name_slab(&name_slab);
+
        git_config(git_show_branch_config, NULL);
 
        /* If nothing is specified, try the default first */
@@ -705,8 +725,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                        static const char *fake_av[2];
 
                        fake_av[0] = resolve_refdup("HEAD",
-                                                   RESOLVE_REF_READING,
-                                                   oid.hash, NULL);
+                                                   RESOLVE_REF_READING, &oid,
+                                                   NULL);
                        fake_av[1] = NULL;
                        av = fake_av;
                        ac = 1;
@@ -720,7 +740,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                        die(Q_("only %d entry can be shown at one time.",
                               "only %d entries can be shown at one time.",
                               MAX_REVS), MAX_REVS);
-               if (!dwim_ref(*av, strlen(*av), oid.hash, &ref))
+               if (!dwim_ref(*av, strlen(*av), &oid, &ref))
                        die(_("no such ref %s"), *av);
 
                /* Has the base been specified? */
@@ -731,7 +751,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                                /* Ah, that is a date spec... */
                                timestamp_t at;
                                at = approxidate(reflog_base);
-                               read_ref_at(ref, flags, at, -1, oid.hash, NULL,
+                               read_ref_at(ref, flags, at, -1, &oid, NULL,
                                            NULL, NULL, &base);
                        }
                }
@@ -743,7 +763,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                        timestamp_t timestamp;
                        int tz;
 
-                       if (read_ref_at(ref, flags, 0, base+i, oid.hash, &logmsg,
+                       if (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,
                                        &timestamp, &tz, NULL)) {
                                reflog = i;
                                break;
@@ -775,7 +795,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
        }
 
        head = resolve_refdup("HEAD", RESOLVE_REF_READING,
-                             head_oid.hash, NULL);
+                             &head_oid, NULL);
 
        if (with_current_branch && head) {
                int has_head = 0;
@@ -808,7 +828,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                        die(Q_("cannot handle more than %d rev.",
                               "cannot handle more than %d revs.",
                               MAX_REVS), MAX_REVS);
-               if (get_sha1(ref_name[num_rev], revkey.hash))
+               if (get_oid(ref_name[num_rev], &revkey))
                        die(_("'%s' is not a valid ref."), ref_name[num_rev]);
                commit = lookup_commit_reference(&revkey);
                if (!commit)