@matheusbsbs / matheus-bagliano / commits / 8092bfb6c2
Fork 0

match_tree_entry(): a pathspec only matches at directory boundaries

Previously the code did a simple prefix match, which means that a path in a directory "frotz/" would have matched with pathspec "f". Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 1, 2009 at 19:34 UTC 8092bfb6c23776d72ce4b38a3b517c3753c3b9fe
2 files changed +12 -2
t/t3101-ls-tree-dirname.sh
+6
@@ -135,4 +135,10 @@ test_expect_success \
135 EOF
136 test_output'
137
138 +test_expect_success 'ls-tree filter is leading path match' '
139 + git ls-tree $tree pa path3/a >current &&
140 + >expected &&
141 + test_output
142 +'
143 +
144 test_done
tree.c
+6 -2
@@ -60,8 +60,12 @@ static int match_tree_entry(const char *base, int baselen, const char *path, uns
60 /* If it doesn't match, move along... */
61 if (strncmp(base, match, matchlen))
62 continue;
63 - /* The base is a subdirectory of a path which was specified. */
64 - return 1;
63 + /* pathspecs match only at the directory boundaries */
64 + if (!matchlen ||
65 + base[matchlen] == '/' ||
66 + match[matchlen - 1] == '/')
67 + return 1;
68 + continue;
69 }
70
71 /* Does the base match? */