All of lore.kernel.org
 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>,
	"Phillip Wood" <phillip.wood123@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 2/5] builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macro
Date: Mon, 27 Sep 2021 14:58:42 +0200	[thread overview]
Message-ID: <patch-v2-2.5-65c5295c1ac-20210927T125715Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v2-0.5-00000000000-20210927T125715Z-avarab@gmail.com>

Remove the commit_info_init() function addded in ea02ffa3857 (mailmap:
simplify map_user() interface, 2013-01-05) and instead initialize the
"struct commit_info" with a macro.

This is the more idiomatic pattern in the codebase, and doesn't leave
us wondering when we see the *_init() function if this struct needs
more complex initialization than a macro can provide.

The get_commit_info() function is only called by the three callers
being changed here immediately after initializing the struct with the
macros, so by moving the initialization to the callers we don't need
to do it in get_commit_info() anymore.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/blame.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 641523ff9af..1c31a996403 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -101,6 +101,16 @@ struct commit_info {
 	struct strbuf summary;
 };
 
+#define COMMIT_INFO_INIT { \
+	.author = STRBUF_INIT, \
+	.author_mail = STRBUF_INIT, \
+	.author_tz = STRBUF_INIT, \
+	.committer = STRBUF_INIT, \
+	.committer_mail = STRBUF_INIT, \
+	.committer_tz = STRBUF_INIT, \
+	.summary = STRBUF_INIT, \
+}
+
 /*
  * Parse author/committer line in the commit object buffer
  */
@@ -160,18 +170,6 @@ static void get_ac_line(const char *inbuf, const char *what,
 	strbuf_add(name, namebuf, namelen);
 }
 
-static void commit_info_init(struct commit_info *ci)
-{
-
-	strbuf_init(&ci->author, 0);
-	strbuf_init(&ci->author_mail, 0);
-	strbuf_init(&ci->author_tz, 0);
-	strbuf_init(&ci->committer, 0);
-	strbuf_init(&ci->committer_mail, 0);
-	strbuf_init(&ci->committer_tz, 0);
-	strbuf_init(&ci->summary, 0);
-}
-
 static void commit_info_destroy(struct commit_info *ci)
 {
 
@@ -192,8 +190,6 @@ static void get_commit_info(struct commit *commit,
 	const char *subject, *encoding;
 	const char *message;
 
-	commit_info_init(ret);
-
 	encoding = get_log_output_encoding();
 	message = logmsg_reencode(commit, NULL, encoding);
 	get_ac_line(message, "\nauthor ",
@@ -246,7 +242,7 @@ static void write_filename_info(struct blame_origin *suspect)
  */
 static int emit_one_suspect_detail(struct blame_origin *suspect, int repeat)
 {
-	struct commit_info ci;
+	struct commit_info ci = COMMIT_INFO_INIT;
 
 	if (!repeat && (suspect->commit->object.flags & METAINFO_SHOWN))
 		return 0;
@@ -440,7 +436,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
 	int cnt;
 	const char *cp;
 	struct blame_origin *suspect = ent->suspect;
-	struct commit_info ci;
+	struct commit_info ci = COMMIT_INFO_INIT;
 	char hex[GIT_MAX_HEXSZ + 1];
 	int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
 	const char *default_color = NULL, *color = NULL, *reset = NULL;
@@ -630,7 +626,7 @@ static void find_alignment(struct blame_scoreboard *sb, int *option)
 		if (longest_file < num)
 			longest_file = num;
 		if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
-			struct commit_info ci;
+			struct commit_info ci = COMMIT_INFO_INIT;
 			suspect->commit->object.flags |= METAINFO_SHOWN;
 			get_commit_info(suspect->commit, &ci, 1);
 			if (*option & OUTPUT_SHOW_EMAIL)
-- 
2.33.0.1316.gb2e9b3ba3ae


  parent reply	other threads:[~2021-09-27 12:58 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27  0:53 [PATCH 0/6] Non-trivial designated initializer conversion Ævar Arnfjörð Bjarmason
2021-09-27  0:53 ` [PATCH 1/6] daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macro Ævar Arnfjörð Bjarmason
2021-09-27  0:53 ` [PATCH 2/6] builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macro Ævar Arnfjörð Bjarmason
2021-09-27  0:53 ` [PATCH 3/6] shortlog: use designated initializer for "struct shortlog" Ævar Arnfjörð Bjarmason
2021-09-27  9:06   ` Phillip Wood
2021-09-27 10:52     ` Ævar Arnfjörð Bjarmason
2021-09-27  0:53 ` [PATCH 4/6] urlmatch.[ch]: add and use URLMATCH_CONFIG_INIT Ævar Arnfjörð Bjarmason
2021-09-27  0:53 ` [PATCH 5/6] builtin/remote.c: add and use a REF_STATES_INIT Ævar Arnfjörð Bjarmason
2021-09-27  0:53 ` [PATCH 6/6] builtin/remote.c: add and use SHOW_INFO_INIT Ævar Arnfjörð Bjarmason
2021-09-27 12:58 ` [PATCH v2 0/5] Non-trivial designated initializer conversion Ævar Arnfjörð Bjarmason
2021-09-27 12:58   ` [PATCH v2 1/5] daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macro Ævar Arnfjörð Bjarmason
2021-09-27 12:58   ` Ævar Arnfjörð Bjarmason [this message]
2021-09-27 12:58   ` [PATCH v2 3/5] urlmatch.[ch]: add and use URLMATCH_CONFIG_INIT Ævar Arnfjörð Bjarmason
2021-09-27 22:12     ` Junio C Hamano
2021-09-27 12:58   ` [PATCH v2 4/5] builtin/remote.c: add and use a REF_STATES_INIT Ævar Arnfjörð Bjarmason
2021-09-27 23:04     ` Junio C Hamano
2021-09-27 23:38       ` Ævar Arnfjörð Bjarmason
2021-09-27 23:56         ` Junio C Hamano
2021-09-27 12:58   ` [PATCH v2 5/5] builtin/remote.c: add and use SHOW_INFO_INIT Ævar Arnfjörð Bjarmason
2021-10-01 10:27   ` [PATCH v3 0/6] Non-trivial designated initializer conversion Ævar Arnfjörð Bjarmason
2021-10-01 10:27     ` [PATCH v3 1/6] daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macro Ævar Arnfjörð Bjarmason
2021-10-01 10:27     ` [PATCH v3 2/6] builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macro Ævar Arnfjörð Bjarmason
2021-10-01 10:27     ` [PATCH v3 3/6] urlmatch.[ch]: add and use URLMATCH_CONFIG_INIT Ævar Arnfjörð Bjarmason
2021-10-01 10:27     ` [PATCH v3 4/6] builtin/remote.c: add and use a REF_STATES_INIT Ævar Arnfjörð Bjarmason
2021-10-01 10:27     ` [PATCH v3 5/6] builtin/remote.c: add and use SHOW_INFO_INIT Ævar Arnfjörð Bjarmason
2021-10-01 10:27     ` [PATCH v3 6/6] unpack-trees.[ch]: define and use a UNPACK_TREES_OPTIONS_INIT Ævar Arnfjörð Bjarmason
2021-10-01 21:39       ` Junio C Hamano
2021-10-02 20:16     ` [PATCH v4 0/5] Non-trivial designated initializer conversion Ævar Arnfjörð Bjarmason
2021-10-02 20:16       ` [PATCH v4 1/5] daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macro Ævar Arnfjörð Bjarmason
2021-10-02 20:16       ` [PATCH v4 2/5] builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macro Ævar Arnfjörð Bjarmason
2021-10-02 20:16       ` [PATCH v4 3/5] urlmatch.[ch]: add and use URLMATCH_CONFIG_INIT Ævar Arnfjörð Bjarmason
2021-10-02 20:16       ` [PATCH v4 4/5] builtin/remote.c: add and use a REF_STATES_INIT Ævar Arnfjörð Bjarmason
2021-10-02 20:16       ` [PATCH v4 5/5] builtin/remote.c: add and use SHOW_INFO_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-v2-2.5-65c5295c1ac-20210927T125715Z-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 \
    --cc=phillip.wood123@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.