Skip to content

Commit 96e832a

Browse files
dschogitster
authored andcommitted
sequencer (rebase -i): refactor setting the reflog message
This makes the code DRYer, with the obvious benefit that we can enhance the code further in a single place. We can also reuse the functionality elsewhere by calling this new function. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent bcbb68b commit 96e832a

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

sequencer.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,26 @@ static int is_final_fixup(struct todo_list *todo_list)
17431743
return 1;
17441744
}
17451745

1746+
static const char *reflog_message(struct replay_opts *opts,
1747+
const char *sub_action, const char *fmt, ...)
1748+
{
1749+
va_list ap;
1750+
static struct strbuf buf = STRBUF_INIT;
1751+
1752+
va_start(ap, fmt);
1753+
strbuf_reset(&buf);
1754+
strbuf_addstr(&buf, action_name(opts));
1755+
if (sub_action)
1756+
strbuf_addf(&buf, " (%s)", sub_action);
1757+
if (fmt) {
1758+
strbuf_addstr(&buf, ": ");
1759+
strbuf_vaddf(&buf, fmt, ap);
1760+
}
1761+
va_end(ap);
1762+
1763+
return buf.buf;
1764+
}
1765+
17461766
static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
17471767
{
17481768
int res = 0;
@@ -1810,6 +1830,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
18101830

18111831
if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
18121832
starts_with(head_ref.buf, "refs/")) {
1833+
const char *msg;
18131834
unsigned char head[20], orig[20];
18141835
int res;
18151836

@@ -1825,23 +1846,21 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
18251846
res = error(_("could not read orig-head"));
18261847
goto cleanup_head_ref;
18271848
}
1828-
strbuf_addf(&buf, "rebase -i (finish): %s onto ",
1829-
head_ref.buf);
18301849
if (!read_oneliner(&buf, rebase_path_onto(), 0)) {
18311850
res = error(_("could not read 'onto'"));
18321851
goto cleanup_head_ref;
18331852
}
1834-
if (update_ref(buf.buf, head_ref.buf, head, orig,
1853+
msg = reflog_message(opts, "finish", "%s onto %s",
1854+
head_ref.buf, buf.buf);
1855+
if (update_ref(msg, head_ref.buf, head, orig,
18351856
REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
18361857
res = error(_("could not update %s"),
18371858
head_ref.buf);
18381859
goto cleanup_head_ref;
18391860
}
1840-
strbuf_reset(&buf);
1841-
strbuf_addf(&buf,
1842-
"rebase -i (finish): returning to %s",
1861+
msg = reflog_message(opts, "finish", "returning to %s",
18431862
head_ref.buf);
1844-
if (create_symref("HEAD", head_ref.buf, buf.buf)) {
1863+
if (create_symref("HEAD", head_ref.buf, msg)) {
18451864
res = error(_("could not update HEAD to %s"),
18461865
head_ref.buf);
18471866
goto cleanup_head_ref;

0 commit comments

Comments
 (0)