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

[PATCH 2/4] revision: expose check for paths maybe changed in Bloom filter

From
Toon Claes <toon@iotcl.com>
Date
Jul 17, 2026, 15:47 UTC
Message-ID
<20260717-toon-speed-up-last-modified-v1-2-410418f18614@iotcl.com>
In-Reply-To
<20260717-toon-speed-up-last-modified-v1-0-410418f18614@iotcl.com>

check_maybe_different_in_bloom_filter() looks up a commit's changed-path Bloom filter and consults it to see whether the commit might have modified any of the paths in the pathspec that `revs` was set up with. In a follow-up commit we want to reuse this logic from another builtin.

That caller, however, has already looked up the commit's Bloom filter for its own purposes, so having the function look it up again would mean a redundant lookup.

Extract the filter-consulting part into a new public function, revs_maybe_changed_in_bloom(). This function takes an already looked-up `struct bloom_filter` instead of a commit. The existing check_maybe_different_in_bloom_filter() becomes a thin wrapper that looks up the filter and delegates.

Expose the new function via revision.h so other builtins can reuse the exact same filtering that `git log <pathspec>` performs.

Signed-off-by: Toon Claes <toon@iotcl.com>
---
 revision.c | 31 +++++++++++++++++++++----------
 revision.h | 17 +++++++++++++++++
 2 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/revision.c b/revision.c
index f3c9407a66..040b30b5ee 100644
--- a/revision.c
+++ b/revision.c
@@ -748,26 +748,20 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
 						 struct commit *commit)
 {
 	struct bloom_filter *filter;
-	int result = 0;
-
-	if (!revs->bloom_keyvecs_nr)
-		return -1;
+	int result;
 
 	if (commit_graph_generation(commit) == GENERATION_NUMBER_INFINITY)
 		return -1;
 
 	filter = get_bloom_filter(revs->repo, commit);
-
 	if (!filter) {
 		count_bloom_filter_not_present++;
 		return -1;
 	}
 
-	for (size_t nr = 0; !result && nr < revs->bloom_keyvecs_nr; nr++) {
-		result = bloom_filter_contains_vec(filter,
-						   revs->bloom_keyvecs[nr],
-						   revs->bloom_filter_settings);
-	}
+	result = revs_maybe_changed_in_bloom(revs, filter);
+	if (result < 0)
+		return result;
 
 	if (result)
 		count_bloom_filter_maybe++;
@@ -777,6 +771,23 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
 	return result;
 }
 
+int revs_maybe_changed_in_bloom(struct rev_info *revs,
+				struct bloom_filter *filter)
+{
+	int result = 0;
+
+	if (!revs->bloom_keyvecs_nr)
+		return -1;
+
+	for (size_t nr = 0; !result && nr < revs->bloom_keyvecs_nr; nr++) {
+		result = bloom_filter_contains_vec(filter,
+						   revs->bloom_keyvecs[nr],
+						   revs->bloom_filter_settings);
+	}
+
+	return result;
+}
+
 static int rev_compare_tree(struct rev_info *revs,
 			    struct commit *parent, struct commit *commit, int nth_parent)
 {
diff --git a/revision.h b/revision.h
index 569b3fa1cb..7569c210cc 100644
--- a/revision.h
+++ b/revision.h
@@ -68,6 +68,7 @@ struct string_list;
 struct saved_parents;
 struct follow_pathspec_slab;
 struct bloom_keyvec;
+struct bloom_filter;
 struct bloom_filter_settings;
 struct option;
 struct parse_opt_ctx_t;
@@ -493,6 +494,22 @@ void reset_revision_walk(void);
  */
 int prepare_revision_walk(struct rev_info *revs);
 
+/**
+ * Take in a changed-path Bloom filter that belongs to a commit, and consult it
+ * to see if it might have modified any of the paths in the `revs`.
+ * The caller should look up `filter`, probably with get_bloom_filter().
+ * prepare_revision_walk() needs to be called in advance to ensure
+ * pathspec key vectors are set up.
+ *
+ * Returns -1 if no sensible answer could be given because of missing
+ * preconditions (no pathspec key vectors).
+ * Returns 0 if the commit definitely did not change any of the paths and 1 if
+ * the commit maybe has changed one of them, although that might be a
+ * false-positive.
+ */
+int revs_maybe_changed_in_bloom(struct rev_info *revs,
+				struct bloom_filter *filter);
+
 /* Drain the commits linked list into the priority queue. */
 void rev_info_commit_list_to_queue(struct rev_info *revs);
 /**
-- 
2.53.0.1323.g189a785ab5
Previous: Jeff KingNext: Junio C Hamano
Message 6 of 30 in “last-modified: use the pathspec's Bloom key to pre-filter commits”
  1. 0/4 last-modified: use the pathspec's Bloom key to pre-filter commitsToon Claes, Jul 17, 2026
  2. 1/4 revision: move bloom keyvec precondition into functionToon Claes, Jul 17, 2026
  3. Jeff KingJul 18, 2026
  4. Toon ClaesAug 5, 2026
  5. Jeff KingAug 5, 2026
  6. 2/4 revision: expose check for paths maybe changed in Bloom filterToon Claes, Jul 17, 2026
  7. Junio C HamanoJul 17, 2026
  8. Taylor BlauJul 17, 2026
  9. 3/4 last-modified: check pathspec against Bloom filter firstToon Claes, Jul 17, 2026
  10. Taylor BlauJul 17, 2026
  11. Jeff KingJul 18, 2026
  12. Taylor BlauJul 18, 2026
  13. Jeff KingJul 20, 2026
  14. 4/4 last-modified: keep per-path Bloom filters for wildcard pathspecsToon Claes, Jul 17, 2026
  15. Toon ClaesJul 17, 2026
  16. Jeff KingJul 18, 2026
  17. Junio C HamanoAug 4, 2026
  18. Taylor BlauAug 5, 2026
  19. Junio C HamanoAug 5, 2026
  20. Jeff KingAug 5, 2026
  21. Taylor BlauJul 17, 2026
  22. Toon ClaesJul 17, 2026
  23. 0/6 last-modified: use the pathspec's Bloom key to pre-filter commitsToon Claes, Aug 7, 2026
  24. 1/6 revision: move bloom keyvec precondition into functionToon Claes, Aug 7, 2026
  25. 2/6 revision: expose check for paths maybe changed in Bloom filterToon Claes, Aug 7, 2026
  26. 3/6 bloom: add helper to check if any key in a vector is presentToon Claes, Aug 7, 2026
  27. 4/6 revision: add Bloom check that includes parent directoriesToon Claes, Aug 7, 2026
  28. 5/6 last-modified: check pathspec against Bloom filter firstToon Claes, Aug 7, 2026
  29. 6/6 last-modified: keep per-path Bloom filters for wildcard pathspecsToon Claes, Aug 7, 2026
  30. Junio C HamanoAug 8, 2026

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.