branch: move 'current' check down to the presentation layer
[gitweb.git] / builtin / branch.c
index a2a35f414636f69701f7d518652c2ce60213cf3d..1a664ed315bc9a0b5b4cc653c4d70caf31a86d0b 100644 (file)
@@ -534,9 +534,10 @@ static char *get_head_description(void)
 }
 
 static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
-                          int abbrev, int current, const char *remote_prefix)
+                          int abbrev, int detached, const char *remote_prefix)
 {
        char c;
+       int current = 0;
        int color;
        struct strbuf out = STRBUF_INIT, name = STRBUF_INIT;
        const char *prefix = "";
@@ -548,15 +549,18 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
 
        switch (item->kind) {
        case REF_LOCAL_BRANCH:
-               color = BRANCH_COLOR_LOCAL;
+               if (!detached && !strcmp(item->name, head))
+                       current = 1;
+               else
+                       color = BRANCH_COLOR_LOCAL;
                break;
        case REF_REMOTE_BRANCH:
                color = BRANCH_COLOR_REMOTE;
                prefix = remote_prefix;
                break;
        case REF_DETACHED_HEAD:
-               color = BRANCH_COLOR_CURRENT;
                desc = to_free = get_head_description();
+               current = 1;
                break;
        default:
                color = BRANCH_COLOR_PLAIN;
@@ -684,15 +688,9 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
 
        qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
 
-       for (i = 0; i < ref_list.index; i++) {
-               int current = !detached && (ref_list.list[i].kind == REF_LOCAL_BRANCH) &&
-                       !strcmp(ref_list.list[i].name, head);
-               /*  If detached the first ref_item is the current ref */
-               if (detached && i == 0)
-                       current = 1;
+       for (i = 0; i < ref_list.index; i++)
                print_ref_item(&ref_list.list[i], maxwidth, verbose,
-                              abbrev, current, remote_prefix);
-       }
+                              abbrev, detached, remote_prefix);
 
        free_ref_list(&ref_list);