Merge branch 'jc/checkout-local-track-report'
[gitweb.git] / builtin / show-branch.c
index d9217ce1e1a957462284224c08786db77f5a8f15..270e39c6c1b0855181a19b12739425035db9ad1d 100644 (file)
@@ -450,7 +450,7 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i
                        slash--;
        if (!*tail)
                return 0;
-       if (fnmatch(match_ref_pattern, tail, 0))
+       if (wildmatch(match_ref_pattern, tail, 0, NULL))
                return 0;
        if (starts_with(refname, "refs/heads/"))
                return append_head_ref(refname, sha1, flag, cb_data);
@@ -563,7 +563,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;
@@ -723,11 +723,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,18 +752,18 @@ 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);
                        }
                }
 
                for (i = 0; i < reflog; i++) {
-                       char *logmsg, *m;
+                       char *logmsg;
                        const char *msg;
                        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;
@@ -770,15 +773,14 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                                msg = "(none)";
                        else
                                msg++;
-                       m = xmalloc(strlen(msg) + 200);
-                       sprintf(m, "(%s) %s",
-                               show_date(timestamp, tz, 1),
-                               msg);
-                       reflog_msg[i] = m;
+                       reflog_msg[i] = xstrfmt("(%s) %s",
+                                               show_date(timestamp, tz, 1),
+                                               msg);
                        free(logmsg);
                        sprintf(nth_desc, "%s@{%d}", *av, base+i);
                        append_ref(nth_desc, sha1, 1);
                }
+               free(ref);
        }
        else if (all_heads + all_remotes)
                snarf_refs(all_heads, all_remotes);
@@ -789,7 +791,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                }
        }
 
-       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);