rebase: stop exporting GIT_REFLOG_ACTION

Now that struct replay_opts has a reflog_action member we no longer need to export GIT_REFLOG_ACTION when starting a rebase. If the user has set GIT_REFLOG_ACTION then we use it when initializing reflog_action. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Reviewed-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Phillip Wood committed Nov 9, 2022 at 14:21 UTC 0e34efb31d89a143e42788f26f07e2bf8776a851
1 file changed +15 -12
builtin/rebase.c
+15 -12
@@ -30,8 +30,6 @@
30 #include "reset.h"
31 #include "hook.h"
32
33 -#define DEFAULT_REFLOG_ACTION "rebase"
34 -
33 static char const * const builtin_rebase_usage[] = {
34 N_("git rebase [-i] [options] [--exec <cmd>] "
35 "[--onto <newbase> | --keep-base] [<upstream> [<branch>]]"),
@@ -106,6 +104,7 @@ struct rebase_options {
104 } flags;
105 struct strvec git_am_opts;
106 enum action action;
107 + char *reflog_action;
108 int signoff;
109 int allow_rerere_autoupdate;
110 int keep_empty;
@@ -159,6 +158,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
158 opts->committer_date_is_author_date;
159 replay.ignore_date = opts->ignore_date;
160 replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
161 + replay.reflog_action = xstrdup(opts->reflog_action);
162 if (opts->strategy)
163 replay.strategy = xstrdup_or_null(opts->strategy);
164 else if (!replay.strategy && replay.default_strategy) {
@@ -585,10 +585,10 @@ static int move_to_original_branch(struct rebase_options *opts)
585 BUG("move_to_original_branch without onto");
586
587 strbuf_addf(&branch_reflog, "%s (finish): %s onto %s",
588 - getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
588 + opts->reflog_action,
589 opts->head_name, oid_to_hex(&opts->onto->object.oid));
590 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);
592 ropts.branch = opts->head_name;
593 ropts.flags = RESET_HEAD_REFS_ONLY;
594 ropts.branch_msg = branch_reflog.buf;
@@ -618,7 +618,7 @@ static int run_am(struct rebase_options *opts)
618 am.git_cmd = 1;
619 strvec_push(&am.args, "am");
620 strvec_pushf(&am.env, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)",
621 - getenv(GIT_REFLOG_ACTION_ENVIRONMENT));
621 + opts->reflog_action);
622 if (opts->action == ACTION_CONTINUE) {
623 strvec_push(&am.args, "--resolved");
624 strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
@@ -685,7 +685,7 @@ static int run_am(struct rebase_options *opts)
685
686 ropts.oid = &opts->orig_head->object.oid;
687 ropts.branch = opts->head_name;
688 - ropts.default_reflog_action = DEFAULT_REFLOG_ACTION;
688 + ropts.default_reflog_action = opts->reflog_action;
689 reset_head(the_repository, &ropts);
690 error(_("\ngit encountered an error while preparing the "
691 "patches to replay\n"
@@ -834,8 +834,7 @@ static int checkout_up_to_date(struct rebase_options *options)
834 int ret = 0;
835
836 strbuf_addf(&buf, "%s: checkout %s",
837 - getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
838 - options->switch_to);
837 + options->reflog_action, options->switch_to);
838 ropts.oid = &options->orig_head->object.oid;
839 ropts.branch = options->head_name;
840 ropts.flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
@@ -1243,7 +1242,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1242
1243 if (options.action != ACTION_NONE && !in_progress)
1244 die(_("No rebase in progress?"));
1246 - setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
1245
1246 if (options.action == ACTION_EDIT_TODO && !is_merge(&options))
1247 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)
1256 trace2_cmd_mode(action_names[options.action]);
1257 }
1258
1259 + options.reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
1260 + options.reflog_action =
1261 + xstrdup(options.reflog_action ? options.reflog_action : "rebase");
1262 +
1263 switch (options.action) {
1264 case ACTION_CONTINUE: {
1265 struct object_id head;
@@ -1310,7 +1312,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1312 exit(1);
1313
1314 strbuf_addf(&head_msg, "%s (abort): returning to %s",
1313 - getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
1315 + options.reflog_action,
1316 options.head_name ? options.head_name
1317 : oid_to_hex(&options.orig_head->object.oid));
1318 ropts.oid = &options.orig_head->object.oid;
@@ -1786,13 +1788,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1788 "it...\n"));
1789
1790 strbuf_addf(&msg, "%s (start): checkout %s",
1789 - getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
1791 + options.reflog_action, options.onto_name);
1792 ropts.oid = &options.onto->object.oid;
1793 ropts.orig_head = &options.orig_head->object.oid,
1794 ropts.flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD |
1795 RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
1796 ropts.head_msg = msg.buf;
1795 - ropts.default_reflog_action = DEFAULT_REFLOG_ACTION;
1797 + ropts.default_reflog_action = options.reflog_action;
1798 if (reset_head(the_repository, &ropts))
1799 die(_("Could not detach HEAD"));
1800 strbuf_release(&msg);
@@ -1824,6 +1826,7 @@ run_rebase:
1826 cleanup:
1827 strbuf_release(&buf);
1828 strbuf_release(&revisions);
1829 + free(options.reflog_action);
1830 free(options.head_name);
1831 free(options.gpg_sign_opt);
1832 free(options.cmd);