add -i: allow prefix highlighting for "Add untracked" as well.
[gitweb.git] / builtin-show-branch.c
index 402a8f79300eced54cf4024b8d10f4fd766996a1..6dc835d30a6a726c3dd40d23564b0dc32d20b7db 100644 (file)
@@ -259,17 +259,18 @@ 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 strbuf pretty;
+       const char *pretty_str = "(unavailable)";
        struct commit_name *name = commit->util;
-       if (commit->object.parsed)
-               pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
-                                   pretty, sizeof(pretty), 0, NULL, NULL, 0);
-       else
-               strcpy(pretty, "(unavailable)");
-       if (!prefixcmp(pretty, "[PATCH] "))
-               cp = pretty + 8;
-       else
-               cp = pretty;
+
+       strbuf_init(&pretty, 0);
+       if (commit->object.parsed) {
+               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;
 
        if (!no_name) {
                if (name && name->head_name) {
@@ -286,7 +287,8 @@ static void show_one_commit(struct commit *commit, int no_name)
                        printf("[%s] ",
                               find_unique_abbrev(commit->object.sha1, 7));
        }
-       puts(cp);
+       puts(pretty_str);
+       strbuf_release(&pretty);
 }
 
 static char *ref_name[MAX_REVS + 1];
@@ -378,7 +380,7 @@ static int append_head_ref(const char *refname, const unsigned char *sha1, int f
 {
        unsigned char tmp[20];
        int ofs = 11;
-       if (strncmp(refname, "refs/heads/", ofs))
+       if (prefixcmp(refname, "refs/heads/"))
                return 0;
        /* If both heads/foo and tags/foo exists, get_sha1 would
         * get confused.
@@ -392,7 +394,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int
 {
        unsigned char tmp[20];
        int ofs = 13;
-       if (strncmp(refname, "refs/remotes/", ofs))
+       if (prefixcmp(refname, "refs/remotes/"))
                return 0;
        /* If both heads/foo and tags/foo exists, get_sha1 would
         * get confused.
@@ -721,7 +723,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                }
 
                for (i = 0; i < reflog; i++) {
-                       char *logmsg, *msg, *m;
+                       char *logmsg, *m;
+                       const char *msg;
                        unsigned long timestamp;
                        int tz;