aboutsummaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-12-15 22:02:45 +0700
committerJunio C Hamano <gitster@pobox.com>2011-02-03 14:08:30 -0800
commit86e4ca69e358836599d4eb0c0e217caa9c9e455b (patch)
tree1b9f49279e2f071bb12b1777481826de1d139908 /dir.c
parentbc96cc87dbb229cbdabfd93391e24ef168713a74 (diff)
downloadgit-86e4ca69e358836599d4eb0c0e217caa9c9e455b.tar.gz
git-86e4ca69e358836599d4eb0c0e217caa9c9e455b.tar.xz
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>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/dir.c b/dir.c
index c3bddb60c..5b4e2b1cb 100644
--- a/dir.c
+++ b/dir.c
@@ -1166,6 +1166,15 @@ int remove_path(const char *name)
return 0;
}
+static int pathspec_item_cmp(const void *a_, const void *b_)
+{
+ struct pathspec_item *a, *b;
+
+ a = (struct pathspec_item *)a_;
+ b = (struct pathspec_item *)b_;
+ return strcmp(a->match, b->match);
+}
+
int init_pathspec(struct pathspec *pathspec, const char **paths)
{
const char **p = paths;
@@ -1189,6 +1198,10 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
item->match = path;
item->len = strlen(path);
}
+
+ qsort(pathspec->items, pathspec->nr,
+ sizeof(struct pathspec_item), pathspec_item_cmp);
+
return 0;
}