Skip to content

Commit 0b293df

Browse files
ttaylorrgitster
authored andcommitted
shortlog: make trailer insertion a noop when appropriate
When there are no trailers to insert, it is natural that insert_records_from_trailers() should return without having done any work. But instead we guard this call unnecessarily by first checking whether `log->groups` has the `SHORTLOG_GROUP_TRAILER` bit set. Prepare to match a similar pattern in the future where a function which inserts records of a certain type does no work when no specifiers matching that type are given. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 251554c commit 0b293df

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/shortlog.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ static void insert_records_from_trailers(struct shortlog *log,
170170
const char *commit_buffer, *body;
171171
struct strbuf ident = STRBUF_INIT;
172172

173+
if (!log->trailers.nr)
174+
return;
175+
173176
/*
174177
* Using format_commit_message("%B") would be simpler here, but
175178
* this saves us copying the message.
@@ -240,9 +243,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
240243
strset_add(&dups, ident.buf))
241244
insert_one_record(log, ident.buf, oneline_str);
242245
}
243-
if (log->groups & SHORTLOG_GROUP_TRAILER) {
244-
insert_records_from_trailers(log, &dups, commit, &ctx, oneline_str);
245-
}
246+
insert_records_from_trailers(log, &dups, commit, &ctx, oneline_str);
246247

247248
strset_clear(&dups);
248249
strbuf_release(&ident);

0 commit comments

Comments
 (0)