Skip to content

Commit 86e4ca6

Browse files
pcloudsgitster
authored andcommitted
tree_entry_interesting(): fix depth limit with overlapping pathspecs
Suppose we have two pathspecs 'a' and 'a/b' (both are dirs) and depth limit 1. In current code, pathspecs are checked in input order. When 'a/b' is checked against pathspec 'a', it fails depth limit and therefore is excluded, although it should match 'a/b' pathspec. This patch reorders all pathspecs alphabetically, then teaches tree_entry_interesting() to check against the deepest pathspec first, so depth limit of a shallower pathspec won't affect a deeper one. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc96cc8 commit 86e4ca6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

dir.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,15 @@ int remove_path(const char *name)
11661166
return 0;
11671167
}
11681168

1169+
static int pathspec_item_cmp(const void *a_, const void *b_)
1170+
{
1171+
struct pathspec_item *a, *b;
1172+
1173+
a = (struct pathspec_item *)a_;
1174+
b = (struct pathspec_item *)b_;
1175+
return strcmp(a->match, b->match);
1176+
}
1177+
11691178
int init_pathspec(struct pathspec *pathspec, const char **paths)
11701179
{
11711180
const char **p = paths;
@@ -1189,6 +1198,10 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
11891198
item->match = path;
11901199
item->len = strlen(path);
11911200
}
1201+
1202+
qsort(pathspec->items, pathspec->nr,
1203+
sizeof(struct pathspec_item), pathspec_item_cmp);
1204+
11921205
return 0;
11931206
}
11941207

tree-walk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ int tree_entry_interesting(const struct name_entry *entry,
570570

571571
pathlen = tree_entry_len(entry->path, entry->sha1);
572572

573-
for (i = 0; i < ps->nr; i++) {
573+
for (i = ps->nr-1; i >= 0; i--) {
574574
const struct pathspec_item *item = ps->items+i;
575575
const char *match = item->match;
576576
int matchlen = item->len;

0 commit comments

Comments
 (0)