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