wt-status: use separate variable for result of shorten_unambiguous_ref

Store the pointer to the string allocated by shorten_unambiguous_ref in a dedicated variable, short_base, and keep base unchanged. A non-const variable is more appropriate for such an object. It avoids having to cast const away on free and stops redefining the meaning of base, making the code slightly clearer. Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 8, 2017 at 12:51 UTC 5e8d2729ae64483efd5e8663cbc9d476364fb472
1 file changed +4 -3
wt-status.c
+4 -3
@@ -1735,6 +1735,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1735 const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s);
1736
1737 const char *base;
1738 + char *short_base;
1739 const char *branch_name;
1740 int num_ours, num_theirs;
1741 int upstream_is_gone = 0;
@@ -1769,10 +1770,10 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1770 upstream_is_gone = 1;
1771 }
1772
1772 - base = shorten_unambiguous_ref(base, 0);
1773 + short_base = shorten_unambiguous_ref(base, 0);
1774 color_fprintf(s->fp, header_color, "...");
1774 - color_fprintf(s->fp, branch_color_remote, "%s", base);
1775 - free((char *)base);
1775 + color_fprintf(s->fp, branch_color_remote, "%s", short_base);
1776 + free(short_base);
1777
1778 if (!upstream_is_gone && !num_ours && !num_theirs)
1779 goto conclude;