]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ref-filter.h: provide `REF_FILTER_INIT`
authorJeff King <peff@peff.net>
Mon, 10 Jul 2023 21:12:07 +0000 (17:12 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Jul 2023 21:48:55 +0000 (14:48 -0700)
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>
builtin/branch.c
builtin/for-each-ref.c
builtin/tag.c
ref-filter.h
t/helper/test-reach.c

index e6c2655af68b339a7aa863cedd6d75e5176dd443..7891dec3615eacdad63fd5de5ba2bcfa3db841cd 100644 (file)
@@ -707,7 +707,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
        int reflog = 0, quiet = 0, icase = 0, force = 0,
            recurse_submodules_explicit = 0;
        enum branch_track track;
-       struct ref_filter filter;
+       struct ref_filter filter = REF_FILTER_INIT;
        static struct ref_sorting *sorting;
        struct string_list sorting_options = STRING_LIST_INIT_DUP;
        struct ref_format format = REF_FORMAT_INIT;
@@ -765,7 +765,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 
        setup_ref_filter_porcelain_msg();
 
-       memset(&filter, 0, sizeof(filter));
        filter.kind = FILTER_REFS_BRANCHES;
        filter.abbrev = -1;
 
index 695fc8f4a5e5622b15de4167f892559aaa8aafd4..99ccb7351853515820ebe429d93c6031760c4306 100644 (file)
@@ -24,7 +24,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
        struct string_list sorting_options = STRING_LIST_INIT_DUP;
        int maxcount = 0, icase = 0, omit_empty = 0;
        struct ref_array array;
-       struct ref_filter filter;
+       struct ref_filter filter = REF_FILTER_INIT;
        struct ref_format format = REF_FORMAT_INIT;
        struct strbuf output = STRBUF_INIT;
        struct strbuf err = STRBUF_INIT;
@@ -61,7 +61,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
        };
 
        memset(&array, 0, sizeof(array));
-       memset(&filter, 0, sizeof(filter));
 
        format.format = "%(objectname) %(objecttype)\t%(refname)";
 
index 1850a6a6fdcf82f18ad3f1f1aefd5d22fc527e3f..6b41bb73749c4ce1721137d9d9569d28aacd1ba6 100644 (file)
@@ -443,7 +443,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
        struct msg_arg msg = { .buf = STRBUF_INIT };
        struct ref_transaction *transaction;
        struct strbuf err = STRBUF_INIT;
-       struct ref_filter filter;
+       struct ref_filter filter = REF_FILTER_INIT;
        struct ref_sorting *sorting;
        struct string_list sorting_options = STRING_LIST_INIT_DUP;
        struct ref_format format = REF_FORMAT_INIT;
@@ -501,7 +501,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
        git_config(git_tag_config, &sorting_options);
 
        memset(&opt, 0, sizeof(opt));
-       memset(&filter, 0, sizeof(filter));
        filter.lines = -1;
        opt.sign = -1;
 
index 430701cfb765b557d62c6004e6ef7fb27ad5e5f0..a920f73b2974b8cbd21bfc0bf7eba954f6ab4ab7 100644 (file)
@@ -92,6 +92,9 @@ struct ref_format {
        struct string_list bases;
 };
 
+#define REF_FILTER_INIT { \
+       .points_at = OID_ARRAY_INIT, \
+}
 #define REF_FORMAT_INIT {             \
        .use_color = -1,              \
        .bases = STRING_LIST_INIT_DUP, \
index 5b6f2174418101575302a7fd083349414d6f283e..ef58f10c2d678d21b23b50cb91a9dd4873de3e38 100644 (file)
@@ -139,7 +139,7 @@ int cmd__reach(int ac, const char **av)
 
                printf("%s(X,_,_,0,0):%d\n", av[1], can_all_from_reach_with_flag(&X_obj, 2, 4, 0, 0));
        } else if (!strcmp(av[1], "commit_contains")) {
-               struct ref_filter filter;
+               struct ref_filter filter = REF_FILTER_INIT;
                struct contains_cache cache;
                init_contains_cache(&cache);