ls-tree: remove path filtering logic in show_tree
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sun, 30 Nov 2014 09:05:01 +0000 (16:05 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Dec 2014 19:32:34 +0000 (11:32 -0800)
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>
builtin/ls-tree.c
quote.c
quote.h
t/t3102-ls-tree-wildcards.sh
index 1ab03812453970ecdaafccb2b4c24a06bb12651a..053edb23a0a3906a0ee64dd49eb2e2f071a465ba 100644 (file)
@@ -65,6 +65,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
                const char *pathname, unsigned mode, int stage, void *context)
 {
        int retval = 0;
+       int baselen;
        const char *type = blob_type;
 
        if (S_ISGITLINK(mode)) {
@@ -89,11 +90,6 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
        else if (ls_options & LS_TREE_ONLY)
                return 0;
 
-       if (chomp_prefix &&
-           (base->len < chomp_prefix ||
-            memcmp(ls_tree_prefix, base->buf, chomp_prefix)))
-               return 0;
-
        if (!(ls_options & LS_NAME_ONLY)) {
                if (ls_options & LS_SHOW_SIZE) {
                        char size_text[24];
@@ -113,8 +109,12 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
                        printf("%06o %s %s\t", mode, type,
                               find_unique_abbrev(sha1, abbrev));
        }
-       write_name_quotedpfx(base->buf + chomp_prefix, base->len - chomp_prefix,
-                         pathname, stdout, line_termination);
+       baselen = base->len;
+       strbuf_addstr(base, pathname);
+       write_name_quoted_relative(base->buf,
+                                  chomp_prefix ? ls_tree_prefix : NULL,
+                                  stdout, line_termination);
+       strbuf_setlen(base, baselen);
        return retval;
 }
 
diff --git a/quote.c b/quote.c
index 45e3db12d514dd7393539ca0aff09f5aa8467b8d..7920e18e44834f1f86c218c172ae10227858ed66 100644 (file)
--- a/quote.c
+++ b/quote.c
@@ -274,27 +274,6 @@ void write_name_quoted(const char *name, FILE *fp, int terminator)
        fputc(terminator, fp);
 }
 
-void write_name_quotedpfx(const char *pfx, size_t pfxlen,
-                         const char *name, FILE *fp, int terminator)
-{
-       int needquote = 0;
-
-       if (terminator) {
-               needquote = next_quote_pos(pfx, pfxlen) < pfxlen
-                       || name[next_quote_pos(name, -1)];
-       }
-       if (needquote) {
-               fputc('"', fp);
-               quote_c_style_counted(pfx, pfxlen, NULL, fp, 1);
-               quote_c_style(name, NULL, fp, 1);
-               fputc('"', fp);
-       } else {
-               fwrite(pfx, pfxlen, 1, fp);
-               fputs(name, fp);
-       }
-       fputc(terminator, fp);
-}
-
 void write_name_quoted_relative(const char *name, const char *prefix,
                                FILE *fp, int terminator)
 {
diff --git a/quote.h b/quote.h
index 71dcc3aa0279af6611f7471d1a4c9949b1dc49fb..99e04d34bf223a0147e65623322ef2c2fb01e01d 100644 (file)
--- a/quote.h
+++ b/quote.h
@@ -56,8 +56,6 @@ extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq
 extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);
 
 extern void write_name_quoted(const char *name, FILE *, int terminator);
-extern void write_name_quotedpfx(const char *pfx, size_t pfxlen,
-                                 const char *name, FILE *, int terminator);
 extern void write_name_quoted_relative(const char *name, const char *prefix,
                FILE *fp, int terminator);
 
index c286854485d065816ff2c9fdd225c54734d48b60..83fca8df8b3672446eb5f78515934a5f78646023 100755 (executable)
@@ -19,4 +19,12 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'ls-tree outside prefix' '
+       cat >expected <<EOF &&
+100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391   ../a[a]/three
+EOF
+       ( cd aa && git ls-tree -r HEAD "../a[a]"; ) >actual &&
+       test_cmp expected actual
+'
+
 test_done