Code

xdiff/xemit.c (xdl_find_func): Elide trailing white space in a context header.
[git.git] / builtin-show-branch.c
index 2895140915cb603e2c5f971d0356f2e48106bc0e..578c9fafd022ce8a8676d348120c2fc7b2b1c5dd 100644 (file)
@@ -6,16 +6,16 @@
 #include "builtin.h"
 
 static const char show_branch_usage[] =
-"git-show-branch [--dense] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...]";
+"git-show-branch [--sparse] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...]";
 
-static int default_num = 0;
-static int default_alloc = 0;
-static const char **default_arg = NULL;
+static int default_num;
+static int default_alloc;
+static const char **default_arg;
 
 #define UNINTERESTING  01
 
 #define REV_SHIFT       2
-#define MAX_REVS       29 /* should not exceed bits_per_int - REV_SHIFT */
+#define MAX_REVS       (FLAG_BITS - REV_SHIFT) /* should not exceed bits_per_int - REV_SHIFT */
 
 static struct commit *interesting(struct commit_list *list)
 {
@@ -51,9 +51,9 @@ struct commit_name {
 static void name_commit(struct commit *commit, const char *head_name, int nth)
 {
        struct commit_name *name;
-       if (!commit->object.util)
-               commit->object.util = xmalloc(sizeof(struct commit_name));
-       name = commit->object.util;
+       if (!commit->util)
+               commit->util = xmalloc(sizeof(struct commit_name));
+       name = commit->util;
        name->head_name = head_name;
        name->generation = nth;
 }
@@ -65,8 +65,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->object.util;
-       struct commit_name *parent_name = parent->object.util;
+       struct commit_name *commit_name = commit->util;
+       struct commit_name *parent_name = parent->util;
        if (!commit_name)
                return;
        if (!parent_name ||
@@ -80,15 +80,17 @@ static int name_first_parent_chain(struct commit *c)
        int i = 0;
        while (c) {
                struct commit *p;
-               if (!c->object.util)
+               if (!c->util)
                        break;
                if (!c->parents)
                        break;
                p = c->parents->item;
-               if (!p->object.util) {
+               if (!p->util) {
                        name_parent(c, p);
                        i++;
                }
+               else
+                       break;
                c = p;
        }
        return i;
@@ -106,7 +108,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->object.util)
+               if (c->util)
                        continue;
                for (i = 0; i < num_rev; i++) {
                        if (rev[i] == c) {
@@ -132,9 +134,9 @@ static void name_commits(struct commit_list *list,
                        struct commit_name *n;
                        int nth;
                        c = cl->item;
-                       if (!c->object.util)
+                       if (!c->util)
                                continue;
-                       n = c->object.util;
+                       n = c->util;
                        parents = c->parents;
                        nth = 0;
                        while (parents) {
@@ -142,7 +144,7 @@ static void name_commits(struct commit_list *list,
                                char newname[1000], *en;
                                parents = parents->next;
                                nth++;
-                               if (p->object.util)
+                               if (p->util)
                                        continue;
                                en = newname;
                                switch (n->generation) {
@@ -161,7 +163,7 @@ static void name_commits(struct commit_list *list,
                                        en += sprintf(en, "^");
                                else
                                        en += sprintf(en, "^%d", nth);
-                               name_commit(p, strdup(newname), 0);
+                               name_commit(p, xstrdup(newname), 0);
                                i++;
                                name_first_parent_chain(p);
                        }
@@ -172,7 +174,7 @@ static void name_commits(struct commit_list *list,
 static int mark_seen(struct commit *commit, struct commit_list **seen_p)
 {
        if (!commit->object.flags) {
-               insert_by_date(commit, seen_p);
+               commit_list_insert(commit, seen_p);
                return 1;
        }
        return 0;
@@ -218,9 +220,8 @@ static void join_revs(struct commit_list **list_p,
         * Postprocess to complete well-poisoning.
         *
         * At this point we have all the commits we have seen in
-        * seen_p list (which happens to be sorted chronologically but
-        * it does not really matter).  Mark anything that can be
-        * reached from uninteresting commits not interesting.
+        * seen_p list.  Mark anything that can be reached from
+        * uninteresting commits not interesting.
         */
        for (;;) {
                int changed = 0;
@@ -257,10 +258,10 @@ static void join_revs(struct commit_list **list_p,
 static void show_one_commit(struct commit *commit, int no_name)
 {
        char pretty[256], *cp;
-       struct commit_name *name = commit->object.util;
+       struct commit_name *name = commit->util;
        if (commit->object.parsed)
                pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
-                                   pretty, sizeof(pretty), 0, NULL, NULL);
+                                   pretty, sizeof(pretty), 0, NULL, NULL, 0);
        else
                strcpy(pretty, "(unavailable)");
        if (!strncmp(pretty, "[PATCH] ", 8))
@@ -363,7 +364,7 @@ static int append_ref(const char *refname, const unsigned char *sha1)
                        refname, MAX_REVS);
                return 0;
        }
-       ref_name[ref_name_cnt++] = strdup(refname);
+       ref_name[ref_name_cnt++] = xstrdup(refname);
        ref_name[ref_name_cnt] = NULL;
        return 0;
 }
@@ -377,7 +378,7 @@ static int append_head_ref(const char *refname, const unsigned char *sha1)
        /* If both heads/foo and tags/foo exists, get_sha1 would
         * get confused.
         */
-       if (get_sha1(refname + ofs, tmp) || memcmp(tmp, sha1, 20))
+       if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
                ofs = 5;
        return append_ref(refname + ofs, sha1);
 }
@@ -441,7 +442,7 @@ static int rev_is_head(char *head_path, int headlen, char *name,
 {
        int namelen;
        if ((!head_path[0]) ||
-           (head_sha1 && sha1 && memcmp(head_sha1, sha1, 20)))
+           (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
                return 0;
        namelen = strlen(name);
        if ((headlen < namelen) ||
@@ -520,7 +521,7 @@ static int git_show_branch_config(const char *var, const char *value)
                        default_alloc = default_alloc * 3 / 2 + 20;
                        default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
                }
-               default_arg[default_num++] = strdup(value);
+               default_arg[default_num++] = xstrdup(value);
                default_arg[default_num] = NULL;
                return 0;
        }
@@ -549,7 +550,7 @@ static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
        return 0;
 }
 
-int cmd_show_branch(int ac, const char **av, char **envp)
+int cmd_show_branch(int ac, const char **av, const char *prefix)
 {
        struct commit *rev[MAX_REVS], *commit;
        struct commit_list *list = NULL, *seen = NULL;
@@ -572,7 +573,6 @@ int cmd_show_branch(int ac, const char **av, char **envp)
        int topics = 0;
        int dense = 1;
 
-       setup_git_directory();
        git_config(git_show_branch_config);
 
        /* If nothing is specified, try the default first */
@@ -701,6 +701,8 @@ int cmd_show_branch(int ac, const char **av, char **envp)
        if (0 <= extra)
                join_revs(&list, &seen, num_rev, extra);
 
+       sort_by_date(&seen);
+
        if (merge_base)
                return show_merge_base(seen, num_rev);