Skip to content

Commit 2dad24a

Browse files
KarthikNayakgitster
authored andcommitted
branch: bump get_head_description() to the top
This is a preperatory patch for 'roll show_detached HEAD into regular ref_list'. This patch moves get_head_description() to the top so that it can be used in print_ref_item(). 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 1051e40 commit 2dad24a

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

builtin/branch.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,37 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item,
497497
strbuf_release(&subject);
498498
}
499499

500+
static char *get_head_description(void)
501+
{
502+
struct strbuf desc = STRBUF_INIT;
503+
struct wt_status_state state;
504+
memset(&state, 0, sizeof(state));
505+
wt_status_get_state(&state, 1);
506+
if (state.rebase_in_progress ||
507+
state.rebase_interactive_in_progress)
508+
strbuf_addf(&desc, _("(no branch, rebasing %s)"),
509+
state.branch);
510+
else if (state.bisect_in_progress)
511+
strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
512+
state.branch);
513+
else if (state.detached_from) {
514+
/* TRANSLATORS: make sure these match _("HEAD detached at ")
515+
and _("HEAD detached from ") in wt-status.c */
516+
if (state.detached_at)
517+
strbuf_addf(&desc, _("(HEAD detached at %s)"),
518+
state.detached_from);
519+
else
520+
strbuf_addf(&desc, _("(HEAD detached from %s)"),
521+
state.detached_from);
522+
}
523+
else
524+
strbuf_addstr(&desc, _("(no branch)"));
525+
free(state.branch);
526+
free(state.onto);
527+
free(state.detached_from);
528+
return strbuf_detach(&desc, NULL);
529+
}
530+
500531
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
501532
int abbrev, int current, const char *remote_prefix)
502533
{
@@ -570,37 +601,6 @@ static int calc_maxwidth(struct ref_list *refs, int remote_bonus)
570601
return max;
571602
}
572603

573-
static char *get_head_description(void)
574-
{
575-
struct strbuf desc = STRBUF_INIT;
576-
struct wt_status_state state;
577-
memset(&state, 0, sizeof(state));
578-
wt_status_get_state(&state, 1);
579-
if (state.rebase_in_progress ||
580-
state.rebase_interactive_in_progress)
581-
strbuf_addf(&desc, _("(no branch, rebasing %s)"),
582-
state.branch);
583-
else if (state.bisect_in_progress)
584-
strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
585-
state.branch);
586-
else if (state.detached_from) {
587-
/* TRANSLATORS: make sure these match _("HEAD detached at ")
588-
and _("HEAD detached from ") in wt-status.c */
589-
if (state.detached_at)
590-
strbuf_addf(&desc, _("(HEAD detached at %s)"),
591-
state.detached_from);
592-
else
593-
strbuf_addf(&desc, _("(HEAD detached from %s)"),
594-
state.detached_from);
595-
}
596-
else
597-
strbuf_addstr(&desc, _("(no branch)"));
598-
free(state.branch);
599-
free(state.onto);
600-
free(state.detached_from);
601-
return strbuf_detach(&desc, NULL);
602-
}
603-
604604
static void show_detached(struct ref_list *ref_list, int maxwidth)
605605
{
606606
struct commit *head_commit = lookup_commit_reference_gently(head_sha1, 1);

0 commit comments

Comments
 (0)