git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] wt-status: use separate variable for result of shorten_unambiguous_ref
@ 2017-07-08 10:51 René Scharfe
  2017-07-10  2:51 ` Stefan Beller
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2017-07-08 10:51 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Stefan Beller

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>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] wt-status: use separate variable for result of shorten_unambiguous_ref
  2017-07-08 10:51 [PATCH] wt-status: use separate variable for result of shorten_unambiguous_ref René Scharfe
@ 2017-07-10  2:51 ` Stefan Beller
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Beller @ 2017-07-10  2:51 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano

On Sat, Jul 8, 2017 at 3:51 AM, René Scharfe <l.s.r@web.de> wrote:
> 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>

> ---
>  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
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-10  2:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-08 10:51 [PATCH] wt-status: use separate variable for result of shorten_unambiguous_ref René Scharfe
2017-07-10  2:51 ` Stefan Beller

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).