Skip to content

Commit 815f534

Browse files
committed
sequencer (rebase -i): refactor setting the reflog message
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 7364756 commit 815f534

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

sequencer.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,26 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset)
16101610
return -1;
16111611
}
16121612

1613+
static const char *reflog_message(struct replay_opts *opts,
1614+
const char *sub_action, const char *fmt, ...)
1615+
{
1616+
va_list ap;
1617+
static struct strbuf buf = STRBUF_INIT;
1618+
1619+
va_start(ap, fmt);
1620+
strbuf_reset(&buf);
1621+
strbuf_addstr(&buf, action_name(opts));
1622+
if (sub_action)
1623+
strbuf_addf(&buf, " (%s)", sub_action);
1624+
if (fmt) {
1625+
strbuf_addstr(&buf, ": ");
1626+
strbuf_vaddf(&buf, fmt, ap);
1627+
}
1628+
va_end(ap);
1629+
1630+
return buf.buf;
1631+
}
1632+
16131633
static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
16141634
{
16151635
int res = 0;
@@ -1678,6 +1698,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
16781698

16791699
if (strbuf_read_file(&head_ref, head_name(), 64) > 0 &&
16801700
starts_with(head_ref.buf, "refs/")) {
1701+
const char *msg;
16811702
unsigned char head[20], orig[20];
16821703

16831704
strbuf_rtrim(&head_ref);
@@ -1686,18 +1707,16 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
16861707
if (strbuf_read_file(&buf, orig_head(), 41) <= 0 ||
16871708
get_sha1_hex(buf.buf, orig))
16881709
return error("Could not read orig-head");
1689-
strbuf_addf(&buf, "rebase -i (finish): %s onto ",
1690-
head_ref.buf);
16911710
strbuf_read_file(&buf, onto(), 64);
1692-
if (update_ref(buf.buf, head_ref.buf, head, orig,
1711+
msg = reflog_message(opts, "finish", "%s onto %s",
1712+
head_ref.buf, buf.buf);
1713+
if (update_ref(msg, head_ref.buf, head, orig,
16931714
REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
16941715
return error("Could not update %s",
16951716
head_ref.buf);
1696-
strbuf_reset(&buf);
1697-
strbuf_addf(&buf,
1698-
"rebase -i (finish): returning to %s",
1717+
msg = reflog_message(opts, "finish", "returning to %s",
16991718
head_ref.buf);
1700-
if (create_symref("HEAD", head_ref.buf, buf.buf))
1719+
if (create_symref("HEAD", head_ref.buf, msg))
17011720
return error("Could not update HEAD to %s",
17021721
head_ref.buf);
17031722
strbuf_reset(&buf);

0 commit comments

Comments
 (0)