]> git.ipfire.org Git - thirdparty/git.git/commitdiff
*.[ch] *_INIT macros: use { 0 } for a "zero out" idiom
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 27 Sep 2021 12:54:25 +0000 (14:54 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Sep 2021 21:47:59 +0000 (14:47 -0700)
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 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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
13 files changed:
builtin/submodule--helper.c
checkout.c
contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
contrib/credential/libsecret/git-credential-libsecret.c
diff.c
lockfile.h
object-store.h
object.h
oid-array.h
path.h
ref-filter.c
remote.c
revision.c

index 5336daf186dcf99d6be015e5b87188dcc086932e..deca75c83ee9a8ea3d0086935c9a1908c1cfca14 100644 (file)
@@ -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)
index 6586e30ca5a64fe61ec982f3d5dbe188d9194258..2e39dae684f8f0a048d172f36b21740f92e7de57 100644 (file)
@@ -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)
 {
index d389bfadceeb26c6d82c05a9c0eac27b67ad8549..5927e27ae6e4af4b42c2a8ec4f6f5044026008ec 100644 (file)
@@ -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 *);
 
index e6598b63833963115d43c62d9dd794bc03e120f1..2c5d76d789f0fabbdcd30d2684a4021b647731db 100644 (file)
@@ -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 c8f530ffdbea8dbd724aff61c7a0aed4e83e5af6..861282db1c3283ad5cd6234237408bb5cf223d2b 100644 (file)
--- 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)
index db93e6ba73e68ddcd114da0c75e5217a33b5a395..90af4e66b28c8f338cb62cf228a2b8d80000e8a8 100644 (file)
@@ -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"
index c5130d8baea54b29fa7279d3ebf7f2f791f15d6a..1e647a5be3033ab34239545674cc668b4b0969aa 100644 (file)
@@ -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
index 549f2d256bc2296de41863e529fafe4b69bbb8dd..cb556ab7753d5ddb01bc9421bbf490c0e684769b 100644 (file)
--- 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:
index 72bca78b7dc129313dfd2e0b6d9271179cda1ce0..f60f9af6741dc5acafb61b8a8a1562f49f92a600 100644 (file)
@@ -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 251c78d980000af0a40f1388ece5c9d68b354982..b68691a86b80417a82e5124aef37b9c8a9a02c95 100644 (file)
--- 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);
index 93ce2a6ef2e7cb2970423da6ab35fb190c7f3d5f..eee4f9b17c57063520b8dc6c860e7ba24baf1d61 100644 (file)
@@ -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;
index 31e141b01faeee699d497737cbfdf3bf4dc746f2..f958543d707d0da5282b7fb1bbb70a53bc834647 100644 (file)
--- 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,
index 0dabb5a0bcfe929124677a34d0fd94831d346c57..73e5004d60ba6543ee905c92425b319bc5f6587e 100644 (file)
@@ -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)
 {