Skip to content

Commit 4eb2bfd

Browse files
avargitster
authored andcommitted
builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macro
Remove the commit_info_init() function addded in ea02ffa (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6e54a32 commit 4eb2bfd

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

builtin/blame.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ struct commit_info {
101101
struct strbuf summary;
102102
};
103103

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+
104114
/*
105115
* Parse author/committer line in the commit object buffer
106116
*/
@@ -160,18 +170,6 @@ static void get_ac_line(const char *inbuf, const char *what,
160170
strbuf_add(name, namebuf, namelen);
161171
}
162172

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-
175173
static void commit_info_destroy(struct commit_info *ci)
176174
{
177175

@@ -192,8 +190,6 @@ static void get_commit_info(struct commit *commit,
192190
const char *subject, *encoding;
193191
const char *message;
194192

195-
commit_info_init(ret);
196-
197193
encoding = get_log_output_encoding();
198194
message = logmsg_reencode(commit, NULL, encoding);
199195
get_ac_line(message, "\nauthor ",
@@ -246,7 +242,7 @@ static void write_filename_info(struct blame_origin *suspect)
246242
*/
247243
static int emit_one_suspect_detail(struct blame_origin *suspect, int repeat)
248244
{
249-
struct commit_info ci;
245+
struct commit_info ci = COMMIT_INFO_INIT;
250246

251247
if (!repeat && (suspect->commit->object.flags & METAINFO_SHOWN))
252248
return 0;
@@ -440,7 +436,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
440436
int cnt;
441437
const char *cp;
442438
struct blame_origin *suspect = ent->suspect;
443-
struct commit_info ci;
439+
struct commit_info ci = COMMIT_INFO_INIT;
444440
char hex[GIT_MAX_HEXSZ + 1];
445441
int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
446442
const char *default_color = NULL, *color = NULL, *reset = NULL;
@@ -630,7 +626,7 @@ static void find_alignment(struct blame_scoreboard *sb, int *option)
630626
if (longest_file < num)
631627
longest_file = num;
632628
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
633-
struct commit_info ci;
629+
struct commit_info ci = COMMIT_INFO_INIT;
634630
suspect->commit->object.flags |= METAINFO_SHOWN;
635631
get_commit_info(suspect->commit, &ci, 1);
636632
if (*option & OUTPUT_SHOW_EMAIL)

0 commit comments

Comments
 (0)