]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ls-tree: remove dead store and strbuf for quote_c_style()
authorRené Scharfe <l.s.r@web.de>
Sat, 14 Jan 2023 15:03:16 +0000 (16:03 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 15 Jan 2023 03:22:26 +0000 (19:22 -0800)
Stop initializing "name" because it is set again before use.

Let quote_c_style() write directly to "sb" instead of taking a detour
through "quoted".  This avoids an allocation and a string copy.  The
result is the same because the function only appends.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/ls-tree.c

index c3284610ddc6a6231b61d0050bb4d931e8d4abda..35e793d4afc7f9b78cdf9b79445f14c667a5f429 100644 (file)
@@ -93,19 +93,16 @@ static size_t expand_show_tree(struct strbuf *sb, const char *start,
        } else if (skip_prefix(start, "(objectname)", &p)) {
                strbuf_add_unique_abbrev(sb, data->oid, abbrev);
        } else if (skip_prefix(start, "(path)", &p)) {
-               const char *name = data->base->buf;
+               const char *name;
                const char *prefix = chomp_prefix ? ls_tree_prefix : NULL;
-               struct strbuf quoted = STRBUF_INIT;
                struct strbuf sbuf = STRBUF_INIT;
                size_t baselen = data->base->len;
 
                strbuf_addstr(data->base, data->pathname);
                name = relative_path(data->base->buf, prefix, &sbuf);
-               quote_c_style(name, &quoted, NULL, 0);
+               quote_c_style(name, sb, NULL, 0);
                strbuf_setlen(data->base, baselen);
-               strbuf_addbuf(sb, &quoted);
                strbuf_release(&sbuf);
-               strbuf_release(&quoted);
        } else {
                errlen = (unsigned long)len;
                die(_("bad ls-tree format: %%%.*s"), errlen, start);