revision: expose check for paths maybe changed in Bloom filter

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>

Toon Claes committed Jul 17, 2026 at 17:47 UTC 6e43a0623ecbebbd4898cd79fc33272b420ef35a
2 files changed +38 -10
revision.c
+21 -10
@@ -750,26 +750,20 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
750 struct commit *commit)
751 {
752 struct bloom_filter *filter;
753 - int result = 0;
754 -
755 - if (!revs->bloom_keyvecs_nr)
756 - return -1;
753 + int result;
754
755 if (commit_graph_generation(commit) == GENERATION_NUMBER_INFINITY)
756 return -1;
757
758 filter = get_bloom_filter(revs->repo, commit);
762 -
759 if (!filter) {
760 count_bloom_filter_not_present++;
761 return -1;
762 }
763
768 - for (size_t nr = 0; !result && nr < revs->bloom_keyvecs_nr; nr++) {
769 - result = bloom_filter_contains_vec(filter,
770 - revs->bloom_keyvecs[nr],
771 - revs->bloom_filter_settings);
772 - }
764 + result = revs_maybe_changed_in_bloom(revs, filter);
765 + if (result < 0)
766 + return result;
767
768 if (result)
769 count_bloom_filter_maybe++;
@@ -779,6 +773,23 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
773 return result;
774 }
775
776 +int revs_maybe_changed_in_bloom(struct rev_info *revs,
777 + struct bloom_filter *filter)
778 +{
779 + int result = 0;
780 +
781 + if (!revs->bloom_keyvecs_nr)
782 + return -1;
783 +
784 + for (size_t nr = 0; !result && nr < revs->bloom_keyvecs_nr; nr++) {
785 + result = bloom_filter_contains_vec(filter,
786 + revs->bloom_keyvecs[nr],
787 + revs->bloom_filter_settings);
788 + }
789 +
790 + return result;
791 +}
792 +
793 static int rev_compare_tree(struct rev_info *revs,
794 struct commit *parent, struct commit *commit, int nth_parent)
795 {
revision.h
+17
@@ -68,6 +68,7 @@ struct string_list;
68 struct saved_parents;
69 struct follow_pathspec_slab;
70 struct bloom_keyvec;
71 +struct bloom_filter;
72 struct bloom_filter_settings;
73 struct option;
74 struct parse_opt_ctx_t;
@@ -493,6 +494,22 @@ void reset_revision_walk(void);
494 */
495 int prepare_revision_walk(struct rev_info *revs);
496
497 +/**
498 + * Take in a changed-path Bloom filter that belongs to a commit, and consult it
499 + * to see if it might have modified any of the paths in the `revs`.
500 + * The caller should look up `filter`, probably with get_bloom_filter().
501 + * prepare_revision_walk() needs to be called in advance to ensure
502 + * pathspec key vectors are set up.
503 + *
504 + * Returns -1 if no sensible answer could be given because of missing
505 + * preconditions (no pathspec key vectors).
506 + * Returns 0 if the commit definitely did not change any of the paths and 1 if
507 + * the commit maybe has changed one of them, although that might be a
508 + * false-positive.
509 + */
510 +int revs_maybe_changed_in_bloom(struct rev_info *revs,
511 + struct bloom_filter *filter);
512 +
513 /* Drain the commits linked list into the priority queue. */
514 void rev_info_commit_list_to_queue(struct rev_info *revs);
515 /**