git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/12] c99: use more designated initializers
@ 2022-02-24  9:32 Ævar Arnfjörð Bjarmason
  2022-02-24  9:32 ` [PATCH 01/12] imap-send.c: use designated initializers for "struct imap_server_conf" Ævar Arnfjörð Bjarmason
                   ` (13 more replies)
  0 siblings, 14 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:32 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

A follow-up to 404c4a54624 (Merge branch 'ab/designated-initializers',
2021-10-11) and a4b9fb6a5cf (Merge branch
'ab/designated-initializers-more', 2021-10-18). These code readability
improvements are something we can allow ourselves now that we have a
hard dependency on C99.

These changes merge cleanly with "seen", so they should be easy to
deal with as far as anything else that's in-flight goes.

Ævar Arnfjörð Bjarmason (12):
  imap-send.c: use designated initializers for "struct imap_server_conf"
  refs: use designated initializers for "struct ref_storage_be"
  refs: use designated initializers for "struct ref_iterator_vtable"
  trace2: use designated initializers for "struct tr2_tgt"
  trace2: use designated initializers for "struct tr2_dst"
  object-file: use designated initializers for "struct git_hash_algo"
  archive-*.c: use designated initializers for "struct archiver"
  userdiff.c: use designated initializers for "struct userdiff_driver"
  convert.c: use designated initializers for "struct stream_filter*"
  refspec.c: use designated initializers for "struct refspec_item"
  misc *.c: use designated initializers for struct assignments
  misc *.c: use designated initializers for "partial" struct assignments

 archive-tar.c           |  6 +--
 archive-zip.c           |  6 +--
 attr.c                  |  2 +-
 builtin/fast-import.c   | 14 +++++--
 convert.c               | 18 ++++-----
 imap-send.c             | 12 +-----
 notes-merge.c           |  1 +
 object-file.c           | 87 +++++++++++++++++++++--------------------
 refs/debug.c            | 55 +++++++++++++-------------
 refs/files-backend.c    | 62 ++++++++++++++---------------
 refs/iterator.c         | 18 ++++-----
 refs/packed-backend.c   | 56 +++++++++++++-------------
 refs/ref-cache.c        |  6 +--
 refspec.c               | 14 +++----
 trace2/tr2_tgt_event.c  | 64 +++++++++++++++---------------
 trace2/tr2_tgt_normal.c | 64 +++++++++++++++---------------
 trace2/tr2_tgt_perf.c   | 64 +++++++++++++++---------------
 userdiff.c              | 36 ++++++++++-------
 18 files changed, 299 insertions(+), 286 deletions(-)

-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 01/12] imap-send.c: use designated initializers for "struct imap_server_conf"
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:32 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:32 ` [PATCH 02/12] refs: use designated initializers for "struct ref_storage_be" Ævar Arnfjörð Bjarmason
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:32 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

Cut down a lot on the verbosity of the "server" assignment in
imap-send.c using designated initializers, only the "ssl_verify"
member was being set to a non-NULL non-0 value.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 imap-send.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/imap-send.c b/imap-send.c
index e6090a0346a..5ac6fa9c664 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -98,17 +98,7 @@ struct imap_server_conf {
 };
 
 static struct imap_server_conf server = {
-	NULL,	/* name */
-	NULL,	/* tunnel */
-	NULL,	/* host */
-	0,	/* port */
-	NULL,	/* folder */
-	NULL,	/* user */
-	NULL,	/* pass */
-	0,   	/* use_ssl */
-	1,   	/* ssl_verify */
-	0,   	/* use_html */
-	NULL,	/* auth_method */
+	.ssl_verify = 1,
 };
 
 struct imap_socket {
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 02/12] refs: use designated initializers for "struct ref_storage_be"
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
  2022-02-24  9:32 ` [PATCH 01/12] imap-send.c: use designated initializers for "struct imap_server_conf" Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:32 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:32 ` [PATCH 03/12] refs: use designated initializers for "struct ref_iterator_vtable" Ævar Arnfjörð Bjarmason
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:32 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

Change the definition of the three refs backends we currently carry to
use designated initializers.

The "= NULL" assignments being retained here are redundant, and could
be removed, but let's keep them for clarity. All of these backends
define almost all fields, so we're not saving much in terms of line
count by omitting these, but e.g. for "refs_be_debug" it's immediately
apparent that we're omitting "init" when comparing its assignment to
the others.

This is a follow-up to similar work merged in bd4232fac33 (Merge
branch 'ab/struct-init', 2021-07-16), a4b9fb6a5cf (Merge branch
'ab/designated-initializers-more', 2021-10-18) and a30321b9eae (Merge
branch 'ab/designated-initializers' into
ab/designated-initializers-more, 2021-09-27).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 refs/debug.c          | 50 +++++++++++++++++++++----------------------
 refs/files-backend.c  | 50 +++++++++++++++++++++----------------------
 refs/packed-backend.c | 50 +++++++++++++++++++++----------------------
 3 files changed, 75 insertions(+), 75 deletions(-)

diff --git a/refs/debug.c b/refs/debug.c
index 2b0771ca53b..c8b52d43a79 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -418,29 +418,29 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname,
 }
 
 struct ref_storage_be refs_be_debug = {
-	NULL,
-	"debug",
-	NULL,
-	debug_init_db,
-	debug_transaction_prepare,
-	debug_transaction_finish,
-	debug_transaction_abort,
-	debug_initial_transaction_commit,
-
-	debug_pack_refs,
-	debug_create_symref,
-	debug_delete_refs,
-	debug_rename_ref,
-	debug_copy_ref,
-
-	debug_ref_iterator_begin,
-	debug_read_raw_ref,
-
-	debug_reflog_iterator_begin,
-	debug_for_each_reflog_ent,
-	debug_for_each_reflog_ent_reverse,
-	debug_reflog_exists,
-	debug_create_reflog,
-	debug_delete_reflog,
-	debug_reflog_expire,
+	.next = NULL,
+	.name = "debug",
+	.init = NULL,
+	.init_db = debug_init_db,
+	.transaction_prepare = debug_transaction_prepare,
+	.transaction_finish = debug_transaction_finish,
+	.transaction_abort = debug_transaction_abort,
+	.initial_transaction_commit = debug_initial_transaction_commit,
+
+	.pack_refs = debug_pack_refs,
+	.create_symref = debug_create_symref,
+	.delete_refs = debug_delete_refs,
+	.rename_ref = debug_rename_ref,
+	.copy_ref = debug_copy_ref,
+
+	.iterator_begin = debug_ref_iterator_begin,
+	.read_raw_ref = debug_read_raw_ref,
+
+	.reflog_iterator_begin = debug_reflog_iterator_begin,
+	.for_each_reflog_ent = debug_for_each_reflog_ent,
+	.for_each_reflog_ent_reverse = debug_for_each_reflog_ent_reverse,
+	.reflog_exists = debug_reflog_exists,
+	.create_reflog = debug_create_reflog,
+	.delete_reflog = debug_delete_reflog,
+	.reflog_expire = debug_reflog_expire,
 };
diff --git a/refs/files-backend.c b/refs/files-backend.c
index f59589d6cce..efc942958ef 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3269,29 +3269,29 @@ static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
 }
 
 struct ref_storage_be refs_be_files = {
-	NULL,
-	"files",
-	files_ref_store_create,
-	files_init_db,
-	files_transaction_prepare,
-	files_transaction_finish,
-	files_transaction_abort,
-	files_initial_transaction_commit,
-
-	files_pack_refs,
-	files_create_symref,
-	files_delete_refs,
-	files_rename_ref,
-	files_copy_ref,
-
-	files_ref_iterator_begin,
-	files_read_raw_ref,
-
-	files_reflog_iterator_begin,
-	files_for_each_reflog_ent,
-	files_for_each_reflog_ent_reverse,
-	files_reflog_exists,
-	files_create_reflog,
-	files_delete_reflog,
-	files_reflog_expire
+	.next = NULL,
+	.name = "files",
+	.init = files_ref_store_create,
+	.init_db = files_init_db,
+	.transaction_prepare = files_transaction_prepare,
+	.transaction_finish = files_transaction_finish,
+	.transaction_abort = files_transaction_abort,
+	.initial_transaction_commit = files_initial_transaction_commit,
+
+	.pack_refs = files_pack_refs,
+	.create_symref = files_create_symref,
+	.delete_refs = files_delete_refs,
+	.rename_ref = files_rename_ref,
+	.copy_ref = files_copy_ref,
+
+	.iterator_begin = files_ref_iterator_begin,
+	.read_raw_ref = files_read_raw_ref,
+
+	.reflog_iterator_begin = files_reflog_iterator_begin,
+	.for_each_reflog_ent = files_for_each_reflog_ent,
+	.for_each_reflog_ent_reverse = files_for_each_reflog_ent_reverse,
+	.reflog_exists = files_reflog_exists,
+	.create_reflog = files_create_reflog,
+	.delete_reflog = files_delete_reflog,
+	.reflog_expire = files_reflog_expire
 };
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 27dd8c3922b..ba75c28f1bf 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1667,29 +1667,29 @@ static int packed_reflog_expire(struct ref_store *ref_store,
 }
 
 struct ref_storage_be refs_be_packed = {
-	NULL,
-	"packed",
-	packed_ref_store_create,
-	packed_init_db,
-	packed_transaction_prepare,
-	packed_transaction_finish,
-	packed_transaction_abort,
-	packed_initial_transaction_commit,
-
-	packed_pack_refs,
-	packed_create_symref,
-	packed_delete_refs,
-	packed_rename_ref,
-	packed_copy_ref,
-
-	packed_ref_iterator_begin,
-	packed_read_raw_ref,
-
-	packed_reflog_iterator_begin,
-	packed_for_each_reflog_ent,
-	packed_for_each_reflog_ent_reverse,
-	packed_reflog_exists,
-	packed_create_reflog,
-	packed_delete_reflog,
-	packed_reflog_expire
+	.next = NULL,
+	.name = "packed",
+	.init = packed_ref_store_create,
+	.init_db = packed_init_db,
+	.transaction_prepare = packed_transaction_prepare,
+	.transaction_finish = packed_transaction_finish,
+	.transaction_abort = packed_transaction_abort,
+	.initial_transaction_commit = packed_initial_transaction_commit,
+
+	.pack_refs = packed_pack_refs,
+	.create_symref = packed_create_symref,
+	.delete_refs = packed_delete_refs,
+	.rename_ref = packed_rename_ref,
+	.copy_ref = packed_copy_ref,
+
+	.iterator_begin = packed_ref_iterator_begin,
+	.read_raw_ref = packed_read_raw_ref,
+
+	.reflog_iterator_begin = packed_reflog_iterator_begin,
+	.for_each_reflog_ent = packed_for_each_reflog_ent,
+	.for_each_reflog_ent_reverse = packed_for_each_reflog_ent_reverse,
+	.reflog_exists = packed_reflog_exists,
+	.create_reflog = packed_create_reflog,
+	.delete_reflog = packed_delete_reflog,
+	.reflog_expire = packed_reflog_expire
 };
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 03/12] refs: use designated initializers for "struct ref_iterator_vtable"
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
  2022-02-24  9:32 ` [PATCH 01/12] imap-send.c: use designated initializers for "struct imap_server_conf" Ævar Arnfjörð Bjarmason
  2022-02-24  9:32 ` [PATCH 02/12] refs: use designated initializers for "struct ref_storage_be" Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:32 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:32 ` [PATCH 04/12] trace2: use designated initializers for "struct tr2_tgt" Ævar Arnfjörð Bjarmason
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:32 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 refs/debug.c          |  5 +++--
 refs/files-backend.c  | 12 ++++++------
 refs/iterator.c       | 18 +++++++++---------
 refs/packed-backend.c |  6 +++---
 refs/ref-cache.c      |  6 +++---
 5 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/refs/debug.c b/refs/debug.c
index c8b52d43a79..c647a20abbd 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -220,8 +220,9 @@ static int debug_ref_iterator_abort(struct ref_iterator *ref_iterator)
 }
 
 static struct ref_iterator_vtable debug_ref_iterator_vtable = {
-	debug_ref_iterator_advance, debug_ref_iterator_peel,
-	debug_ref_iterator_abort
+	.advance = debug_ref_iterator_advance,
+	.peel = debug_ref_iterator_peel,
+	.abort = debug_ref_iterator_abort,
 };
 
 static struct ref_iterator *
diff --git a/refs/files-backend.c b/refs/files-backend.c
index efc942958ef..3159be5a37a 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -800,9 +800,9 @@ static int files_ref_iterator_abort(struct ref_iterator *ref_iterator)
 }
 
 static struct ref_iterator_vtable files_ref_iterator_vtable = {
-	files_ref_iterator_advance,
-	files_ref_iterator_peel,
-	files_ref_iterator_abort
+	.advance = files_ref_iterator_advance,
+	.peel = files_ref_iterator_peel,
+	.abort = files_ref_iterator_abort,
 };
 
 static struct ref_iterator *files_ref_iterator_begin(
@@ -2209,9 +2209,9 @@ static int files_reflog_iterator_abort(struct ref_iterator *ref_iterator)
 }
 
 static struct ref_iterator_vtable files_reflog_iterator_vtable = {
-	files_reflog_iterator_advance,
-	files_reflog_iterator_peel,
-	files_reflog_iterator_abort
+	.advance = files_reflog_iterator_advance,
+	.peel = files_reflog_iterator_peel,
+	.abort = files_reflog_iterator_abort,
 };
 
 static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,
diff --git a/refs/iterator.c b/refs/iterator.c
index a89d132d4fe..b2e56bae1c6 100644
--- a/refs/iterator.c
+++ b/refs/iterator.c
@@ -64,9 +64,9 @@ static int empty_ref_iterator_abort(struct ref_iterator *ref_iterator)
 }
 
 static struct ref_iterator_vtable empty_ref_iterator_vtable = {
-	empty_ref_iterator_advance,
-	empty_ref_iterator_peel,
-	empty_ref_iterator_abort
+	.advance = empty_ref_iterator_advance,
+	.peel = empty_ref_iterator_peel,
+	.abort = empty_ref_iterator_abort,
 };
 
 struct ref_iterator *empty_ref_iterator_begin(void)
@@ -201,9 +201,9 @@ static int merge_ref_iterator_abort(struct ref_iterator *ref_iterator)
 }
 
 static struct ref_iterator_vtable merge_ref_iterator_vtable = {
-	merge_ref_iterator_advance,
-	merge_ref_iterator_peel,
-	merge_ref_iterator_abort
+	.advance = merge_ref_iterator_advance,
+	.peel = merge_ref_iterator_peel,
+	.abort = merge_ref_iterator_abort,
 };
 
 struct ref_iterator *merge_ref_iterator_begin(
@@ -378,9 +378,9 @@ static int prefix_ref_iterator_abort(struct ref_iterator *ref_iterator)
 }
 
 static struct ref_iterator_vtable prefix_ref_iterator_vtable = {
-	prefix_ref_iterator_advance,
-	prefix_ref_iterator_peel,
-	prefix_ref_iterator_abort
+	.advance = prefix_ref_iterator_advance,
+	.peel = prefix_ref_iterator_peel,
+	.abort = prefix_ref_iterator_abort,
 };
 
 struct ref_iterator *prefix_ref_iterator_begin(struct ref_iterator *iter0,
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index ba75c28f1bf..1406cb959c1 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -911,9 +911,9 @@ static int packed_ref_iterator_abort(struct ref_iterator *ref_iterator)
 }
 
 static struct ref_iterator_vtable packed_ref_iterator_vtable = {
-	packed_ref_iterator_advance,
-	packed_ref_iterator_peel,
-	packed_ref_iterator_abort
+	.advance = packed_ref_iterator_advance,
+	.peel = packed_ref_iterator_peel,
+	.abort = packed_ref_iterator_abort
 };
 
 static struct ref_iterator *packed_ref_iterator_begin(
diff --git a/refs/ref-cache.c b/refs/ref-cache.c
index be4aa5e0981..3080ef944d9 100644
--- a/refs/ref-cache.c
+++ b/refs/ref-cache.c
@@ -456,9 +456,9 @@ static int cache_ref_iterator_abort(struct ref_iterator *ref_iterator)
 }
 
 static struct ref_iterator_vtable cache_ref_iterator_vtable = {
-	cache_ref_iterator_advance,
-	cache_ref_iterator_peel,
-	cache_ref_iterator_abort
+	.advance = cache_ref_iterator_advance,
+	.peel = cache_ref_iterator_peel,
+	.abort = cache_ref_iterator_abort
 };
 
 struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 04/12] trace2: use designated initializers for "struct tr2_tgt"
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (2 preceding siblings ...)
  2022-02-24  9:32 ` [PATCH 03/12] refs: use designated initializers for "struct ref_iterator_vtable" Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:32 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:33 ` [PATCH 05/12] trace2: use designated initializers for "struct tr2_dst" Ævar Arnfjörð Bjarmason
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:32 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

As with the preceding commit, change another set of file-level struct
assignments to use designated initializers.

As before the "= NULL" assignments are redundant, but we're keeping
them for self-documentation purposes. The comments left to explain the
pre-image can now be removed in favor of working code that relays the
same information to the reader.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 trace2/tr2_tgt_event.c  | 60 ++++++++++++++++++++---------------------
 trace2/tr2_tgt_normal.c | 60 ++++++++++++++++++++---------------------
 trace2/tr2_tgt_perf.c   | 60 ++++++++++++++++++++---------------------
 3 files changed, 90 insertions(+), 90 deletions(-)

diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c
index bd17ecdc321..b5c63622d1e 100644
--- a/trace2/tr2_tgt_event.c
+++ b/trace2/tr2_tgt_event.c
@@ -613,34 +613,34 @@ static void fn_data_json_fl(const char *file, int line,
 }
 
 struct tr2_tgt tr2_tgt_event = {
-	&tr2dst_event,
-
-	fn_init,
-	fn_term,
-
-	fn_version_fl,
-	fn_start_fl,
-	fn_exit_fl,
-	fn_signal,
-	fn_atexit,
-	fn_error_va_fl,
-	fn_command_path_fl,
-	fn_command_ancestry_fl,
-	fn_command_name_fl,
-	fn_command_mode_fl,
-	fn_alias_fl,
-	fn_child_start_fl,
-	fn_child_exit_fl,
-	fn_child_ready_fl,
-	fn_thread_start_fl,
-	fn_thread_exit_fl,
-	fn_exec_fl,
-	fn_exec_result_fl,
-	fn_param_fl,
-	fn_repo_fl,
-	fn_region_enter_printf_va_fl,
-	fn_region_leave_printf_va_fl,
-	fn_data_fl,
-	fn_data_json_fl,
-	NULL, /* printf */
+	.pdst = &tr2dst_event,
+
+	.pfn_init = fn_init,
+	.pfn_term = fn_term,
+
+	.pfn_version_fl = fn_version_fl,
+	.pfn_start_fl = fn_start_fl,
+	.pfn_exit_fl = fn_exit_fl,
+	.pfn_signal = fn_signal,
+	.pfn_atexit = fn_atexit,
+	.pfn_error_va_fl = fn_error_va_fl,
+	.pfn_command_path_fl = fn_command_path_fl,
+	.pfn_command_ancestry_fl = fn_command_ancestry_fl,
+	.pfn_command_name_fl = fn_command_name_fl,
+	.pfn_command_mode_fl = fn_command_mode_fl,
+	.pfn_alias_fl = fn_alias_fl,
+	.pfn_child_start_fl = fn_child_start_fl,
+	.pfn_child_exit_fl = fn_child_exit_fl,
+	.pfn_child_ready_fl = fn_child_ready_fl,
+	.pfn_thread_start_fl = fn_thread_start_fl,
+	.pfn_thread_exit_fl = fn_thread_exit_fl,
+	.pfn_exec_fl = fn_exec_fl,
+	.pfn_exec_result_fl = fn_exec_result_fl,
+	.pfn_param_fl = fn_param_fl,
+	.pfn_repo_fl = fn_repo_fl,
+	.pfn_region_enter_printf_va_fl = fn_region_enter_printf_va_fl,
+	.pfn_region_leave_printf_va_fl = fn_region_leave_printf_va_fl,
+	.pfn_data_fl = fn_data_fl,
+	.pfn_data_json_fl = fn_data_json_fl,
+	.pfn_printf_va_fl = NULL,
 };
diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c
index 6e429a3fb9e..c7992650018 100644
--- a/trace2/tr2_tgt_normal.c
+++ b/trace2/tr2_tgt_normal.c
@@ -325,34 +325,34 @@ static void fn_printf_va_fl(const char *file, int line,
 }
 
 struct tr2_tgt tr2_tgt_normal = {
-	&tr2dst_normal,
-
-	fn_init,
-	fn_term,
-
-	fn_version_fl,
-	fn_start_fl,
-	fn_exit_fl,
-	fn_signal,
-	fn_atexit,
-	fn_error_va_fl,
-	fn_command_path_fl,
-	fn_command_ancestry_fl,
-	fn_command_name_fl,
-	fn_command_mode_fl,
-	fn_alias_fl,
-	fn_child_start_fl,
-	fn_child_exit_fl,
-	fn_child_ready_fl,
-	NULL, /* thread_start */
-	NULL, /* thread_exit */
-	fn_exec_fl,
-	fn_exec_result_fl,
-	fn_param_fl,
-	fn_repo_fl,
-	NULL, /* region_enter */
-	NULL, /* region_leave */
-	NULL, /* data */
-	NULL, /* data_json */
-	fn_printf_va_fl,
+	.pdst = &tr2dst_normal,
+
+	.pfn_init = fn_init,
+	.pfn_term = fn_term,
+
+	.pfn_version_fl = fn_version_fl,
+	.pfn_start_fl = fn_start_fl,
+	.pfn_exit_fl = fn_exit_fl,
+	.pfn_signal = fn_signal,
+	.pfn_atexit = fn_atexit,
+	.pfn_error_va_fl = fn_error_va_fl,
+	.pfn_command_path_fl = fn_command_path_fl,
+	.pfn_command_ancestry_fl = fn_command_ancestry_fl,
+	.pfn_command_name_fl = fn_command_name_fl,
+	.pfn_command_mode_fl = fn_command_mode_fl,
+	.pfn_alias_fl = fn_alias_fl,
+	.pfn_child_start_fl = fn_child_start_fl,
+	.pfn_child_exit_fl = fn_child_exit_fl,
+	.pfn_child_ready_fl = fn_child_ready_fl,
+	.pfn_thread_start_fl = NULL,
+	.pfn_thread_exit_fl = NULL,
+	.pfn_exec_fl = fn_exec_fl,
+	.pfn_exec_result_fl = fn_exec_result_fl,
+	.pfn_param_fl = fn_param_fl,
+	.pfn_repo_fl = fn_repo_fl,
+	.pfn_region_enter_printf_va_fl = NULL,
+	.pfn_region_leave_printf_va_fl = NULL,
+	.pfn_data_fl = NULL,
+	.pfn_data_json_fl = NULL,
+	.pfn_printf_va_fl = fn_printf_va_fl,
 };
diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
index 2ff9cf70835..a2a0195e0f4 100644
--- a/trace2/tr2_tgt_perf.c
+++ b/trace2/tr2_tgt_perf.c
@@ -549,34 +549,34 @@ static void fn_printf_va_fl(const char *file, int line,
 }
 
 struct tr2_tgt tr2_tgt_perf = {
-	&tr2dst_perf,
-
-	fn_init,
-	fn_term,
-
-	fn_version_fl,
-	fn_start_fl,
-	fn_exit_fl,
-	fn_signal,
-	fn_atexit,
-	fn_error_va_fl,
-	fn_command_path_fl,
-	fn_command_ancestry_fl,
-	fn_command_name_fl,
-	fn_command_mode_fl,
-	fn_alias_fl,
-	fn_child_start_fl,
-	fn_child_exit_fl,
-	fn_child_ready_fl,
-	fn_thread_start_fl,
-	fn_thread_exit_fl,
-	fn_exec_fl,
-	fn_exec_result_fl,
-	fn_param_fl,
-	fn_repo_fl,
-	fn_region_enter_printf_va_fl,
-	fn_region_leave_printf_va_fl,
-	fn_data_fl,
-	fn_data_json_fl,
-	fn_printf_va_fl,
+	.pdst = &tr2dst_perf,
+
+	.pfn_init = fn_init,
+	.pfn_term = fn_term,
+
+	.pfn_version_fl = fn_version_fl,
+	.pfn_start_fl = fn_start_fl,
+	.pfn_exit_fl = fn_exit_fl,
+	.pfn_signal = fn_signal,
+	.pfn_atexit = fn_atexit,
+	.pfn_error_va_fl = fn_error_va_fl,
+	.pfn_command_path_fl = fn_command_path_fl,
+	.pfn_command_ancestry_fl = fn_command_ancestry_fl,
+	.pfn_command_name_fl = fn_command_name_fl,
+	.pfn_command_mode_fl = fn_command_mode_fl,
+	.pfn_alias_fl = fn_alias_fl,
+	.pfn_child_start_fl = fn_child_start_fl,
+	.pfn_child_exit_fl = fn_child_exit_fl,
+	.pfn_child_ready_fl = fn_child_ready_fl,
+	.pfn_thread_start_fl = fn_thread_start_fl,
+	.pfn_thread_exit_fl = fn_thread_exit_fl,
+	.pfn_exec_fl = fn_exec_fl,
+	.pfn_exec_result_fl = fn_exec_result_fl,
+	.pfn_param_fl = fn_param_fl,
+	.pfn_repo_fl = fn_repo_fl,
+	.pfn_region_enter_printf_va_fl = fn_region_enter_printf_va_fl,
+	.pfn_region_leave_printf_va_fl = fn_region_leave_printf_va_fl,
+	.pfn_data_fl = fn_data_fl,
+	.pfn_data_json_fl = fn_data_json_fl,
+	.pfn_printf_va_fl = fn_printf_va_fl,
 };
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 05/12] trace2: use designated initializers for "struct tr2_dst"
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (3 preceding siblings ...)
  2022-02-24  9:32 ` [PATCH 04/12] trace2: use designated initializers for "struct tr2_tgt" Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:33 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:33 ` [PATCH 06/12] object-file: use designated initializers for "struct git_hash_algo" Ævar Arnfjörð Bjarmason
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:33 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

Convert the "static struct tr2_dst" assignments in trace2/* to use
designated initializers. I don't think it improves readability to
include the explicit 0-ing out of the
fd/initialized/need_close/too_many_files members, so let's have those
be initialized implicitly by the compiler.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 trace2/tr2_tgt_event.c  | 4 +++-
 trace2/tr2_tgt_normal.c | 4 +++-
 trace2/tr2_tgt_perf.c   | 4 +++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c
index b5c63622d1e..c5c8cfbbaa0 100644
--- a/trace2/tr2_tgt_event.c
+++ b/trace2/tr2_tgt_event.c
@@ -10,7 +10,9 @@
 #include "trace2/tr2_tgt.h"
 #include "trace2/tr2_tls.h"
 
-static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0, 0 };
+static struct tr2_dst tr2dst_event = {
+	.sysenv_var = TR2_SYSENV_EVENT,
+};
 
 /*
  * The version number of the JSON data generated by the EVENT target in this
diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c
index c7992650018..c42fbade7f0 100644
--- a/trace2/tr2_tgt_normal.c
+++ b/trace2/tr2_tgt_normal.c
@@ -9,7 +9,9 @@
 #include "trace2/tr2_tgt.h"
 #include "trace2/tr2_tls.h"
 
-static struct tr2_dst tr2dst_normal = { TR2_SYSENV_NORMAL, 0, 0, 0, 0 };
+static struct tr2_dst tr2dst_normal = {
+	.sysenv_var = TR2_SYSENV_NORMAL,
+};
 
 /*
  * Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the "<time> <file>:<line>"
diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
index a2a0195e0f4..a1eff8bea31 100644
--- a/trace2/tr2_tgt_perf.c
+++ b/trace2/tr2_tgt_perf.c
@@ -11,7 +11,9 @@
 #include "trace2/tr2_tgt.h"
 #include "trace2/tr2_tls.h"
 
-static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0, 0 };
+static struct tr2_dst tr2dst_perf = {
+	.sysenv_var = TR2_SYSENV_PERF,
+};
 
 /*
  * Use TR2_SYSENV_PERF_BRIEF to omit the "<time> <file>:<line>"
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 06/12] object-file: use designated initializers for "struct git_hash_algo"
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (4 preceding siblings ...)
  2022-02-24  9:33 ` [PATCH 05/12] trace2: use designated initializers for "struct tr2_dst" Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:33 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:33 ` [PATCH 07/12] archive-*.c: use designated initializers for "struct archiver" Ævar Arnfjörð Bjarmason
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:33 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

As with the preceding commit, change another file-level struct
assignment to use designated initializers.

Retain the ".name = NULL" etc. in the case of the first element of
"unknown hash algorithm", to make it explicit that we're intentionally
not setting those, it's not just that we forgot.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 object-file.c | 78 +++++++++++++++++++++++++--------------------------
 1 file changed, 39 insertions(+), 39 deletions(-)

diff --git a/object-file.c b/object-file.c
index 8be57f48de7..03bd6a3baf3 100644
--- a/object-file.c
+++ b/object-file.c
@@ -167,49 +167,49 @@ static void git_hash_unknown_final_oid(struct object_id *oid, git_hash_ctx *ctx)
 
 const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
 	{
-		NULL,
-		0x00000000,
-		0,
-		0,
-		0,
-		git_hash_unknown_init,
-		git_hash_unknown_clone,
-		git_hash_unknown_update,
-		git_hash_unknown_final,
-		git_hash_unknown_final_oid,
-		NULL,
-		NULL,
-		NULL,
+		.name = NULL,
+		.format_id = 0x00000000,
+		.rawsz = 0,
+		.hexsz = 0,
+		.blksz = 0,
+		.init_fn = git_hash_unknown_init,
+		.clone_fn = git_hash_unknown_clone,
+		.update_fn = git_hash_unknown_update,
+		.final_fn = git_hash_unknown_final,
+		.final_oid_fn = git_hash_unknown_final_oid,
+		.empty_tree = NULL,
+		.empty_blob = NULL,
+		.null_oid = NULL,
 	},
 	{
-		"sha1",
-		GIT_SHA1_FORMAT_ID,
-		GIT_SHA1_RAWSZ,
-		GIT_SHA1_HEXSZ,
-		GIT_SHA1_BLKSZ,
-		git_hash_sha1_init,
-		git_hash_sha1_clone,
-		git_hash_sha1_update,
-		git_hash_sha1_final,
-		git_hash_sha1_final_oid,
-		&empty_tree_oid,
-		&empty_blob_oid,
-		&null_oid_sha1,
+		.name = "sha1",
+		.format_id = GIT_SHA1_FORMAT_ID,
+		.rawsz = GIT_SHA1_RAWSZ,
+		.hexsz = GIT_SHA1_HEXSZ,
+		.blksz = GIT_SHA1_BLKSZ,
+		.init_fn = git_hash_sha1_init,
+		.clone_fn = git_hash_sha1_clone,
+		.update_fn = git_hash_sha1_update,
+		.final_fn = git_hash_sha1_final,
+		.final_oid_fn = git_hash_sha1_final_oid,
+		.empty_tree = &empty_tree_oid,
+		.empty_blob = &empty_blob_oid,
+		.null_oid = &null_oid_sha1,
 	},
 	{
-		"sha256",
-		GIT_SHA256_FORMAT_ID,
-		GIT_SHA256_RAWSZ,
-		GIT_SHA256_HEXSZ,
-		GIT_SHA256_BLKSZ,
-		git_hash_sha256_init,
-		git_hash_sha256_clone,
-		git_hash_sha256_update,
-		git_hash_sha256_final,
-		git_hash_sha256_final_oid,
-		&empty_tree_oid_sha256,
-		&empty_blob_oid_sha256,
-		&null_oid_sha256,
+		.name = "sha256",
+		.format_id = GIT_SHA256_FORMAT_ID,
+		.rawsz = GIT_SHA256_RAWSZ,
+		.hexsz = GIT_SHA256_HEXSZ,
+		.blksz = GIT_SHA256_BLKSZ,
+		.init_fn = git_hash_sha256_init,
+		.clone_fn = git_hash_sha256_clone,
+		.update_fn = git_hash_sha256_update,
+		.final_fn = git_hash_sha256_final,
+		.final_oid_fn = git_hash_sha256_final_oid,
+		.empty_tree = &empty_tree_oid_sha256,
+		.empty_blob = &empty_blob_oid_sha256,
+		.null_oid = &null_oid_sha256,
 	}
 };
 
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 07/12] archive-*.c: use designated initializers for "struct archiver"
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (5 preceding siblings ...)
  2022-02-24  9:33 ` [PATCH 06/12] object-file: use designated initializers for "struct git_hash_algo" Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:33 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:33 ` [PATCH 08/12] userdiff.c: use designated initializers for "struct userdiff_driver" Ævar Arnfjörð Bjarmason
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:33 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 archive-tar.c | 6 +++---
 archive-zip.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/archive-tar.c b/archive-tar.c
index 3c74db17468..042feb66d28 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -461,9 +461,9 @@ static int write_tar_filter_archive(const struct archiver *ar,
 }
 
 static struct archiver tar_archiver = {
-	"tar",
-	write_tar_archive,
-	ARCHIVER_REMOTE
+	.name = "tar",
+	.write_archive = write_tar_archive,
+	.flags = ARCHIVER_REMOTE,
 };
 
 void init_tar_archiver(void)
diff --git a/archive-zip.c b/archive-zip.c
index 2961e01c754..90fe99eaaed 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -637,9 +637,9 @@ static int write_zip_archive(const struct archiver *ar,
 }
 
 static struct archiver zip_archiver = {
-	"zip",
-	write_zip_archive,
-	ARCHIVER_WANT_COMPRESSION_LEVELS|ARCHIVER_REMOTE
+	.name = "zip",
+	.write_archive = write_zip_archive,
+	.flags = ARCHIVER_WANT_COMPRESSION_LEVELS|ARCHIVER_REMOTE,
 };
 
 void init_zip_archiver(void)
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 08/12] userdiff.c: use designated initializers for "struct userdiff_driver"
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (6 preceding siblings ...)
  2022-02-24  9:33 ` [PATCH 07/12] archive-*.c: use designated initializers for "struct archiver" Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:33 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:33 ` [PATCH 09/12] convert.c: use designated initializers for "struct stream_filter*" Ævar Arnfjörð Bjarmason
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:33 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

Change the "struct userdiff_driver" assignmentns to use designated
initializers, but let's keep the PATTERNS() and IPATTERN() convenience
macros to avoid churn, but have them defined in terms of designated
initializers.

For the "driver_true" and "driver_false" let's have the compiler
implicitly initialize most of the fields, but let's leave a redundant
".binary = 0" for "driver_true" to make it obvious that it's the
opposite of the the ".binary = 1" for "driver_false".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 userdiff.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/userdiff.c b/userdiff.c
index 8578cb0d12e..2d9eb99bf28 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -7,12 +7,24 @@ static struct userdiff_driver *drivers;
 static int ndrivers;
 static int drivers_alloc;
 
-#define PATTERNS(name, pattern, word_regex)			\
-	{ name, NULL, -1, { pattern, REG_EXTENDED },		\
-	  word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
-#define IPATTERN(name, pattern, word_regex)			\
-	{ name, NULL, -1, { pattern, REG_EXTENDED | REG_ICASE }, \
-	  word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
+#define PATTERNS(lang, rx, wrx) { \
+	.name = lang, \
+	.binary = -1, \
+	.funcname = { \
+		.pattern = rx, \
+		.cflags = REG_EXTENDED, \
+	}, \
+	.word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
+}
+#define IPATTERN(lang, rx, wrx) { \
+	.name = lang, \
+	.binary = -1, \
+	.funcname = { \
+		.pattern = rx, \
+		.cflags = REG_EXTENDED | REG_ICASE, \
+	}, \
+	.word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
+}
 
 /*
  * Built-in drivers for various languages, sorted by their names
@@ -275,17 +287,13 @@ PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
 #undef IPATTERN
 
 static struct userdiff_driver driver_true = {
-	"diff=true",
-	NULL,
-	0,
-	{ NULL, 0 }
+	.name = "diff=true",
+	.binary = 0,
 };
 
 static struct userdiff_driver driver_false = {
-	"!diff",
-	NULL,
-	1,
-	{ NULL, 0 }
+	.name = "!diff",
+	.binary = 1,
 };
 
 struct find_by_namelen_data {
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 09/12] convert.c: use designated initializers for "struct stream_filter*"
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (7 preceding siblings ...)
  2022-02-24  9:33 ` [PATCH 08/12] userdiff.c: use designated initializers for "struct userdiff_driver" Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:33 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:33 ` [PATCH 10/12] refspec.c: use designated initializers for "struct refspec_item" Ævar Arnfjörð Bjarmason
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:33 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

Change the "struct stream_filter_vtbl" and "struct stream_filter"
assignments in convert.c to use designated initializers.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 convert.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/convert.c b/convert.c
index df7186bd813..3d53a75a784 100644
--- a/convert.c
+++ b/convert.c
@@ -1574,12 +1574,12 @@ static void null_free_fn(struct stream_filter *filter)
 }
 
 static struct stream_filter_vtbl null_vtbl = {
-	null_filter_fn,
-	null_free_fn,
+	.filter = null_filter_fn,
+	.free = null_free_fn,
 };
 
 static struct stream_filter null_filter_singleton = {
-	&null_vtbl,
+	.vtbl = &null_vtbl,
 };
 
 int is_null_stream_filter(struct stream_filter *filter)
@@ -1683,8 +1683,8 @@ static void lf_to_crlf_free_fn(struct stream_filter *filter)
 }
 
 static struct stream_filter_vtbl lf_to_crlf_vtbl = {
-	lf_to_crlf_filter_fn,
-	lf_to_crlf_free_fn,
+	.filter = lf_to_crlf_filter_fn,
+	.free = lf_to_crlf_free_fn,
 };
 
 static struct stream_filter *lf_to_crlf_filter(void)
@@ -1779,8 +1779,8 @@ static void cascade_free_fn(struct stream_filter *filter)
 }
 
 static struct stream_filter_vtbl cascade_vtbl = {
-	cascade_filter_fn,
-	cascade_free_fn,
+	.filter = cascade_filter_fn,
+	.free = cascade_free_fn,
 };
 
 static struct stream_filter *cascade_filter(struct stream_filter *one,
@@ -1931,8 +1931,8 @@ static void ident_free_fn(struct stream_filter *filter)
 }
 
 static struct stream_filter_vtbl ident_vtbl = {
-	ident_filter_fn,
-	ident_free_fn,
+	.filter = ident_filter_fn,
+	.free = ident_free_fn,
 };
 
 static struct stream_filter *ident_filter(const struct object_id *oid)
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 10/12] refspec.c: use designated initializers for "struct refspec_item"
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (8 preceding siblings ...)
  2022-02-24  9:33 ` [PATCH 09/12] convert.c: use designated initializers for "struct stream_filter*" Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:33 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:33 ` [PATCH 11/12] misc *.c: use designated initializers for struct assignments Ævar Arnfjörð Bjarmason
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:33 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

Change the "struct refspec_item" at the top of refspec.c to use
designated initializers. Let's keep the "= 0" assignments for
self-documentation purposes, even though they're now redundant.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 refspec.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/refspec.c b/refspec.c
index e3d852c0bfe..63e3112104a 100644
--- a/refspec.c
+++ b/refspec.c
@@ -4,13 +4,13 @@
 #include "refspec.h"
 
 static struct refspec_item s_tag_refspec = {
-	0,
-	1,
-	0,
-	0,
-	0,
-	"refs/tags/*",
-	"refs/tags/*"
+	.force = 0,
+	.pattern = 1,
+	.matching = 0,
+	.exact_sha1 = 0,
+	.negative = 0,
+	.src = "refs/tags/*",
+	.dst = "refs/tags/*",
 };
 
 /* See TAG_REFSPEC for the string version */
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 11/12] misc *.c: use designated initializers for struct assignments
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (9 preceding siblings ...)
  2022-02-24  9:33 ` [PATCH 10/12] refspec.c: use designated initializers for "struct refspec_item" Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:33 ` Ævar Arnfjörð Bjarmason
  2022-02-24  9:33 ` [PATCH 12/12] misc *.c: use designated initializers for "partial" " Ævar Arnfjörð Bjarmason
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:33 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

Change a few miscellaneous non-designated initializer assignments to
use designated initializers.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 attr.c        | 2 +-
 notes-merge.c | 1 +
 object-file.c | 9 +++++----
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/attr.c b/attr.c
index 79adaa50ea1..9ad12578cce 100644
--- a/attr.c
+++ b/attr.c
@@ -80,7 +80,7 @@ static int attr_hash_entry_cmp(const void *unused_cmp_data,
  * Access to this dictionary must be surrounded with a mutex.
  */
 static struct attr_hashmap g_attr_hashmap = {
-	HASHMAP_INIT(attr_hash_entry_cmp, NULL)
+	.map = HASHMAP_INIT(attr_hash_entry_cmp, NULL),
 };
 
 /*
diff --git a/notes-merge.c b/notes-merge.c
index 01d596920ea..d749af1ab8b 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -113,6 +113,7 @@ static struct notes_merge_pair *find_notes_merge_pair_pos(
 }
 
 static struct object_id uninitialized = {
+	.hash =
 	"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" \
 	"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
 };
diff --git a/object-file.c b/object-file.c
index 03bd6a3baf3..5074471b471 100644
--- a/object-file.c
+++ b/object-file.c
@@ -274,10 +274,11 @@ static struct cached_object {
 static int cached_object_nr, cached_object_alloc;
 
 static struct cached_object empty_tree = {
-	{ EMPTY_TREE_SHA1_BIN_LITERAL },
-	OBJ_TREE,
-	"",
-	0
+	.oid = {
+		.hash = EMPTY_TREE_SHA1_BIN_LITERAL,
+	},
+	.type = OBJ_TREE,
+	.buf = "",
 };
 
 static struct cached_object *find_cached_object(const struct object_id *oid)
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 12/12] misc *.c: use designated initializers for "partial" struct assignments
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (10 preceding siblings ...)
  2022-02-24  9:33 ` [PATCH 11/12] misc *.c: use designated initializers for struct assignments Ævar Arnfjörð Bjarmason
@ 2022-02-24  9:33 ` Ævar Arnfjörð Bjarmason
  2022-02-24 19:22 ` [PATCH 00/12] c99: use more designated initializers Johannes Schindelin
  2022-02-25  0:03 ` Junio C Hamano
  13 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24  9:33 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Martin Ågren,
	Ævar Arnfjörð Bjarmason

Change a few existing non-designated initializer assignments to use
"partial" designated initializer assignments. I.e. we're now omitting
the "NULL" or "0" fields and letting the initializer take care of them
for us.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/fast-import.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 2b2e28bad79..2c244c68f7e 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -176,8 +176,9 @@ static int global_argc;
 static const char **global_argv;
 
 /* Memory pools */
-static struct mem_pool fi_mem_pool =  {NULL, 2*1024*1024 -
-				       sizeof(struct mp_block), 0 };
+static struct mem_pool fi_mem_pool = {
+	.block_alloc = 2*1024*1024 - sizeof(struct mp_block),
+};
 
 /* Atom management */
 static unsigned int atom_table_sz = 4451;
@@ -205,7 +206,9 @@ static int import_marks_file_done;
 static int relative_marks_paths;
 
 /* Our last blob */
-static struct last_object last_blob = { STRBUF_INIT, 0, 0, 0 };
+static struct last_object last_blob = {
+	.data = STRBUF_INIT,
+ };
 
 /* Tree management */
 static unsigned int tree_entry_alloc = 1000;
@@ -231,7 +234,10 @@ static struct tag *last_tag;
 static whenspec_type whenspec = WHENSPEC_RAW;
 static struct strbuf command_buf = STRBUF_INIT;
 static int unread_command_buf;
-static struct recent_command cmd_hist = {&cmd_hist, &cmd_hist, NULL};
+static struct recent_command cmd_hist = {
+	.prev = &cmd_hist,
+	.next = &cmd_hist,
+};
 static struct recent_command *cmd_tail = &cmd_hist;
 static struct recent_command *rc_free;
 static unsigned int cmd_save = 100;
-- 
2.35.1.1157.g524e2d5a0db


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 00/12] c99: use more designated initializers
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (11 preceding siblings ...)
  2022-02-24  9:33 ` [PATCH 12/12] misc *.c: use designated initializers for "partial" " Ævar Arnfjörð Bjarmason
@ 2022-02-24 19:22 ` Johannes Schindelin
  2022-02-24 19:53   ` Junio C Hamano
  2022-02-25  0:03 ` Junio C Hamano
  13 siblings, 1 reply; 17+ messages in thread
From: Johannes Schindelin @ 2022-02-24 19:22 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Martin Ågren

[-- Attachment #1: Type: text/plain, Size: 872 bytes --]

Hi Ævar,

On Thu, 24 Feb 2022, Ævar Arnfjörð Bjarmason wrote:

> A follow-up to 404c4a54624 (Merge branch 'ab/designated-initializers',
> 2021-10-11) and a4b9fb6a5cf (Merge branch
> 'ab/designated-initializers-more', 2021-10-18). These code readability
> improvements are something we can allow ourselves now that we have a
> hard dependency on C99.

This is probably a bit premature given that we still are treating the
C99-isms as weather balloons. The idea was to keep things in an
easily-revertable state for at least a couple of major versions.

The referenced changes are only in core Git as of v2.34.0, and we are not
even half-way through the v2.36.0 cycle.

Do not get me wrong, I have nothing against this living in `seen` for now,
but it should wait before it advances, probably at least until v2.36.0 if
not v2.37.0.

Ciao,
Johannes

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 00/12] c99: use more designated initializers
  2022-02-24 19:22 ` [PATCH 00/12] c99: use more designated initializers Johannes Schindelin
@ 2022-02-24 19:53   ` Junio C Hamano
  2022-02-24 22:43     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 17+ messages in thread
From: Junio C Hamano @ 2022-02-24 19:53 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Ævar Arnfjörð Bjarmason, git, Martin Ågren

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> This is probably a bit premature given that we still are treating the
> C99-isms as weather balloons. The idea was to keep things in an
> easily-revertable state for at least a couple of major versions.
>
> The referenced changes are only in core Git as of v2.34.0, and we are not
> even half-way through the v2.36.0 cycle.

The proposed commit log messages need updating.  By refering to much
newer commits created by the same author, instead of the beginning
of the official weather balloon experiments, it created an unnecessary
confusion.

Read the CodingGuidelines document.  Everybody knows what it says by
heart by now, right? ;-)

   . since mid 2017 with cbc0f81d, we have been using designated
     initializers for struct (e.g. "struct t v = { .val = 'a' };").

   . since mid 2017 with 512f41cf, we have been using designated
     initializers for array (e.g. "int array[10] = { [5] = 2 }").

I do not think doing this in early 2022 is still premature.

I hate to having to deal with such a tree-wide churn, though.  I'd
rather see "let's do this only on quiescent part of the tree a small
bit at a time" like on imap-send.c but not involving anything known
to be actively touched, like ref backends.

Thanks.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 00/12] c99: use more designated initializers
  2022-02-24 19:53   ` Junio C Hamano
@ 2022-02-24 22:43     ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 17+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-24 22:43 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git, Martin Ågren


On Thu, Feb 24 2022, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
>> This is probably a bit premature given that we still are treating the
>> C99-isms as weather balloons. The idea was to keep things in an
>> easily-revertable state for at least a couple of major versions.
>>
>> The referenced changes are only in core Git as of v2.34.0, and we are not
>> even half-way through the v2.36.0 cycle.
>
> The proposed commit log messages need updating.  By refering to much
> newer commits created by the same author, instead of the beginning
> of the official weather balloon experiments, it created an unnecessary
> confusion.
>
> Read the CodingGuidelines document.  Everybody knows what it says by
> heart by now, right? ;-)
>
>    . since mid 2017 with cbc0f81d, we have been using designated
>      initializers for struct (e.g. "struct t v = { .val = 'a' };").
>
>    . since mid 2017 with 512f41cf, we have been using designated
>      initializers for array (e.g. "int array[10] = { [5] = 2 }").
>
> I do not think doing this in early 2022 is still premature.

It's hard sometimes to anticipate what'll be the best reference. I
figured linking to similar recent tree-wide changes would make it easier
for reviewers to shortcut to "oh, we had similar tree-wide changes
recently, so this is OK too".

As opposed to referencing the initial forays into designated
initializers, which wouldn't provide the same overview of how tree-wide
this pattern already is at a glance.

But sure, I can mention that more prominently/discuss both.

> I hate to having to deal with such a tree-wide churn, though.  I'd
> rather see "let's do this only on quiescent part of the tree a small
> bit at a time" like on imap-send.c but not involving anything known
> to be actively touched, like ref backends.

While these are tree-wide, I don't think you'll have any trouble with
them, including the ones touching the refs backend.

We're anticipating the final bits of the reftable integration, which
will add another declaration like the one in 2/12, but that won't
conflict with these modifications of the existing assignment.

Of course such a change might also want to use designated initializers
to match, but that would have been a good idea anyway for new code
regardless of whether this series got merged or not.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 00/12] c99: use more designated initializers
  2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
                   ` (12 preceding siblings ...)
  2022-02-24 19:22 ` [PATCH 00/12] c99: use more designated initializers Johannes Schindelin
@ 2022-02-25  0:03 ` Junio C Hamano
  13 siblings, 0 replies; 17+ messages in thread
From: Junio C Hamano @ 2022-02-25  0:03 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git, Martin Ågren

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Ævar Arnfjörð Bjarmason (12):
>   imap-send.c: use designated initializers for "struct imap_server_conf"
>   refs: use designated initializers for "struct ref_storage_be"
>   refs: use designated initializers for "struct ref_iterator_vtable"
>   trace2: use designated initializers for "struct tr2_tgt"
>   trace2: use designated initializers for "struct tr2_dst"
>   object-file: use designated initializers for "struct git_hash_algo"
>   archive-*.c: use designated initializers for "struct archiver"
>   userdiff.c: use designated initializers for "struct userdiff_driver"
>   convert.c: use designated initializers for "struct stream_filter*"
>   refspec.c: use designated initializers for "struct refspec_item"
>   misc *.c: use designated initializers for struct assignments
>   misc *.c: use designated initializers for "partial" struct assignments

These patches touch really dormant parts so let's apply them and
immediately merge to 'next' and down to 'master' by the end of
month.  I really hate these non-urgent changes that might help
future code to be in flight for too long.

 imap-send.c: use designated initializers for "struct imap_server_conf"
 trace2: use designated initializers for "struct tr2_tgt"
 trace2: use designated initializers for "struct tr2_dst"
 object-file: use designated initializers for "struct git_hash_algo"
 archive-*.c: use designated initializers for "struct archiver"
 userdiff.c: use designated initializers for "struct userdiff_driver"
 convert.c: use designated initializers for "struct stream_filter*"
 refspec.c: use designated initializers for "struct refspec_item"
 fast-import.c: use designated initializers for "partial" struct assignments

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2022-02-25  0:03 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
2022-02-24  9:32 ` [PATCH 01/12] imap-send.c: use designated initializers for "struct imap_server_conf" Ævar Arnfjörð Bjarmason
2022-02-24  9:32 ` [PATCH 02/12] refs: use designated initializers for "struct ref_storage_be" Ævar Arnfjörð Bjarmason
2022-02-24  9:32 ` [PATCH 03/12] refs: use designated initializers for "struct ref_iterator_vtable" Ævar Arnfjörð Bjarmason
2022-02-24  9:32 ` [PATCH 04/12] trace2: use designated initializers for "struct tr2_tgt" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 05/12] trace2: use designated initializers for "struct tr2_dst" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 06/12] object-file: use designated initializers for "struct git_hash_algo" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 07/12] archive-*.c: use designated initializers for "struct archiver" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 08/12] userdiff.c: use designated initializers for "struct userdiff_driver" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 09/12] convert.c: use designated initializers for "struct stream_filter*" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 10/12] refspec.c: use designated initializers for "struct refspec_item" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 11/12] misc *.c: use designated initializers for struct assignments Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 12/12] misc *.c: use designated initializers for "partial" " Ævar Arnfjörð Bjarmason
2022-02-24 19:22 ` [PATCH 00/12] c99: use more designated initializers Johannes Schindelin
2022-02-24 19:53   ` Junio C Hamano
2022-02-24 22:43     ` Ævar Arnfjörð Bjarmason
2022-02-25  0:03 ` Junio C Hamano

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