sequencer: honor GIT_REFLOG_ACTION
There is a lot of code to honor GIT_REFLOG_ACTION throughout git, including some in sequencer.c; unfortunately, reflog_message() and its callers ignored it. Instruct reflog_message() to check the existing environment variable, and use it when present as an override to action_name(). Also restructure pick_commits() to only temporarily modify GIT_REFLOG_ACTION for a short duration and then restore the old value, so that when we do this setting within a loop we do not keep adding " (pick)" substrings and end up with a reflog message of the form rebase (pick) (pick) (pick) (finish): returning to refs/heads/master Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Apr 7, 2020 at 16:59 UTC
1f6965f994f8fe2fca80e17b5dbb293d05716be9
2 files changed
+16
-10
sequencer.c
+8
-2
@@ -3708,10 +3708,11 @@ static const char *reflog_message(struct replay_opts *opts,
3708
{
3709
va_list ap;
3710
static struct strbuf buf = STRBUF_INIT;
3711
+ char *reflog_action = getenv(GIT_REFLOG_ACTION);
3712
3713
va_start(ap, fmt);
3714
strbuf_reset(&buf);
3714
- strbuf_addstr(&buf, action_name(opts));
3715
+ strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
3716
if (sub_action)
3717
strbuf_addf(&buf, " (%s)", sub_action);
3718
if (fmt) {
@@ -3799,8 +3800,11 @@ static int pick_commits(struct repository *r,
3800
struct replay_opts *opts)
3801
{
3802
int res = 0, reschedule = 0;
3803
+ char *prev_reflog_action;
3804
3805
+ /* Note that 0 for 3rd parameter of setenv means set only if not set */
3806
setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
3807
+ prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
3808
if (opts->allow_ff)
3809
assert(!(opts->signoff || opts->no_commit ||
3810
opts->record_origin || opts->edit));
@@ -3845,12 +3849,14 @@ static int pick_commits(struct repository *r,
3849
}
3850
if (item->command <= TODO_SQUASH) {
3851
if (is_rebase_i(opts))
3848
- setenv("GIT_REFLOG_ACTION", reflog_message(opts,
3852
+ setenv(GIT_REFLOG_ACTION, reflog_message(opts,
3853
command_to_string(item->command), NULL),
3854
1);
3855
res = do_pick_commit(r, item->command, item->commit,
3856
opts, is_final_fixup(todo_list),
3857
&check_todo);
3858
+ if (is_rebase_i(opts))
3859
+ setenv(GIT_REFLOG_ACTION, prev_reflog_action, 1);
3860
if (is_rebase_i(opts) && res < 0) {
3861
/* Reschedule */
3862
advise(_(rescheduled_advice),
t/t3406-rebase-message.sh
+8
-8
@@ -89,22 +89,22 @@ test_expect_success 'GIT_REFLOG_ACTION' '
89
git checkout -b reflog-topic start &&
90
test_commit reflog-to-rebase &&
91
92
- git rebase --apply reflog-onto &&
92
+ git rebase reflog-onto &&
93
git log -g --format=%gs -3 >actual &&
94
cat >expect <<-\EOF &&
95
- rebase finished: returning to refs/heads/reflog-topic
96
- rebase: reflog-to-rebase
97
- rebase: checkout reflog-onto
95
+ rebase (finish): returning to refs/heads/reflog-topic
96
+ rebase (pick): reflog-to-rebase
97
+ rebase (start): checkout reflog-onto
98
EOF
99
test_cmp expect actual &&
100
101
git checkout -b reflog-prefix reflog-to-rebase &&
102
- GIT_REFLOG_ACTION=change-the-reflog git rebase --apply reflog-onto &&
102
+ GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
103
git log -g --format=%gs -3 >actual &&
104
cat >expect <<-\EOF &&
105
- rebase finished: returning to refs/heads/reflog-prefix
106
- change-the-reflog: reflog-to-rebase
107
- change-the-reflog: checkout reflog-onto
105
+ change-the-reflog (finish): returning to refs/heads/reflog-prefix
106
+ change-the-reflog (pick): reflog-to-rebase
107
+ change-the-reflog (start): checkout reflog-onto
108
EOF
109
test_cmp expect actual
110
'