[PATCH v2 0/5] Designated initializer cleanup & conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Migrates more code to designated initializers, see
http://lore.kernel.org/git/cover-0.5-00000000000-20210927T003330Z-avarab@xxxxxxxxx
for the v1.

This addresses all the feedback on v1, thanks all! Changes:

 * I'd misread the text around section 6.7.8 in C99 and misconverted
   the CHECKOUT_INIT macro. Thanks to Johannes Sixt for pointing it
   out.

 * Typo change in commit message & elaborate on why I'm not using the
   "*t = (struct cb_tree){ 0 };" pattern in 5/5.

 * Convert the LIST_HEAD_INIT and TRACE_KEY_INIT macros, which I
   missed in v1.

Nothing else changed as far as the end-state is concerned, but as the
range-diff shows I did some of the changes in the previous 4/5
partially in 3/5, e.g. for CACHE_DEF_INIT I first remove the duplicate
and redundant "0" fields, and then convert it to a designated
initializer.

Ævar Arnfjörð Bjarmason (5):
  submodule-config.h: remove unused SUBMODULE_INIT macro
  *.[ch] *_INIT macros: use { 0 } for a "zero out" idiom
  *.h _INIT macros: don't specify fields equal to 0
  *.h: move some *_INIT to designated initializers
  cbtree.h: define cb_init() in terms of CBTREE_INIT

 add-interactive.c                             |  8 +++++--
 builtin/submodule--helper.c                   | 21 ++++++++++---------
 cache.h                                       |  4 +++-
 cbtree.h                                      |  5 +++--
 checkout.c                                    |  2 +-
 .../git-credential-gnome-keyring.c            |  2 +-
 .../libsecret/git-credential-libsecret.c      |  2 +-
 diff.c                                        |  4 ++--
 entry.h                                       |  2 +-
 list.h                                        |  5 ++++-
 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 +-
 sequencer.h                                   |  4 +++-
 shallow.h                                     |  4 +++-
 simple-ipc.h                                  |  6 +-----
 strbuf.h                                      |  2 +-
 strvec.h                                      |  4 +++-
 submodule-config.h                            |  4 ----
 submodule.c                                   |  8 ++++---
 submodule.h                                   |  4 +++-
 t/helper/test-run-command.c                   |  6 ++++--
 trace.h                                       |  2 +-
 transport.h                                   |  4 +++-
 29 files changed, 68 insertions(+), 54 deletions(-)

Range-diff against v1:
1:  7a7a0141515 = 1:  7a7a0141515 submodule-config.h: remove unused SUBMODULE_INIT macro
2:  d612e7df7a5 ! 2:  afcd2729c95 *.[ch] *_INIT macros: use { 0 } for a "zero out" idiom
    @@ Commit message
         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
    +    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,
    @@ diff.c: struct emitted_diff_symbol {
      static void append_emitted_diff_symbol(struct diff_options *o,
      				       struct emitted_diff_symbol *e)
     
    - ## entry.h ##
    -@@ entry.h: struct checkout {
    - 		 clone:1,
    - 		 refresh_cache:1;
    - };
    --#define CHECKOUT_INIT { NULL, "" }
    -+#define CHECKOUT_INIT { 0 }
    - 
    - #define TEMPORARY_FILENAME_LENGTH 25
    - /*
    -
      ## lockfile.h ##
     @@ lockfile.h: struct lock_file {
      	struct tempfile *tempfile;
3:  9e45d2e7bb3 ! 3:  590220bbdcc *.h _INIT macros: don't specify fields equal to 0
    @@ Commit message
         "struct ipc_client_connect_option" struct added in
         59c7b88198a (simple-ipc: add win32 implementation, 2021-03-15).
     
    +    Do the same for a few other initializers, e.g. STRVEC_INIT and
    +    CACHE_DEF_INIT.
    +
         Finally, start incrementally changing the same pattern in
         "t/helper/test-run-command.c". This change was part of an earlier
         on-list version[1] of c90be786da9 (test-tool run-command: fix
    @@ Commit message
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
     
    + ## cache.h ##
    +@@ cache.h: struct cache_def {
    + 	int track_flags;
    + 	int prefix_len_stat_func;
    + };
    +-#define CACHE_DEF_INIT { STRBUF_INIT, 0, 0, 0 }
    ++#define CACHE_DEF_INIT { STRBUF_INIT }
    + static inline void cache_def_clear(struct cache_def *cache)
    + {
    + 	strbuf_release(&cache->path);
    +
      ## simple-ipc.h ##
     @@ simple-ipc.h: struct ipc_client_connect_options {
      	unsigned int uds_disallow_chdir:1;
    @@ strbuf.h: struct strbuf {
      /*
       * Predeclare this here, since cache.h includes this file before it defines the
     
    + ## strvec.h ##
    +@@ strvec.h: struct strvec {
    + 	size_t alloc;
    + };
    + 
    +-#define STRVEC_INIT { empty_strvec, 0, 0 }
    ++#define STRVEC_INIT { empty_strvec }
    + 
    + /**
    +  * Initialize an array. This is no different than assigning from
    +
    + ## submodule.h ##
    +@@ submodule.h: struct submodule_update_strategy {
    + 	enum submodule_update_type type;
    + 	const char *command;
    + };
    +-#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
    ++#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED}
    + 
    + int is_gitmodules_unmerged(struct index_state *istate);
    + int is_writing_gitmodules_ok(void);
    +
      ## t/helper/test-run-command.c ##
     @@ t/helper/test-run-command.c: struct testsuite {
      	int quiet, immediate, verbose, verbose_log, trace, write_junit_xml;
    @@ t/helper/test-run-command.c: struct testsuite {
      
      static int next_test(struct child_process *cp, struct strbuf *err, void *cb,
      		     void **task_cb)
    +
    + ## trace.h ##
    +@@ trace.h: struct trace_key {
    + 
    + extern struct trace_key trace_default_key;
    + 
    +-#define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name, 0, 0, 0 }
    ++#define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name }
    + extern struct trace_key trace_perf_key;
    + extern struct trace_key trace_setup_key;
    + 
4:  1f364565111 ! 4:  dd4ec1a0219 *.h: move some *_INIT to designated initializers
    @@ cache.h: struct cache_def {
      	int track_flags;
      	int prefix_len_stat_func;
      };
    --#define CACHE_DEF_INIT { STRBUF_INIT, 0, 0, 0 }
    +-#define CACHE_DEF_INIT { STRBUF_INIT }
     +#define CACHE_DEF_INIT { \
     +	.path = STRBUF_INIT, \
     +}
    @@ cache.h: struct cache_def {
      {
      	strbuf_release(&cache->path);
     
    + ## entry.h ##
    +@@ entry.h: struct checkout {
    + 		 clone:1,
    + 		 refresh_cache:1;
    + };
    +-#define CHECKOUT_INIT { NULL, "" }
    ++#define CHECKOUT_INIT { .base_dir = "" }
    + 
    + #define TEMPORARY_FILENAME_LENGTH 25
    + /*
    +
    + ## list.h ##
    +@@ list.h: struct list_head {
    + #define INIT_LIST_HEAD(ptr) \
    + 	(ptr)->next = (ptr)->prev = (ptr)
    + 
    +-#define LIST_HEAD_INIT(name) { &(name), &(name) }
    ++#define LIST_HEAD_INIT(name) { \
    ++	.next = &(name), \
    ++	.prev = &(name), \
    ++}
    + 
    + /* Add new element at the head of the list. */
    + static inline void list_add(struct list_head *newp, struct list_head *head)
    +
      ## sequencer.h ##
     @@ sequencer.h: struct todo_list {
      	struct stat_data stat;
    @@ strvec.h: struct strvec {
      	size_t alloc;
      };
      
    --#define STRVEC_INIT { empty_strvec, 0, 0 }
    +-#define STRVEC_INIT { empty_strvec }
     +#define STRVEC_INIT { \
     +	.v = empty_strvec, \
     +}
    @@ submodule.h: struct submodule_update_strategy {
      	enum submodule_update_type type;
      	const char *command;
      };
    --#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
    +-#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED}
     +#define SUBMODULE_UPDATE_STRATEGY_INIT { \
     +	.type = SM_UPDATE_UNSPECIFIED, \
     +}
    @@ t/helper/test-run-command.c: struct testsuite {
      static int next_test(struct child_process *cp, struct strbuf *err, void *cb,
      		     void **task_cb)
     
    + ## trace.h ##
    +@@ trace.h: struct trace_key {
    + 
    + extern struct trace_key trace_default_key;
    + 
    +-#define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name }
    ++#define TRACE_KEY_INIT(name) { .key = "GIT_TRACE_" #name }
    + extern struct trace_key trace_perf_key;
    + extern struct trace_key trace_setup_key;
    + 
    +
      ## transport.h ##
     @@ transport.h: struct transport_ls_refs_options {
      	 */
5:  7e571667674 ! 5:  76b47e7c80a cbtree.h: define cb_init() in terms of CBTREE_INIT
    @@ Commit message
         5726a6b4012 (*.c *_init(): define in terms of corresponding *_INIT
         macro, 2021-07-01).
     
    +    It has been pointed out[1] that we could perhaps use this C99
    +    replacement of using a compound literal for all of these:
    +
    +        *t = (struct cb_tree){ 0 };
    +
    +    But let's just stick to the existing pattern established in
    +    5726a6b4012 for now, we can leave another weather balloon for some
    +    other time.
    +
    +    1. http://lore.kernel.org/git/ef724a3a-a4b8-65d3-c928-13a7d78f189a@xxxxxxxxx
    +
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
     
      ## cbtree.h ##
-- 
2.33.0.1316.gb2e9b3ba3ae




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux