ls-tree: remove path filtering logic in show_tree

ls-tree uses read_tree_recursive() which already does path filtering using pathspec. No need to filter one more time based on prefix only. "ls-tree ../somewhere" does not work because of this. write_name_quotedpfx() can now be retired because nobody else uses it. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Nov 30, 2014 at 16:05 UTC 1cf9952db243c624cc2763fa74e98adbb38537b1
4 files changed +15 -30
builtin/ls-tree.c
+7 -7
@@ -65,6 +65,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
65 const char *pathname, unsigned mode, int stage, void *context)
66 {
67 int retval = 0;
68 + int baselen;
69 const char *type = blob_type;
70
71 if (S_ISGITLINK(mode)) {
@@ -89,11 +90,6 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
90 else if (ls_options & LS_TREE_ONLY)
91 return 0;
92
92 - if (chomp_prefix &&
93 - (base->len < chomp_prefix ||
94 - memcmp(ls_tree_prefix, base->buf, chomp_prefix)))
95 - return 0;
96 -
93 if (!(ls_options & LS_NAME_ONLY)) {
94 if (ls_options & LS_SHOW_SIZE) {
95 char size_text[24];
@@ -113,8 +109,12 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
109 printf("%06o %s %s\t", mode, type,
110 find_unique_abbrev(sha1, abbrev));
111 }
116 - write_name_quotedpfx(base->buf + chomp_prefix, base->len - chomp_prefix,
117 - pathname, stdout, line_termination);
112 + baselen = base->len;
113 + strbuf_addstr(base, pathname);
114 + write_name_quoted_relative(base->buf,
115 + chomp_prefix ? ls_tree_prefix : NULL,
116 + stdout, line_termination);
117 + strbuf_setlen(base, baselen);
118 return retval;
119 }
120
quote.c
-21
@@ -274,27 +274,6 @@ void write_name_quoted(const char *name, FILE *fp, int terminator)
274 fputc(terminator, fp);
275 }
276
277 -void write_name_quotedpfx(const char *pfx, size_t pfxlen,
278 - const char *name, FILE *fp, int terminator)
279 -{
280 - int needquote = 0;
281 -
282 - if (terminator) {
283 - needquote = next_quote_pos(pfx, pfxlen) < pfxlen
284 - || name[next_quote_pos(name, -1)];
285 - }
286 - if (needquote) {
287 - fputc('"', fp);
288 - quote_c_style_counted(pfx, pfxlen, NULL, fp, 1);
289 - quote_c_style(name, NULL, fp, 1);
290 - fputc('"', fp);
291 - } else {
292 - fwrite(pfx, pfxlen, 1, fp);
293 - fputs(name, fp);
294 - }
295 - fputc(terminator, fp);
296 -}
297 -
277 void write_name_quoted_relative(const char *name, const char *prefix,
278 FILE *fp, int terminator)
279 {
quote.h
-2
@@ -56,8 +56,6 @@ extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq
56 extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);
57
58 extern void write_name_quoted(const char *name, FILE *, int terminator);
59 -extern void write_name_quotedpfx(const char *pfx, size_t pfxlen,
60 - const char *name, FILE *, int terminator);
59 extern void write_name_quoted_relative(const char *name, const char *prefix,
60 FILE *fp, int terminator);
61
t/t3102-ls-tree-wildcards.sh
+8
@@ -19,4 +19,12 @@ EOF
19 test_cmp expected actual
20 '
21
22 +test_expect_success 'ls-tree outside prefix' '
23 + cat >expected <<EOF &&
24 +100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 ../a[a]/three
25 +EOF
26 + ( cd aa && git ls-tree -r HEAD "../a[a]"; ) >actual &&
27 + test_cmp expected actual
28 +'
29 +
30 test_done