tree_entry_interesting: a pathspec only matches at directory boundary
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: Björn Steinbrink <B.Steinbrink@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Björn Steinbrink committed
Mar 31, 2009 at 17:05 UTC
f0946cb826b9b6c01976860fdd9dfd498ce0ec5e
2 files changed
+17
-3
t/t4010-diff-pathspec.sh
+8
@@ -62,4 +62,12 @@ test_expect_success \
62
'git diff-index --cached $tree -- file0/ >current &&
63
compare_diff_raw current expected'
64
65
+test_expect_success 'diff-tree pathspec' '
66
+ tree2=$(git write-tree) &&
67
+ echo "$tree2" &&
68
+ git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
69
+ >expected &&
70
+ test_cmp expected current
71
+'
72
+
73
test_done
tree-diff.c
+9
-3
@@ -118,10 +118,16 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
118
continue;
119
120
/*
121
- * The base is a subdirectory of a path which
122
- * was specified, so all of them are interesting.
121
+ * If the base is a subdirectory of a path which
122
+ * was specified, all of them are interesting.
123
*/
124
- return 2;
124
+ if (!matchlen ||
125
+ base[matchlen] == '/' ||
126
+ match[matchlen - 1] == '/')
127
+ return 2;
128
+
129
+ /* Just a random prefix match */
130
+ continue;
131
}
132
133
/* Does the base match? */