]> git.ipfire.org Git - thirdparty/git.git/commitdiff
*.h: move some *_INIT to designated initializers
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 27 Sep 2021 12:54:27 +0000 (14:54 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Sep 2021 21:48:00 +0000 (14:48 -0700)
Move various *_INIT macros to use designated initializers. This helps
readability. I've only picked those leftover macros that were not
touched by another in-flight series of mine which changed others, but
also how initialization was done.

In the case of SUBMODULE_ALTERNATE_SETUP_INIT I've left an explicit
initialization of "error_mode", even though
SUBMODULE_ALTERNATE_ERROR_IGNORE itself is defined as "0". Let's not
peek under the hood and assume that enum fields we know the value of
will stay at "0".

The change to "TESTSUITE_INIT" in "t/helper/test-run-command.c" was
part of an earlier on-list version[1] of c90be786da9 (test-tool
run-command: fix flip-flop init pattern, 2021-09-11).

1. https://lore.kernel.org/git/patch-1.1-0aa4523ab6e-20210909T130849Z-avarab@gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
13 files changed:
add-interactive.c
builtin/submodule--helper.c
cache.h
entry.h
list.h
sequencer.h
shallow.h
strvec.h
submodule.c
submodule.h
t/helper/test-run-command.c
trace.h
transport.h

index 36ebdbdf7e2c8d6a5598e3e773b44d53b290ada7..6498ae196f1e1ed34001e2da87d64defa64c8507 100644 (file)
@@ -102,8 +102,12 @@ struct prefix_item_list {
        int *selected; /* for multi-selections */
        size_t min_length, max_length;
 };
-#define PREFIX_ITEM_LIST_INIT \
-       { STRING_LIST_INIT_DUP, STRING_LIST_INIT_NODUP, NULL, 1, 4 }
+#define PREFIX_ITEM_LIST_INIT { \
+       .items = STRING_LIST_INIT_DUP, \
+       .sorted = STRING_LIST_INIT_NODUP, \
+       .min_length = 1, \
+       .max_length = 4, \
+}
 
 static void prefix_item_list_clear(struct prefix_item_list *list)
 {
index deca75c83ee9a8ea3d0086935c9a1908c1cfca14..57f09925157c4aa1f14129d2c64bb8045030028b 100644 (file)
@@ -1647,8 +1647,9 @@ struct submodule_alternate_setup {
        } error_mode;
        struct string_list *reference;
 };
-#define SUBMODULE_ALTERNATE_SETUP_INIT { NULL, \
-       SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }
+#define SUBMODULE_ALTERNATE_SETUP_INIT { \
+       .error_mode = SUBMODULE_ALTERNATE_ERROR_IGNORE, \
+}
 
 static const char alternate_error_advice[] = N_(
 "An alternate computed from a superproject's alternate is invalid.\n"
diff --git a/cache.h b/cache.h
index 25c6b0b1200d6398479bf1697c3cd07492207c2f..794237515b9f1fa7aaff49a7b3e4ae0f0cebe8b9 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1668,7 +1668,9 @@ struct cache_def {
        int track_flags;
        int prefix_len_stat_func;
 };
-#define CACHE_DEF_INIT { STRBUF_INIT }
+#define CACHE_DEF_INIT { \
+       .path = STRBUF_INIT, \
+}
 static inline void cache_def_clear(struct cache_def *cache)
 {
        strbuf_release(&cache->path);
diff --git a/entry.h b/entry.h
index 7c889e58fd7831086afe9b9267f537bcd9a80dca..2254c62727fdcf1d530d66bc9e70597a8aece1ad 100644 (file)
--- a/entry.h
+++ b/entry.h
@@ -16,7 +16,7 @@ struct checkout {
                 clone:1,
                 refresh_cache:1;
 };
-#define CHECKOUT_INIT { NULL, "" }
+#define CHECKOUT_INIT { .base_dir = "" }
 
 #define TEMPORARY_FILENAME_LENGTH 25
 /*
diff --git a/list.h b/list.h
index eb601192f4ca9a6af126c82f4c2a24cb9145009d..362a4cd7f5f10f17f174086911dc30e60e07e6ec 100644 (file)
--- a/list.h
+++ b/list.h
@@ -46,7 +46,10 @@ struct list_head {
 #define INIT_LIST_HEAD(ptr) \
        (ptr)->next = (ptr)->prev = (ptr)
 
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
+#define LIST_HEAD_INIT(name) { \
+       .next = &(name), \
+       .prev = &(name), \
+}
 
 /* Add new element at the head of the list. */
 static inline void list_add(struct list_head *newp, struct list_head *head)
index 2088344cb370be514a78b0a6f5e9a1b0aab38777..259d4eb4a8aaf9482a756b0b726e00e143285bb9 100644 (file)
@@ -119,7 +119,9 @@ struct todo_list {
        struct stat_data stat;
 };
 
-#define TODO_LIST_INIT { STRBUF_INIT }
+#define TODO_LIST_INIT { \
+       .buf = STRBUF_INIT, \
+}
 
 int todo_list_parse_insn_buffer(struct repository *r, char *buf,
                                struct todo_list *todo_list);
index 5b4a96dcd69a2e94f4dcb2b3715e18e6373d5cac..aba6ff5829405647070c5b2a475318e2fd76282d 100644 (file)
--- a/shallow.h
+++ b/shallow.h
@@ -23,7 +23,9 @@ int is_repository_shallow(struct repository *r);
 struct shallow_lock {
        struct lock_file lock;
 };
-#define SHALLOW_LOCK_INIT { LOCK_INIT }
+#define SHALLOW_LOCK_INIT { \
+       .lock = LOCK_INIT, \
+}
 
 /* commit $GIT_DIR/shallow and reset stat-validity checks */
 int commit_shallow_file(struct repository *r, struct shallow_lock *lk);
index a10aad5f645bdd4238c710c57522400a9e3d489b..9f55c8766ba9de77437275b8796f8e348fe35e03 100644 (file)
--- a/strvec.h
+++ b/strvec.h
@@ -33,7 +33,9 @@ struct strvec {
        size_t alloc;
 };
 
-#define STRVEC_INIT { empty_strvec }
+#define STRVEC_INIT { \
+       .v = empty_strvec, \
+}
 
 /**
  * Initialize an array. This is no different than assigning from
index 78aed03d9282313e053bcfad7ffcde9418ad2616..03cf36707ae2ab03d0deb68bab126de5cc8184f0 100644 (file)
@@ -1321,9 +1321,11 @@ struct submodule_parallel_fetch {
 
        struct strbuf submodules_with_errors;
 };
-#define SPF_INIT {0, STRVEC_INIT, NULL, NULL, 0, 0, 0, 0, \
-                 STRING_LIST_INIT_DUP, \
-                 NULL, 0, 0, STRBUF_INIT}
+#define SPF_INIT { \
+       .args = STRVEC_INIT, \
+       .changed_submodule_names = STRING_LIST_INIT_DUP, \
+       .submodules_with_errors = STRBUF_INIT, \
+}
 
 static int get_fetch_recurse_config(const struct submodule *submodule,
                                    struct submodule_parallel_fetch *spf)
index 35d18c7868ab92cf6599db5c19de23c1eb3a872d..6bd2c99fd99d409abd89771d511b3a7db5f47252 100644 (file)
@@ -37,7 +37,9 @@ struct submodule_update_strategy {
        enum submodule_update_type type;
        const char *command;
 };
-#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED}
+#define SUBMODULE_UPDATE_STRATEGY_INIT { \
+       .type = SM_UPDATE_UNSPECIFIED, \
+}
 
 int is_gitmodules_unmerged(struct index_state *istate);
 int is_writing_gitmodules_ok(void);
index 50bb98b7e04a4d0c02bcaada5d27ddf812559fde..3c4fb862234da8bd50bbe820d8e6510e0b4630e9 100644 (file)
@@ -60,8 +60,10 @@ struct testsuite {
        int next;
        int quiet, immediate, verbose, verbose_log, trace, write_junit_xml;
 };
-#define TESTSUITE_INIT \
-       { STRING_LIST_INIT_DUP, STRING_LIST_INIT_DUP }
+#define TESTSUITE_INIT { \
+       .tests = STRING_LIST_INIT_DUP, \
+       .failed = STRING_LIST_INIT_DUP, \
+}
 
 static int next_test(struct child_process *cp, struct strbuf *err, void *cb,
                     void **task_cb)
diff --git a/trace.h b/trace.h
index 74f62919c57b16095d4e58f5177167e3254e6756..e25984051aa041eb7557766a29a8c8b4743c62fd 100644 (file)
--- a/trace.h
+++ b/trace.h
@@ -89,7 +89,7 @@ struct trace_key {
 
 extern struct trace_key trace_default_key;
 
-#define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name }
+#define TRACE_KEY_INIT(name) { .key = "GIT_TRACE_" #name }
 extern struct trace_key trace_perf_key;
 extern struct trace_key trace_setup_key;
 
index 1cbab11373080f73df22fdd510537aa8f66bf164..8bb4c8bbc8cae2059060ae25044a160192a4354e 100644 (file)
@@ -262,7 +262,9 @@ struct transport_ls_refs_options {
         */
        char *unborn_head_target;
 };
-#define TRANSPORT_LS_REFS_OPTIONS_INIT { STRVEC_INIT }
+#define TRANSPORT_LS_REFS_OPTIONS_INIT { \
+       .ref_prefixes = STRVEC_INIT, \
+}
 
 /*
  * Retrieve refs from a remote.