Skip to content

Commit 9d7d10e

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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c4dc9d4 commit 9d7d10e

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
@@ -1086,6 +1086,15 @@ int remove_path(const char *name)
10861086
return 0;
10871087
}
10881088

1089+
static int pathspec_item_cmp(const void *a_, const void *b_)
1090+
{
1091+
struct pathspec_item *a, *b;
1092+
1093+
a = (struct pathspec_item *)a_;
1094+
b = (struct pathspec_item *)b_;
1095+
return strcmp(a->match, b->match);
1096+
}
1097+
10891098
int init_pathspec(struct pathspec *pathspec, const char **paths)
10901099
{
10911100
const char **p = paths;
@@ -1109,6 +1118,10 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
11091118
item->match = path;
11101119
item->len = strlen(path);
11111120
}
1121+
1122+
qsort(pathspec->items, pathspec->nr,
1123+
sizeof(struct pathspec_item), pathspec_item_cmp);
1124+
11121125
return 0;
11131126
}
11141127

tree-walk.c

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

569569
pathlen = tree_entry_len(entry->path, entry->sha1);
570570

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

0 commit comments

Comments
 (0)