*.h: move some *_INIT to designated initializers

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>

Ævar Arnfjörð Bjarmason committed Sep 27, 2021 at 14:54 UTC f69a6e4f076ec9ec89d94a6d960d0c161381a597
13 files changed +42 -18
add-interactive.c
+6 -2
@@ -102,8 +102,12 @@ struct prefix_item_list {
102 int *selected; /* for multi-selections */
103 size_t min_length, max_length;
104 };
105 -#define PREFIX_ITEM_LIST_INIT \
106 - { STRING_LIST_INIT_DUP, STRING_LIST_INIT_NODUP, NULL, 1, 4 }
105 +#define PREFIX_ITEM_LIST_INIT { \
106 + .items = STRING_LIST_INIT_DUP, \
107 + .sorted = STRING_LIST_INIT_NODUP, \
108 + .min_length = 1, \
109 + .max_length = 4, \
110 +}
111
112 static void prefix_item_list_clear(struct prefix_item_list *list)
113 {
builtin/submodule--helper.c
+3 -2
@@ -1647,8 +1647,9 @@ struct submodule_alternate_setup {
1647 } error_mode;
1648 struct string_list *reference;
1649 };
1650 -#define SUBMODULE_ALTERNATE_SETUP_INIT { NULL, \
1651 - SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }
1650 +#define SUBMODULE_ALTERNATE_SETUP_INIT { \
1651 + .error_mode = SUBMODULE_ALTERNATE_ERROR_IGNORE, \
1652 +}
1653
1654 static const char alternate_error_advice[] = N_(
1655 "An alternate computed from a superproject's alternate is invalid.\n"
cache.h
+3 -1
@@ -1668,7 +1668,9 @@ struct cache_def {
1668 int track_flags;
1669 int prefix_len_stat_func;
1670 };
1671 -#define CACHE_DEF_INIT { STRBUF_INIT }
1671 +#define CACHE_DEF_INIT { \
1672 + .path = STRBUF_INIT, \
1673 +}
1674 static inline void cache_def_clear(struct cache_def *cache)
1675 {
1676 strbuf_release(&cache->path);
entry.h
+1 -1
@@ -16,7 +16,7 @@ struct checkout {
16 clone:1,
17 refresh_cache:1;
18 };
19 -#define CHECKOUT_INIT { NULL, "" }
19 +#define CHECKOUT_INIT { .base_dir = "" }
20
21 #define TEMPORARY_FILENAME_LENGTH 25
22 /*
list.h
+4 -1
@@ -46,7 +46,10 @@ struct list_head {
46 #define INIT_LIST_HEAD(ptr) \
47 (ptr)->next = (ptr)->prev = (ptr)
48
49 -#define LIST_HEAD_INIT(name) { &(name), &(name) }
49 +#define LIST_HEAD_INIT(name) { \
50 + .next = &(name), \
51 + .prev = &(name), \
52 +}
53
54 /* Add new element at the head of the list. */
55 static inline void list_add(struct list_head *newp, struct list_head *head)
sequencer.h
+3 -1
@@ -119,7 +119,9 @@ struct todo_list {
119 struct stat_data stat;
120 };
121
122 -#define TODO_LIST_INIT { STRBUF_INIT }
122 +#define TODO_LIST_INIT { \
123 + .buf = STRBUF_INIT, \
124 +}
125
126 int todo_list_parse_insn_buffer(struct repository *r, char *buf,
127 struct todo_list *todo_list);
shallow.h
+3 -1
@@ -23,7 +23,9 @@ int is_repository_shallow(struct repository *r);
23 struct shallow_lock {
24 struct lock_file lock;
25 };
26 -#define SHALLOW_LOCK_INIT { LOCK_INIT }
26 +#define SHALLOW_LOCK_INIT { \
27 + .lock = LOCK_INIT, \
28 +}
29
30 /* commit $GIT_DIR/shallow and reset stat-validity checks */
31 int commit_shallow_file(struct repository *r, struct shallow_lock *lk);
strvec.h
+3 -1
@@ -33,7 +33,9 @@ struct strvec {
33 size_t alloc;
34 };
35
36 -#define STRVEC_INIT { empty_strvec }
36 +#define STRVEC_INIT { \
37 + .v = empty_strvec, \
38 +}
39
40 /**
41 * Initialize an array. This is no different than assigning from
submodule.c
+5 -3
@@ -1321,9 +1321,11 @@ struct submodule_parallel_fetch {
1321
1322 struct strbuf submodules_with_errors;
1323 };
1324 -#define SPF_INIT {0, STRVEC_INIT, NULL, NULL, 0, 0, 0, 0, \
1325 - STRING_LIST_INIT_DUP, \
1326 - NULL, 0, 0, STRBUF_INIT}
1324 +#define SPF_INIT { \
1325 + .args = STRVEC_INIT, \
1326 + .changed_submodule_names = STRING_LIST_INIT_DUP, \
1327 + .submodules_with_errors = STRBUF_INIT, \
1328 +}
1329
1330 static int get_fetch_recurse_config(const struct submodule *submodule,
1331 struct submodule_parallel_fetch *spf)
submodule.h
+3 -1
@@ -37,7 +37,9 @@ struct submodule_update_strategy {
37 enum submodule_update_type type;
38 const char *command;
39 };
40 -#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED}
40 +#define SUBMODULE_UPDATE_STRATEGY_INIT { \
41 + .type = SM_UPDATE_UNSPECIFIED, \
42 +}
43
44 int is_gitmodules_unmerged(struct index_state *istate);
45 int is_writing_gitmodules_ok(void);
t/helper/test-run-command.c
+4 -2
@@ -60,8 +60,10 @@ struct testsuite {
60 int next;
61 int quiet, immediate, verbose, verbose_log, trace, write_junit_xml;
62 };
63 -#define TESTSUITE_INIT \
64 - { STRING_LIST_INIT_DUP, STRING_LIST_INIT_DUP }
63 +#define TESTSUITE_INIT { \
64 + .tests = STRING_LIST_INIT_DUP, \
65 + .failed = STRING_LIST_INIT_DUP, \
66 +}
67
68 static int next_test(struct child_process *cp, struct strbuf *err, void *cb,
69 void **task_cb)
trace.h
+1 -1
@@ -89,7 +89,7 @@ struct trace_key {
89
90 extern struct trace_key trace_default_key;
91
92 -#define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name }
92 +#define TRACE_KEY_INIT(name) { .key = "GIT_TRACE_" #name }
93 extern struct trace_key trace_perf_key;
94 extern struct trace_key trace_setup_key;
95
transport.h
+3 -1
@@ -262,7 +262,9 @@ struct transport_ls_refs_options {
262 */
263 char *unborn_head_target;
264 };
265 -#define TRANSPORT_LS_REFS_OPTIONS_INIT { STRVEC_INIT }
265 +#define TRANSPORT_LS_REFS_OPTIONS_INIT { \
266 + .ref_prefixes = STRVEC_INIT, \
267 +}
268
269 /*
270 * Retrieve refs from a remote.