git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] pathspec: turn on tries when appropriate

From
Jeff King <peff@peff.net>
Date
Jul 1, 2021, 21:30 UTC
Message-ID
<YN40B00vK2ul6yMW@coredump.intra.peff.net>
In-Reply-To
<YN4zKVK7gvuIZ0vK@coredump.intra.peff.net>

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(-)
diff --git a/pathspec.c b/pathspec.c
index 24a24f627e..435dfd3117 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -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,
diff --git a/pathspec.h b/pathspec.h
index 15c9244d08..5329c0a6f6 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -61,6 +61,7 @@ struct pathspec {
 		} *attr_match;
 		struct attr_check *attr_check;
 	} *items;
+	struct pathspec_trie *trie;
 };
 
 #define GUARD_PATHSPEC(ps, mask) \
diff --git a/t/helper/test-pathspec.c b/t/helper/test-pathspec.c
index 3f1b8f1a79..0fb059409b 100644
--- a/t/helper/test-pathspec.c
+++ b/t/helper/test-pathspec.c
@@ -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");
-- 
2.32.0.359.g3de86e008e.dirty
Previous: Jeff KingNext: Jeff King
Message 6 of 8 in “git log exclude pathspec from file - supported? plans?”
  1. Martin LanghoffJun 30, 2021
  2. Jeff KingJun 30, 2021
  3. Ævar Arnfjörð BjarmasonJun 30, 2021
  4. Jeff KingJul 1, 2021
  5. 1/3 pathspec: add optional trie indexJeff King, Jul 1, 2021
  6. 2/3 pathspec: turn on tries when appropriateJeff King, Jul 1, 2021
  7. 3/3 tree-diff: use pathspec triesJeff King, Jul 1, 2021
  8. Jeff KingJul 1, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.