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>
Johannes Schindelin committed
Jan 2, 2017 at 16:28 UTC
96e832a5fd6a97f8d40d89d4c1e97e7e3534edf0
1 file changed
+26
-7
sequencer.c
+26
-7
@@ -1743,6 +1743,26 @@ static int is_final_fixup(struct todo_list *todo_list)
1743
return 1;
1744
}
1745
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
+
1766
static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
1767
{
1768
int res = 0;
@@ -1810,6 +1830,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
1830
1831
if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
1832
starts_with(head_ref.buf, "refs/")) {
1833
+ const char *msg;
1834
unsigned char head[20], orig[20];
1835
int res;
1836
@@ -1825,23 +1846,21 @@ cleanup_head_ref:
1846
res = error(_("could not read orig-head"));
1847
goto cleanup_head_ref;
1848
}
1828
- strbuf_addf(&buf, "rebase -i (finish): %s onto ",
1829
- head_ref.buf);
1849
if (!read_oneliner(&buf, rebase_path_onto(), 0)) {
1850
res = error(_("could not read 'onto'"));
1851
goto cleanup_head_ref;
1852
}
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,
1856
REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
1857
res = error(_("could not update %s"),
1858
head_ref.buf);
1859
goto cleanup_head_ref;
1860
}
1840
- strbuf_reset(&buf);
1841
- strbuf_addf(&buf,
1842
- "rebase -i (finish): returning to %s",
1861
+ msg = reflog_message(opts, "finish", "returning to %s",
1862
head_ref.buf);
1844
- if (create_symref("HEAD", head_ref.buf, buf.buf)) {
1863
+ if (create_symref("HEAD", head_ref.buf, msg)) {
1864
res = error(_("could not update HEAD to %s"),
1865
head_ref.buf);
1866
goto cleanup_head_ref;