{"thread":{"id":"56590","subject":"[PATCH 0/5] Designated initializer cleanup & conversion","startedAt":"2021-09-27T00:40:00Z","lastAt":"2021-09-30T10:01:46Z","messageCount":32,"participants":["Ævar Arnfjörð Bjarmason","Eric Sunshine","Johannes Sixt","Phillip Wood","Junio C Hamano","Jeff King","Ramsay Jones"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"437100","messageId":"cover-0.5-00000000000-20210927T003330Z-avarab@gmail.com","threadId":"56590","inReplyTo":null,"subject":"[PATCH 0/5] Designated initializer cleanup & conversion","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T00:39:47Z","receivedAt":"2021-09-27T00:40:00Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"For some of the memory leak fixes I've got queued up the first step is\noften to migrate the relevant code to using modern initializer\npatterns. I.e. using an *_INIT macro, initializing on the stack not\nthe heap when possible etc.\n\nI found that for some of those I'd start with a migration to\ndesignated initializers, but if we're doing that we might as well do\n(almost) all of them.\n\nThis series does /most/ of that, the remaining parts are things that\nwould conflict with other in-flight changes, i.e. this merges cleanly\nwith \"seen\". We can clean up any stray stragglers some other time.\n\nSee\nhttps://lore.kernel.org/git/cover-0.5-00000000000-20210701T104855Z-avarab@gmail.com/\nfor a predecessor series which already landed as bd4232fac33 (Merge\nbranch 'ab/struct-init', 2021-07-16).\n\nÆvar Arnfjörð Bjarmason (5):\n  submodule-config.h: remove unused SUBMODULE_INIT macro\n  *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom\n  *.h _INIT macros: don't specify fields equal to 0\n  *.h: move some *_INIT to designated initializers\n  cbtree.h: define cb_init() in terms of CBTREE_INIT\n\n add-interactive.c                             |  8 +++++--\n builtin/submodule--helper.c                   | 21 ++++++++++---------\n cache.h                                       |  4 +++-\n cbtree.h                                      |  5 +++--\n checkout.c                                    |  2 +-\n .../git-credential-gnome-keyring.c            |  2 +-\n .../libsecret/git-credential-libsecret.c      |  2 +-\n diff.c                                        |  4 ++--\n entry.h                                       |  2 +-\n lockfile.h                                    |  2 +-\n object-store.h                                |  2 +-\n object.h                                      |  2 +-\n oid-array.h                                   |  2 +-\n path.h                                        |  5 +----\n ref-filter.c                                  |  2 +-\n remote.c                                      |  2 +-\n revision.c                                    |  2 +-\n sequencer.h                                   |  4 +++-\n shallow.h                                     |  4 +++-\n simple-ipc.h                                  |  6 +-----\n strbuf.h                                      |  2 +-\n strvec.h                                      |  4 +++-\n submodule-config.h                            |  4 ----\n submodule.c                                   |  8 ++++---\n submodule.h                                   |  4 +++-\n t/helper/test-run-command.c                   |  6 ++++--\n transport.h                                   |  4 +++-\n 27 files changed, 63 insertions(+), 52 deletions(-)\n\n-- \n2.33.0.1294.g2bdf2798764\n\n"},{"id":"437101","messageId":"patch-2.5-d612e7df7a5-20210927T003330Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-0.5-00000000000-20210927T003330Z-avarab@gmail.com","subject":"[PATCH 2/5] *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T00:39:49Z","receivedAt":"2021-09-27T00:40:00Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"In C it isn't required to specify that all members of a struct are\nzero'd out to 0, NULL or '\\0', just providing a \"{ 0 }\" will\naccomplish that.\n\nLet's also change change code that provided N zero'd fields to just\nprovide one, and change e.g. \"{ NULL }\" to \"{ 0 }\" for\nconsistency. I.e. even if the first member is a pointer let's use \"0\"\ninstead of \"NULL\". The point of using \"0\" consistently is to pick one,\nand to not have the reader wonder why we're not using the same pattern\neverywhere.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/submodule--helper.c                      | 16 ++++++++--------\n checkout.c                                       |  2 +-\n .../gnome-keyring/git-credential-gnome-keyring.c |  2 +-\n .../libsecret/git-credential-libsecret.c         |  2 +-\n diff.c                                           |  4 ++--\n entry.h                                          |  2 +-\n lockfile.h                                       |  2 +-\n object-store.h                                   |  2 +-\n object.h                                         |  2 +-\n oid-array.h                                      |  2 +-\n path.h                                           |  5 +----\n ref-filter.c                                     |  2 +-\n remote.c                                         |  2 +-\n revision.c                                       |  2 +-\n 14 files changed, 22 insertions(+), 25 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 5336daf186d..deca75c83ee 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -307,7 +307,7 @@ struct module_list {\n \tconst struct cache_entry **entries;\n \tint alloc, nr;\n };\n-#define MODULE_LIST_INIT { NULL, 0, 0 }\n+#define MODULE_LIST_INIT { 0 }\n \n static int module_list_compute(int argc, const char **argv,\n \t\t\t       const char *prefix,\n@@ -588,7 +588,7 @@ struct init_cb {\n \tconst char *prefix;\n \tunsigned int flags;\n };\n-#define INIT_CB_INIT { NULL, 0 }\n+#define INIT_CB_INIT { 0 }\n \n static void init_submodule(const char *path, const char *prefix,\n \t\t\t   unsigned int flags)\n@@ -717,7 +717,7 @@ struct status_cb {\n \tconst char *prefix;\n \tunsigned int flags;\n };\n-#define STATUS_CB_INIT { NULL, 0 }\n+#define STATUS_CB_INIT { 0 }\n \n static void print_status(unsigned int flags, char state, const char *path,\n \t\t\t const struct object_id *oid, const char *displaypath)\n@@ -911,13 +911,13 @@ struct module_cb {\n \tchar status;\n \tconst char *sm_path;\n };\n-#define MODULE_CB_INIT { 0, 0, NULL, NULL, '\\0', NULL }\n+#define MODULE_CB_INIT { 0 }\n \n struct module_cb_list {\n \tstruct module_cb **entries;\n \tint alloc, nr;\n };\n-#define MODULE_CB_LIST_INIT { NULL, 0, 0 }\n+#define MODULE_CB_LIST_INIT { 0 }\n \n struct summary_cb {\n \tint argc;\n@@ -928,7 +928,7 @@ struct summary_cb {\n \tunsigned int files: 1;\n \tint summary_limit;\n };\n-#define SUMMARY_CB_INIT { 0, NULL, NULL, 0, 0, 0, 0 }\n+#define SUMMARY_CB_INIT { 0 }\n \n enum diff_cmd {\n \tDIFF_INDEX,\n@@ -1334,7 +1334,7 @@ struct sync_cb {\n \tconst char *prefix;\n \tunsigned int flags;\n };\n-#define SYNC_CB_INIT { NULL, 0 }\n+#define SYNC_CB_INIT { 0 }\n \n static void sync_submodule(const char *path, const char *prefix,\n \t\t\t   unsigned int flags)\n@@ -1480,7 +1480,7 @@ struct deinit_cb {\n \tconst char *prefix;\n \tunsigned int flags;\n };\n-#define DEINIT_CB_INIT { NULL, 0 }\n+#define DEINIT_CB_INIT { 0 }\n \n static void deinit_submodule(const char *path, const char *prefix,\n \t\t\t     unsigned int flags)\ndiff --git a/checkout.c b/checkout.c\nindex 6586e30ca5a..2e39dae684f 100644\n--- a/checkout.c\n+++ b/checkout.c\n@@ -14,7 +14,7 @@ struct tracking_name_data {\n \tstruct object_id *default_dst_oid;\n };\n \n-#define TRACKING_NAME_DATA_INIT { NULL, NULL, NULL, 0, NULL, NULL, NULL }\n+#define TRACKING_NAME_DATA_INIT { 0 }\n \n static int check_tracking_name(struct remote *remote, void *cb_data)\n {\ndiff --git a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c b/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c\nindex d389bfadcee..5927e27ae6e 100644\n--- a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c\n+++ b/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c\n@@ -138,7 +138,7 @@ struct credential {\n \tchar *password;\n };\n \n-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }\n+#define CREDENTIAL_INIT { 0 }\n \n typedef int (*credential_op_cb)(struct credential *);\n \ndiff --git a/contrib/credential/libsecret/git-credential-libsecret.c b/contrib/credential/libsecret/git-credential-libsecret.c\nindex e6598b63833..2c5d76d789f 100644\n--- a/contrib/credential/libsecret/git-credential-libsecret.c\n+++ b/contrib/credential/libsecret/git-credential-libsecret.c\n@@ -41,7 +41,7 @@ struct credential {\n \tchar *password;\n };\n \n-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }\n+#define CREDENTIAL_INIT { 0 }\n \n typedef int (*credential_op_cb)(struct credential *);\n \ndiff --git a/diff.c b/diff.c\nindex c8f530ffdbe..861282db1c3 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -775,13 +775,13 @@ struct emitted_diff_symbol {\n \tint indent_width; /* The visual width of the indentation */\n \tenum diff_symbol s;\n };\n-#define EMITTED_DIFF_SYMBOL_INIT {NULL}\n+#define EMITTED_DIFF_SYMBOL_INIT { 0 }\n \n struct emitted_diff_symbols {\n \tstruct emitted_diff_symbol *buf;\n \tint nr, alloc;\n };\n-#define EMITTED_DIFF_SYMBOLS_INIT {NULL, 0, 0}\n+#define EMITTED_DIFF_SYMBOLS_INIT { 0 }\n \n static void append_emitted_diff_symbol(struct diff_options *o,\n \t\t\t\t       struct emitted_diff_symbol *e)\ndiff --git a/entry.h b/entry.h\nindex 7c889e58fd7..04bc8bb59f0 100644\n--- a/entry.h\n+++ b/entry.h\n@@ -16,7 +16,7 @@ struct checkout {\n \t\t clone:1,\n \t\t refresh_cache:1;\n };\n-#define CHECKOUT_INIT { NULL, \"\" }\n+#define CHECKOUT_INIT { 0 }\n \n #define TEMPORARY_FILENAME_LENGTH 25\n /*\ndiff --git a/lockfile.h b/lockfile.h\nindex db93e6ba73e..90af4e66b28 100644\n--- a/lockfile.h\n+++ b/lockfile.h\n@@ -121,7 +121,7 @@ struct lock_file {\n \tstruct tempfile *tempfile;\n };\n \n-#define LOCK_INIT { NULL }\n+#define LOCK_INIT { 0 }\n \n /* String appended to a filename to derive the lockfile name: */\n #define LOCK_SUFFIX \".lock\"\ndiff --git a/object-store.h b/object-store.h\nindex c5130d8baea..1e647a5be30 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -371,7 +371,7 @@ struct object_info {\n  * Initializer for a \"struct object_info\" that wants no items. You may\n  * also memset() the memory to all-zeroes.\n  */\n-#define OBJECT_INFO_INIT {NULL}\n+#define OBJECT_INFO_INIT { 0 }\n \n /* Invoke lookup_replace_object() on the given hash */\n #define OBJECT_INFO_LOOKUP_REPLACE 1\ndiff --git a/object.h b/object.h\nindex 549f2d256bc..cb556ab7753 100644\n--- a/object.h\n+++ b/object.h\n@@ -55,7 +55,7 @@ struct object_array {\n \t} *objects;\n };\n \n-#define OBJECT_ARRAY_INIT { 0, 0, NULL }\n+#define OBJECT_ARRAY_INIT { 0 }\n \n /*\n  * object flag allocation:\ndiff --git a/oid-array.h b/oid-array.h\nindex 72bca78b7dc..f60f9af6741 100644\n--- a/oid-array.h\n+++ b/oid-array.h\n@@ -56,7 +56,7 @@ struct oid_array {\n \tint sorted;\n };\n \n-#define OID_ARRAY_INIT { NULL, 0, 0, 0 }\n+#define OID_ARRAY_INIT { 0 }\n \n /**\n  * Add an item to the set. The object ID will be placed at the end of the array\ndiff --git a/path.h b/path.h\nindex 251c78d9800..b68691a86b8 100644\n--- a/path.h\n+++ b/path.h\n@@ -181,10 +181,7 @@ struct path_cache {\n \tconst char *shallow;\n };\n \n-#define PATH_CACHE_INIT                                        \\\n-\t{                                                      \\\n-\t\tNULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \\\n-\t}\n+#define PATH_CACHE_INIT { 0 }\n \n const char *git_path_squash_msg(struct repository *r);\n const char *git_path_merge_msg(struct repository *r);\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 93ce2a6ef2e..eee4f9b17c5 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -633,7 +633,7 @@ static struct {\n \t */\n };\n \n-#define REF_FORMATTING_STATE_INIT  { 0, NULL }\n+#define REF_FORMATTING_STATE_INIT  { 0 }\n \n struct ref_formatting_stack {\n \tstruct ref_formatting_stack *prev;\ndiff --git a/remote.c b/remote.c\nindex 31e141b01fa..f958543d707 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2403,7 +2403,7 @@ struct reflog_commit_array {\n \tsize_t nr, alloc;\n };\n \n-#define REFLOG_COMMIT_ARRAY_INIT { NULL, 0, 0 }\n+#define REFLOG_COMMIT_ARRAY_INIT { 0 }\n \n /* Append a commit to the array. */\n static void append_commit(struct reflog_commit_array *arr,\ndiff --git a/revision.c b/revision.c\nindex 0dabb5a0bcf..73e5004d60b 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -249,7 +249,7 @@ struct commit_stack {\n \tstruct commit **items;\n \tsize_t nr, alloc;\n };\n-#define COMMIT_STACK_INIT { NULL, 0, 0 }\n+#define COMMIT_STACK_INIT { 0 }\n \n static void commit_stack_push(struct commit_stack *stack, struct commit *commit)\n {\n-- \n2.33.0.1294.g2bdf2798764\n\n"},{"id":"437102","messageId":"patch-1.5-7a7a0141515-20210927T003330Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-0.5-00000000000-20210927T003330Z-avarab@gmail.com","subject":"[PATCH 1/5] submodule-config.h: remove unused SUBMODULE_INIT macro","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T00:39:48Z","receivedAt":"2021-09-27T00:40:00Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This macro was added and used in c68f8375760 (implement fetching of\nmoved submodules, 2017-10-16) but its last user went away in\nbe76c212823 (fetch: ensure submodule objects fetched, 2018-12-06).\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n submodule-config.h | 4 ----\n 1 file changed, 4 deletions(-)\n\ndiff --git a/submodule-config.h b/submodule-config.h\nindex c11e22cf509..65875b94ea5 100644\n--- a/submodule-config.h\n+++ b/submodule-config.h\n@@ -45,10 +45,6 @@ struct submodule {\n \tstruct object_id gitmodules_oid;\n \tint recommend_shallow;\n };\n-\n-#define SUBMODULE_INIT { NULL, NULL, NULL, RECURSE_SUBMODULES_NONE, \\\n-\tNULL, NULL, SUBMODULE_UPDATE_STRATEGY_INIT, { { 0 } }, -1 };\n-\n struct submodule_cache;\n struct repository;\n \n-- \n2.33.0.1294.g2bdf2798764\n\n"},{"id":"437103","messageId":"patch-3.5-9e45d2e7bb3-20210927T003330Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-0.5-00000000000-20210927T003330Z-avarab@gmail.com","subject":"[PATCH 3/5] *.h _INIT macros: don't specify fields equal to 0","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T00:39:50Z","receivedAt":"2021-09-27T00:40:03Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the initialization of \"struct strbuf\" changed in\ncbc0f81d96f (strbuf: use designated initializers in STRBUF_INIT,\n2017-07-10) to omit specifying \"alloc\" and \"len\", as we do with other\n\"alloc\" and \"len\" (or \"nr\") in similar structs.\n\nLet's likewise omit the explicit initialization of all fields in the\n\"struct ipc_client_connect_option\" struct added in\n59c7b88198a (simple-ipc: add win32 implementation, 2021-03-15).\n\nFinally, start incrementally changing the same pattern in\n\"t/helper/test-run-command.c\". This change was part of an earlier\non-list version[1] of c90be786da9 (test-tool run-command: fix\nflip-flop init pattern, 2021-09-11).\n\n1. https://lore.kernel.org/git/patch-1.1-0aa4523ab6e-20210909T130849Z-avarab@gmail.com/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n simple-ipc.h                | 6 +-----\n strbuf.h                    | 2 +-\n t/helper/test-run-command.c | 2 +-\n 3 files changed, 3 insertions(+), 7 deletions(-)\n\ndiff --git a/simple-ipc.h b/simple-ipc.h\nindex 2c48a5ee004..08b2908d5f8 100644\n--- a/simple-ipc.h\n+++ b/simple-ipc.h\n@@ -65,11 +65,7 @@ struct ipc_client_connect_options {\n \tunsigned int uds_disallow_chdir:1;\n };\n \n-#define IPC_CLIENT_CONNECT_OPTIONS_INIT { \\\n-\t.wait_if_busy = 0, \\\n-\t.wait_if_not_found = 0, \\\n-\t.uds_disallow_chdir = 0, \\\n-}\n+#define IPC_CLIENT_CONNECT_OPTIONS_INIT { 0 }\n \n /*\n  * Determine if a server is listening on this named pipe or socket using\ndiff --git a/strbuf.h b/strbuf.h\nindex 5b1113abf8f..3b36bbc49f0 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -70,7 +70,7 @@ struct strbuf {\n };\n \n extern char strbuf_slopbuf[];\n-#define STRBUF_INIT  { .alloc = 0, .len = 0, .buf = strbuf_slopbuf }\n+#define STRBUF_INIT  { .buf = strbuf_slopbuf }\n \n /*\n  * Predeclare this here, since cache.h includes this file before it defines the\ndiff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c\nindex 14c57365e76..50bb98b7e04 100644\n--- a/t/helper/test-run-command.c\n+++ b/t/helper/test-run-command.c\n@@ -61,7 +61,7 @@ struct testsuite {\n \tint quiet, immediate, verbose, verbose_log, trace, write_junit_xml;\n };\n #define TESTSUITE_INIT \\\n-\t{ STRING_LIST_INIT_DUP, STRING_LIST_INIT_DUP, 0, 0, 0, 0, 0, 0, 0 }\n+\t{ STRING_LIST_INIT_DUP, STRING_LIST_INIT_DUP }\n \n static int next_test(struct child_process *cp, struct strbuf *err, void *cb,\n \t\t     void **task_cb)\n-- \n2.33.0.1294.g2bdf2798764\n\n"},{"id":"437104","messageId":"patch-5.5-7e571667674-20210927T003330Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-0.5-00000000000-20210927T003330Z-avarab@gmail.com","subject":"[PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T00:39:52Z","receivedAt":"2021-09-27T00:40:08Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Use the same pattern for cb_init() as the one established in the\nrecent refactoring of other such patterns in\n5726a6b4012 (*.c *_init(): define in terms of corresponding *_INIT\nmacro, 2021-07-01).\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n cbtree.h | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/cbtree.h b/cbtree.h\nindex a04a312c3f5..dedbb8e2a45 100644\n--- a/cbtree.h\n+++ b/cbtree.h\n@@ -37,11 +37,12 @@ enum cb_next {\n \tCB_BREAK = 1\n };\n \n-#define CBTREE_INIT { .root = NULL }\n+#define CBTREE_INIT { 0 }\n \n static inline void cb_init(struct cb_tree *t)\n {\n-\tt->root = NULL;\n+\tstruct cb_tree blank = CBTREE_INIT;\n+\tmemcpy(t, &blank, sizeof(*t));\n }\n \n struct cb_node *cb_lookup(struct cb_tree *, const uint8_t *k, size_t klen);\n-- \n2.33.0.1294.g2bdf2798764\n\n"},{"id":"437105","messageId":"patch-4.5-1f364565111-20210927T003330Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-0.5-00000000000-20210927T003330Z-avarab@gmail.com","subject":"[PATCH 4/5] *.h: move some *_INIT to designated initializers","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T00:39:51Z","receivedAt":"2021-09-27T00:40:08Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Move various *_INIT macros to use designated initializers. This helps\nreadability. I've only picked those leftover macros that were not\ntouched by another in-flight series of mine which changed others, but\nalso how initialization was done.\n\nIn the case of SUBMODULE_ALTERNATE_SETUP_INIT I've left an explicit\ninitialization of \"error_mode\", even though\nSUBMODULE_ALTERNATE_ERROR_IGNORE itself is defined as \"0\". Let's not\npeek under the hood and assume that enum fields we know the value of\nwill stay at \"0\".\n\nThe change to \"TESTSUITE_INIT\" in \"t/helper/test-run-command.c\" was\npart of an earlier on-list version[1] of c90be786da9 (test-tool\nrun-command: fix flip-flop init pattern, 2021-09-11).\n\n1. https://lore.kernel.org/git/patch-1.1-0aa4523ab6e-20210909T130849Z-avarab@gmail.com/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n add-interactive.c           | 8 ++++++--\n builtin/submodule--helper.c | 5 +++--\n cache.h                     | 4 +++-\n sequencer.h                 | 4 +++-\n shallow.h                   | 4 +++-\n strvec.h                    | 4 +++-\n submodule.c                 | 8 +++++---\n submodule.h                 | 4 +++-\n t/helper/test-run-command.c | 6 ++++--\n transport.h                 | 4 +++-\n 10 files changed, 36 insertions(+), 15 deletions(-)\n\ndiff --git a/add-interactive.c b/add-interactive.c\nindex 36ebdbdf7e2..6498ae196f1 100644\n--- a/add-interactive.c\n+++ b/add-interactive.c\n@@ -102,8 +102,12 @@ struct prefix_item_list {\n \tint *selected; /* for multi-selections */\n \tsize_t min_length, max_length;\n };\n-#define PREFIX_ITEM_LIST_INIT \\\n-\t{ STRING_LIST_INIT_DUP, STRING_LIST_INIT_NODUP, NULL, 1, 4 }\n+#define PREFIX_ITEM_LIST_INIT { \\\n+\t.items = STRING_LIST_INIT_DUP, \\\n+\t.sorted = STRING_LIST_INIT_NODUP, \\\n+\t.min_length = 1, \\\n+\t.max_length = 4, \\\n+}\n \n static void prefix_item_list_clear(struct prefix_item_list *list)\n {\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex deca75c83ee..57f09925157 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1647,8 +1647,9 @@ struct submodule_alternate_setup {\n \t} error_mode;\n \tstruct string_list *reference;\n };\n-#define SUBMODULE_ALTERNATE_SETUP_INIT { NULL, \\\n-\tSUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }\n+#define SUBMODULE_ALTERNATE_SETUP_INIT { \\\n+\t.error_mode = SUBMODULE_ALTERNATE_ERROR_IGNORE, \\\n+}\n \n static const char alternate_error_advice[] = N_(\n \"An alternate computed from a superproject's alternate is invalid.\\n\"\ndiff --git a/cache.h b/cache.h\nindex f6295f3b048..794237515b9 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1668,7 +1668,9 @@ struct cache_def {\n \tint track_flags;\n \tint prefix_len_stat_func;\n };\n-#define CACHE_DEF_INIT { STRBUF_INIT, 0, 0, 0 }\n+#define CACHE_DEF_INIT { \\\n+\t.path = STRBUF_INIT, \\\n+}\n static inline void cache_def_clear(struct cache_def *cache)\n {\n \tstrbuf_release(&cache->path);\ndiff --git a/sequencer.h b/sequencer.h\nindex 2088344cb37..259d4eb4a8a 100644\n--- a/sequencer.h\n+++ b/sequencer.h\n@@ -119,7 +119,9 @@ struct todo_list {\n \tstruct stat_data stat;\n };\n \n-#define TODO_LIST_INIT { STRBUF_INIT }\n+#define TODO_LIST_INIT { \\\n+\t.buf = STRBUF_INIT, \\\n+}\n \n int todo_list_parse_insn_buffer(struct repository *r, char *buf,\n \t\t\t\tstruct todo_list *todo_list);\ndiff --git a/shallow.h b/shallow.h\nindex 5b4a96dcd69..aba6ff58294 100644\n--- a/shallow.h\n+++ b/shallow.h\n@@ -23,7 +23,9 @@ int is_repository_shallow(struct repository *r);\n struct shallow_lock {\n \tstruct lock_file lock;\n };\n-#define SHALLOW_LOCK_INIT { LOCK_INIT }\n+#define SHALLOW_LOCK_INIT { \\\n+\t.lock = LOCK_INIT, \\\n+}\n \n /* commit $GIT_DIR/shallow and reset stat-validity checks */\n int commit_shallow_file(struct repository *r, struct shallow_lock *lk);\ndiff --git a/strvec.h b/strvec.h\nindex 6b3cbd67589..9f55c8766ba 100644\n--- a/strvec.h\n+++ b/strvec.h\n@@ -33,7 +33,9 @@ struct strvec {\n \tsize_t alloc;\n };\n \n-#define STRVEC_INIT { empty_strvec, 0, 0 }\n+#define STRVEC_INIT { \\\n+\t.v = empty_strvec, \\\n+}\n \n /**\n  * Initialize an array. This is no different than assigning from\ndiff --git a/submodule.c b/submodule.c\nindex 78aed03d928..03cf36707ae 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1321,9 +1321,11 @@ struct submodule_parallel_fetch {\n \n \tstruct strbuf submodules_with_errors;\n };\n-#define SPF_INIT {0, STRVEC_INIT, NULL, NULL, 0, 0, 0, 0, \\\n-\t\t  STRING_LIST_INIT_DUP, \\\n-\t\t  NULL, 0, 0, STRBUF_INIT}\n+#define SPF_INIT { \\\n+\t.args = STRVEC_INIT, \\\n+\t.changed_submodule_names = STRING_LIST_INIT_DUP, \\\n+\t.submodules_with_errors = STRBUF_INIT, \\\n+}\n \n static int get_fetch_recurse_config(const struct submodule *submodule,\n \t\t\t\t    struct submodule_parallel_fetch *spf)\ndiff --git a/submodule.h b/submodule.h\nindex 4578e501b86..6bd2c99fd99 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -37,7 +37,9 @@ struct submodule_update_strategy {\n \tenum submodule_update_type type;\n \tconst char *command;\n };\n-#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}\n+#define SUBMODULE_UPDATE_STRATEGY_INIT { \\\n+\t.type = SM_UPDATE_UNSPECIFIED, \\\n+}\n \n int is_gitmodules_unmerged(struct index_state *istate);\n int is_writing_gitmodules_ok(void);\ndiff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c\nindex 50bb98b7e04..3c4fb862234 100644\n--- a/t/helper/test-run-command.c\n+++ b/t/helper/test-run-command.c\n@@ -60,8 +60,10 @@ struct testsuite {\n \tint next;\n \tint quiet, immediate, verbose, verbose_log, trace, write_junit_xml;\n };\n-#define TESTSUITE_INIT \\\n-\t{ STRING_LIST_INIT_DUP, STRING_LIST_INIT_DUP }\n+#define TESTSUITE_INIT { \\\n+\t.tests = STRING_LIST_INIT_DUP, \\\n+\t.failed = STRING_LIST_INIT_DUP, \\\n+}\n \n static int next_test(struct child_process *cp, struct strbuf *err, void *cb,\n \t\t     void **task_cb)\ndiff --git a/transport.h b/transport.h\nindex 1cbab113730..8bb4c8bbc8c 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -262,7 +262,9 @@ struct transport_ls_refs_options {\n \t */\n \tchar *unborn_head_target;\n };\n-#define TRANSPORT_LS_REFS_OPTIONS_INIT { STRVEC_INIT }\n+#define TRANSPORT_LS_REFS_OPTIONS_INIT { \\\n+\t.ref_prefixes = STRVEC_INIT, \\\n+}\n \n /*\n  * Retrieve refs from a remote.\n-- \n2.33.0.1294.g2bdf2798764\n\n"},{"id":"437114","messageId":"CAPig+cRBPVpa4+2jm0X-u0Ki8bmihS4dycj9RLwf0Mwx+zjOKQ@mail.gmail.com","threadId":"56590","inReplyTo":"patch-2.5-d612e7df7a5-20210927T003330Z-avarab@gmail.com","subject":"Re: [PATCH 2/5] *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-09-27T02:27:30Z","receivedAt":"2021-09-27T02:28:38Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Sep 26, 2021 at 8:40 PM Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n> In C it isn't required to specify that all members of a struct are\n> zero'd out to 0, NULL or '\\0', just providing a \"{ 0 }\" will\n> accomplish that.\n>\n> Let's also change change code that provided N zero'd fields to just\n\ns/change change/change/\n\n> provide one, and change e.g. \"{ NULL }\" to \"{ 0 }\" for\n> consistency. I.e. even if the first member is a pointer let's use \"0\"\n> instead of \"NULL\". The point of using \"0\" consistently is to pick one,\n> and to not have the reader wonder why we're not using the same pattern\n> everywhere.\n>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n"},{"id":"437116","messageId":"68c9c6da-d215-a39b-64f5-8b8930ce5a09@kdbg.org","threadId":"56590","inReplyTo":"patch-2.5-d612e7df7a5-20210927T003330Z-avarab@gmail.com","subject":"Re: [PATCH 2/5] *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2021-09-27T06:35:25Z","receivedAt":"2021-09-27T06:35:30Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 27.09.21 um 02:39 schrieb Ævar Arnfjörð Bjarmason:\n> diff --git a/entry.h b/entry.h\n> index 7c889e58fd7..04bc8bb59f0 100644\n> --- a/entry.h\n> +++ b/entry.h\n> @@ -16,7 +16,7 @@ struct checkout {\n>  \t\t clone:1,\n>  \t\t refresh_cache:1;\n>  };\n> -#define CHECKOUT_INIT { NULL, \"\" }\n> +#define CHECKOUT_INIT { 0 }\n\nThis is not an equivalence transformation and does not belong in this patch.\n\n-- Hannes\n"},{"id":"437118","messageId":"694f477d-b387-c8ea-4138-0e9334540c69@kdbg.org","threadId":"56590","inReplyTo":"patch-5.5-7e571667674-20210927T003330Z-avarab@gmail.com","subject":"Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2021-09-27T06:37:50Z","receivedAt":"2021-09-27T06:37:56Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 27.09.21 um 02:39 schrieb Ævar Arnfjörð Bjarmason:\n> --- a/cbtree.h\n> +++ b/cbtree.h\n> @@ -37,11 +37,12 @@ enum cb_next {\n>  \tCB_BREAK = 1\n>  };\n>  \n> -#define CBTREE_INIT { .root = NULL }\n> +#define CBTREE_INIT { 0 }\n>  \n>  static inline void cb_init(struct cb_tree *t)\n>  {\n> -\tt->root = NULL;\n> +\tstruct cb_tree blank = CBTREE_INIT;\n\nThis could be\n\n\tstatic const struct cb_tree blank = CBTREE_INIT;\n\n> +\tmemcpy(t, &blank, sizeof(*t));\n\nIs\n\t*t = blank;\n\nnot a thing in C?\n\n-- Hannes\n"},{"id":"437120","messageId":"ef724a3a-a4b8-65d3-c928-13a7d78f189a@gmail.com","threadId":"56590","inReplyTo":"patch-5.5-7e571667674-20210927T003330Z-avarab@gmail.com","subject":"Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2021-09-27T09:13:50Z","receivedAt":"2021-09-27T09:13:58Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Ævar\n\nOn 27/09/2021 01:39, Ævar Arnfjörð Bjarmason wrote:\n> Use the same pattern for cb_init() as the one established in the\n> recent refactoring of other such patterns in\n> 5726a6b4012 (*.c *_init(): define in terms of corresponding *_INIT\n> macro, 2021-07-01).\n> \n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>   cbtree.h | 5 +++--\n>   1 file changed, 3 insertions(+), 2 deletions(-)\n> \n> diff --git a/cbtree.h b/cbtree.h\n> index a04a312c3f5..dedbb8e2a45 100644\n> --- a/cbtree.h\n> +++ b/cbtree.h\n> @@ -37,11 +37,12 @@ enum cb_next {\n>   \tCB_BREAK = 1\n>   };\n>   \n> -#define CBTREE_INIT { .root = NULL }\n> +#define CBTREE_INIT { 0 }\n>   \n>   static inline void cb_init(struct cb_tree *t)\n>   {\n> -\tt->root = NULL;\n> +\tstruct cb_tree blank = CBTREE_INIT;\n> +\tmemcpy(t, &blank, sizeof(*t));\n>   }\n\nSlightly off topic but would this be a good site for a compound literal \ntest balloon?\n\n\t*t = (struct cb_tree){ 0 };\n\nCompound literals are in C99 and seem to have been supported by MSVC \nsince 2013 [1].\n\nBest Wishes\n\nPhillip\n\n[1] \nhttps://docs.microsoft.com/en-us/cpp/porting/visual-cpp-what-s-new-2003-through-2015?view=msvc-160#whats-new-for-c-in-visual-studio-2013\n\n>   struct cb_node *cb_lookup(struct cb_tree *, const uint8_t *k, size_t klen);\n> \n"},{"id":"437130","messageId":"87h7e61duk.fsf@evledraar.gmail.com","threadId":"56590","inReplyTo":"ef724a3a-a4b8-65d3-c928-13a7d78f189a@gmail.com","subject":"Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T11:00:01Z","receivedAt":"2021-09-27T11:02:10Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Sep 27 2021, Phillip Wood wrote:\n\n> Hi Ævar\n>\n> On 27/09/2021 01:39, Ævar Arnfjörð Bjarmason wrote:\n>> Use the same pattern for cb_init() as the one established in the\n>> recent refactoring of other such patterns in\n>> 5726a6b4012 (*.c *_init(): define in terms of corresponding *_INIT\n>> macro, 2021-07-01).\n>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>> ---\n>>   cbtree.h | 5 +++--\n>>   1 file changed, 3 insertions(+), 2 deletions(-)\n>> diff --git a/cbtree.h b/cbtree.h\n>> index a04a312c3f5..dedbb8e2a45 100644\n>> --- a/cbtree.h\n>> +++ b/cbtree.h\n>> @@ -37,11 +37,12 @@ enum cb_next {\n>>   \tCB_BREAK = 1\n>>   };\n>>   -#define CBTREE_INIT { .root = NULL }\n>> +#define CBTREE_INIT { 0 }\n>>     static inline void cb_init(struct cb_tree *t)\n>>   {\n>> -\tt->root = NULL;\n>> +\tstruct cb_tree blank = CBTREE_INIT;\n>> +\tmemcpy(t, &blank, sizeof(*t));\n>>   }\n>\n> Slightly off topic but would this be a good site for a compound\n> literal test balloon?\n>\n> \t*t = (struct cb_tree){ 0 };\n>\n> Compound literals are in C99 and seem to have been supported by MSVC\n> since 2013 [1].\n\nI think that's a good thing to test out, FWIW I've also tested it on the\nIBM xlc, Oracle SunCC and HP/UX's aCC, they all seem to accept it.\n\nBut I'd prefer just doing that in some general follow-up to bd4232fac33\n(Merge branch 'ab/struct-init', 2021-07-16), i.e. let's just use the\ninit pattern it established here.\n"},{"id":"437131","messageId":"87czou1dmp.fsf@evledraar.gmail.com","threadId":"56590","inReplyTo":"694f477d-b387-c8ea-4138-0e9334540c69@kdbg.org","subject":"Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T11:02:35Z","receivedAt":"2021-09-27T11:06:43Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Sep 27 2021, Johannes Sixt wrote:\n\n> Am 27.09.21 um 02:39 schrieb Ævar Arnfjörð Bjarmason:\n>> --- a/cbtree.h\n>> +++ b/cbtree.h\n>> @@ -37,11 +37,12 @@ enum cb_next {\n>>  \tCB_BREAK = 1\n>>  };\n>>  \n>> -#define CBTREE_INIT { .root = NULL }\n>> +#define CBTREE_INIT { 0 }\n>>  \n>>  static inline void cb_init(struct cb_tree *t)\n>>  {\n>> -\tt->root = NULL;\n>> +\tstruct cb_tree blank = CBTREE_INIT;\n>\n> This could be\n>\n> \tstatic const struct cb_tree blank = CBTREE_INIT;\n\n*nod*...\n\n>> +\tmemcpy(t, &blank, sizeof(*t));\n>\n> Is\n> \t*t = blank;\n>\n> not a thing in C?\n>\n> -- Hannes\n\n...but to both this & the above my reply in the side-thread at\nhttps://lore.kernel.org/git/87h7e61duk.fsf@evledraar.gmail.com/\napplies. I.e. this is just following a pattern I got from Jeff King &\nused in bd4232fac33 (Merge branch 'ab/struct-init', 2021-07-16).\n\nFWIW with \"const\" in general I don't use it as much as I'd personally\nprefer, see e.g. [1] for one recent discussion, but maybe there wouldn't\nbe any push-back in this case...\n\n1. https://lore.kernel.org/git/patch-1.1-c317e6e125e-20210921T124416Z-avarab@gmail.com/\n"},{"id":"437134","messageId":"cover-v2-0.5-00000000000-20210927T124407Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-0.5-00000000000-20210927T003330Z-avarab@gmail.com","subject":"[PATCH v2 0/5] Designated initializer cleanup & conversion","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T12:54:23Z","receivedAt":"2021-09-27T12:54:47Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Migrates more code to designated initializers, see\nhttp://lore.kernel.org/git/cover-0.5-00000000000-20210927T003330Z-avarab@gmail.com\nfor the v1.\n\nThis addresses all the feedback on v1, thanks all! Changes:\n\n * I'd misread the text around section 6.7.8 in C99 and misconverted\n   the CHECKOUT_INIT macro. Thanks to Johannes Sixt for pointing it\n   out.\n\n * Typo change in commit message & elaborate on why I'm not using the\n   \"*t = (struct cb_tree){ 0 };\" pattern in 5/5.\n\n * Convert the LIST_HEAD_INIT and TRACE_KEY_INIT macros, which I\n   missed in v1.\n\nNothing else changed as far as the end-state is concerned, but as the\nrange-diff shows I did some of the changes in the previous 4/5\npartially in 3/5, e.g. for CACHE_DEF_INIT I first remove the duplicate\nand redundant \"0\" fields, and then convert it to a designated\ninitializer.\n\nÆvar Arnfjörð Bjarmason (5):\n  submodule-config.h: remove unused SUBMODULE_INIT macro\n  *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom\n  *.h _INIT macros: don't specify fields equal to 0\n  *.h: move some *_INIT to designated initializers\n  cbtree.h: define cb_init() in terms of CBTREE_INIT\n\n add-interactive.c                             |  8 +++++--\n builtin/submodule--helper.c                   | 21 ++++++++++---------\n cache.h                                       |  4 +++-\n cbtree.h                                      |  5 +++--\n checkout.c                                    |  2 +-\n .../git-credential-gnome-keyring.c            |  2 +-\n .../libsecret/git-credential-libsecret.c      |  2 +-\n diff.c                                        |  4 ++--\n entry.h                                       |  2 +-\n list.h                                        |  5 ++++-\n lockfile.h                                    |  2 +-\n object-store.h                                |  2 +-\n object.h                                      |  2 +-\n oid-array.h                                   |  2 +-\n path.h                                        |  5 +----\n ref-filter.c                                  |  2 +-\n remote.c                                      |  2 +-\n revision.c                                    |  2 +-\n sequencer.h                                   |  4 +++-\n shallow.h                                     |  4 +++-\n simple-ipc.h                                  |  6 +-----\n strbuf.h                                      |  2 +-\n strvec.h                                      |  4 +++-\n submodule-config.h                            |  4 ----\n submodule.c                                   |  8 ++++---\n submodule.h                                   |  4 +++-\n t/helper/test-run-command.c                   |  6 ++++--\n trace.h                                       |  2 +-\n transport.h                                   |  4 +++-\n 29 files changed, 68 insertions(+), 54 deletions(-)\n\nRange-diff against v1:\n1:  7a7a0141515 = 1:  7a7a0141515 submodule-config.h: remove unused SUBMODULE_INIT macro\n2:  d612e7df7a5 ! 2:  afcd2729c95 *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom\n    @@ Commit message\n         zero'd out to 0, NULL or '\\0', just providing a \"{ 0 }\" will\n         accomplish that.\n     \n    -    Let's also change change code that provided N zero'd fields to just\n    +    Let's also change code that provided N zero'd fields to just\n         provide one, and change e.g. \"{ NULL }\" to \"{ 0 }\" for\n         consistency. I.e. even if the first member is a pointer let's use \"0\"\n         instead of \"NULL\". The point of using \"0\" consistently is to pick one,\n    @@ diff.c: struct emitted_diff_symbol {\n      static void append_emitted_diff_symbol(struct diff_options *o,\n      \t\t\t\t       struct emitted_diff_symbol *e)\n     \n    - ## entry.h ##\n    -@@ entry.h: struct checkout {\n    - \t\t clone:1,\n    - \t\t refresh_cache:1;\n    - };\n    --#define CHECKOUT_INIT { NULL, \"\" }\n    -+#define CHECKOUT_INIT { 0 }\n    - \n    - #define TEMPORARY_FILENAME_LENGTH 25\n    - /*\n    -\n      ## lockfile.h ##\n     @@ lockfile.h: struct lock_file {\n      \tstruct tempfile *tempfile;\n3:  9e45d2e7bb3 ! 3:  590220bbdcc *.h _INIT macros: don't specify fields equal to 0\n    @@ Commit message\n         \"struct ipc_client_connect_option\" struct added in\n         59c7b88198a (simple-ipc: add win32 implementation, 2021-03-15).\n     \n    +    Do the same for a few other initializers, e.g. STRVEC_INIT and\n    +    CACHE_DEF_INIT.\n    +\n         Finally, start incrementally changing the same pattern in\n         \"t/helper/test-run-command.c\". This change was part of an earlier\n         on-list version[1] of c90be786da9 (test-tool run-command: fix\n    @@ Commit message\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n    + ## cache.h ##\n    +@@ cache.h: struct cache_def {\n    + \tint track_flags;\n    + \tint prefix_len_stat_func;\n    + };\n    +-#define CACHE_DEF_INIT { STRBUF_INIT, 0, 0, 0 }\n    ++#define CACHE_DEF_INIT { STRBUF_INIT }\n    + static inline void cache_def_clear(struct cache_def *cache)\n    + {\n    + \tstrbuf_release(&cache->path);\n    +\n      ## simple-ipc.h ##\n     @@ simple-ipc.h: struct ipc_client_connect_options {\n      \tunsigned int uds_disallow_chdir:1;\n    @@ strbuf.h: struct strbuf {\n      /*\n       * Predeclare this here, since cache.h includes this file before it defines the\n     \n    + ## strvec.h ##\n    +@@ strvec.h: struct strvec {\n    + \tsize_t alloc;\n    + };\n    + \n    +-#define STRVEC_INIT { empty_strvec, 0, 0 }\n    ++#define STRVEC_INIT { empty_strvec }\n    + \n    + /**\n    +  * Initialize an array. This is no different than assigning from\n    +\n    + ## submodule.h ##\n    +@@ submodule.h: struct submodule_update_strategy {\n    + \tenum submodule_update_type type;\n    + \tconst char *command;\n    + };\n    +-#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}\n    ++#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED}\n    + \n    + int is_gitmodules_unmerged(struct index_state *istate);\n    + int is_writing_gitmodules_ok(void);\n    +\n      ## t/helper/test-run-command.c ##\n     @@ t/helper/test-run-command.c: struct testsuite {\n      \tint quiet, immediate, verbose, verbose_log, trace, write_junit_xml;\n    @@ t/helper/test-run-command.c: struct testsuite {\n      \n      static int next_test(struct child_process *cp, struct strbuf *err, void *cb,\n      \t\t     void **task_cb)\n    +\n    + ## trace.h ##\n    +@@ trace.h: struct trace_key {\n    + \n    + extern struct trace_key trace_default_key;\n    + \n    +-#define TRACE_KEY_INIT(name) { \"GIT_TRACE_\" #name, 0, 0, 0 }\n    ++#define TRACE_KEY_INIT(name) { \"GIT_TRACE_\" #name }\n    + extern struct trace_key trace_perf_key;\n    + extern struct trace_key trace_setup_key;\n    + \n4:  1f364565111 ! 4:  dd4ec1a0219 *.h: move some *_INIT to designated initializers\n    @@ cache.h: struct cache_def {\n      \tint track_flags;\n      \tint prefix_len_stat_func;\n      };\n    --#define CACHE_DEF_INIT { STRBUF_INIT, 0, 0, 0 }\n    +-#define CACHE_DEF_INIT { STRBUF_INIT }\n     +#define CACHE_DEF_INIT { \\\n     +\t.path = STRBUF_INIT, \\\n     +}\n    @@ cache.h: struct cache_def {\n      {\n      \tstrbuf_release(&cache->path);\n     \n    + ## entry.h ##\n    +@@ entry.h: struct checkout {\n    + \t\t clone:1,\n    + \t\t refresh_cache:1;\n    + };\n    +-#define CHECKOUT_INIT { NULL, \"\" }\n    ++#define CHECKOUT_INIT { .base_dir = \"\" }\n    + \n    + #define TEMPORARY_FILENAME_LENGTH 25\n    + /*\n    +\n    + ## list.h ##\n    +@@ list.h: struct list_head {\n    + #define INIT_LIST_HEAD(ptr) \\\n    + \t(ptr)->next = (ptr)->prev = (ptr)\n    + \n    +-#define LIST_HEAD_INIT(name) { &(name), &(name) }\n    ++#define LIST_HEAD_INIT(name) { \\\n    ++\t.next = &(name), \\\n    ++\t.prev = &(name), \\\n    ++}\n    + \n    + /* Add new element at the head of the list. */\n    + static inline void list_add(struct list_head *newp, struct list_head *head)\n    +\n      ## sequencer.h ##\n     @@ sequencer.h: struct todo_list {\n      \tstruct stat_data stat;\n    @@ strvec.h: struct strvec {\n      \tsize_t alloc;\n      };\n      \n    --#define STRVEC_INIT { empty_strvec, 0, 0 }\n    +-#define STRVEC_INIT { empty_strvec }\n     +#define STRVEC_INIT { \\\n     +\t.v = empty_strvec, \\\n     +}\n    @@ submodule.h: struct submodule_update_strategy {\n      \tenum submodule_update_type type;\n      \tconst char *command;\n      };\n    --#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}\n    +-#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED}\n     +#define SUBMODULE_UPDATE_STRATEGY_INIT { \\\n     +\t.type = SM_UPDATE_UNSPECIFIED, \\\n     +}\n    @@ t/helper/test-run-command.c: struct testsuite {\n      static int next_test(struct child_process *cp, struct strbuf *err, void *cb,\n      \t\t     void **task_cb)\n     \n    + ## trace.h ##\n    +@@ trace.h: struct trace_key {\n    + \n    + extern struct trace_key trace_default_key;\n    + \n    +-#define TRACE_KEY_INIT(name) { \"GIT_TRACE_\" #name }\n    ++#define TRACE_KEY_INIT(name) { .key = \"GIT_TRACE_\" #name }\n    + extern struct trace_key trace_perf_key;\n    + extern struct trace_key trace_setup_key;\n    + \n    +\n      ## transport.h ##\n     @@ transport.h: struct transport_ls_refs_options {\n      \t */\n5:  7e571667674 ! 5:  76b47e7c80a cbtree.h: define cb_init() in terms of CBTREE_INIT\n    @@ Commit message\n         5726a6b4012 (*.c *_init(): define in terms of corresponding *_INIT\n         macro, 2021-07-01).\n     \n    +    It has been pointed out[1] that we could perhaps use this C99\n    +    replacement of using a compound literal for all of these:\n    +\n    +        *t = (struct cb_tree){ 0 };\n    +\n    +    But let's just stick to the existing pattern established in\n    +    5726a6b4012 for now, we can leave another weather balloon for some\n    +    other time.\n    +\n    +    1. http://lore.kernel.org/git/ef724a3a-a4b8-65d3-c928-13a7d78f189a@gmail.com\n    +\n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n      ## cbtree.h ##\n-- \n2.33.0.1316.gb2e9b3ba3ae\n\n"},{"id":"437135","messageId":"patch-v2-1.5-7a7a0141515-20210927T124407Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-v2-0.5-00000000000-20210927T124407Z-avarab@gmail.com","subject":"[PATCH v2 1/5] submodule-config.h: remove unused SUBMODULE_INIT macro","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T12:54:24Z","receivedAt":"2021-09-27T12:54:47Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This macro was added and used in c68f8375760 (implement fetching of\nmoved submodules, 2017-10-16) but its last user went away in\nbe76c212823 (fetch: ensure submodule objects fetched, 2018-12-06).\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n submodule-config.h | 4 ----\n 1 file changed, 4 deletions(-)\n\ndiff --git a/submodule-config.h b/submodule-config.h\nindex c11e22cf509..65875b94ea5 100644\n--- a/submodule-config.h\n+++ b/submodule-config.h\n@@ -45,10 +45,6 @@ struct submodule {\n \tstruct object_id gitmodules_oid;\n \tint recommend_shallow;\n };\n-\n-#define SUBMODULE_INIT { NULL, NULL, NULL, RECURSE_SUBMODULES_NONE, \\\n-\tNULL, NULL, SUBMODULE_UPDATE_STRATEGY_INIT, { { 0 } }, -1 };\n-\n struct submodule_cache;\n struct repository;\n \n-- \n2.33.0.1316.gb2e9b3ba3ae\n\n"},{"id":"437136","messageId":"patch-v2-2.5-afcd2729c95-20210927T124407Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-v2-0.5-00000000000-20210927T124407Z-avarab@gmail.com","subject":"[PATCH v2 2/5] *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T12:54:25Z","receivedAt":"2021-09-27T12:54:50Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"In C it isn't required to specify that all members of a struct are\nzero'd out to 0, NULL or '\\0', just providing a \"{ 0 }\" will\naccomplish that.\n\nLet's also change code that provided N zero'd fields to just\nprovide one, and change e.g. \"{ NULL }\" to \"{ 0 }\" for\nconsistency. I.e. even if the first member is a pointer let's use \"0\"\ninstead of \"NULL\". The point of using \"0\" consistently is to pick one,\nand to not have the reader wonder why we're not using the same pattern\neverywhere.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/submodule--helper.c                      | 16 ++++++++--------\n checkout.c                                       |  2 +-\n .../gnome-keyring/git-credential-gnome-keyring.c |  2 +-\n .../libsecret/git-credential-libsecret.c         |  2 +-\n diff.c                                           |  4 ++--\n lockfile.h                                       |  2 +-\n object-store.h                                   |  2 +-\n object.h                                         |  2 +-\n oid-array.h                                      |  2 +-\n path.h                                           |  5 +----\n ref-filter.c                                     |  2 +-\n remote.c                                         |  2 +-\n revision.c                                       |  2 +-\n 13 files changed, 21 insertions(+), 24 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 5336daf186d..deca75c83ee 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -307,7 +307,7 @@ struct module_list {\n \tconst struct cache_entry **entries;\n \tint alloc, nr;\n };\n-#define MODULE_LIST_INIT { NULL, 0, 0 }\n+#define MODULE_LIST_INIT { 0 }\n \n static int module_list_compute(int argc, const char **argv,\n \t\t\t       const char *prefix,\n@@ -588,7 +588,7 @@ struct init_cb {\n \tconst char *prefix;\n \tunsigned int flags;\n };\n-#define INIT_CB_INIT { NULL, 0 }\n+#define INIT_CB_INIT { 0 }\n \n static void init_submodule(const char *path, const char *prefix,\n \t\t\t   unsigned int flags)\n@@ -717,7 +717,7 @@ struct status_cb {\n \tconst char *prefix;\n \tunsigned int flags;\n };\n-#define STATUS_CB_INIT { NULL, 0 }\n+#define STATUS_CB_INIT { 0 }\n \n static void print_status(unsigned int flags, char state, const char *path,\n \t\t\t const struct object_id *oid, const char *displaypath)\n@@ -911,13 +911,13 @@ struct module_cb {\n \tchar status;\n \tconst char *sm_path;\n };\n-#define MODULE_CB_INIT { 0, 0, NULL, NULL, '\\0', NULL }\n+#define MODULE_CB_INIT { 0 }\n \n struct module_cb_list {\n \tstruct module_cb **entries;\n \tint alloc, nr;\n };\n-#define MODULE_CB_LIST_INIT { NULL, 0, 0 }\n+#define MODULE_CB_LIST_INIT { 0 }\n \n struct summary_cb {\n \tint argc;\n@@ -928,7 +928,7 @@ struct summary_cb {\n \tunsigned int files: 1;\n \tint summary_limit;\n };\n-#define SUMMARY_CB_INIT { 0, NULL, NULL, 0, 0, 0, 0 }\n+#define SUMMARY_CB_INIT { 0 }\n \n enum diff_cmd {\n \tDIFF_INDEX,\n@@ -1334,7 +1334,7 @@ struct sync_cb {\n \tconst char *prefix;\n \tunsigned int flags;\n };\n-#define SYNC_CB_INIT { NULL, 0 }\n+#define SYNC_CB_INIT { 0 }\n \n static void sync_submodule(const char *path, const char *prefix,\n \t\t\t   unsigned int flags)\n@@ -1480,7 +1480,7 @@ struct deinit_cb {\n \tconst char *prefix;\n \tunsigned int flags;\n };\n-#define DEINIT_CB_INIT { NULL, 0 }\n+#define DEINIT_CB_INIT { 0 }\n \n static void deinit_submodule(const char *path, const char *prefix,\n \t\t\t     unsigned int flags)\ndiff --git a/checkout.c b/checkout.c\nindex 6586e30ca5a..2e39dae684f 100644\n--- a/checkout.c\n+++ b/checkout.c\n@@ -14,7 +14,7 @@ struct tracking_name_data {\n \tstruct object_id *default_dst_oid;\n };\n \n-#define TRACKING_NAME_DATA_INIT { NULL, NULL, NULL, 0, NULL, NULL, NULL }\n+#define TRACKING_NAME_DATA_INIT { 0 }\n \n static int check_tracking_name(struct remote *remote, void *cb_data)\n {\ndiff --git a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c b/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c\nindex d389bfadcee..5927e27ae6e 100644\n--- a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c\n+++ b/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c\n@@ -138,7 +138,7 @@ struct credential {\n \tchar *password;\n };\n \n-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }\n+#define CREDENTIAL_INIT { 0 }\n \n typedef int (*credential_op_cb)(struct credential *);\n \ndiff --git a/contrib/credential/libsecret/git-credential-libsecret.c b/contrib/credential/libsecret/git-credential-libsecret.c\nindex e6598b63833..2c5d76d789f 100644\n--- a/contrib/credential/libsecret/git-credential-libsecret.c\n+++ b/contrib/credential/libsecret/git-credential-libsecret.c\n@@ -41,7 +41,7 @@ struct credential {\n \tchar *password;\n };\n \n-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }\n+#define CREDENTIAL_INIT { 0 }\n \n typedef int (*credential_op_cb)(struct credential *);\n \ndiff --git a/diff.c b/diff.c\nindex c8f530ffdbe..861282db1c3 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -775,13 +775,13 @@ struct emitted_diff_symbol {\n \tint indent_width; /* The visual width of the indentation */\n \tenum diff_symbol s;\n };\n-#define EMITTED_DIFF_SYMBOL_INIT {NULL}\n+#define EMITTED_DIFF_SYMBOL_INIT { 0 }\n \n struct emitted_diff_symbols {\n \tstruct emitted_diff_symbol *buf;\n \tint nr, alloc;\n };\n-#define EMITTED_DIFF_SYMBOLS_INIT {NULL, 0, 0}\n+#define EMITTED_DIFF_SYMBOLS_INIT { 0 }\n \n static void append_emitted_diff_symbol(struct diff_options *o,\n \t\t\t\t       struct emitted_diff_symbol *e)\ndiff --git a/lockfile.h b/lockfile.h\nindex db93e6ba73e..90af4e66b28 100644\n--- a/lockfile.h\n+++ b/lockfile.h\n@@ -121,7 +121,7 @@ struct lock_file {\n \tstruct tempfile *tempfile;\n };\n \n-#define LOCK_INIT { NULL }\n+#define LOCK_INIT { 0 }\n \n /* String appended to a filename to derive the lockfile name: */\n #define LOCK_SUFFIX \".lock\"\ndiff --git a/object-store.h b/object-store.h\nindex c5130d8baea..1e647a5be30 100644\n--- a/object-store.h\n+++ b/object-store.h\n@@ -371,7 +371,7 @@ struct object_info {\n  * Initializer for a \"struct object_info\" that wants no items. You may\n  * also memset() the memory to all-zeroes.\n  */\n-#define OBJECT_INFO_INIT {NULL}\n+#define OBJECT_INFO_INIT { 0 }\n \n /* Invoke lookup_replace_object() on the given hash */\n #define OBJECT_INFO_LOOKUP_REPLACE 1\ndiff --git a/object.h b/object.h\nindex 549f2d256bc..cb556ab7753 100644\n--- a/object.h\n+++ b/object.h\n@@ -55,7 +55,7 @@ struct object_array {\n \t} *objects;\n };\n \n-#define OBJECT_ARRAY_INIT { 0, 0, NULL }\n+#define OBJECT_ARRAY_INIT { 0 }\n \n /*\n  * object flag allocation:\ndiff --git a/oid-array.h b/oid-array.h\nindex 72bca78b7dc..f60f9af6741 100644\n--- a/oid-array.h\n+++ b/oid-array.h\n@@ -56,7 +56,7 @@ struct oid_array {\n \tint sorted;\n };\n \n-#define OID_ARRAY_INIT { NULL, 0, 0, 0 }\n+#define OID_ARRAY_INIT { 0 }\n \n /**\n  * Add an item to the set. The object ID will be placed at the end of the array\ndiff --git a/path.h b/path.h\nindex 251c78d9800..b68691a86b8 100644\n--- a/path.h\n+++ b/path.h\n@@ -181,10 +181,7 @@ struct path_cache {\n \tconst char *shallow;\n };\n \n-#define PATH_CACHE_INIT                                        \\\n-\t{                                                      \\\n-\t\tNULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \\\n-\t}\n+#define PATH_CACHE_INIT { 0 }\n \n const char *git_path_squash_msg(struct repository *r);\n const char *git_path_merge_msg(struct repository *r);\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 93ce2a6ef2e..eee4f9b17c5 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -633,7 +633,7 @@ static struct {\n \t */\n };\n \n-#define REF_FORMATTING_STATE_INIT  { 0, NULL }\n+#define REF_FORMATTING_STATE_INIT  { 0 }\n \n struct ref_formatting_stack {\n \tstruct ref_formatting_stack *prev;\ndiff --git a/remote.c b/remote.c\nindex 31e141b01fa..f958543d707 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2403,7 +2403,7 @@ struct reflog_commit_array {\n \tsize_t nr, alloc;\n };\n \n-#define REFLOG_COMMIT_ARRAY_INIT { NULL, 0, 0 }\n+#define REFLOG_COMMIT_ARRAY_INIT { 0 }\n \n /* Append a commit to the array. */\n static void append_commit(struct reflog_commit_array *arr,\ndiff --git a/revision.c b/revision.c\nindex 0dabb5a0bcf..73e5004d60b 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -249,7 +249,7 @@ struct commit_stack {\n \tstruct commit **items;\n \tsize_t nr, alloc;\n };\n-#define COMMIT_STACK_INIT { NULL, 0, 0 }\n+#define COMMIT_STACK_INIT { 0 }\n \n static void commit_stack_push(struct commit_stack *stack, struct commit *commit)\n {\n-- \n2.33.0.1316.gb2e9b3ba3ae\n\n"},{"id":"437137","messageId":"patch-v2-3.5-590220bbdcc-20210927T124407Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-v2-0.5-00000000000-20210927T124407Z-avarab@gmail.com","subject":"[PATCH v2 3/5] *.h _INIT macros: don't specify fields equal to 0","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T12:54:26Z","receivedAt":"2021-09-27T12:54:52Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the initialization of \"struct strbuf\" changed in\ncbc0f81d96f (strbuf: use designated initializers in STRBUF_INIT,\n2017-07-10) to omit specifying \"alloc\" and \"len\", as we do with other\n\"alloc\" and \"len\" (or \"nr\") in similar structs.\n\nLet's likewise omit the explicit initialization of all fields in the\n\"struct ipc_client_connect_option\" struct added in\n59c7b88198a (simple-ipc: add win32 implementation, 2021-03-15).\n\nDo the same for a few other initializers, e.g. STRVEC_INIT and\nCACHE_DEF_INIT.\n\nFinally, start incrementally changing the same pattern in\n\"t/helper/test-run-command.c\". This change was part of an earlier\non-list version[1] of c90be786da9 (test-tool run-command: fix\nflip-flop init pattern, 2021-09-11).\n\n1. https://lore.kernel.org/git/patch-1.1-0aa4523ab6e-20210909T130849Z-avarab@gmail.com/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n cache.h                     | 2 +-\n simple-ipc.h                | 6 +-----\n strbuf.h                    | 2 +-\n strvec.h                    | 2 +-\n submodule.h                 | 2 +-\n t/helper/test-run-command.c | 2 +-\n trace.h                     | 2 +-\n 7 files changed, 7 insertions(+), 11 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex f6295f3b048..25c6b0b1200 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1668,7 +1668,7 @@ struct cache_def {\n \tint track_flags;\n \tint prefix_len_stat_func;\n };\n-#define CACHE_DEF_INIT { STRBUF_INIT, 0, 0, 0 }\n+#define CACHE_DEF_INIT { STRBUF_INIT }\n static inline void cache_def_clear(struct cache_def *cache)\n {\n \tstrbuf_release(&cache->path);\ndiff --git a/simple-ipc.h b/simple-ipc.h\nindex 2c48a5ee004..08b2908d5f8 100644\n--- a/simple-ipc.h\n+++ b/simple-ipc.h\n@@ -65,11 +65,7 @@ struct ipc_client_connect_options {\n \tunsigned int uds_disallow_chdir:1;\n };\n \n-#define IPC_CLIENT_CONNECT_OPTIONS_INIT { \\\n-\t.wait_if_busy = 0, \\\n-\t.wait_if_not_found = 0, \\\n-\t.uds_disallow_chdir = 0, \\\n-}\n+#define IPC_CLIENT_CONNECT_OPTIONS_INIT { 0 }\n \n /*\n  * Determine if a server is listening on this named pipe or socket using\ndiff --git a/strbuf.h b/strbuf.h\nindex 5b1113abf8f..3b36bbc49f0 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -70,7 +70,7 @@ struct strbuf {\n };\n \n extern char strbuf_slopbuf[];\n-#define STRBUF_INIT  { .alloc = 0, .len = 0, .buf = strbuf_slopbuf }\n+#define STRBUF_INIT  { .buf = strbuf_slopbuf }\n \n /*\n  * Predeclare this here, since cache.h includes this file before it defines the\ndiff --git a/strvec.h b/strvec.h\nindex 6b3cbd67589..a10aad5f645 100644\n--- a/strvec.h\n+++ b/strvec.h\n@@ -33,7 +33,7 @@ struct strvec {\n \tsize_t alloc;\n };\n \n-#define STRVEC_INIT { empty_strvec, 0, 0 }\n+#define STRVEC_INIT { empty_strvec }\n \n /**\n  * Initialize an array. This is no different than assigning from\ndiff --git a/submodule.h b/submodule.h\nindex 4578e501b86..35d18c7868a 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -37,7 +37,7 @@ struct submodule_update_strategy {\n \tenum submodule_update_type type;\n \tconst char *command;\n };\n-#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}\n+#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED}\n \n int is_gitmodules_unmerged(struct index_state *istate);\n int is_writing_gitmodules_ok(void);\ndiff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c\nindex 14c57365e76..50bb98b7e04 100644\n--- a/t/helper/test-run-command.c\n+++ b/t/helper/test-run-command.c\n@@ -61,7 +61,7 @@ struct testsuite {\n \tint quiet, immediate, verbose, verbose_log, trace, write_junit_xml;\n };\n #define TESTSUITE_INIT \\\n-\t{ STRING_LIST_INIT_DUP, STRING_LIST_INIT_DUP, 0, 0, 0, 0, 0, 0, 0 }\n+\t{ STRING_LIST_INIT_DUP, STRING_LIST_INIT_DUP }\n \n static int next_test(struct child_process *cp, struct strbuf *err, void *cb,\n \t\t     void **task_cb)\ndiff --git a/trace.h b/trace.h\nindex 0dbbad0e41c..74f62919c57 100644\n--- a/trace.h\n+++ b/trace.h\n@@ -89,7 +89,7 @@ struct trace_key {\n \n extern struct trace_key trace_default_key;\n \n-#define TRACE_KEY_INIT(name) { \"GIT_TRACE_\" #name, 0, 0, 0 }\n+#define TRACE_KEY_INIT(name) { \"GIT_TRACE_\" #name }\n extern struct trace_key trace_perf_key;\n extern struct trace_key trace_setup_key;\n \n-- \n2.33.0.1316.gb2e9b3ba3ae\n\n"},{"id":"437138","messageId":"patch-v2-4.5-dd4ec1a0219-20210927T124407Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-v2-0.5-00000000000-20210927T124407Z-avarab@gmail.com","subject":"[PATCH v2 4/5] *.h: move some *_INIT to designated initializers","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T12:54:27Z","receivedAt":"2021-09-27T12:54:53Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Move various *_INIT macros to use designated initializers. This helps\nreadability. I've only picked those leftover macros that were not\ntouched by another in-flight series of mine which changed others, but\nalso how initialization was done.\n\nIn the case of SUBMODULE_ALTERNATE_SETUP_INIT I've left an explicit\ninitialization of \"error_mode\", even though\nSUBMODULE_ALTERNATE_ERROR_IGNORE itself is defined as \"0\". Let's not\npeek under the hood and assume that enum fields we know the value of\nwill stay at \"0\".\n\nThe change to \"TESTSUITE_INIT\" in \"t/helper/test-run-command.c\" was\npart of an earlier on-list version[1] of c90be786da9 (test-tool\nrun-command: fix flip-flop init pattern, 2021-09-11).\n\n1. https://lore.kernel.org/git/patch-1.1-0aa4523ab6e-20210909T130849Z-avarab@gmail.com/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n add-interactive.c           | 8 ++++++--\n builtin/submodule--helper.c | 5 +++--\n cache.h                     | 4 +++-\n entry.h                     | 2 +-\n list.h                      | 5 ++++-\n sequencer.h                 | 4 +++-\n shallow.h                   | 4 +++-\n strvec.h                    | 4 +++-\n submodule.c                 | 8 +++++---\n submodule.h                 | 4 +++-\n t/helper/test-run-command.c | 6 ++++--\n trace.h                     | 2 +-\n transport.h                 | 4 +++-\n 13 files changed, 42 insertions(+), 18 deletions(-)\n\ndiff --git a/add-interactive.c b/add-interactive.c\nindex 36ebdbdf7e2..6498ae196f1 100644\n--- a/add-interactive.c\n+++ b/add-interactive.c\n@@ -102,8 +102,12 @@ struct prefix_item_list {\n \tint *selected; /* for multi-selections */\n \tsize_t min_length, max_length;\n };\n-#define PREFIX_ITEM_LIST_INIT \\\n-\t{ STRING_LIST_INIT_DUP, STRING_LIST_INIT_NODUP, NULL, 1, 4 }\n+#define PREFIX_ITEM_LIST_INIT { \\\n+\t.items = STRING_LIST_INIT_DUP, \\\n+\t.sorted = STRING_LIST_INIT_NODUP, \\\n+\t.min_length = 1, \\\n+\t.max_length = 4, \\\n+}\n \n static void prefix_item_list_clear(struct prefix_item_list *list)\n {\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex deca75c83ee..57f09925157 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1647,8 +1647,9 @@ struct submodule_alternate_setup {\n \t} error_mode;\n \tstruct string_list *reference;\n };\n-#define SUBMODULE_ALTERNATE_SETUP_INIT { NULL, \\\n-\tSUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }\n+#define SUBMODULE_ALTERNATE_SETUP_INIT { \\\n+\t.error_mode = SUBMODULE_ALTERNATE_ERROR_IGNORE, \\\n+}\n \n static const char alternate_error_advice[] = N_(\n \"An alternate computed from a superproject's alternate is invalid.\\n\"\ndiff --git a/cache.h b/cache.h\nindex 25c6b0b1200..794237515b9 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1668,7 +1668,9 @@ struct cache_def {\n \tint track_flags;\n \tint prefix_len_stat_func;\n };\n-#define CACHE_DEF_INIT { STRBUF_INIT }\n+#define CACHE_DEF_INIT { \\\n+\t.path = STRBUF_INIT, \\\n+}\n static inline void cache_def_clear(struct cache_def *cache)\n {\n \tstrbuf_release(&cache->path);\ndiff --git a/entry.h b/entry.h\nindex 7c889e58fd7..2254c62727f 100644\n--- a/entry.h\n+++ b/entry.h\n@@ -16,7 +16,7 @@ struct checkout {\n \t\t clone:1,\n \t\t refresh_cache:1;\n };\n-#define CHECKOUT_INIT { NULL, \"\" }\n+#define CHECKOUT_INIT { .base_dir = \"\" }\n \n #define TEMPORARY_FILENAME_LENGTH 25\n /*\ndiff --git a/list.h b/list.h\nindex eb601192f4c..362a4cd7f5f 100644\n--- a/list.h\n+++ b/list.h\n@@ -46,7 +46,10 @@ struct list_head {\n #define INIT_LIST_HEAD(ptr) \\\n \t(ptr)->next = (ptr)->prev = (ptr)\n \n-#define LIST_HEAD_INIT(name) { &(name), &(name) }\n+#define LIST_HEAD_INIT(name) { \\\n+\t.next = &(name), \\\n+\t.prev = &(name), \\\n+}\n \n /* Add new element at the head of the list. */\n static inline void list_add(struct list_head *newp, struct list_head *head)\ndiff --git a/sequencer.h b/sequencer.h\nindex 2088344cb37..259d4eb4a8a 100644\n--- a/sequencer.h\n+++ b/sequencer.h\n@@ -119,7 +119,9 @@ struct todo_list {\n \tstruct stat_data stat;\n };\n \n-#define TODO_LIST_INIT { STRBUF_INIT }\n+#define TODO_LIST_INIT { \\\n+\t.buf = STRBUF_INIT, \\\n+}\n \n int todo_list_parse_insn_buffer(struct repository *r, char *buf,\n \t\t\t\tstruct todo_list *todo_list);\ndiff --git a/shallow.h b/shallow.h\nindex 5b4a96dcd69..aba6ff58294 100644\n--- a/shallow.h\n+++ b/shallow.h\n@@ -23,7 +23,9 @@ int is_repository_shallow(struct repository *r);\n struct shallow_lock {\n \tstruct lock_file lock;\n };\n-#define SHALLOW_LOCK_INIT { LOCK_INIT }\n+#define SHALLOW_LOCK_INIT { \\\n+\t.lock = LOCK_INIT, \\\n+}\n \n /* commit $GIT_DIR/shallow and reset stat-validity checks */\n int commit_shallow_file(struct repository *r, struct shallow_lock *lk);\ndiff --git a/strvec.h b/strvec.h\nindex a10aad5f645..9f55c8766ba 100644\n--- a/strvec.h\n+++ b/strvec.h\n@@ -33,7 +33,9 @@ struct strvec {\n \tsize_t alloc;\n };\n \n-#define STRVEC_INIT { empty_strvec }\n+#define STRVEC_INIT { \\\n+\t.v = empty_strvec, \\\n+}\n \n /**\n  * Initialize an array. This is no different than assigning from\ndiff --git a/submodule.c b/submodule.c\nindex 78aed03d928..03cf36707ae 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1321,9 +1321,11 @@ struct submodule_parallel_fetch {\n \n \tstruct strbuf submodules_with_errors;\n };\n-#define SPF_INIT {0, STRVEC_INIT, NULL, NULL, 0, 0, 0, 0, \\\n-\t\t  STRING_LIST_INIT_DUP, \\\n-\t\t  NULL, 0, 0, STRBUF_INIT}\n+#define SPF_INIT { \\\n+\t.args = STRVEC_INIT, \\\n+\t.changed_submodule_names = STRING_LIST_INIT_DUP, \\\n+\t.submodules_with_errors = STRBUF_INIT, \\\n+}\n \n static int get_fetch_recurse_config(const struct submodule *submodule,\n \t\t\t\t    struct submodule_parallel_fetch *spf)\ndiff --git a/submodule.h b/submodule.h\nindex 35d18c7868a..6bd2c99fd99 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -37,7 +37,9 @@ struct submodule_update_strategy {\n \tenum submodule_update_type type;\n \tconst char *command;\n };\n-#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED}\n+#define SUBMODULE_UPDATE_STRATEGY_INIT { \\\n+\t.type = SM_UPDATE_UNSPECIFIED, \\\n+}\n \n int is_gitmodules_unmerged(struct index_state *istate);\n int is_writing_gitmodules_ok(void);\ndiff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c\nindex 50bb98b7e04..3c4fb862234 100644\n--- a/t/helper/test-run-command.c\n+++ b/t/helper/test-run-command.c\n@@ -60,8 +60,10 @@ struct testsuite {\n \tint next;\n \tint quiet, immediate, verbose, verbose_log, trace, write_junit_xml;\n };\n-#define TESTSUITE_INIT \\\n-\t{ STRING_LIST_INIT_DUP, STRING_LIST_INIT_DUP }\n+#define TESTSUITE_INIT { \\\n+\t.tests = STRING_LIST_INIT_DUP, \\\n+\t.failed = STRING_LIST_INIT_DUP, \\\n+}\n \n static int next_test(struct child_process *cp, struct strbuf *err, void *cb,\n \t\t     void **task_cb)\ndiff --git a/trace.h b/trace.h\nindex 74f62919c57..e25984051aa 100644\n--- a/trace.h\n+++ b/trace.h\n@@ -89,7 +89,7 @@ struct trace_key {\n \n extern struct trace_key trace_default_key;\n \n-#define TRACE_KEY_INIT(name) { \"GIT_TRACE_\" #name }\n+#define TRACE_KEY_INIT(name) { .key = \"GIT_TRACE_\" #name }\n extern struct trace_key trace_perf_key;\n extern struct trace_key trace_setup_key;\n \ndiff --git a/transport.h b/transport.h\nindex 1cbab113730..8bb4c8bbc8c 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -262,7 +262,9 @@ struct transport_ls_refs_options {\n \t */\n \tchar *unborn_head_target;\n };\n-#define TRANSPORT_LS_REFS_OPTIONS_INIT { STRVEC_INIT }\n+#define TRANSPORT_LS_REFS_OPTIONS_INIT { \\\n+\t.ref_prefixes = STRVEC_INIT, \\\n+}\n \n /*\n  * Retrieve refs from a remote.\n-- \n2.33.0.1316.gb2e9b3ba3ae\n\n"},{"id":"437139","messageId":"patch-v2-5.5-76b47e7c80a-20210927T124407Z-avarab@gmail.com","threadId":"56590","inReplyTo":"cover-v2-0.5-00000000000-20210927T124407Z-avarab@gmail.com","subject":"[PATCH v2 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-27T12:54:28Z","receivedAt":"2021-09-27T12:54:56Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Use the same pattern for cb_init() as the one established in the\nrecent refactoring of other such patterns in\n5726a6b4012 (*.c *_init(): define in terms of corresponding *_INIT\nmacro, 2021-07-01).\n\nIt has been pointed out[1] that we could perhaps use this C99\nreplacement of using a compound literal for all of these:\n\n    *t = (struct cb_tree){ 0 };\n\nBut let's just stick to the existing pattern established in\n5726a6b4012 for now, we can leave another weather balloon for some\nother time.\n\n1. http://lore.kernel.org/git/ef724a3a-a4b8-65d3-c928-13a7d78f189a@gmail.com\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n cbtree.h | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/cbtree.h b/cbtree.h\nindex a04a312c3f5..dedbb8e2a45 100644\n--- a/cbtree.h\n+++ b/cbtree.h\n@@ -37,11 +37,12 @@ enum cb_next {\n \tCB_BREAK = 1\n };\n \n-#define CBTREE_INIT { .root = NULL }\n+#define CBTREE_INIT { 0 }\n \n static inline void cb_init(struct cb_tree *t)\n {\n-\tt->root = NULL;\n+\tstruct cb_tree blank = CBTREE_INIT;\n+\tmemcpy(t, &blank, sizeof(*t));\n }\n \n struct cb_node *cb_lookup(struct cb_tree *, const uint8_t *k, size_t klen);\n-- \n2.33.0.1316.gb2e9b3ba3ae\n\n"},{"id":"437185","messageId":"xmqqfstppxzm.fsf@gitster.g","threadId":"56590","inReplyTo":"68c9c6da-d215-a39b-64f5-8b8930ce5a09@kdbg.org","subject":"Re: [PATCH 2/5] *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-09-27T20:25:17Z","receivedAt":"2021-09-27T20:25:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j6t@kdbg.org> writes:\n\n> Am 27.09.21 um 02:39 schrieb Ævar Arnfjörð Bjarmason:\n>> diff --git a/entry.h b/entry.h\n>> index 7c889e58fd7..04bc8bb59f0 100644\n>> --- a/entry.h\n>> +++ b/entry.h\n>> @@ -16,7 +16,7 @@ struct checkout {\n>>  \t\t clone:1,\n>>  \t\t refresh_cache:1;\n>>  };\n>> -#define CHECKOUT_INIT { NULL, \"\" }\n>> +#define CHECKOUT_INIT { 0 }\n>\n> This is not an equivalence transformation and does not belong in this patch.\n\nThanks for carefully reading.  This is the kind of mistake I hate\nabout these mind-numbing \"let's do the clean-up\" series.\n\n"},{"id":"437199","messageId":"xmqqk0j1ofa6.fsf@gitster.g","threadId":"56590","inReplyTo":"patch-v2-3.5-590220bbdcc-20210927T124407Z-avarab@gmail.com","subject":"Re: [PATCH v2 3/5] *.h _INIT macros: don't specify fields equal to 0","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-09-27T21:54:41Z","receivedAt":"2021-09-27T21:54:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n\n> -#define IPC_CLIENT_CONNECT_OPTIONS_INIT { \\\n> -\t.wait_if_busy = 0, \\\n> -\t.wait_if_not_found = 0, \\\n> -\t.uds_disallow_chdir = 0, \\\n> -}\n> +#define IPC_CLIENT_CONNECT_OPTIONS_INIT { 0 }\n\nThe original explicitly initializes the members using designated\ninit, and the loss somewhat feels like a temporary regression, but\nas long as the new norm is\n\n - If there is *no* member that is initialized to non-zero value, we\n   use { 0 }, and\n\n - Otherwise, we only explicitly initialize members to non-zero\n   value using designated initializers\n\nthis conversion is perfectly fine.\n"},{"id":"437204","messageId":"YVJSwuqjolz28+mG@coredump.intra.peff.net","threadId":"56590","inReplyTo":"patch-v2-2.5-afcd2729c95-20210927T124407Z-avarab@gmail.com","subject":"Re: [PATCH v2 2/5] *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-09-27T23:24:50Z","receivedAt":"2021-09-27T23:24:52Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Sep 27, 2021 at 02:54:25PM +0200, Ævar Arnfjörð Bjarmason wrote:\n\n> In C it isn't required to specify that all members of a struct are\n> zero'd out to 0, NULL or '\\0', just providing a \"{ 0 }\" will\n> accomplish that.\n> \n> Let's also change code that provided N zero'd fields to just\n> provide one, and change e.g. \"{ NULL }\" to \"{ 0 }\" for\n> consistency. I.e. even if the first member is a pointer let's use \"0\"\n> instead of \"NULL\". The point of using \"0\" consistently is to pick one,\n> and to not have the reader wonder why we're not using the same pattern\n> everywhere.\n\nI seem to recall we've had some linter complaints about using \"0\" to\ninitialize a pointer, but I think these days it's OK, per:\n\n - 1c96642326 (sparse: allow '{ 0 }' to be used without warnings,\n   2020-05-22)\n\nand\n\n - https://lore.kernel.org/git/18bd6127-be72-b7b7-8e2a-17bbe7214a2e@ramsayjones.plus.com/\n\nI think this is a good step, as the long lists are unwieldy and difficult to\nkeep up to date without actually providing any readability or functional\nvalue.\n\n-Peff\n"},{"id":"437205","messageId":"YVJU89iekC0zZSkF@coredump.intra.peff.net","threadId":"56590","inReplyTo":"patch-v2-1.5-7a7a0141515-20210927T124407Z-avarab@gmail.com","subject":"Re: [PATCH v2 1/5] submodule-config.h: remove unused SUBMODULE_INIT macro","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-09-27T23:34:11Z","receivedAt":"2021-09-27T23:34:13Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Sep 27, 2021 at 02:54:24PM +0200, Ævar Arnfjörð Bjarmason wrote:\n\n> This macro was added and used in c68f8375760 (implement fetching of\n> moved submodules, 2017-10-16) but its last user went away in\n> be76c212823 (fetch: ensure submodule objects fetched, 2018-12-06).\n> \n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>  submodule-config.h | 4 ----\n>  1 file changed, 4 deletions(-)\n> \n> diff --git a/submodule-config.h b/submodule-config.h\n> index c11e22cf509..65875b94ea5 100644\n> --- a/submodule-config.h\n> +++ b/submodule-config.h\n> @@ -45,10 +45,6 @@ struct submodule {\n>  \tstruct object_id gitmodules_oid;\n>  \tint recommend_shallow;\n>  };\n> -\n> -#define SUBMODULE_INIT { NULL, NULL, NULL, RECURSE_SUBMODULES_NONE, \\\n> -\tNULL, NULL, SUBMODULE_UPDATE_STRATEGY_INIT, { { 0 } }, -1 };\n\nI was a bit surprised by this one, just because we generally prefer the\nbuiltin initializers to init functions. And even if we are only using\nthe latter, I like the move to implementing it in terms of the former.\n\nBut this struct is extra funny, as now it will have neither. It comes\nonly from submodule_from_name() or submodule_from_path(), which in turn\nare building up from config and the initialization in\nlookup_or_create_by_name(). And keeping those two in sync is potentially\nerror-prone.\n\nSo this whole \"make a submodule struct on the stack\" thing is pretty odd\nin the first place, and I'm happy to see this initializer going away.\n\n-Peff\n"},{"id":"437208","messageId":"YVJZrOYucywgoi+v@coredump.intra.peff.net","threadId":"56590","inReplyTo":"87czou1dmp.fsf@evledraar.gmail.com","subject":"Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-09-27T23:54:20Z","receivedAt":"2021-09-27T23:54:24Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Sep 27, 2021 at 01:02:35PM +0200, Ævar Arnfjörð Bjarmason wrote:\n\n> >>  static inline void cb_init(struct cb_tree *t)\n> >>  {\n> >> -\tt->root = NULL;\n> >> +\tstruct cb_tree blank = CBTREE_INIT;\n> >\n> > This could be\n> >\n> > \tstatic const struct cb_tree blank = CBTREE_INIT;\n> \n> *nod*...\n> [...]\n> ...but to both this & the above my reply in the side-thread at\n> https://lore.kernel.org/git/87h7e61duk.fsf@evledraar.gmail.com/\n> applies. I.e. this is just following a pattern I got from Jeff King &\n> used in bd4232fac33 (Merge branch 'ab/struct-init', 2021-07-16).\n\nI'm not sure how a compiler would react to the \"static const\" thing. I\ntested the compiler output for the \"auto\" struct case you've written\nhere, and at least gcc and clang are smart enough to just initialize the\npointed-to struct directly, with no extra copy.\n\nFor a \"static const\" I'm not sure if they'd end up with the same code,\nor if they'd allocate a struct in the data segment and just memcpy()\ninto place. A non-const static would perhaps push it in the direction of the\ndata/memcpy thing, though the compiler should be well aware that the\nstruct is never changed nor aliased, and thus we're always writing the\nINIT values.\n\nI suspect the performance is not that different either way (the big\nthing to avoid is initializing an auto struct on the fly and then\ncopying from it, but this is a pretty easy optimization for compilers to\nget right).\n\n> >> +\tmemcpy(t, &blank, sizeof(*t));\n> >\n> > Is\n> > \t*t = blank;\n> >\n> > not a thing in C?\n\nIt would be fine to use struct assignment here, and should be equivalent\nin most compilers. They know about memcpy() and will inline it as\nappropriate.\n\nI think some C programmers tend to prefer memcpy() just because that's\nhow they think. It also wasn't legal in old K&R compilers, but as far as\nI know was in C89.\n\nYou have to take care with assignment of flex-structs, of course, but\nyou also have to do so with memcpy(), too. :)\n\n> FWIW with \"const\" in general I don't use it as much as I'd personally\n> prefer, see e.g. [1] for one recent discussion, but maybe there wouldn't\n> be any push-back in this case...\n\nThis isn't a parameter, so I don't think that discussion applies. _If_\nyou are going to make it a static, I think a const makes sense here (but\nprobably does nothing beyond signaling your intention, because the\ncompiler can see that it is never modified), but I wouldn't bother with\neither.\n\n-Peff\n"},{"id":"437210","messageId":"xmqqpmstmv0s.fsf@gitster.g","threadId":"56590","inReplyTo":"patch-v2-4.5-dd4ec1a0219-20210927T124407Z-avarab@gmail.com","subject":"Re: [PATCH v2 4/5] *.h: move some *_INIT to designated initializers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-09-27T23:57:39Z","receivedAt":"2021-09-27T23:57:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n\n> -#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED}\n> +#define SUBMODULE_UPDATE_STRATEGY_INIT { \\\n> +\t.type = SM_UPDATE_UNSPECIFIED, \\\n> +}\n\nMuch better ;-)\n"},{"id":"437216","messageId":"87h7e5zgjw.fsf@evledraar.gmail.com","threadId":"56590","inReplyTo":"YVJSwuqjolz28+mG@coredump.intra.peff.net","subject":"Re: [PATCH v2 2/5] *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-28T00:25:16Z","receivedAt":"2021-09-28T00:31:51Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Sep 27 2021, Jeff King wrote:\n\n> On Mon, Sep 27, 2021 at 02:54:25PM +0200, Ævar Arnfjörð Bjarmason wrote:\n>\n>> In C it isn't required to specify that all members of a struct are\n>> zero'd out to 0, NULL or '\\0', just providing a \"{ 0 }\" will\n>> accomplish that.\n>> \n>> Let's also change code that provided N zero'd fields to just\n>> provide one, and change e.g. \"{ NULL }\" to \"{ 0 }\" for\n>> consistency. I.e. even if the first member is a pointer let's use \"0\"\n>> instead of \"NULL\". The point of using \"0\" consistently is to pick one,\n>> and to not have the reader wonder why we're not using the same pattern\n>> everywhere.\n>\n> I seem to recall we've had some linter complaints about using \"0\" to\n> initialize a pointer, but I think these days it's OK, per:\n>\n>  - 1c96642326 (sparse: allow '{ 0 }' to be used without warnings,\n>    2020-05-22)\n>\n> and\n>\n>  - https://lore.kernel.org/git/18bd6127-be72-b7b7-8e2a-17bbe7214a2e@ramsayjones.plus.com/\n>\n> I think this is a good step, as the long lists are unwieldy and difficult to\n> keep up to date without actually providing any readability or functional\n> value.\n\n[+CC Luc Van Oostenryck <luc.vanoostenryck@gmail.com>]\n\nIt seems like we should just revert 1c96642326, looking at the history\nof sparse.git there's:\n\n - 537e3e2d (univ-init: conditionally accept { 0 } without warnings, 2020-05-18)\n\nFollowed by git.git's 1c96642326 a few days later, but then in sparse.git:\n\n - 41f651b4 (univ-init: set default to -Wno-universal-initializer, 2020-05-29)\n\nI.e. a few days after the workaround in git.git the upstream repo\nchanged the default. The 537e3e2d isn't in any release of sparse that\n41f651b4 isn't in, they both first appeared in v0.6.2.\n\nSo us having -Wno-universal-initializer only seems useful if you're\nusing some old commit in sparse.git.\n\nHaving written the above I found\nhttps://lore.kernel.org/git/20200530162432.a7fitzjc53hsn2ej@ltop.local/;\ni.e. sparse's maintainer pretty much saying the same thing.\n"},{"id":"437219","messageId":"YVJl2OPT9RRVEpQa@coredump.intra.peff.net","threadId":"56590","inReplyTo":"87h7e5zgjw.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 2/5] *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-09-28T00:46:16Z","receivedAt":"2021-09-28T00:46:18Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Sep 28, 2021 at 02:25:16AM +0200, Ævar Arnfjörð Bjarmason wrote:\n\n> It seems like we should just revert 1c96642326, looking at the history\n> of sparse.git there's:\n> \n>  - 537e3e2d (univ-init: conditionally accept { 0 } without warnings, 2020-05-18)\n> \n> Followed by git.git's 1c96642326 a few days later, but then in sparse.git:\n> \n>  - 41f651b4 (univ-init: set default to -Wno-universal-initializer, 2020-05-29)\n> \n> I.e. a few days after the workaround in git.git the upstream repo\n> changed the default. The 537e3e2d isn't in any release of sparse that\n> 41f651b4 isn't in, they both first appeared in v0.6.2.\n> \n> So us having -Wno-universal-initializer only seems useful if you're\n> using some old commit in sparse.git.\n> \n> Having written the above I found\n> https://lore.kernel.org/git/20200530162432.a7fitzjc53hsn2ej@ltop.local/;\n> i.e. sparse's maintainer pretty much saying the same thing.\n\nYeah, that seems reasonable. If somebody has an old version of sparse\nthey'll presumably see actual \"don't use 0 to initialize a pointer\"\nwarnings, as opposed to \"hey, I don't understand -Wno-universal-initializer\".\nBut either way, they should upgrade.\n\n-Peff\n"},{"id":"437223","messageId":"4516b271-c9ed-2413-67c9-a783119fc0dd@ramsayjones.plus.com","threadId":"56590","inReplyTo":"87h7e5zgjw.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 2/5] *.[ch] *_INIT macros: use { 0 } for a \"zero out\" idiom","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2021-09-28T01:44:39Z","receivedAt":"2021-09-28T01:44:44Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 28/09/2021 01:25, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Mon, Sep 27 2021, Jeff King wrote:\n> \n>> On Mon, Sep 27, 2021 at 02:54:25PM +0200, Ævar Arnfjörð Bjarmason wrote:\n>>\n>>> In C it isn't required to specify that all members of a struct are\n>>> zero'd out to 0, NULL or '\\0', just providing a \"{ 0 }\" will\n>>> accomplish that.\n>>>\n>>> Let's also change code that provided N zero'd fields to just\n>>> provide one, and change e.g. \"{ NULL }\" to \"{ 0 }\" for\n>>> consistency. I.e. even if the first member is a pointer let's use \"0\"\n>>> instead of \"NULL\". The point of using \"0\" consistently is to pick one,\n>>> and to not have the reader wonder why we're not using the same pattern\n>>> everywhere.\n>>\n>> I seem to recall we've had some linter complaints about using \"0\" to\n>> initialize a pointer, but I think these days it's OK, per:\n>>\n>>  - 1c96642326 (sparse: allow '{ 0 }' to be used without warnings,\n>>    2020-05-22)\n>>\n>> and\n>>\n>>  - https://lore.kernel.org/git/18bd6127-be72-b7b7-8e2a-17bbe7214a2e@ramsayjones.plus.com/\n>>\n>> I think this is a good step, as the long lists are unwieldy and difficult to\n>> keep up to date without actually providing any readability or functional\n>> value.\n> \n> [+CC Luc Van Oostenryck <luc.vanoostenryck@gmail.com>]\n> \n> It seems like we should just revert 1c96642326, looking at the history\n> of sparse.git there's:\n> \n>  - 537e3e2d (univ-init: conditionally accept { 0 } without warnings, 2020-05-18)\n> \n> Followed by git.git's 1c96642326 a few days later, but then in sparse.git:\n> \n>  - 41f651b4 (univ-init: set default to -Wno-universal-initializer, 2020-05-29)\n> \n> I.e. a few days after the workaround in git.git the upstream repo\n> changed the default. The 537e3e2d isn't in any release of sparse that\n> 41f651b4 isn't in, they both first appeared in v0.6.2.\n> \n> So us having -Wno-universal-initializer only seems useful if you're\n> using some old commit in sparse.git.\n> \n> Having written the above I found\n> https://lore.kernel.org/git/20200530162432.a7fitzjc53hsn2ej@ltop.local/;\n> i.e. sparse's maintainer pretty much saying the same thing.\n\nYes, this has been on my TODO list pretty much since commit 41f651b4, but\nit wasn't a priority. ;-)\n\nATB,\nRamsay Jones\n\n"},{"id":"437252","messageId":"5bda4e3e-0951-c28e-320d-23cdadba5bc6@kdbg.org","threadId":"56590","inReplyTo":"YVJZrOYucywgoi+v@coredump.intra.peff.net","subject":"Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2021-09-28T06:15:12Z","receivedAt":"2021-09-28T06:15:21Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 28.09.21 um 01:54 schrieb Jeff King:\n> On Mon, Sep 27, 2021 at 01:02:35PM +0200, Ævar Arnfjörð Bjarmason wrote:\n> \n>>>>  static inline void cb_init(struct cb_tree *t)\n>>>>  {\n>>>> -\tt->root = NULL;\n>>>> +\tstruct cb_tree blank = CBTREE_INIT;\n>>>\n>>> This could be\n>>>\n>>> \tstatic const struct cb_tree blank = CBTREE_INIT;\n>>\n>> *nod*...\n>> [...]\n>> ...but to both this & the above my reply in the side-thread at\n>> https://lore.kernel.org/git/87h7e61duk.fsf@evledraar.gmail.com/\n>> applies. I.e. this is just following a pattern I got from Jeff King &\n>> used in bd4232fac33 (Merge branch 'ab/struct-init', 2021-07-16).\n> \n> I'm not sure how a compiler would react to the \"static const\" thing. I\n> tested the compiler output for the \"auto\" struct case you've written\n> here, and at least gcc and clang are smart enough to just initialize the\n> pointed-to struct directly, with no extra copy.\n\nGood! Then a deviation from established patterns is not warranted.\n\n-- Hannes\n"},{"id":"437343","messageId":"xmqqpmssk0v1.fsf@gitster.g","threadId":"56590","inReplyTo":"YVJZrOYucywgoi+v@coredump.intra.peff.net","subject":"Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-09-28T18:32:02Z","receivedAt":"2021-09-28T18:33:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n>> >> +\tmemcpy(t, &blank, sizeof(*t));\n>> >\n>> > Is\n>> > \t*t = blank;\n>> >\n>> > not a thing in C?\n>\n> It would be fine to use struct assignment here, and should be equivalent\n> in most compilers. They know about memcpy() and will inline it as\n> appropriate.\n\nFWIW, I'd be fine with structure assignment, but we already have too\nmany such memcpy(<ptr>, &<struct>, sizeof(struct)), adding one more\nis not giving us too much incremental burden for later clean-up.\n\n> I think some C programmers tend to prefer memcpy() just because that's\n> how they think. It also wasn't legal in old K&R compilers, but as far as\n> I know was in C89.\n\nI think so, too.\n"},{"id":"437346","messageId":"877df0wknp.fsf@evledraar.gmail.com","threadId":"56590","inReplyTo":"xmqqpmssk0v1.fsf@gitster.g","subject":"Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-09-28T19:42:45Z","receivedAt":"2021-09-28T19:43:43Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Tue, Sep 28 2021, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n>\n>>> >> +\tmemcpy(t, &blank, sizeof(*t));\n>>> >\n>>> > Is\n>>> > \t*t = blank;\n>>> >\n>>> > not a thing in C?\n>>\n>> It would be fine to use struct assignment here, and should be equivalent\n>> in most compilers. They know about memcpy() and will inline it as\n>> appropriate.\n>\n> FWIW, I'd be fine with structure assignment, but we already have too\n> many such memcpy(<ptr>, &<struct>, sizeof(struct)), adding one more\n> is not giving us too much incremental burden for later clean-up.\n>\n>> I think some C programmers tend to prefer memcpy() just because that's\n>> how they think. It also wasn't legal in old K&R compilers, but as far as\n>> I know was in C89.\n>\n> I think so, too.\n\nGetting back to the topic of this v2 in general, my reading of the\ndiscussion since then is that nothing in it necessitated a v3 re-roll to\naddress outstanding issues. If I've got that wrong please shout...\n"},{"id":"437363","messageId":"xmqqlf3gjufm.fsf@gitster.g","threadId":"56590","inReplyTo":"877df0wknp.fsf@evledraar.gmail.com","subject":"Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-09-28T20:50:53Z","receivedAt":"2021-09-28T20:50:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n> On Tue, Sep 28 2021, Junio C Hamano wrote:\n>\n>> Jeff King <peff@peff.net> writes:\n>>\n>>>> >> +\tmemcpy(t, &blank, sizeof(*t));\n>>>> >\n>>>> > Is\n>>>> > \t*t = blank;\n>>>> >\n>>>> > not a thing in C?\n>>>\n>>> It would be fine to use struct assignment here, and should be equivalent\n>>> in most compilers. They know about memcpy() and will inline it as\n>>> appropriate.\n>>\n>> FWIW, I'd be fine with structure assignment, but we already have too\n>> many such memcpy(<ptr>, &<struct>, sizeof(struct)), adding one more\n>> is not giving us too much incremental burden for later clean-up.\n>>\n>>> I think some C programmers tend to prefer memcpy() just because that's\n>>> how they think. It also wasn't legal in old K&R compilers, but as far as\n>>> I know was in C89.\n>>\n>> I think so, too.\n>\n> Getting back to the topic of this v2 in general, my reading of the\n> discussion since then is that nothing in it necessitated a v3 re-roll to\n> address outstanding issues. If I've got that wrong please shout...\n\nI was hoping that these can hit 'next' soonish.\n"},{"id":"437512","messageId":"05770f9c-49e9-2572-d610-dcbd2b97cca3@gmail.com","threadId":"56590","inReplyTo":"87h7e61duk.fsf@evledraar.gmail.com","subject":"Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2021-09-30T10:01:04Z","receivedAt":"2021-09-30T10:01:46Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 27/09/2021 12:00, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Mon, Sep 27 2021, Phillip Wood wrote:\n> \n>> Hi Ævar\n>>\n>> On 27/09/2021 01:39, Ævar Arnfjörð Bjarmason wrote:\n>>> Use the same pattern for cb_init() as the one established in the\n>>> recent refactoring of other such patterns in\n>>> 5726a6b4012 (*.c *_init(): define in terms of corresponding *_INIT\n>>> macro, 2021-07-01).\n>>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>>> ---\n>>>    cbtree.h | 5 +++--\n>>>    1 file changed, 3 insertions(+), 2 deletions(-)\n>>> diff --git a/cbtree.h b/cbtree.h\n>>> index a04a312c3f5..dedbb8e2a45 100644\n>>> --- a/cbtree.h\n>>> +++ b/cbtree.h\n>>> @@ -37,11 +37,12 @@ enum cb_next {\n>>>    \tCB_BREAK = 1\n>>>    };\n>>>    -#define CBTREE_INIT { .root = NULL }\n>>> +#define CBTREE_INIT { 0 }\n>>>      static inline void cb_init(struct cb_tree *t)\n>>>    {\n>>> -\tt->root = NULL;\n>>> +\tstruct cb_tree blank = CBTREE_INIT;\n>>> +\tmemcpy(t, &blank, sizeof(*t));\n>>>    }\n>>\n>> Slightly off topic but would this be a good site for a compound\n>> literal test balloon?\n>>\n>> \t*t = (struct cb_tree){ 0 };\n>>\n>> Compound literals are in C99 and seem to have been supported by MSVC\n>> since 2013 [1].\n> \n> I think that's a good thing to test out, FWIW I've also tested it on the\n> IBM xlc, Oracle SunCC and HP/UX's aCC, they all seem to accept it.\n\nThanks for taking the time to test those other systems, it's good to \nknow they support compound literals\n\n> But I'd prefer just doing that in some general follow-up to bd4232fac33\n> (Merge branch 'ab/struct-init', 2021-07-16), i.e. let's just use the\n> init pattern it established here.\n\nI agree it makes sense to introduce it as a separate series. I'm not \nsure if there is a pressing need for them but it is the sort of thing \nthat is occasionally useful.\n\nBest Wishes\n\nPhillip\n\n"}]}