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 <peff@peff.net> Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
23e714df91
commit
f65f13911a
@ -534,9 +534,10 @@ static char *get_head_description(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
|
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;
|
char c;
|
||||||
|
int current = 0;
|
||||||
int color;
|
int color;
|
||||||
struct strbuf out = STRBUF_INIT, name = STRBUF_INIT;
|
struct strbuf out = STRBUF_INIT, name = STRBUF_INIT;
|
||||||
const char *prefix = "";
|
const char *prefix = "";
|
||||||
@ -548,6 +549,9 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
|
|||||||
|
|
||||||
switch (item->kind) {
|
switch (item->kind) {
|
||||||
case REF_LOCAL_BRANCH:
|
case REF_LOCAL_BRANCH:
|
||||||
|
if (!detached && !strcmp(item->name, head))
|
||||||
|
current = 1;
|
||||||
|
else
|
||||||
color = BRANCH_COLOR_LOCAL;
|
color = BRANCH_COLOR_LOCAL;
|
||||||
break;
|
break;
|
||||||
case REF_REMOTE_BRANCH:
|
case REF_REMOTE_BRANCH:
|
||||||
@ -555,8 +559,8 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
|
|||||||
prefix = remote_prefix;
|
prefix = remote_prefix;
|
||||||
break;
|
break;
|
||||||
case REF_DETACHED_HEAD:
|
case REF_DETACHED_HEAD:
|
||||||
color = BRANCH_COLOR_CURRENT;
|
|
||||||
desc = to_free = get_head_description();
|
desc = to_free = get_head_description();
|
||||||
|
current = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
color = BRANCH_COLOR_PLAIN;
|
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);
|
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
|
||||||
|
|
||||||
for (i = 0; i < ref_list.index; i++) {
|
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;
|
|
||||||
print_ref_item(&ref_list.list[i], maxwidth, verbose,
|
print_ref_item(&ref_list.list[i], maxwidth, verbose,
|
||||||
abbrev, current, remote_prefix);
|
abbrev, detached, remote_prefix);
|
||||||
}
|
|
||||||
|
|
||||||
free_ref_list(&ref_list);
|
free_ref_list(&ref_list);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user