Merge branch 'jk/init-core-worktree-at-root'
[gitweb.git] / builtin / show-branch.c
index 298c95e3f8b03e7f89d7767407ca8cee3eecc591..e69fb7c489885ad2466397a8a25c34d87eff9ce9 100644 (file)
@@ -6,8 +6,11 @@
 #include "parse-options.h"
 
 static const char* show_branch_usage[] = {
-    N_("git show-branch [-a|--all] [-r|--remotes] [--topo-order | --date-order] [--current] [--color[=<when>] | --no-color] [--sparse] [--more=<n> | --list | --independent | --merge-base] [--no-name | --sha1-name] [--topics] [(<rev> | <glob>)...]"),
-    N_("git show-branch (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>]"),
+    N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
+       "               [--current] [--color[=<when>] | --no-color] [--sparse]\n"
+       "               [--more=<n> | --list | --independent | --merge-base]\n"
+       "               [--no-name | --sha1-name] [--topics] [(<rev> | <glob>)...]"),
+    N_("git show-branch (-g | --reflog)[=<n>[,<base>]] [--list] [<ref>]"),
     NULL
 };
 
@@ -563,7 +566,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
                        default_arg[default_num++] = "show-branch";
                } else if (default_alloc <= default_num + 1) {
                        default_alloc = default_alloc * 3 / 2 + 20;
-                       default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
+                       REALLOC_ARRAY(default_arg, default_alloc);
                }
                default_arg[default_num++] = xstrdup(value);
                default_arg[default_num] = NULL;
@@ -715,7 +718,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
        }
 
        /* If nothing is specified, show all branches by default */
-       if (ac + all_heads + all_remotes == 0)
+       if (ac <= topics && all_heads + all_remotes == 0)
                all_heads = 1;
 
        if (reflog) {
@@ -723,11 +726,14 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                char nth_desc[256];
                char *ref;
                int base = 0;
+               unsigned int flags = 0;
 
                if (ac == 0) {
                        static const char *fake_av[2];
 
-                       fake_av[0] = resolve_refdup("HEAD", sha1, 1, NULL);
+                       fake_av[0] = resolve_refdup("HEAD",
+                                                   RESOLVE_REF_READING,
+                                                   sha1, NULL);
                        fake_av[1] = NULL;
                        av = fake_av;
                        ac = 1;
@@ -749,7 +755,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                                /* Ah, that is a date spec... */
                                unsigned long at;
                                at = approxidate(reflog_base);
-                               read_ref_at(ref, at, -1, sha1, NULL,
+                               read_ref_at(ref, flags, at, -1, sha1, NULL,
                                            NULL, NULL, &base);
                        }
                }
@@ -760,7 +766,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                        unsigned long timestamp;
                        int tz;
 
-                       if (read_ref_at(ref, 0, base+i, sha1, &logmsg,
+                       if (read_ref_at(ref, flags, 0, base+i, sha1, &logmsg,
                                        &timestamp, &tz, NULL)) {
                                reflog = i;
                                break;
@@ -779,16 +785,17 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                }
                free(ref);
        }
-       else if (all_heads + all_remotes)
-               snarf_refs(all_heads, all_remotes);
        else {
                while (0 < ac) {
                        append_one_rev(*av);
                        ac--; av++;
                }
+               if (all_heads + all_remotes)
+                       snarf_refs(all_heads, all_remotes);
        }
 
-       head_p = resolve_ref_unsafe("HEAD", head_sha1, 1, NULL);
+       head_p = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
+                                   head_sha1, NULL);
        if (head_p) {
                head_len = strlen(head_p);
                memcpy(head, head_p, head_len + 1);