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>

Karthik Nayak committed Sep 23, 2015 at 23:41 UTC 2dad24a5c39bb26a815c35c5db7a35499bad48e1
1 file changed +31 -31
builtin/branch.c
+31 -31
@@ -497,6 +497,37 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item,
497 strbuf_release(&subject);
498 }
499
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 +
531 static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
532 int abbrev, int current, const char *remote_prefix)
533 {
@@ -570,37 +601,6 @@ static int calc_maxwidth(struct ref_list *refs, int remote_bonus)
601 return max;
602 }
603
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 -
604 static void show_detached(struct ref_list *ref_list, int maxwidth)
605 {
606 struct commit *head_commit = lookup_commit_reference_gently(head_sha1, 1);