From: Junio C Hamano Date: Mon, 23 Jan 2023 21:39:50 +0000 (-0800) Subject: Merge branch 'rs/ls-tree-path-expansion-fix' X-Git-Tag: v2.40.0-rc0~64 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8a40af9cabe2efbb830bf90c864ffda3136926ba;p=thirdparty%2Fgit.git Merge branch 'rs/ls-tree-path-expansion-fix' "git ls-tree --format='%(path) %(path)' $tree $path" showed the path three times, which has been corrected. * rs/ls-tree-path-expansion-fix: ls-tree: remove dead store and strbuf for quote_c_style() ls-tree: fix expansion of repeated %(path) --- 8a40af9cabe2efbb830bf90c864ffda3136926ba diff --cc builtin/ls-tree.c index 72eb70823d,35e793d4af..8cc8c995df --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@@ -90,18 -91,18 +90,18 @@@ static size_t expand_show_tree(struct s } else if (skip_prefix(start, "(objectsize)", &p)) { expand_objectsize(sb, data->oid, data->type, 0); } else if (skip_prefix(start, "(objectname)", &p)) { - strbuf_add_unique_abbrev(sb, data->oid, abbrev); + strbuf_add_unique_abbrev(sb, data->oid, options->abbrev); } else if (skip_prefix(start, "(path)", &p)) { - const char *name; - const char *prefix = chomp_prefix ? ls_tree_prefix : NULL; + const char *name = data->base->buf; + const char *prefix = options->chomp_prefix ? options->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, "ed, NULL, 0); - strbuf_addbuf(sb, "ed); + quote_c_style(name, sb, NULL, 0); + strbuf_setlen(data->base, baselen); strbuf_release(&sbuf); - strbuf_release("ed); } else { errlen = (unsigned long)len; die(_("bad ls-tree format: %%%.*s"), errlen, start); @@@ -143,8 -143,6 +143,7 @@@ static int show_recursive(struct ls_tre static int show_tree_fmt(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *context) { + struct ls_tree_options *options = context; - size_t baselen; int recurse = 0; struct strbuf sb = STRBUF_INIT; enum object_type type = object_type(mode); @@@ -157,19 -155,17 +156,17 @@@ .base = base, }; - if (type == OBJ_TREE && show_recursive(base->buf, base->len, pathname)) + if (type == OBJ_TREE && show_recursive(options, base->buf, base->len, pathname)) recurse = READ_TREE_RECURSIVE; - if (type == OBJ_TREE && recurse && !(ls_options & LS_SHOW_TREES)) + if (type == OBJ_TREE && recurse && !(options->ls_options & LS_SHOW_TREES)) return recurse; - if (type == OBJ_BLOB && (ls_options & LS_TREE_ONLY)) + if (type == OBJ_BLOB && (options->ls_options & LS_TREE_ONLY)) return 0; - baselen = base->len; - strbuf_expand(&sb, format, expand_show_tree, &data); - strbuf_addch(&sb, line_termination); + strbuf_expand(&sb, options->format, expand_show_tree, &cb_data); + strbuf_addch(&sb, options->null_termination ? '\0' : '\n'); fwrite(sb.buf, sb.len, 1, stdout); strbuf_release(&sb); - strbuf_setlen(base, baselen); return recurse; }