builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macro
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Sep 27, 2021 at 14:58 UTC
4eb2bfdc92139f04619be21a354c025747e7ceea
1 file changed
+13
-17
builtin/blame.c
+13
-17
@@ -101,6 +101,16 @@ struct commit_info {
101
struct strbuf summary;
102
};
103
104
+#define COMMIT_INFO_INIT { \
105
+ .author = STRBUF_INIT, \
106
+ .author_mail = STRBUF_INIT, \
107
+ .author_tz = STRBUF_INIT, \
108
+ .committer = STRBUF_INIT, \
109
+ .committer_mail = STRBUF_INIT, \
110
+ .committer_tz = STRBUF_INIT, \
111
+ .summary = STRBUF_INIT, \
112
+}
113
+
114
/*
115
* Parse author/committer line in the commit object buffer
116
*/
@@ -160,18 +170,6 @@ static void get_ac_line(const char *inbuf, const char *what,
170
strbuf_add(name, namebuf, namelen);
171
}
172
163
-static void commit_info_init(struct commit_info *ci)
164
-{
165
-
166
- strbuf_init(&ci->author, 0);
167
- strbuf_init(&ci->author_mail, 0);
168
- strbuf_init(&ci->author_tz, 0);
169
- strbuf_init(&ci->committer, 0);
170
- strbuf_init(&ci->committer_mail, 0);
171
- strbuf_init(&ci->committer_tz, 0);
172
- strbuf_init(&ci->summary, 0);
173
-}
174
-
173
static void commit_info_destroy(struct commit_info *ci)
174
{
175
@@ -192,8 +190,6 @@ static void get_commit_info(struct commit *commit,
190
const char *subject, *encoding;
191
const char *message;
192
195
- commit_info_init(ret);
196
-
193
encoding = get_log_output_encoding();
194
message = logmsg_reencode(commit, NULL, encoding);
195
get_ac_line(message, "\nauthor ",
@@ -246,7 +242,7 @@ static void write_filename_info(struct blame_origin *suspect)
242
*/
243
static int emit_one_suspect_detail(struct blame_origin *suspect, int repeat)
244
{
249
- struct commit_info ci;
245
+ struct commit_info ci = COMMIT_INFO_INIT;
246
247
if (!repeat && (suspect->commit->object.flags & METAINFO_SHOWN))
248
return 0;
@@ -440,7 +436,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
436
int cnt;
437
const char *cp;
438
struct blame_origin *suspect = ent->suspect;
443
- struct commit_info ci;
439
+ struct commit_info ci = COMMIT_INFO_INIT;
440
char hex[GIT_MAX_HEXSZ + 1];
441
int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
442
const char *default_color = NULL, *color = NULL, *reset = NULL;
@@ -630,7 +626,7 @@ static void find_alignment(struct blame_scoreboard *sb, int *option)
626
if (longest_file < num)
627
longest_file = num;
628
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
633
- struct commit_info ci;
629
+ struct commit_info ci = COMMIT_INFO_INIT;
630
suspect->commit->object.flags |= METAINFO_SHOWN;
631
get_commit_info(suspect->commit, &ci, 1);
632
if (*option & OUTPUT_SHOW_EMAIL)