Skip to content

Commit ff84d03

Browse files
committed
Merge branch 'pw/rebase-no-reflog-action'
Avoid setting GIT_REFLOG_ACTION to improve readability of the sequencer internals. * pw/rebase-no-reflog-action: rebase: stop exporting GIT_REFLOG_ACTION sequencer: stop exporting GIT_REFLOG_ACTION
2 parents 4a04f71 + 0e34efb commit ff84d03

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

builtin/rebase.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#include "reset.h"
3131
#include "hook.h"
3232

33-
#define DEFAULT_REFLOG_ACTION "rebase"
34-
3533
static char const * const builtin_rebase_usage[] = {
3634
N_("git rebase [-i] [options] [--exec <cmd>] "
3735
"[--onto <newbase> | --keep-base] [<upstream> [<branch>]]"),
@@ -106,6 +104,7 @@ struct rebase_options {
106104
} flags;
107105
struct strvec git_am_opts;
108106
enum action action;
107+
char *reflog_action;
109108
int signoff;
110109
int allow_rerere_autoupdate;
111110
int keep_empty;
@@ -159,6 +158,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
159158
opts->committer_date_is_author_date;
160159
replay.ignore_date = opts->ignore_date;
161160
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
161+
replay.reflog_action = xstrdup(opts->reflog_action);
162162
if (opts->strategy)
163163
replay.strategy = xstrdup_or_null(opts->strategy);
164164
else if (!replay.strategy && replay.default_strategy) {
@@ -585,10 +585,10 @@ static int move_to_original_branch(struct rebase_options *opts)
585585
BUG("move_to_original_branch without onto");
586586

587587
strbuf_addf(&branch_reflog, "%s (finish): %s onto %s",
588-
getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
588+
opts->reflog_action,
589589
opts->head_name, oid_to_hex(&opts->onto->object.oid));
590590
strbuf_addf(&head_reflog, "%s (finish): returning to %s",
591-
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), opts->head_name);
591+
opts->reflog_action, opts->head_name);
592592
ropts.branch = opts->head_name;
593593
ropts.flags = RESET_HEAD_REFS_ONLY;
594594
ropts.branch_msg = branch_reflog.buf;
@@ -618,7 +618,7 @@ static int run_am(struct rebase_options *opts)
618618
am.git_cmd = 1;
619619
strvec_push(&am.args, "am");
620620
strvec_pushf(&am.env, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)",
621-
getenv(GIT_REFLOG_ACTION_ENVIRONMENT));
621+
opts->reflog_action);
622622
if (opts->action == ACTION_CONTINUE) {
623623
strvec_push(&am.args, "--resolved");
624624
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
@@ -685,7 +685,7 @@ static int run_am(struct rebase_options *opts)
685685

686686
ropts.oid = &opts->orig_head->object.oid;
687687
ropts.branch = opts->head_name;
688-
ropts.default_reflog_action = DEFAULT_REFLOG_ACTION;
688+
ropts.default_reflog_action = opts->reflog_action;
689689
reset_head(the_repository, &ropts);
690690
error(_("\ngit encountered an error while preparing the "
691691
"patches to replay\n"
@@ -834,8 +834,7 @@ static int checkout_up_to_date(struct rebase_options *options)
834834
int ret = 0;
835835

836836
strbuf_addf(&buf, "%s: checkout %s",
837-
getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
838-
options->switch_to);
837+
options->reflog_action, options->switch_to);
839838
ropts.oid = &options->orig_head->object.oid;
840839
ropts.branch = options->head_name;
841840
ropts.flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
@@ -1243,7 +1242,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12431242

12441243
if (options.action != ACTION_NONE && !in_progress)
12451244
die(_("No rebase in progress?"));
1246-
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
12471245

12481246
if (options.action == ACTION_EDIT_TODO && !is_merge(&options))
12491247
die(_("The --edit-todo action can only be used during "
@@ -1258,6 +1256,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12581256
trace2_cmd_mode(action_names[options.action]);
12591257
}
12601258

1259+
options.reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
1260+
options.reflog_action =
1261+
xstrdup(options.reflog_action ? options.reflog_action : "rebase");
1262+
12611263
switch (options.action) {
12621264
case ACTION_CONTINUE: {
12631265
struct object_id head;
@@ -1310,7 +1312,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13101312
exit(1);
13111313

13121314
strbuf_addf(&head_msg, "%s (abort): returning to %s",
1313-
getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
1315+
options.reflog_action,
13141316
options.head_name ? options.head_name
13151317
: oid_to_hex(&options.orig_head->object.oid));
13161318
ropts.oid = &options.orig_head->object.oid;
@@ -1786,13 +1788,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17861788
"it...\n"));
17871789

17881790
strbuf_addf(&msg, "%s (start): checkout %s",
1789-
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
1791+
options.reflog_action, options.onto_name);
17901792
ropts.oid = &options.onto->object.oid;
17911793
ropts.orig_head = &options.orig_head->object.oid,
17921794
ropts.flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD |
17931795
RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
17941796
ropts.head_msg = msg.buf;
1795-
ropts.default_reflog_action = DEFAULT_REFLOG_ACTION;
1797+
ropts.default_reflog_action = options.reflog_action;
17961798
if (reset_head(the_repository, &ropts))
17971799
die(_("Could not detach HEAD"));
17981800
strbuf_release(&msg);
@@ -1824,6 +1826,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
18241826
cleanup:
18251827
strbuf_release(&buf);
18261828
strbuf_release(&revisions);
1829+
free(options.reflog_action);
18271830
free(options.head_name);
18281831
free(options.gpg_sign_opt);
18291832
free(options.cmd);

sequencer.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ int sequencer_remove_state(struct replay_opts *opts)
375375
}
376376

377377
free(opts->gpg_sign);
378+
free(opts->reflog_action);
378379
free(opts->default_strategy);
379380
free(opts->strategy);
380381
for (i = 0; i < opts->xopts_nr; i++)
@@ -1050,6 +1051,8 @@ static int run_git_commit(const char *defmsg,
10501051
gpg_opt, gpg_opt);
10511052
}
10521053

1054+
strvec_pushf(&cmd.env, GIT_REFLOG_ACTION "=%s", opts->reflog_message);
1055+
10531056
if (opts->committer_date_is_author_date)
10541057
strvec_pushf(&cmd.env, "GIT_COMMITTER_DATE=%s",
10551058
opts->ignore_date ?
@@ -1589,8 +1592,8 @@ static int try_to_commit(struct repository *r,
15891592
goto out;
15901593
}
15911594

1592-
if (update_head_with_reflog(current_head, oid,
1593-
getenv("GIT_REFLOG_ACTION"), msg, &err)) {
1595+
if (update_head_with_reflog(current_head, oid, opts->reflog_message,
1596+
msg, &err)) {
15941597
res = error("%s", err.buf);
15951598
goto out;
15961599
}
@@ -3672,17 +3675,28 @@ static int do_label(struct repository *r, const char *name, int len)
36723675
return ret;
36733676
}
36743677

3678+
static const char *sequencer_reflog_action(struct replay_opts *opts)
3679+
{
3680+
if (!opts->reflog_action) {
3681+
opts->reflog_action = getenv(GIT_REFLOG_ACTION);
3682+
opts->reflog_action =
3683+
xstrdup(opts->reflog_action ? opts->reflog_action
3684+
: action_name(opts));
3685+
}
3686+
3687+
return opts->reflog_action;
3688+
}
3689+
36753690
__attribute__((format (printf, 3, 4)))
36763691
static const char *reflog_message(struct replay_opts *opts,
36773692
const char *sub_action, const char *fmt, ...)
36783693
{
36793694
va_list ap;
36803695
static struct strbuf buf = STRBUF_INIT;
3681-
char *reflog_action = getenv(GIT_REFLOG_ACTION);
36823696

36833697
va_start(ap, fmt);
36843698
strbuf_reset(&buf);
3685-
strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
3699+
strbuf_addstr(&buf, sequencer_reflog_action(opts));
36863700
if (sub_action)
36873701
strbuf_addf(&buf, " (%s)", sub_action);
36883702
if (fmt) {
@@ -4502,7 +4516,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,
45024516
RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
45034517
.head_msg = reflog_message(opts, "start", "checkout %s",
45044518
onto_name),
4505-
.default_reflog_action = "rebase"
4519+
.default_reflog_action = sequencer_reflog_action(opts)
45064520
};
45074521
if (reset_head(r, &ropts)) {
45084522
apply_autostash(rebase_path_autostash());
@@ -4571,11 +4585,8 @@ static int pick_commits(struct repository *r,
45714585
struct replay_opts *opts)
45724586
{
45734587
int res = 0, reschedule = 0;
4574-
char *prev_reflog_action;
45754588

4576-
/* Note that 0 for 3rd parameter of setenv means set only if not set */
4577-
setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
4578-
prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
4589+
opts->reflog_message = sequencer_reflog_action(opts);
45794590
if (opts->allow_ff)
45804591
assert(!(opts->signoff || opts->no_commit ||
45814592
opts->record_origin || should_edit(opts) ||
@@ -4623,14 +4634,12 @@ static int pick_commits(struct repository *r,
46234634
}
46244635
if (item->command <= TODO_SQUASH) {
46254636
if (is_rebase_i(opts))
4626-
setenv(GIT_REFLOG_ACTION, reflog_message(opts,
4627-
command_to_string(item->command), NULL),
4628-
1);
4637+
opts->reflog_message = reflog_message(opts,
4638+
command_to_string(item->command), NULL);
4639+
46294640
res = do_pick_commit(r, item, opts,
46304641
is_final_fixup(todo_list),
46314642
&check_todo);
4632-
if (is_rebase_i(opts))
4633-
setenv(GIT_REFLOG_ACTION, prev_reflog_action, 1);
46344643
if (is_rebase_i(opts) && res < 0) {
46354644
/* Reschedule */
46364645
advise(_(rescheduled_advice),
@@ -5053,8 +5062,6 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
50535062
if (read_populate_opts(opts))
50545063
return -1;
50555064
if (is_rebase_i(opts)) {
5056-
char *previous_reflog_action;
5057-
50585065
if ((res = read_populate_todo(r, &todo_list, opts)))
50595066
goto release_todo_list;
50605067

@@ -5065,13 +5072,11 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
50655072
unlink(rebase_path_dropped());
50665073
}
50675074

5068-
previous_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
5069-
setenv(GIT_REFLOG_ACTION, reflog_message(opts, "continue", NULL), 1);
5075+
opts->reflog_message = reflog_message(opts, "continue", NULL);
50705076
if (commit_staged_changes(r, opts, &todo_list)) {
50715077
res = -1;
50725078
goto release_todo_list;
50735079
}
5074-
setenv(GIT_REFLOG_ACTION, previous_reflog_action, 1);
50755080
} else if (!file_exists(get_todo_path(opts)))
50765081
return continue_single_pick(r, opts);
50775082
else if ((res = read_populate_todo(r, &todo_list, opts)))
@@ -5119,7 +5124,7 @@ static int single_pick(struct repository *r,
51195124
TODO_PICK : TODO_REVERT;
51205125
item.commit = cmit;
51215126

5122-
setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
5127+
opts->reflog_message = sequencer_reflog_action(opts);
51235128
return do_pick_commit(r, &item, opts, 0, &check_todo);
51245129
}
51255130

sequencer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ struct replay_opts {
6363
char **xopts;
6464
size_t xopts_nr, xopts_alloc;
6565

66+
/* Reflog */
67+
char *reflog_action;
68+
6669
/* Used by fixup/squash */
6770
struct strbuf current_fixups;
6871
int current_fixup_count;
@@ -73,6 +76,9 @@ struct replay_opts {
7376

7477
/* Only used by REPLAY_NONE */
7578
struct rev_info *revs;
79+
80+
/* Private use */
81+
const char *reflog_message;
7682
};
7783
#define REPLAY_OPTS_INIT { .edit = -1, .action = -1, .current_fixups = STRBUF_INIT }
7884

0 commit comments

Comments
 (0)