ref-filter.h: provide `REF_FILTER_INIT`

Provide a sane initialization value for `struct ref_filter`, which in a subsequent patch will be used to initialize a new field. In the meantime, ensure that the `ref_filter` struct used in the test-helper's `cmd__reach()` is zero-initialized. The lack of initialization is OK, since `commit_contains()` only looks at the single `with_commit_tag_algo` field that *is* initialized directly above. So this does not fix a bug, but rather prevents one from biting us in the future. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 10, 2023 at 17:12 UTC b9f7daa6ef52ad8894b5f730eaee0599668d66d5
5 files changed +7 -7
builtin/branch.c
+1 -2
@@ -707,7 +707,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
707 int reflog = 0, quiet = 0, icase = 0, force = 0,
708 recurse_submodules_explicit = 0;
709 enum branch_track track;
710 - struct ref_filter filter;
710 + struct ref_filter filter = REF_FILTER_INIT;
711 static struct ref_sorting *sorting;
712 struct string_list sorting_options = STRING_LIST_INIT_DUP;
713 struct ref_format format = REF_FORMAT_INIT;
@@ -765,7 +765,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
765
766 setup_ref_filter_porcelain_msg();
767
768 - memset(&filter, 0, sizeof(filter));
768 filter.kind = FILTER_REFS_BRANCHES;
769 filter.abbrev = -1;
770
builtin/for-each-ref.c
+1 -2
@@ -24,7 +24,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
24 struct string_list sorting_options = STRING_LIST_INIT_DUP;
25 int maxcount = 0, icase = 0, omit_empty = 0;
26 struct ref_array array;
27 - struct ref_filter filter;
27 + struct ref_filter filter = REF_FILTER_INIT;
28 struct ref_format format = REF_FORMAT_INIT;
29 struct strbuf output = STRBUF_INIT;
30 struct strbuf err = STRBUF_INIT;
@@ -61,7 +61,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
61 };
62
63 memset(&array, 0, sizeof(array));
64 - memset(&filter, 0, sizeof(filter));
64
65 format.format = "%(objectname) %(objecttype)\t%(refname)";
66
builtin/tag.c
+1 -2
@@ -443,7 +443,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
443 struct msg_arg msg = { .buf = STRBUF_INIT };
444 struct ref_transaction *transaction;
445 struct strbuf err = STRBUF_INIT;
446 - struct ref_filter filter;
446 + struct ref_filter filter = REF_FILTER_INIT;
447 struct ref_sorting *sorting;
448 struct string_list sorting_options = STRING_LIST_INIT_DUP;
449 struct ref_format format = REF_FORMAT_INIT;
@@ -501,7 +501,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
501 git_config(git_tag_config, &sorting_options);
502
503 memset(&opt, 0, sizeof(opt));
504 - memset(&filter, 0, sizeof(filter));
504 filter.lines = -1;
505 opt.sign = -1;
506
ref-filter.h
+3
@@ -92,6 +92,9 @@ struct ref_format {
92 struct string_list bases;
93 };
94
95 +#define REF_FILTER_INIT { \
96 + .points_at = OID_ARRAY_INIT, \
97 +}
98 #define REF_FORMAT_INIT { \
99 .use_color = -1, \
100 .bases = STRING_LIST_INIT_DUP, \
t/helper/test-reach.c
+1 -1
@@ -139,7 +139,7 @@ int cmd__reach(int ac, const char **av)
139
140 printf("%s(X,_,_,0,0):%d\n", av[1], can_all_from_reach_with_flag(&X_obj, 2, 4, 0, 0));
141 } else if (!strcmp(av[1], "commit_contains")) {
142 - struct ref_filter filter;
142 + struct ref_filter filter = REF_FILTER_INIT;
143 struct contains_cache cache;
144 init_contains_cache(&cache);
145