]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tree_entry_interesting(): fix depth limit with overlapping pathspecs
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Wed, 15 Dec 2010 15:02:45 +0000 (22:02 +0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Feb 2011 22:08:30 +0000 (14:08 -0800)
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>
dir.c
tree-walk.c

diff --git a/dir.c b/dir.c
index c3bddb60c81fbf362614f081a5b62f0160a01c63..5b4e2b1cb32c9a00d001d4202d8ebb09e30e7103 100644 (file)
--- 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;
 }
 
index 33feafa964c86bd76df0d9d53d930530cf78918d..be8182c72f90764c77807f6e872a0f333efa3edc 100644 (file)
@@ -570,7 +570,7 @@ int tree_entry_interesting(const struct name_entry *entry,
 
        pathlen = tree_entry_len(entry->path, entry->sha1);
 
-       for (i = 0; i < ps->nr; i++) {
+       for (i = ps->nr-1; i >= 0; i--) {
                const struct pathspec_item *item = ps->items+i;
                const char *match = item->match;
                int matchlen = item->len;