aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLidong Yan <yldhome2d2@gmail.com>2025-07-12 17:35:16 +0800
committerJunio C Hamano <gitster@pobox.com>2025-07-14 10:03:03 -0700
commit937153dece3c2b1e04b0e071298745abd57cd347 (patch)
treefc5f978a91e4da031e95669314661bb1236eb961
parentbloom: replace struct bloom_key * with struct bloom_keyvec (diff)
downloadgit-937153dece3c2b1e04b0e071298745abd57cd347.tar.gz
git-937153dece3c2b1e04b0e071298745abd57cd347.zip
revision: make helper for pathspec to bloom keyvec
When preparing to use bloom filters in a revision walk, Git populates a boom_keyvec with an array of bloom keys for the components of a path. Before we create the ability to map multiple pathspecs to multiple bloom_keyvecs, extract the conversion from a pathspec to a bloom_keyvec into its own helper method. This simplifies the state that persists in prepare_to_use_bloom_filter() as well as makes the future change much simpler. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--revision.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/revision.c b/revision.c
index d106fa4173..ed849b31c7 100644
--- a/revision.c
+++ b/revision.c
@@ -687,13 +687,37 @@ static int forbid_bloom_filters(struct pathspec *spec)
static void release_revisions_bloom_keyvecs(struct rev_info *revs);
-static void prepare_to_use_bloom_filter(struct rev_info *revs)
+static int convert_pathspec_to_bloom_keyvec(struct bloom_keyvec **out,
+ const struct pathspec_item *pi,
+ const struct bloom_filter_settings *settings)
{
- struct pathspec_item *pi;
char *path_alloc = NULL;
const char *path;
size_t len;
+ int res = 0;
+
+ /* remove single trailing slash from path, if needed */
+ if (pi->len > 0 && pi->match[pi->len - 1] == '/') {
+ path_alloc = xmemdupz(pi->match, pi->len - 1);
+ path = path_alloc;
+ } else
+ path = pi->match;
+
+ len = strlen(path);
+ if (!len) {
+ res = -1;
+ goto cleanup;
+ }
+ *out = bloom_keyvec_new(path, len, settings);
+
+cleanup:
+ free(path_alloc);
+ return res;
+}
+
+static void prepare_to_use_bloom_filter(struct rev_info *revs)
+{
if (!revs->commits)
return;
@@ -711,22 +735,12 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
revs->bloom_keyvecs_nr = 1;
CALLOC_ARRAY(revs->bloom_keyvecs, 1);
- pi = &revs->pruning.pathspec.items[0];
- /* remove single trailing slash from path, if needed */
- if (pi->len > 0 && pi->match[pi->len - 1] == '/') {
- path_alloc = xmemdupz(pi->match, pi->len - 1);
- path = path_alloc;
- } else
- path = pi->match;
-
- len = strlen(path);
- if (!len)
+ if (convert_pathspec_to_bloom_keyvec(&revs->bloom_keyvecs[0],
+ &revs->pruning.pathspec.items[0],
+ revs->bloom_filter_settings))
goto fail;
- revs->bloom_keyvecs[0] =
- bloom_keyvec_new(path, len, revs->bloom_filter_settings);
-
if (trace2_is_enabled() && !bloom_filter_atexit_registered) {
atexit(trace2_bloom_filter_statistics_atexit);
bloom_filter_atexit_registered = 1;
@@ -736,7 +750,6 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
fail:
revs->bloom_filter_settings = NULL;
- free(path_alloc);
release_revisions_bloom_keyvecs(revs);
}