@matheusbsbs / matheus-bagliano / commits / 86e4ca69e3
Fork 0

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>

Nguyễn Thái Ngọc Duy committed Dec 15, 2010 at 22:02 UTC 86e4ca69e358836599d4eb0c0e217caa9c9e455b
2 files changed +14 -1
dir.c
+13
@@ -1166,6 +1166,15 @@ int remove_path(const char *name)
1166 return 0;
1167 }
1168
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 +
1178 int init_pathspec(struct pathspec *pathspec, const char **paths)
1179 {
1180 const char **p = paths;
@@ -1189,6 +1198,10 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
1198 item->match = path;
1199 item->len = strlen(path);
1200 }
1201 +
1202 + qsort(pathspec->items, pathspec->nr,
1203 + sizeof(struct pathspec_item), pathspec_item_cmp);
1204 +
1205 return 0;
1206 }
1207
tree-walk.c
+1 -1
@@ -570,7 +570,7 @@ int tree_entry_interesting(const struct name_entry *entry,
570
571 pathlen = tree_entry_len(entry->path, entry->sha1);
572
573 - for (i = 0; i < ps->nr; i++) {
573 + for (i = ps->nr-1; i >= 0; i--) {
574 const struct pathspec_item *item = ps->items+i;
575 const char *match = item->match;
576 int matchlen = item->len;