[PATCH] match_tree_entry(): a pathspec only matches at directory boundaries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---

 * And this is a companion patch to fix ls-tree.  The test case uses a
   tree that has path3/1.txt and path3/2.txt in it.

   The bug Eric diagnosed and worked around in git-svn makes the current
   code show these two paths when pathspec "pa" and "path3/a" are given.
   The presense of "path3/a" makes the tree walker traverse down to path3
   subtree (in case something that matches "a" is in there---this is a
   correct behaviour), but then in that subtree, "pa" incorrectly matches
   "path3/1.txt".

   This logic dates back to 0ca14a5 (Start adding interfaces to read in
   partial trees, 2005-07-14).  I think it is just a simple oversight and
   we should fix it.

 t/t3101-ls-tree-dirname.sh |    6 ++++++
 tree.c                     |    8 ++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/t/t3101-ls-tree-dirname.sh b/t/t3101-ls-tree-dirname.sh
index 4dd7d12..51cb4a3 100755
--- a/t/t3101-ls-tree-dirname.sh
+++ b/t/t3101-ls-tree-dirname.sh
@@ -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
--- 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? */
-- 
1.6.2.1.483.gcc994

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux