Skip to content

Commit f65f139

Browse files
KarthikNayakgitster
authored andcommitted
branch: move 'current' check down to the presentation layer
We check if given ref is the current branch in print_ref_list(). Move this check to print_ref_item() where it is checked right before printing. This enables a smooth transition to using ref-filter APIs, as we can later replace the current check while printing to just check for FILTER_REFS_DETACHED instead. Based-on-patch-by: Jeff King <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored-by: Matthieu Moy <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 23e714d commit f65f139

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

builtin/branch.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,10 @@ static char *get_head_description(void)
534534
}
535535

536536
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
537-
int abbrev, int current, const char *remote_prefix)
537+
int abbrev, int detached, const char *remote_prefix)
538538
{
539539
char c;
540+
int current = 0;
540541
int color;
541542
struct strbuf out = STRBUF_INIT, name = STRBUF_INIT;
542543
const char *prefix = "";
@@ -548,15 +549,18 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
548549

549550
switch (item->kind) {
550551
case REF_LOCAL_BRANCH:
551-
color = BRANCH_COLOR_LOCAL;
552+
if (!detached && !strcmp(item->name, head))
553+
current = 1;
554+
else
555+
color = BRANCH_COLOR_LOCAL;
552556
break;
553557
case REF_REMOTE_BRANCH:
554558
color = BRANCH_COLOR_REMOTE;
555559
prefix = remote_prefix;
556560
break;
557561
case REF_DETACHED_HEAD:
558-
color = BRANCH_COLOR_CURRENT;
559562
desc = to_free = get_head_description();
563+
current = 1;
560564
break;
561565
default:
562566
color = BRANCH_COLOR_PLAIN;
@@ -684,15 +688,9 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
684688

685689
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
686690

687-
for (i = 0; i < ref_list.index; i++) {
688-
int current = !detached && (ref_list.list[i].kind == REF_LOCAL_BRANCH) &&
689-
!strcmp(ref_list.list[i].name, head);
690-
/* If detached the first ref_item is the current ref */
691-
if (detached && i == 0)
692-
current = 1;
691+
for (i = 0; i < ref_list.index; i++)
693692
print_ref_item(&ref_list.list[i], maxwidth, verbose,
694-
abbrev, current, remote_prefix);
695-
}
693+
abbrev, detached, remote_prefix);
696694

697695
free_ref_list(&ref_list);
698696

0 commit comments

Comments
 (0)