git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] wt-status: use separate variable for result of shorten_unambiguous_ref

From
Stefan Beller <sbeller@google.com>
Date
Jul 10, 2017, 02:51 UTC
Message-ID
<CAGZ79kZgJpLttFOT01XOD-dj8Ag6A_1kkwGngbH2MMaO=_F-NA@mail.gmail.com>
In-Reply-To
<d70bf87c-f8b3-9f02-14bd-b3ceb5e9f7e4@web.de>
On Sat, Jul 8, 2017 at 3:51 AM, René Scharfe <l.s.r@web.de> wrote:
Show 7 quoted lines
> 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>
Thanks,
Reviewed-by: Stefan Beller <sbeller@google.com>
Show 33 quoted lines
> ---
>  wt-status.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/wt-status.c b/wt-status.c
> index 8d2fb35b08..77c27c5113 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -1763,6 +1763,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
>         const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s);
>
>         const char *base;
> +       char *short_base;
>         const char *branch_name;
>         int num_ours, num_theirs;
>         int upstream_is_gone = 0;
> @@ -1797,10 +1798,10 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
>                 upstream_is_gone = 1;
>         }
>
> -       base = shorten_unambiguous_ref(base, 0);
> +       short_base = shorten_unambiguous_ref(base, 0);
>         color_fprintf(s->fp, header_color, "...");
> -       color_fprintf(s->fp, branch_color_remote, "%s", base);
> -       free((char *)base);
> +       color_fprintf(s->fp, branch_color_remote, "%s", short_base);
> +       free(short_base);
>
>         if (!upstream_is_gone && !num_ours && !num_theirs)
>                 goto conclude;
> --
> 2.13.2
>
Previous: René Scharfe
Message 2 of 2 in “wt-status: use separate variable for result of shorten_unambiguous_ref”
  1. wt-status: use separate variable for result of shorten_unambiguous_refRené Scharfe, Jul 8, 2017
  2. Stefan BellerJul 10, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.