Skip to content

Commit 652f0c8

Browse files
committed
Merge branch 'bs/maint-1.6.0-tree-walk-prefix' into maint-1.6.1
* bs/maint-1.6.0-tree-walk-prefix: match_tree_entry(): a pathspec only matches at directory boundaries tree_entry_interesting: a pathspec only matches at directory boundary
2 parents 9347473 + 8092bfb commit 652f0c8

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

t/t3101-ls-tree-dirname.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,10 @@ test_expect_success \
135135
EOF
136136
test_output'
137137

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+
138144
test_done

t/t4010-diff-pathspec.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@ test_expect_success \
6262
'git diff-index --cached $tree -- file0/ >current &&
6363
compare_diff_raw current expected'
6464

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+
6573
test_done

tree-diff.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,16 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
118118
continue;
119119

120120
/*
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.
123123
*/
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;
125131
}
126132

127133
/* Does the base match? */

tree.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ static int match_tree_entry(const char *base, int baselen, const char *path, uns
6060
/* If it doesn't match, move along... */
6161
if (strncmp(base, match, matchlen))
6262
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;
6569
}
6670

6771
/* Does the base match? */

0 commit comments

Comments
 (0)