match_tree_entry(): a pathspec only matches at directory boundaries
authorJunio C Hamano <gitster@pobox.com>
Thu, 2 Apr 2009 02:34:03 +0000 (19:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Apr 2009 02:35:31 +0000 (19:35 -0700)
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>
t/t3101-ls-tree-dirname.sh
tree.c

index 4dd7d12..51cb4a3 100755 (executable)
@@ -135,4 +135,10 @@ test_expect_success \
 EOF
      test_output'
 
+test_expect_success 'ls-tree filter is leading path match' '
+       git ls-tree $tree pa path3/a >current &&
+       >expected &&
+       test_output
+'
+
 test_done
diff --git a/tree.c b/tree.c
index 03e782a..d82a047 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -60,8 +60,12 @@ static int match_tree_entry(const char *base, int baselen, const char *path, uns
                        /* If it doesn't match, move along... */
                        if (strncmp(base, match, matchlen))
                                continue;
-                       /* The base is a subdirectory of a path which was specified. */
-                       return 1;
+                       /* pathspecs match only at the directory boundaries */
+                       if (!matchlen ||
+                           base[matchlen] == '/' ||
+                           match[matchlen - 1] == '/')
+                               return 1;
+                       continue;
                }
 
                /* Does the base match? */