Skip to content

Commit 9e13136

Browse files
artagnongitster
authored andcommitted
revert: simplify getting commit subject in format_todo()
format_todo() calls get_message(), but uses only the subject line of the commit message. As a minor optimization, save work and unnecessary memory allocations by using find_commit_subject() instead. Also, remove the unnecessary check on cur->item->buffer: the lookup_commit_reference() call in parse_insn_line() has already made sure of this. Suggested-by: Jonathan Nieder <[email protected]> Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Ramkumar Ramachandra <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0db7696 commit 9e13136

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

builtin/revert.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -700,16 +700,16 @@ static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
700700
struct replay_opts *opts)
701701
{
702702
struct commit_list *cur = NULL;
703-
struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
704703
const char *sha1_abbrev = NULL;
705704
const char *action_str = opts->action == REVERT ? "revert" : "pick";
705+
const char *subject;
706+
int subject_len;
706707

707708
for (cur = todo_list; cur; cur = cur->next) {
708709
sha1_abbrev = find_unique_abbrev(cur->item->object.sha1, DEFAULT_ABBREV);
709-
if (get_message(cur->item, &msg))
710-
return error(_("Cannot get commit message for %s"), sha1_abbrev);
711-
strbuf_addf(buf, "%s %s %s\n", action_str, sha1_abbrev, msg.subject);
712-
free_message(&msg);
710+
subject_len = find_commit_subject(cur->item->buffer, &subject);
711+
strbuf_addf(buf, "%s %s %.*s\n", action_str, sha1_abbrev,
712+
subject_len, subject);
713713
}
714714
return 0;
715715
}

0 commit comments

Comments
 (0)