Skip to content

Commit 937153d

Browse files
brandb97gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Lidong Yan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90d5518 commit 937153d

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

revision.c

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -687,13 +687,37 @@ static int forbid_bloom_filters(struct pathspec *spec)
687687

688688
static void release_revisions_bloom_keyvecs(struct rev_info *revs);
689689

690-
static void prepare_to_use_bloom_filter(struct rev_info *revs)
690+
static int convert_pathspec_to_bloom_keyvec(struct bloom_keyvec **out,
691+
const struct pathspec_item *pi,
692+
const struct bloom_filter_settings *settings)
691693
{
692-
struct pathspec_item *pi;
693694
char *path_alloc = NULL;
694695
const char *path;
695696
size_t len;
697+
int res = 0;
698+
699+
/* remove single trailing slash from path, if needed */
700+
if (pi->len > 0 && pi->match[pi->len - 1] == '/') {
701+
path_alloc = xmemdupz(pi->match, pi->len - 1);
702+
path = path_alloc;
703+
} else
704+
path = pi->match;
705+
706+
len = strlen(path);
707+
if (!len) {
708+
res = -1;
709+
goto cleanup;
710+
}
696711

712+
*out = bloom_keyvec_new(path, len, settings);
713+
714+
cleanup:
715+
free(path_alloc);
716+
return res;
717+
}
718+
719+
static void prepare_to_use_bloom_filter(struct rev_info *revs)
720+
{
697721
if (!revs->commits)
698722
return;
699723

@@ -711,22 +735,12 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
711735

712736
revs->bloom_keyvecs_nr = 1;
713737
CALLOC_ARRAY(revs->bloom_keyvecs, 1);
714-
pi = &revs->pruning.pathspec.items[0];
715738

716-
/* remove single trailing slash from path, if needed */
717-
if (pi->len > 0 && pi->match[pi->len - 1] == '/') {
718-
path_alloc = xmemdupz(pi->match, pi->len - 1);
719-
path = path_alloc;
720-
} else
721-
path = pi->match;
722-
723-
len = strlen(path);
724-
if (!len)
739+
if (convert_pathspec_to_bloom_keyvec(&revs->bloom_keyvecs[0],
740+
&revs->pruning.pathspec.items[0],
741+
revs->bloom_filter_settings))
725742
goto fail;
726743

727-
revs->bloom_keyvecs[0] =
728-
bloom_keyvec_new(path, len, revs->bloom_filter_settings);
729-
730744
if (trace2_is_enabled() && !bloom_filter_atexit_registered) {
731745
atexit(trace2_bloom_filter_statistics_atexit);
732746
bloom_filter_atexit_registered = 1;
@@ -736,7 +750,6 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
736750

737751
fail:
738752
revs->bloom_filter_settings = NULL;
739-
free(path_alloc);
740753
release_revisions_bloom_keyvecs(revs);
741754
}
742755

0 commit comments

Comments
 (0)