Merge branch 'ab/designated-initializers'

Code clean-up.

* 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
This commit is contained in:
Junio C Hamano 2021-10-11 10:21:48 -07:00
Родитель 859a585bdf 538835d2ac
Коммит 404c4a5462
29 изменённых файлов: 68 добавлений и 54 удалений

Просмотреть файл

@ -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)
{

Просмотреть файл

@ -307,7 +307,7 @@ struct module_list {
const struct cache_entry **entries;
int alloc, nr;
};
#define MODULE_LIST_INIT { NULL, 0, 0 }
#define MODULE_LIST_INIT { 0 }
static int module_list_compute(int argc, const char **argv,
const char *prefix,
@ -588,7 +588,7 @@ struct init_cb {
const char *prefix;
unsigned int flags;
};
#define INIT_CB_INIT { NULL, 0 }
#define INIT_CB_INIT { 0 }
static void init_submodule(const char *path, const char *prefix,
unsigned int flags)
@ -717,7 +717,7 @@ struct status_cb {
const char *prefix;
unsigned int flags;
};
#define STATUS_CB_INIT { NULL, 0 }
#define STATUS_CB_INIT { 0 }
static void print_status(unsigned int flags, char state, const char *path,
const struct object_id *oid, const char *displaypath)
@ -911,13 +911,13 @@ struct module_cb {
char status;
const char *sm_path;
};
#define MODULE_CB_INIT { 0, 0, NULL, NULL, '\0', NULL }
#define MODULE_CB_INIT { 0 }
struct module_cb_list {
struct module_cb **entries;
int alloc, nr;
};
#define MODULE_CB_LIST_INIT { NULL, 0, 0 }
#define MODULE_CB_LIST_INIT { 0 }
struct summary_cb {
int argc;
@ -928,7 +928,7 @@ struct summary_cb {
unsigned int files: 1;
int summary_limit;
};
#define SUMMARY_CB_INIT { 0, NULL, NULL, 0, 0, 0, 0 }
#define SUMMARY_CB_INIT { 0 }
enum diff_cmd {
DIFF_INDEX,
@ -1334,7 +1334,7 @@ struct sync_cb {
const char *prefix;
unsigned int flags;
};
#define SYNC_CB_INIT { NULL, 0 }
#define SYNC_CB_INIT { 0 }
static void sync_submodule(const char *path, const char *prefix,
unsigned int flags)
@ -1480,7 +1480,7 @@ struct deinit_cb {
const char *prefix;
unsigned int flags;
};
#define DEINIT_CB_INIT { NULL, 0 }
#define DEINIT_CB_INIT { 0 }
static void deinit_submodule(const char *path, const char *prefix,
unsigned int flags)
@ -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"

Просмотреть файл

@ -1617,7 +1617,9 @@ struct cache_def {
int track_flags;
int prefix_len_stat_func;
};
#define CACHE_DEF_INIT { STRBUF_INIT, 0, 0, 0 }
#define CACHE_DEF_INIT { \
.path = STRBUF_INIT, \
}
static inline void cache_def_clear(struct cache_def *cache)
{
strbuf_release(&cache->path);

Просмотреть файл

@ -37,11 +37,12 @@ enum cb_next {
CB_BREAK = 1
};
#define CBTREE_INIT { .root = NULL }
#define CBTREE_INIT { 0 }
static inline void cb_init(struct cb_tree *t)
{
t->root = NULL;
struct cb_tree blank = CBTREE_INIT;
memcpy(t, &blank, sizeof(*t));
}
struct cb_node *cb_lookup(struct cb_tree *, const uint8_t *k, size_t klen);

Просмотреть файл

@ -14,7 +14,7 @@ struct tracking_name_data {
struct object_id *default_dst_oid;
};
#define TRACKING_NAME_DATA_INIT { NULL, NULL, NULL, 0, NULL, NULL, NULL }
#define TRACKING_NAME_DATA_INIT { 0 }
static int check_tracking_name(struct remote *remote, void *cb_data)
{

Просмотреть файл

@ -138,7 +138,7 @@ struct credential {
char *password;
};
#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
#define CREDENTIAL_INIT { 0 }
typedef int (*credential_op_cb)(struct credential *);

Просмотреть файл

@ -41,7 +41,7 @@ struct credential {
char *password;
};
#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
#define CREDENTIAL_INIT { 0 }
typedef int (*credential_op_cb)(struct credential *);

4
diff.c
Просмотреть файл

@ -775,13 +775,13 @@ struct emitted_diff_symbol {
int indent_width; /* The visual width of the indentation */
enum diff_symbol s;
};
#define EMITTED_DIFF_SYMBOL_INIT {NULL}
#define EMITTED_DIFF_SYMBOL_INIT { 0 }
struct emitted_diff_symbols {
struct emitted_diff_symbol *buf;
int nr, alloc;
};
#define EMITTED_DIFF_SYMBOLS_INIT {NULL, 0, 0}
#define EMITTED_DIFF_SYMBOLS_INIT { 0 }
static void append_emitted_diff_symbol(struct diff_options *o,
struct emitted_diff_symbol *e)

Просмотреть файл

@ -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
/*

5
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)

Просмотреть файл

@ -121,7 +121,7 @@ struct lock_file {
struct tempfile *tempfile;
};
#define LOCK_INIT { NULL }
#define LOCK_INIT { 0 }
/* String appended to a filename to derive the lockfile name: */
#define LOCK_SUFFIX ".lock"

Просмотреть файл

@ -371,7 +371,7 @@ struct object_info {
* Initializer for a "struct object_info" that wants no items. You may
* also memset() the memory to all-zeroes.
*/
#define OBJECT_INFO_INIT {NULL}
#define OBJECT_INFO_INIT { 0 }
/* Invoke lookup_replace_object() on the given hash */
#define OBJECT_INFO_LOOKUP_REPLACE 1

Просмотреть файл

@ -55,7 +55,7 @@ struct object_array {
} *objects;
};
#define OBJECT_ARRAY_INIT { 0, 0, NULL }
#define OBJECT_ARRAY_INIT { 0 }
/*
* object flag allocation:

Просмотреть файл

@ -56,7 +56,7 @@ struct oid_array {
int sorted;
};
#define OID_ARRAY_INIT { NULL, 0, 0, 0 }
#define OID_ARRAY_INIT { 0 }
/**
* Add an item to the set. The object ID will be placed at the end of the array

5
path.h
Просмотреть файл

@ -181,10 +181,7 @@ struct path_cache {
const char *shallow;
};
#define PATH_CACHE_INIT \
{ \
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \
}
#define PATH_CACHE_INIT { 0 }
const char *git_path_squash_msg(struct repository *r);
const char *git_path_merge_msg(struct repository *r);

Просмотреть файл

@ -633,7 +633,7 @@ static struct {
*/
};
#define REF_FORMATTING_STATE_INIT { 0, NULL }
#define REF_FORMATTING_STATE_INIT { 0 }
struct ref_formatting_stack {
struct ref_formatting_stack *prev;

Просмотреть файл

@ -2403,7 +2403,7 @@ struct reflog_commit_array {
size_t nr, alloc;
};
#define REFLOG_COMMIT_ARRAY_INIT { NULL, 0, 0 }
#define REFLOG_COMMIT_ARRAY_INIT { 0 }
/* Append a commit to the array. */
static void append_commit(struct reflog_commit_array *arr,

Просмотреть файл

@ -249,7 +249,7 @@ struct commit_stack {
struct commit **items;
size_t nr, alloc;
};
#define COMMIT_STACK_INIT { NULL, 0, 0 }
#define COMMIT_STACK_INIT { 0 }
static void commit_stack_push(struct commit_stack *stack, struct commit *commit)
{

Просмотреть файл

@ -118,7 +118,9 @@ struct todo_list {
int done_nr, total_nr;
};
#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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -65,11 +65,7 @@ struct ipc_client_connect_options {
unsigned int uds_disallow_chdir:1;
};
#define IPC_CLIENT_CONNECT_OPTIONS_INIT { \
.wait_if_busy = 0, \
.wait_if_not_found = 0, \
.uds_disallow_chdir = 0, \
}
#define IPC_CLIENT_CONNECT_OPTIONS_INIT { 0 }
/*
* Determine if a server is listening on this named pipe or socket using

Просмотреть файл

@ -70,7 +70,7 @@ struct strbuf {
};
extern char strbuf_slopbuf[];
#define STRBUF_INIT { .alloc = 0, .len = 0, .buf = strbuf_slopbuf }
#define STRBUF_INIT { .buf = strbuf_slopbuf }
/*
* Predeclare this here, since cache.h includes this file before it defines the

Просмотреть файл

@ -33,7 +33,9 @@ struct strvec {
size_t alloc;
};
#define STRVEC_INIT { empty_strvec, 0, 0 }
#define STRVEC_INIT { \
.v = empty_strvec, \
}
/**
* Initialize an array. This is no different than assigning from

Просмотреть файл

@ -45,10 +45,6 @@ struct submodule {
struct object_id gitmodules_oid;
int recommend_shallow;
};
#define SUBMODULE_INIT { NULL, NULL, NULL, RECURSE_SUBMODULES_NONE, \
NULL, NULL, SUBMODULE_UPDATE_STRATEGY_INIT, { { 0 } }, -1 };
struct submodule_cache;
struct repository;

Просмотреть файл

@ -1318,9 +1318,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)

Просмотреть файл

@ -37,7 +37,9 @@ struct submodule_update_strategy {
enum submodule_update_type type;
const char *command;
};
#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
#define SUBMODULE_UPDATE_STRATEGY_INIT { \
.type = SM_UPDATE_UNSPECIFIED, \
}
int is_gitmodules_unmerged(struct index_state *istate);
int is_writing_gitmodules_ok(void);

Просмотреть файл

@ -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, 0, 0, 0, 0, 0, 0, 0 }
#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)

Просмотреть файл

@ -89,7 +89,7 @@ struct trace_key {
extern struct trace_key trace_default_key;
#define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name, 0, 0, 0 }
#define TRACE_KEY_INIT(name) { .key = "GIT_TRACE_" #name }
extern struct trace_key trace_perf_key;
extern struct trace_key trace_setup_key;

Просмотреть файл

@ -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.