@@ -117,6 +117,19 @@ struct pathspec_trie *pathspec_trie_build(const struct pathspec *pathspec)
return ret;
}
+static void pathspec_trie_clear(struct pathspec_trie *t)
+{
+ if (t) {
+ for (size_t i = 0; i < t->nr; i++) {
+ pathspec_trie_clear(t->entries[i]);
+ FREE_AND_NULL(t->entries[i]);
+ }
+
+ t->nr = 0;
+ FREE_AND_NULL(t->entries);
+ }
+}
+
int pathspec_trie_lookup(const struct pathspec_trie *parent,
const char *path, size_t len)
{
@@ -799,6 +812,8 @@ void parse_pathspec(struct pathspec *pathspec,
BUG("PATHSPEC_MAXDEPTH_VALID and PATHSPEC_KEEP_ORDER are incompatible");
QSORT(pathspec->items, pathspec->nr, pathspec_item_cmp);
}
+
+ pathspec->trie = pathspec_trie_build(pathspec);
}
void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask,
@@ -859,6 +874,8 @@ void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
d->attr_check = attr_check_dup(s->attr_check);
}
+
+ dst->trie = pathspec_trie_build(dst);
}
void clear_pathspec(struct pathspec *pathspec)
@@ -877,6 +894,8 @@ void clear_pathspec(struct pathspec *pathspec)
attr_check_free(pathspec->items[i].attr_check);
}
+ pathspec_trie_clear(pathspec->trie);
+ FREE_AND_NULL(pathspec->trie);
FREE_AND_NULL(pathspec->items);
pathspec->nr = 0;
}
@@ -76,6 +76,7 @@ struct pathspec {
} *attr_match;
struct attr_check *attr_check;
} *items;
+ struct pathspec_trie *trie;
};
#define GUARD_PATHSPEC(ps, mask) \
@@ -63,7 +63,6 @@ static int cmd_trie(const char **argv)
{
const char **specs, **paths;
struct pathspec pathspec;
- struct pathspec_trie *trie;
paths = specs = argv;
while (*paths && strcmp(*paths, "--"))
@@ -72,12 +71,11 @@ static int cmd_trie(const char **argv)
*paths++ = NULL;
parse_pathspec(&pathspec, 0, 0, "", specs);
- trie = pathspec_trie_build(&pathspec);
- if (!trie)
+ if (!pathspec.trie)
die("unable to make trie from pathspec");
for (; *paths; paths++) {
- if (trie_match(trie, *paths))
+ if (trie_match(pathspec.trie, *paths))
printf("yes\n");
else
printf("no\n");