summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dir.c13
-rw-r--r--tree-walk.c2
2 files changed, 14 insertions, 1 deletions
diff --git a/dir.c b/dir.c
index c3bddb6..5b4e2b1 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;
}
diff --git a/tree-walk.c b/tree-walk.c
index 33feafa..be8182c 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -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;