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, "ed, NULL, 0);
+ strbuf_setlen(data->base, baselen);
strbuf_addbuf(sb, "ed);
strbuf_release(&sbuf);
strbuf_release("ed);
static int show_tree_fmt(const struct object_id *oid, struct strbuf *base,
const char *pathname, unsigned mode, void *context)
{
- size_t baselen;
int recurse = 0;
struct strbuf sb = STRBUF_INIT;
enum object_type type = object_type(mode);
if (type == OBJ_BLOB && (ls_options & LS_TREE_ONLY))
return 0;
- baselen = base->len;
strbuf_expand(&sb, format, expand_show_tree, &data);
strbuf_addch(&sb, line_termination);
fwrite(sb.buf, sb.len, 1, stdout);
strbuf_release(&sb);
- strbuf_setlen(base, baselen);
return recurse;
}
'
}
+test_expect_success "ls-tree --format='%(path) %(path) %(path)' HEAD top-file" '
+ git ls-tree --format="%(path) %(path) %(path)" HEAD top-file.t >actual &&
+ echo top-file.t top-file.t top-file.t >expect &&
+ test_cmp expect actual
+'
+
test_ls_tree_format \
"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
""