Skip to content

Commit 6d6e5c5

Browse files
vdyegitster
authored andcommitted
ref-filter.h: move contains caches into filter
Move the 'contains_cache' and 'no_contains_cache' used in filter_refs into an 'internal' struct of the 'struct ref_filter'. In later patches, the 'struct ref_filter *' will be a common data structure across multiple filtering functions. These caches are part of the common functionality the filter struct will support, so they are updated to be internally accessible wherever the filter is used. The design used here mirrors what was introduced in 576de3d (unpack_trees: start splitting internal fields from public API, 2023-02-27) for 'unpack_trees_options'. Signed-off-by: Victoria Dye <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9d4fcfe commit 6d6e5c5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

ref-filter.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,8 +2680,6 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname)
26802680
struct ref_filter_cbdata {
26812681
struct ref_array *array;
26822682
struct ref_filter *filter;
2683-
struct contains_cache contains_cache;
2684-
struct contains_cache no_contains_cache;
26852683
};
26862684

26872685
/*
@@ -2732,11 +2730,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
27322730
return 0;
27332731
/* We perform the filtering for the '--contains' option... */
27342732
if (filter->with_commit &&
2735-
!commit_contains(filter, commit, filter->with_commit, &ref_cbdata->contains_cache))
2733+
!commit_contains(filter, commit, filter->with_commit, &filter->internal.contains_cache))
27362734
return 0;
27372735
/* ...or for the `--no-contains' option */
27382736
if (filter->no_commit &&
2739-
commit_contains(filter, commit, filter->no_commit, &ref_cbdata->no_contains_cache))
2737+
commit_contains(filter, commit, filter->no_commit, &filter->internal.no_contains_cache))
27402738
return 0;
27412739
}
27422740

@@ -2905,8 +2903,8 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
29052903
save_commit_buffer_orig = save_commit_buffer;
29062904
save_commit_buffer = 0;
29072905

2908-
init_contains_cache(&ref_cbdata.contains_cache);
2909-
init_contains_cache(&ref_cbdata.no_contains_cache);
2906+
init_contains_cache(&filter->internal.contains_cache);
2907+
init_contains_cache(&filter->internal.no_contains_cache);
29102908

29112909
/* Simple per-ref filtering */
29122910
if (!filter->kind)
@@ -2930,8 +2928,8 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
29302928
head_ref(ref_filter_handler, &ref_cbdata);
29312929
}
29322930

2933-
clear_contains_cache(&ref_cbdata.contains_cache);
2934-
clear_contains_cache(&ref_cbdata.no_contains_cache);
2931+
clear_contains_cache(&filter->internal.contains_cache);
2932+
clear_contains_cache(&filter->internal.no_contains_cache);
29352933

29362934
/* Filters that need revision walking */
29372935
reach_filter(array, &filter->reachable_from, INCLUDE_REACHED);

ref-filter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "commit.h"
88
#include "string-list.h"
99
#include "strvec.h"
10+
#include "commit-reach.h"
1011

1112
/* Quoting styles */
1213
#define QUOTE_NONE 0
@@ -75,6 +76,11 @@ struct ref_filter {
7576
lines;
7677
int abbrev,
7778
verbose;
79+
80+
struct {
81+
struct contains_cache contains_cache;
82+
struct contains_cache no_contains_cache;
83+
} internal;
7884
};
7985

8086
struct ref_format {

0 commit comments

Comments
 (0)