Code

builtin-fetch.c (store_updated_refs): Honor update_local_ref() return value
[git.git] / builtin-show-branch.c
index b9cf1b379f60d42408eb75009e57030173448d8c..93047f5117796fb7556fa23871397e68e9f5e4c2 100644 (file)
@@ -259,16 +259,15 @@ static void join_revs(struct commit_list **list_p,
 
 static void show_one_commit(struct commit *commit, int no_name)
 {
-       char *pretty = NULL;
+       struct strbuf pretty;
        const char *pretty_str = "(unavailable)";
-       unsigned long pretty_len = 0;
        struct commit_name *name = commit->util;
 
+       strbuf_init(&pretty, 0);
        if (commit->object.parsed) {
-               pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
-                                   &pretty, &pretty_len,
-                                   0, NULL, NULL, 0, 0);
-               pretty_str = pretty;
+               pretty_print_commit(CMIT_FMT_ONELINE, commit,
+                                   &pretty, 0, NULL, NULL, 0, 0);
+               pretty_str = pretty.buf;
        }
        if (!prefixcmp(pretty_str, "[PATCH] "))
                pretty_str += 8;
@@ -289,7 +288,7 @@ static void show_one_commit(struct commit *commit, int no_name)
                               find_unique_abbrev(commit->object.sha1, 7));
        }
        puts(pretty_str);
-       free(pretty);
+       strbuf_release(&pretty);
 }
 
 static char *ref_name[MAX_REVS + 1];
@@ -534,9 +533,11 @@ static void append_one_rev(const char *av)
        die("bad sha1 reference %s", av);
 }
 
-static int git_show_branch_config(const char *var, const char *value)
+static int git_show_branch_config(const char *var, const char *value, void *cb)
 {
        if (!strcmp(var, "showbranch.default")) {
+               if (!value)
+                       return config_error_nonbool(var);
                if (default_alloc <= default_num + 1) {
                        default_alloc = default_alloc * 3 / 2 + 20;
                        default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
@@ -546,7 +547,7 @@ static int git_show_branch_config(const char *var, const char *value)
                return 0;
        }
 
-       return git_default_config(var, value);
+       return git_default_config(var, value, cb);
 }
 
 static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
@@ -610,7 +611,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
        int reflog = 0;
        const char *reflog_base = NULL;
 
-       git_config(git_show_branch_config);
+       git_config(git_show_branch_config, NULL);
 
        /* If nothing is specified, try the default first */
        if (ac == 1 && default_num) {
@@ -781,8 +782,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                                has_head++;
                }
                if (!has_head) {
-                       int pfxlen = strlen("refs/heads/");
-                       append_one_rev(head + pfxlen);
+                       int offset = !prefixcmp(head, "refs/heads/") ? 11 : 0;
+                       append_one_rev(head + offset);
                }
        }