]> git.ipfire.org Git - thirdparty/git.git/commitdiff
revision: expose check for paths maybe changed in Bloom filter
authorToon Claes <toon@iotcl.com>
Fri, 17 Jul 2026 15:47:00 +0000 (17:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Jul 2026 20:20:57 +0000 (13:20 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c
revision.h

index 087d64d572c141e76c47e43051bdd9623255d263..deaabec3e4ee211df9ef5606c50720c44004578f 100644 (file)
@@ -750,26 +750,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++;
@@ -779,6 +773,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)
 {
index 569b3fa1cb5a339e2b9c2fbfa6318e6ad9f7073c..7569c210cc0833bb15c4670873187268b8469732 100644 (file)
@@ -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);
 /**