Re: [PATCH] describe: use strbuf_add_unique_abbrev() for adding short hashes
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Jan 16, 2018, 13:48 UTC
- Message-ID
- <6f91c34e-3ab0-30fc-4678-4424ac350cd9@gmail.com>
- In-Reply-To
- <422ae05b-6541-38f3-7638-4bee1b766d91@web.de>
On 1/15/2018 12:10 PM, René Scharfe wrote:
Show 29 quoted lines
> Call strbuf_add_unique_abbrev() to add an abbreviated hash to a strbuf
> instead of taking a detour through find_unique_abbrev() and its static
> buffer. This is shorter and a bit more efficient.
>
> Patch generated by Coccinelle (and contrib/coccinelle/strbuf.cocci).
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
> The changed line was added by 4dbc59a4cc (builtin/describe.c: factor
> out describe_commit).
>
> "make coccicheck" doesn't propose any other changes for current master.
>
> builtin/describe.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/describe.c b/builtin/describe.c
> index 3b0b204b1e..21e37f5dae 100644
> --- a/builtin/describe.c
> +++ b/builtin/describe.c
> @@ -380,7 +380,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
> if (!match_cnt) {
> struct object_id *cmit_oid = &cmit->object.oid;
> if (always) {
> - strbuf_addstr(dst, find_unique_abbrev(cmit_oid->hash, abbrev));
> + strbuf_add_unique_abbrev(dst, cmit_oid->hash, abbrev);
> if (suffix)
> strbuf_addstr(dst, suffix);
> return;René,
Thanks for this cleanup! I just learned about strbuf_add_unique_abbrev() and like that it uses the reentrant find_unique_abbrev_r() instead.
Looks good to me. -Stolee