Skip to content

Commit a30321b

Browse files
committed
Merge branch 'ab/designated-initializers' into ab/designated-initializers-more
* ab/designated-initializers: cbtree.h: define cb_init() in terms of CBTREE_INIT *.h: move some *_INIT to designated initializers *.h _INIT macros: don't specify fields equal to 0 *.[ch] *_INIT macros: use { 0 } for a "zero out" idiom submodule-config.h: remove unused SUBMODULE_INIT macro
2 parents ddb1055 + 538835d commit a30321b

29 files changed

+68
-54
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: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ struct module_list {
307307
const struct cache_entry **entries;
308308
int alloc, nr;
309309
};
310-
#define MODULE_LIST_INIT { NULL, 0, 0 }
310+
#define MODULE_LIST_INIT { 0 }
311311

312312
static int module_list_compute(int argc, const char **argv,
313313
const char *prefix,
@@ -588,7 +588,7 @@ struct init_cb {
588588
const char *prefix;
589589
unsigned int flags;
590590
};
591-
#define INIT_CB_INIT { NULL, 0 }
591+
#define INIT_CB_INIT { 0 }
592592

593593
static void init_submodule(const char *path, const char *prefix,
594594
unsigned int flags)
@@ -717,7 +717,7 @@ struct status_cb {
717717
const char *prefix;
718718
unsigned int flags;
719719
};
720-
#define STATUS_CB_INIT { NULL, 0 }
720+
#define STATUS_CB_INIT { 0 }
721721

722722
static void print_status(unsigned int flags, char state, const char *path,
723723
const struct object_id *oid, const char *displaypath)
@@ -911,13 +911,13 @@ struct module_cb {
911911
char status;
912912
const char *sm_path;
913913
};
914-
#define MODULE_CB_INIT { 0, 0, NULL, NULL, '\0', NULL }
914+
#define MODULE_CB_INIT { 0 }
915915

916916
struct module_cb_list {
917917
struct module_cb **entries;
918918
int alloc, nr;
919919
};
920-
#define MODULE_CB_LIST_INIT { NULL, 0, 0 }
920+
#define MODULE_CB_LIST_INIT { 0 }
921921

922922
struct summary_cb {
923923
int argc;
@@ -928,7 +928,7 @@ struct summary_cb {
928928
unsigned int files: 1;
929929
int summary_limit;
930930
};
931-
#define SUMMARY_CB_INIT { 0, NULL, NULL, 0, 0, 0, 0 }
931+
#define SUMMARY_CB_INIT { 0 }
932932

933933
enum diff_cmd {
934934
DIFF_INDEX,
@@ -1334,7 +1334,7 @@ struct sync_cb {
13341334
const char *prefix;
13351335
unsigned int flags;
13361336
};
1337-
#define SYNC_CB_INIT { NULL, 0 }
1337+
#define SYNC_CB_INIT { 0 }
13381338

13391339
static void sync_submodule(const char *path, const char *prefix,
13401340
unsigned int flags)
@@ -1480,7 +1480,7 @@ struct deinit_cb {
14801480
const char *prefix;
14811481
unsigned int flags;
14821482
};
1483-
#define DEINIT_CB_INIT { NULL, 0 }
1483+
#define DEINIT_CB_INIT { 0 }
14841484

14851485
static void deinit_submodule(const char *path, const char *prefix,
14861486
unsigned int flags)
@@ -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, 0, 0, 0 }
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);

cbtree.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ enum cb_next {
3737
CB_BREAK = 1
3838
};
3939

40-
#define CBTREE_INIT { .root = NULL }
40+
#define CBTREE_INIT { 0 }
4141

4242
static inline void cb_init(struct cb_tree *t)
4343
{
44-
t->root = NULL;
44+
struct cb_tree blank = CBTREE_INIT;
45+
memcpy(t, &blank, sizeof(*t));
4546
}
4647

4748
struct cb_node *cb_lookup(struct cb_tree *, const uint8_t *k, size_t klen);

checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct tracking_name_data {
1414
struct object_id *default_dst_oid;
1515
};
1616

17-
#define TRACKING_NAME_DATA_INIT { NULL, NULL, NULL, 0, NULL, NULL, NULL }
17+
#define TRACKING_NAME_DATA_INIT { 0 }
1818

1919
static int check_tracking_name(struct remote *remote, void *cb_data)
2020
{

contrib/credential/gnome-keyring/git-credential-gnome-keyring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct credential {
138138
char *password;
139139
};
140140

141-
#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
141+
#define CREDENTIAL_INIT { 0 }
142142

143143
typedef int (*credential_op_cb)(struct credential *);
144144

contrib/credential/libsecret/git-credential-libsecret.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct credential {
4141
char *password;
4242
};
4343

44-
#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
44+
#define CREDENTIAL_INIT { 0 }
4545

4646
typedef int (*credential_op_cb)(struct credential *);
4747

diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,13 @@ struct emitted_diff_symbol {
775775
int indent_width; /* The visual width of the indentation */
776776
enum diff_symbol s;
777777
};
778-
#define EMITTED_DIFF_SYMBOL_INIT {NULL}
778+
#define EMITTED_DIFF_SYMBOL_INIT { 0 }
779779

780780
struct emitted_diff_symbols {
781781
struct emitted_diff_symbol *buf;
782782
int nr, alloc;
783783
};
784-
#define EMITTED_DIFF_SYMBOLS_INIT {NULL, 0, 0}
784+
#define EMITTED_DIFF_SYMBOLS_INIT { 0 }
785785

786786
static void append_emitted_diff_symbol(struct diff_options *o,
787787
struct emitted_diff_symbol *e)

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)

0 commit comments

Comments
 (0)