git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Martin Ågren" <martin.agren@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 2/5] *.[ch] *_INIT macros: use { 0 } for a "zero out" idiom
Date: Mon, 27 Sep 2021 02:39:49 +0200	[thread overview]
Message-ID: <patch-2.5-d612e7df7a5-20210927T003330Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-0.5-00000000000-20210927T003330Z-avarab@gmail.com>

In C it isn't required to specify that all members of a struct are
zero'd out to 0, NULL or '\0', just providing a "{ 0 }" will
accomplish that.

Let's also change change code that provided N zero'd fields to just
provide one, and change e.g. "{ NULL }" to "{ 0 }" for
consistency. I.e. even if the first member is a pointer let's use "0"
instead of "NULL". The point of using "0" consistently is to pick one,
and to not have the reader wonder why we're not using the same pattern
everywhere.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/submodule--helper.c                      | 16 ++++++++--------
 checkout.c                                       |  2 +-
 .../gnome-keyring/git-credential-gnome-keyring.c |  2 +-
 .../libsecret/git-credential-libsecret.c         |  2 +-
 diff.c                                           |  4 ++--
 entry.h                                          |  2 +-
 lockfile.h                                       |  2 +-
 object-store.h                                   |  2 +-
 object.h                                         |  2 +-
 oid-array.h                                      |  2 +-
 path.h                                           |  5 +----
 ref-filter.c                                     |  2 +-
 remote.c                                         |  2 +-
 revision.c                                       |  2 +-
 14 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 5336daf186d..deca75c83ee 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -307,7 +307,7 @@ struct module_list {
 	const struct cache_entry **entries;
 	int alloc, nr;
 };
-#define MODULE_LIST_INIT { NULL, 0, 0 }
+#define MODULE_LIST_INIT { 0 }
 
 static int module_list_compute(int argc, const char **argv,
 			       const char *prefix,
@@ -588,7 +588,7 @@ struct init_cb {
 	const char *prefix;
 	unsigned int flags;
 };
-#define INIT_CB_INIT { NULL, 0 }
+#define INIT_CB_INIT { 0 }
 
 static void init_submodule(const char *path, const char *prefix,
 			   unsigned int flags)
@@ -717,7 +717,7 @@ struct status_cb {
 	const char *prefix;
 	unsigned int flags;
 };
-#define STATUS_CB_INIT { NULL, 0 }
+#define STATUS_CB_INIT { 0 }
 
 static void print_status(unsigned int flags, char state, const char *path,
 			 const struct object_id *oid, const char *displaypath)
@@ -911,13 +911,13 @@ struct module_cb {
 	char status;
 	const char *sm_path;
 };
-#define MODULE_CB_INIT { 0, 0, NULL, NULL, '\0', NULL }
+#define MODULE_CB_INIT { 0 }
 
 struct module_cb_list {
 	struct module_cb **entries;
 	int alloc, nr;
 };
-#define MODULE_CB_LIST_INIT { NULL, 0, 0 }
+#define MODULE_CB_LIST_INIT { 0 }
 
 struct summary_cb {
 	int argc;
@@ -928,7 +928,7 @@ struct summary_cb {
 	unsigned int files: 1;
 	int summary_limit;
 };
-#define SUMMARY_CB_INIT { 0, NULL, NULL, 0, 0, 0, 0 }
+#define SUMMARY_CB_INIT { 0 }
 
 enum diff_cmd {
 	DIFF_INDEX,
@@ -1334,7 +1334,7 @@ struct sync_cb {
 	const char *prefix;
 	unsigned int flags;
 };
-#define SYNC_CB_INIT { NULL, 0 }
+#define SYNC_CB_INIT { 0 }
 
 static void sync_submodule(const char *path, const char *prefix,
 			   unsigned int flags)
@@ -1480,7 +1480,7 @@ struct deinit_cb {
 	const char *prefix;
 	unsigned int flags;
 };
-#define DEINIT_CB_INIT { NULL, 0 }
+#define DEINIT_CB_INIT { 0 }
 
 static void deinit_submodule(const char *path, const char *prefix,
 			     unsigned int flags)
diff --git a/checkout.c b/checkout.c
index 6586e30ca5a..2e39dae684f 100644
--- a/checkout.c
+++ b/checkout.c
@@ -14,7 +14,7 @@ struct tracking_name_data {
 	struct object_id *default_dst_oid;
 };
 
-#define TRACKING_NAME_DATA_INIT { NULL, NULL, NULL, 0, NULL, NULL, NULL }
+#define TRACKING_NAME_DATA_INIT { 0 }
 
 static int check_tracking_name(struct remote *remote, void *cb_data)
 {
diff --git a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c b/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
index d389bfadcee..5927e27ae6e 100644
--- a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
+++ b/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
@@ -138,7 +138,7 @@ struct credential {
 	char *password;
 };
 
-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
+#define CREDENTIAL_INIT { 0 }
 
 typedef int (*credential_op_cb)(struct credential *);
 
diff --git a/contrib/credential/libsecret/git-credential-libsecret.c b/contrib/credential/libsecret/git-credential-libsecret.c
index e6598b63833..2c5d76d789f 100644
--- a/contrib/credential/libsecret/git-credential-libsecret.c
+++ b/contrib/credential/libsecret/git-credential-libsecret.c
@@ -41,7 +41,7 @@ struct credential {
 	char *password;
 };
 
-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
+#define CREDENTIAL_INIT { 0 }
 
 typedef int (*credential_op_cb)(struct credential *);
 
diff --git a/diff.c b/diff.c
index c8f530ffdbe..861282db1c3 100644
--- a/diff.c
+++ b/diff.c
@@ -775,13 +775,13 @@ struct emitted_diff_symbol {
 	int indent_width; /* The visual width of the indentation */
 	enum diff_symbol s;
 };
-#define EMITTED_DIFF_SYMBOL_INIT {NULL}
+#define EMITTED_DIFF_SYMBOL_INIT { 0 }
 
 struct emitted_diff_symbols {
 	struct emitted_diff_symbol *buf;
 	int nr, alloc;
 };
-#define EMITTED_DIFF_SYMBOLS_INIT {NULL, 0, 0}
+#define EMITTED_DIFF_SYMBOLS_INIT { 0 }
 
 static void append_emitted_diff_symbol(struct diff_options *o,
 				       struct emitted_diff_symbol *e)
diff --git a/entry.h b/entry.h
index 7c889e58fd7..04bc8bb59f0 100644
--- a/entry.h
+++ b/entry.h
@@ -16,7 +16,7 @@ struct checkout {
 		 clone:1,
 		 refresh_cache:1;
 };
-#define CHECKOUT_INIT { NULL, "" }
+#define CHECKOUT_INIT { 0 }
 
 #define TEMPORARY_FILENAME_LENGTH 25
 /*
diff --git a/lockfile.h b/lockfile.h
index db93e6ba73e..90af4e66b28 100644
--- a/lockfile.h
+++ b/lockfile.h
@@ -121,7 +121,7 @@ struct lock_file {
 	struct tempfile *tempfile;
 };
 
-#define LOCK_INIT { NULL }
+#define LOCK_INIT { 0 }
 
 /* String appended to a filename to derive the lockfile name: */
 #define LOCK_SUFFIX ".lock"
diff --git a/object-store.h b/object-store.h
index c5130d8baea..1e647a5be30 100644
--- a/object-store.h
+++ b/object-store.h
@@ -371,7 +371,7 @@ struct object_info {
  * Initializer for a "struct object_info" that wants no items. You may
  * also memset() the memory to all-zeroes.
  */
-#define OBJECT_INFO_INIT {NULL}
+#define OBJECT_INFO_INIT { 0 }
 
 /* Invoke lookup_replace_object() on the given hash */
 #define OBJECT_INFO_LOOKUP_REPLACE 1
diff --git a/object.h b/object.h
index 549f2d256bc..cb556ab7753 100644
--- a/object.h
+++ b/object.h
@@ -55,7 +55,7 @@ struct object_array {
 	} *objects;
 };
 
-#define OBJECT_ARRAY_INIT { 0, 0, NULL }
+#define OBJECT_ARRAY_INIT { 0 }
 
 /*
  * object flag allocation:
diff --git a/oid-array.h b/oid-array.h
index 72bca78b7dc..f60f9af6741 100644
--- a/oid-array.h
+++ b/oid-array.h
@@ -56,7 +56,7 @@ struct oid_array {
 	int sorted;
 };
 
-#define OID_ARRAY_INIT { NULL, 0, 0, 0 }
+#define OID_ARRAY_INIT { 0 }
 
 /**
  * Add an item to the set. The object ID will be placed at the end of the array
diff --git a/path.h b/path.h
index 251c78d9800..b68691a86b8 100644
--- a/path.h
+++ b/path.h
@@ -181,10 +181,7 @@ struct path_cache {
 	const char *shallow;
 };
 
-#define PATH_CACHE_INIT                                        \
-	{                                                      \
-		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \
-	}
+#define PATH_CACHE_INIT { 0 }
 
 const char *git_path_squash_msg(struct repository *r);
 const char *git_path_merge_msg(struct repository *r);
diff --git a/ref-filter.c b/ref-filter.c
index 93ce2a6ef2e..eee4f9b17c5 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -633,7 +633,7 @@ static struct {
 	 */
 };
 
-#define REF_FORMATTING_STATE_INIT  { 0, NULL }
+#define REF_FORMATTING_STATE_INIT  { 0 }
 
 struct ref_formatting_stack {
 	struct ref_formatting_stack *prev;
diff --git a/remote.c b/remote.c
index 31e141b01fa..f958543d707 100644
--- a/remote.c
+++ b/remote.c
@@ -2403,7 +2403,7 @@ struct reflog_commit_array {
 	size_t nr, alloc;
 };
 
-#define REFLOG_COMMIT_ARRAY_INIT { NULL, 0, 0 }
+#define REFLOG_COMMIT_ARRAY_INIT { 0 }
 
 /* Append a commit to the array. */
 static void append_commit(struct reflog_commit_array *arr,
diff --git a/revision.c b/revision.c
index 0dabb5a0bcf..73e5004d60b 100644
--- a/revision.c
+++ b/revision.c
@@ -249,7 +249,7 @@ struct commit_stack {
 	struct commit **items;
 	size_t nr, alloc;
 };
-#define COMMIT_STACK_INIT { NULL, 0, 0 }
+#define COMMIT_STACK_INIT { 0 }
 
 static void commit_stack_push(struct commit_stack *stack, struct commit *commit)
 {
-- 
2.33.0.1294.g2bdf2798764


  parent reply	other threads:[~2021-09-27  0:40 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27  0:39 [PATCH 0/5] Designated initializer cleanup & conversion Ævar Arnfjörð Bjarmason
2021-09-27  0:39 ` [PATCH 1/5] submodule-config.h: remove unused SUBMODULE_INIT macro Ævar Arnfjörð Bjarmason
2021-09-27  0:39 ` Ævar Arnfjörð Bjarmason [this message]
2021-09-27  2:27   ` [PATCH 2/5] *.[ch] *_INIT macros: use { 0 } for a "zero out" idiom Eric Sunshine
2021-09-27  6:35   ` Johannes Sixt
2021-09-27 20:25     ` Junio C Hamano
2021-09-27  0:39 ` [PATCH 3/5] *.h _INIT macros: don't specify fields equal to 0 Ævar Arnfjörð Bjarmason
2021-09-27  0:39 ` [PATCH 4/5] *.h: move some *_INIT to designated initializers Ævar Arnfjörð Bjarmason
2021-09-27  0:39 ` [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT Ævar Arnfjörð Bjarmason
2021-09-27  6:37   ` Johannes Sixt
2021-09-27 11:02     ` Ævar Arnfjörð Bjarmason
2021-09-27 23:54       ` Jeff King
2021-09-28  6:15         ` Johannes Sixt
2021-09-28 18:32         ` Junio C Hamano
2021-09-28 19:42           ` Ævar Arnfjörð Bjarmason
2021-09-28 20:50             ` Junio C Hamano
2021-09-27  9:13   ` Phillip Wood
2021-09-27 11:00     ` Ævar Arnfjörð Bjarmason
2021-09-30 10:01       ` Phillip Wood
2021-09-27 12:54 ` [PATCH v2 0/5] Designated initializer cleanup & conversion Ævar Arnfjörð Bjarmason
2021-09-27 12:54   ` [PATCH v2 1/5] submodule-config.h: remove unused SUBMODULE_INIT macro Ævar Arnfjörð Bjarmason
2021-09-27 23:34     ` Jeff King
2021-09-27 12:54   ` [PATCH v2 2/5] *.[ch] *_INIT macros: use { 0 } for a "zero out" idiom Ævar Arnfjörð Bjarmason
2021-09-27 23:24     ` Jeff King
2021-09-28  0:25       ` Ævar Arnfjörð Bjarmason
2021-09-28  0:46         ` Jeff King
2021-09-28  1:44         ` Ramsay Jones
2021-09-27 12:54   ` [PATCH v2 3/5] *.h _INIT macros: don't specify fields equal to 0 Ævar Arnfjörð Bjarmason
2021-09-27 21:54     ` Junio C Hamano
2021-09-27 12:54   ` [PATCH v2 4/5] *.h: move some *_INIT to designated initializers Ævar Arnfjörð Bjarmason
2021-09-27 23:57     ` Junio C Hamano
2021-09-27 12:54   ` [PATCH v2 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=patch-2.5-d612e7df7a5-20210927T003330Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=martin.agren@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).