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 <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:
Karthik Nayak 2015-09-23 23:41:07 +05:30 committed by Junio C Hamano
parent 1051e40dba
commit 2dad24a5c3

View File

@ -497,6 +497,37 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item,
strbuf_release(&subject);
}
static char *get_head_description(void)
{
struct strbuf desc = STRBUF_INIT;
struct wt_status_state state;
memset(&state, 0, sizeof(state));
wt_status_get_state(&state, 1);
if (state.rebase_in_progress ||
state.rebase_interactive_in_progress)
strbuf_addf(&desc, _("(no branch, rebasing %s)"),
state.branch);
else if (state.bisect_in_progress)
strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
state.branch);
else if (state.detached_from) {
/* TRANSLATORS: make sure these match _("HEAD detached at ")
and _("HEAD detached from ") in wt-status.c */
if (state.detached_at)
strbuf_addf(&desc, _("(HEAD detached at %s)"),
state.detached_from);
else
strbuf_addf(&desc, _("(HEAD detached from %s)"),
state.detached_from);
}
else
strbuf_addstr(&desc, _("(no branch)"));
free(state.branch);
free(state.onto);
free(state.detached_from);
return strbuf_detach(&desc, NULL);
}
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
int abbrev, int current, const char *remote_prefix)
{
@ -570,37 +601,6 @@ static int calc_maxwidth(struct ref_list *refs, int remote_bonus)
return max;
}
static char *get_head_description(void)
{
struct strbuf desc = STRBUF_INIT;
struct wt_status_state state;
memset(&state, 0, sizeof(state));
wt_status_get_state(&state, 1);
if (state.rebase_in_progress ||
state.rebase_interactive_in_progress)
strbuf_addf(&desc, _("(no branch, rebasing %s)"),
state.branch);
else if (state.bisect_in_progress)
strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
state.branch);
else if (state.detached_from) {
/* TRANSLATORS: make sure these match _("HEAD detached at ")
and _("HEAD detached from ") in wt-status.c */
if (state.detached_at)
strbuf_addf(&desc, _("(HEAD detached at %s)"),
state.detached_from);
else
strbuf_addf(&desc, _("(HEAD detached from %s)"),
state.detached_from);
}
else
strbuf_addstr(&desc, _("(no branch)"));
free(state.branch);
free(state.onto);
free(state.detached_from);
return strbuf_detach(&desc, NULL);
}
static void show_detached(struct ref_list *ref_list, int maxwidth)
{
struct commit *head_commit = lookup_commit_reference_gently(head_sha1, 1);