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 576de3d956 (unpack_trees: start splitting internal fields from public API, 2023-02-27) for 'unpack_trees_options'. Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Victoria Dye committed Nov 14, 2023 at 19:53 UTC 6d6e5c53b0c3d5566680ee8786d40405db917917
2 files changed +12 -8
ref-filter.c
+6 -8
@@ -2680,8 +2680,6 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname)
2680 struct ref_filter_cbdata {
2681 struct ref_array *array;
2682 struct ref_filter *filter;
2683 - struct contains_cache contains_cache;
2684 - struct contains_cache no_contains_cache;
2683 };
2684
2685 /*
@@ -2732,11 +2730,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
2730 return 0;
2731 /* We perform the filtering for the '--contains' option... */
2732 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))
2734 return 0;
2735 /* ...or for the `--no-contains' option */
2736 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))
2738 return 0;
2739 }
2740
@@ -2905,8 +2903,8 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
2903 save_commit_buffer_orig = save_commit_buffer;
2904 save_commit_buffer = 0;
2905
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);
2908
2909 /* Simple per-ref filtering */
2910 if (!filter->kind)
@@ -2930,8 +2928,8 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
2928 head_ref(ref_filter_handler, &ref_cbdata);
2929 }
2930
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);
2933
2934 /* Filters that need revision walking */
2935 reach_filter(array, &filter->reachable_from, INCLUDE_REACHED);
ref-filter.h
+6
@@ -7,6 +7,7 @@
7 #include "commit.h"
8 #include "string-list.h"
9 #include "strvec.h"
10 +#include "commit-reach.h"
11
12 /* Quoting styles */
13 #define QUOTE_NONE 0
@@ -75,6 +76,11 @@ struct ref_filter {
76 lines;
77 int abbrev,
78 verbose;
79 +
80 + struct {
81 + struct contains_cache contains_cache;
82 + struct contains_cache no_contains_cache;
83 + } internal;
84 };
85
86 struct ref_format {