Skip to content

Commit f69a6e4

Browse files
avargitster
authored andcommitted
*.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 c90be78 (test-tool run-command: fix flip-flop init pattern, 2021-09-11). 1. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 608cfd3 commit f69a6e4

File tree

13 files changed

+42
-18
lines changed

13 files changed

+42
-18
lines changed

add-interactive.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ struct prefix_item_list {
102102
int *selected; /* for multi-selections */
103103
size_t min_length, max_length;
104104
};
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+
}
107111

108112
static void prefix_item_list_clear(struct prefix_item_list *list)
109113
{

builtin/submodule--helper.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,8 +1647,9 @@ struct submodule_alternate_setup {
16471647
} error_mode;
16481648
struct string_list *reference;
16491649
};
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+
}
16521653

16531654
static const char alternate_error_advice[] = N_(
16541655
"An alternate computed from a superproject's alternate is invalid.\n"

cache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,9 @@ struct cache_def {
16681668
int track_flags;
16691669
int prefix_len_stat_func;
16701670
};
1671-
#define CACHE_DEF_INIT { STRBUF_INIT }
1671+
#define CACHE_DEF_INIT { \
1672+
.path = STRBUF_INIT, \
1673+
}
16721674
static inline void cache_def_clear(struct cache_def *cache)
16731675
{
16741676
strbuf_release(&cache->path);

entry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct checkout {
1616
clone:1,
1717
refresh_cache:1;
1818
};
19-
#define CHECKOUT_INIT { NULL, "" }
19+
#define CHECKOUT_INIT { .base_dir = "" }
2020

2121
#define TEMPORARY_FILENAME_LENGTH 25
2222
/*

list.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ struct list_head {
4646
#define INIT_LIST_HEAD(ptr) \
4747
(ptr)->next = (ptr)->prev = (ptr)
4848

49-
#define LIST_HEAD_INIT(name) { &(name), &(name) }
49+
#define LIST_HEAD_INIT(name) { \
50+
.next = &(name), \
51+
.prev = &(name), \
52+
}
5053

5154
/* Add new element at the head of the list. */
5255
static inline void list_add(struct list_head *newp, struct list_head *head)

sequencer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ struct todo_list {
119119
struct stat_data stat;
120120
};
121121

122-
#define TODO_LIST_INIT { STRBUF_INIT }
122+
#define TODO_LIST_INIT { \
123+
.buf = STRBUF_INIT, \
124+
}
123125

124126
int todo_list_parse_insn_buffer(struct repository *r, char *buf,
125127
struct todo_list *todo_list);

shallow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ int is_repository_shallow(struct repository *r);
2323
struct shallow_lock {
2424
struct lock_file lock;
2525
};
26-
#define SHALLOW_LOCK_INIT { LOCK_INIT }
26+
#define SHALLOW_LOCK_INIT { \
27+
.lock = LOCK_INIT, \
28+
}
2729

2830
/* commit $GIT_DIR/shallow and reset stat-validity checks */
2931
int commit_shallow_file(struct repository *r, struct shallow_lock *lk);

strvec.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ struct strvec {
3333
size_t alloc;
3434
};
3535

36-
#define STRVEC_INIT { empty_strvec }
36+
#define STRVEC_INIT { \
37+
.v = empty_strvec, \
38+
}
3739

3840
/**
3941
* Initialize an array. This is no different than assigning from

submodule.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,9 +1321,11 @@ struct submodule_parallel_fetch {
13211321

13221322
struct strbuf submodules_with_errors;
13231323
};
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+
}
13271329

13281330
static int get_fetch_recurse_config(const struct submodule *submodule,
13291331
struct submodule_parallel_fetch *spf)

submodule.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ struct submodule_update_strategy {
3737
enum submodule_update_type type;
3838
const char *command;
3939
};
40-
#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED}
40+
#define SUBMODULE_UPDATE_STRATEGY_INIT { \
41+
.type = SM_UPDATE_UNSPECIFIED, \
42+
}
4143

4244
int is_gitmodules_unmerged(struct index_state *istate);
4345
int is_writing_gitmodules_ok(void);

0 commit comments

Comments
 (0)