@@ -639,6 +639,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 = build_pathspec_trie(pathspec);
}
void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask,
@@ -61,6 +61,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 = build_pathspec_trie(&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");
An earlier commit introduced pathspec_tries, but we did not actually generate them by default. This patch causes us to do so when it is possible (i.e., when no wildcards or other pathspec magic are in use). This doesn't actually do anything yet, though, as none of the pathspec users have learned to make use of the tries. We embed the pathspec_trie directly inside the "struct pathspec". This is not strictly necessary, as once created, the trie does not depend on the original pathspec. However, since the intended use is to optimize existing pathspec callers, passing the trie around as part of the pathspec will minimize disruption to the call chain. Signed-off-by: Jeff King <peff@peff.net> --- pathspec.c | 2 ++ pathspec.h | 1 + t/helper/test-pathspec.c | 6 ++---- 3 files changed, 5 insertions(+), 4 deletions(-)