@@ -59,6 +59,26 @@ enum empty_type {
59
59
EMPTY_ASK
60
60
};
61
61
62
+ enum action {
63
+ ACTION_NONE = 0 ,
64
+ ACTION_CONTINUE ,
65
+ ACTION_SKIP ,
66
+ ACTION_ABORT ,
67
+ ACTION_QUIT ,
68
+ ACTION_EDIT_TODO ,
69
+ ACTION_SHOW_CURRENT_PATCH
70
+ };
71
+
72
+ static const char * action_names [] = {
73
+ "undefined" ,
74
+ "continue" ,
75
+ "skip" ,
76
+ "abort" ,
77
+ "quit" ,
78
+ "edit_todo" ,
79
+ "show_current_patch"
80
+ };
81
+
62
82
struct rebase_options {
63
83
enum rebase_type type ;
64
84
enum empty_type empty ;
@@ -85,7 +105,7 @@ struct rebase_options {
85
105
REBASE_INTERACTIVE_EXPLICIT = 1 <<4 ,
86
106
} flags ;
87
107
struct strvec git_am_opts ;
88
- const char * action ;
108
+ enum action action ;
89
109
int signoff ;
90
110
int allow_rerere_autoupdate ;
91
111
int keep_empty ;
@@ -157,24 +177,6 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
157
177
return replay ;
158
178
}
159
179
160
- enum action {
161
- ACTION_NONE = 0 ,
162
- ACTION_CONTINUE ,
163
- ACTION_SKIP ,
164
- ACTION_ABORT ,
165
- ACTION_QUIT ,
166
- ACTION_EDIT_TODO ,
167
- ACTION_SHOW_CURRENT_PATCH
168
- };
169
-
170
- static const char * action_names [] = { "undefined" ,
171
- "continue" ,
172
- "skip" ,
173
- "abort" ,
174
- "quit" ,
175
- "edit_todo" ,
176
- "show_current_patch" };
177
-
178
180
static int edit_todo_file (unsigned flags )
179
181
{
180
182
const char * todo_file = rebase_path_todo ();
@@ -311,8 +313,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
311
313
return ret ;
312
314
}
313
315
314
- static int run_sequencer_rebase (struct rebase_options * opts ,
315
- enum action command )
316
+ static int run_sequencer_rebase (struct rebase_options * opts )
316
317
{
317
318
unsigned flags = 0 ;
318
319
int abbreviate_commands = 0 , ret = 0 ;
@@ -327,7 +328,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
327
328
flags |= opts -> reapply_cherry_picks ? TODO_LIST_REAPPLY_CHERRY_PICKS : 0 ;
328
329
flags |= opts -> flags & REBASE_NO_QUIET ? TODO_LIST_WARN_SKIPPED_CHERRY_PICKS : 0 ;
329
330
330
- switch (command ) {
331
+ switch (opts -> action ) {
331
332
case ACTION_NONE : {
332
333
if (!opts -> onto && !opts -> upstream )
333
334
die (_ ("a base commit must be provided with --upstream or --onto" ));
@@ -360,7 +361,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
360
361
break ;
361
362
}
362
363
default :
363
- BUG ("invalid command '%d'" , command );
364
+ BUG ("invalid command '%d'" , opts -> action );
364
365
}
365
366
366
367
return ret ;
@@ -583,10 +584,11 @@ static int move_to_original_branch(struct rebase_options *opts)
583
584
if (!opts -> onto )
584
585
BUG ("move_to_original_branch without onto" );
585
586
586
- strbuf_addf (& branch_reflog , "rebase finished: %s onto %s" ,
587
+ strbuf_addf (& branch_reflog , "%s (finish): %s onto %s" ,
588
+ getenv (GIT_REFLOG_ACTION_ENVIRONMENT ),
587
589
opts -> head_name , oid_to_hex (& opts -> onto -> object .oid ));
588
- strbuf_addf (& head_reflog , "rebase finished : returning to %s" ,
589
- opts -> head_name );
590
+ strbuf_addf (& head_reflog , "%s (finish) : returning to %s" ,
591
+ getenv ( GIT_REFLOG_ACTION_ENVIRONMENT ), opts -> head_name );
590
592
ropts .branch = opts -> head_name ;
591
593
ropts .flags = RESET_HEAD_REFS_ONLY ;
592
594
ropts .branch_msg = branch_reflog .buf ;
@@ -615,8 +617,9 @@ static int run_am(struct rebase_options *opts)
615
617
616
618
am .git_cmd = 1 ;
617
619
strvec_push (& am .args , "am" );
618
-
619
- if (opts -> action && !strcmp ("continue" , opts -> action )) {
620
+ strvec_pushf (& am .env , GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)" ,
621
+ getenv (GIT_REFLOG_ACTION_ENVIRONMENT ));
622
+ if (opts -> action == ACTION_CONTINUE ) {
620
623
strvec_push (& am .args , "--resolved" );
621
624
strvec_pushf (& am .args , "--resolvemsg=%s" , resolvemsg );
622
625
if (opts -> gpg_sign_opt )
@@ -627,7 +630,7 @@ static int run_am(struct rebase_options *opts)
627
630
628
631
return move_to_original_branch (opts );
629
632
}
630
- if (opts -> action && ! strcmp ( "skip" , opts -> action ) ) {
633
+ if (opts -> action == ACTION_SKIP ) {
631
634
strvec_push (& am .args , "--skip" );
632
635
strvec_pushf (& am .args , "--resolvemsg=%s" , resolvemsg );
633
636
status = run_command (& am );
@@ -636,7 +639,7 @@ static int run_am(struct rebase_options *opts)
636
639
637
640
return move_to_original_branch (opts );
638
641
}
639
- if (opts -> action && ! strcmp ( "show-current-patch" , opts -> action ) ) {
642
+ if (opts -> action == ACTION_SHOW_CURRENT_PATCH ) {
640
643
strvec_push (& am .args , "--show-current-patch" );
641
644
return run_command (& am );
642
645
}
@@ -729,7 +732,7 @@ static int run_am(struct rebase_options *opts)
729
732
return status ;
730
733
}
731
734
732
- static int run_specific_rebase (struct rebase_options * opts , enum action action )
735
+ static int run_specific_rebase (struct rebase_options * opts )
733
736
{
734
737
int status ;
735
738
@@ -747,7 +750,7 @@ static int run_specific_rebase(struct rebase_options *opts, enum action action)
747
750
opts -> gpg_sign_opt = tmp ;
748
751
}
749
752
750
- status = run_sequencer_rebase (opts , action );
753
+ status = run_sequencer_rebase (opts );
751
754
} else if (opts -> type == REBASE_APPLY )
752
755
status = run_am (opts );
753
756
else
@@ -1005,23 +1008,6 @@ static void NORETURN error_on_missing_default_upstream(void)
1005
1008
exit (1 );
1006
1009
}
1007
1010
1008
- static void set_reflog_action (struct rebase_options * options )
1009
- {
1010
- const char * env ;
1011
- struct strbuf buf = STRBUF_INIT ;
1012
-
1013
- if (!is_merge (options ))
1014
- return ;
1015
-
1016
- env = getenv (GIT_REFLOG_ACTION_ENVIRONMENT );
1017
- if (env && strcmp ("rebase" , env ))
1018
- return ; /* only override it if it is "rebase" */
1019
-
1020
- strbuf_addf (& buf , "rebase (%s)" , options -> action );
1021
- setenv (GIT_REFLOG_ACTION_ENVIRONMENT , buf .buf , 1 );
1022
- strbuf_release (& buf );
1023
- }
1024
-
1025
1011
static int check_exec_cmd (const char * cmd )
1026
1012
{
1027
1013
if (strchr (cmd , '\n' ))
@@ -1046,7 +1032,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1046
1032
struct strbuf buf = STRBUF_INIT ;
1047
1033
struct object_id branch_base ;
1048
1034
int ignore_whitespace = 0 ;
1049
- enum action action = ACTION_NONE ;
1050
1035
const char * gpg_sign = NULL ;
1051
1036
struct string_list exec = STRING_LIST_INIT_NODUP ;
1052
1037
const char * rebase_merges = NULL ;
@@ -1095,18 +1080,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1095
1080
OPT_BIT (0 , "no-ff" , & options .flags ,
1096
1081
N_ ("cherry-pick all commits, even if unchanged" ),
1097
1082
REBASE_FORCE ),
1098
- OPT_CMDMODE (0 , "continue" , & action , N_ ("continue" ),
1083
+ OPT_CMDMODE (0 , "continue" , & options . action , N_ ("continue" ),
1099
1084
ACTION_CONTINUE ),
1100
- OPT_CMDMODE (0 , "skip" , & action ,
1085
+ OPT_CMDMODE (0 , "skip" , & options . action ,
1101
1086
N_ ("skip current patch and continue" ), ACTION_SKIP ),
1102
- OPT_CMDMODE (0 , "abort" , & action ,
1087
+ OPT_CMDMODE (0 , "abort" , & options . action ,
1103
1088
N_ ("abort and check out the original branch" ),
1104
1089
ACTION_ABORT ),
1105
- OPT_CMDMODE (0 , "quit" , & action ,
1090
+ OPT_CMDMODE (0 , "quit" , & options . action ,
1106
1091
N_ ("abort but keep HEAD where it is" ), ACTION_QUIT ),
1107
- OPT_CMDMODE (0 , "edit-todo" , & action , N_ ("edit the todo list "
1092
+ OPT_CMDMODE (0 , "edit-todo" , & options . action , N_ ("edit the todo list "
1108
1093
"during an interactive rebase" ), ACTION_EDIT_TODO ),
1109
- OPT_CMDMODE (0 , "show-current-patch" , & action ,
1094
+ OPT_CMDMODE (0 , "show-current-patch" , & options . action ,
1110
1095
N_ ("show the patch file being applied or merged" ),
1111
1096
ACTION_SHOW_CURRENT_PATCH ),
1112
1097
OPT_CALLBACK_F (0 , "apply" , & options , NULL ,
@@ -1198,7 +1183,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1198
1183
} else if (is_directory (merge_dir ())) {
1199
1184
strbuf_reset (& buf );
1200
1185
strbuf_addf (& buf , "%s/rewritten" , merge_dir ());
1201
- if (!(action == ACTION_ABORT ) && is_directory (buf .buf )) {
1186
+ if (!(options . action == ACTION_ABORT ) && is_directory (buf .buf )) {
1202
1187
die (_ ("`rebase --preserve-merges` (-p) is no longer supported.\n"
1203
1188
"Use `git rebase --abort` to terminate current rebase.\n"
1204
1189
"Or downgrade to v2.33, or earlier, to complete the rebase." ));
@@ -1225,7 +1210,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1225
1210
"Note: Your `pull.rebase` configuration may also be set to 'preserve',\n"
1226
1211
"which is no longer supported; use 'merges' instead" ));
1227
1212
1228
- if (action != ACTION_NONE && total_argc != 2 ) {
1213
+ if (options . action != ACTION_NONE && total_argc != 2 ) {
1229
1214
usage_with_options (builtin_rebase_usage ,
1230
1215
builtin_rebase_options );
1231
1216
}
@@ -1256,11 +1241,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1256
1241
if (options .root && options .fork_point > 0 )
1257
1242
die (_ ("options '%s' and '%s' cannot be used together" ), "--root" , "--fork-point" );
1258
1243
1259
- if (action != ACTION_NONE && !in_progress )
1244
+ if (options . action != ACTION_NONE && !in_progress )
1260
1245
die (_ ("No rebase in progress?" ));
1261
1246
setenv (GIT_REFLOG_ACTION_ENVIRONMENT , "rebase" , 0 );
1262
1247
1263
- if (action == ACTION_EDIT_TODO && !is_merge (& options ))
1248
+ if (options . action == ACTION_EDIT_TODO && !is_merge (& options ))
1264
1249
die (_ ("The --edit-todo action can only be used during "
1265
1250
"interactive rebase." ));
1266
1251
@@ -1270,18 +1255,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1270
1255
else if (exec .nr )
1271
1256
trace2_cmd_mode ("interactive-exec" );
1272
1257
else
1273
- trace2_cmd_mode (action_names [action ]);
1258
+ trace2_cmd_mode (action_names [options . action ]);
1274
1259
}
1275
1260
1276
- switch (action ) {
1261
+ switch (options . action ) {
1277
1262
case ACTION_CONTINUE : {
1278
1263
struct object_id head ;
1279
1264
struct lock_file lock_file = LOCK_INIT ;
1280
1265
int fd ;
1281
1266
1282
- options .action = "continue" ;
1283
- set_reflog_action (& options );
1284
-
1285
1267
/* Sanity check */
1286
1268
if (get_oid ("HEAD" , & head ))
1287
1269
die (_ ("Cannot read HEAD" ));
@@ -1307,9 +1289,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1307
1289
case ACTION_SKIP : {
1308
1290
struct string_list merge_rr = STRING_LIST_INIT_DUP ;
1309
1291
1310
- options .action = "skip" ;
1311
- set_reflog_action (& options );
1312
-
1313
1292
rerere_clear (the_repository , & merge_rr );
1314
1293
string_list_clear (& merge_rr , 1 );
1315
1294
ropts .flags = RESET_HEAD_HARD ;
@@ -1322,18 +1301,22 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1322
1301
}
1323
1302
case ACTION_ABORT : {
1324
1303
struct string_list merge_rr = STRING_LIST_INIT_DUP ;
1325
- options .action = "abort" ;
1326
- set_reflog_action (& options );
1304
+ struct strbuf head_msg = STRBUF_INIT ;
1327
1305
1328
1306
rerere_clear (the_repository , & merge_rr );
1329
1307
string_list_clear (& merge_rr , 1 );
1330
1308
1331
1309
if (read_basic_state (& options ))
1332
1310
exit (1 );
1311
+
1312
+ strbuf_addf (& head_msg , "%s (abort): returning to %s" ,
1313
+ getenv (GIT_REFLOG_ACTION_ENVIRONMENT ),
1314
+ options .head_name ? options .head_name
1315
+ : oid_to_hex (& options .orig_head -> object .oid ));
1333
1316
ropts .oid = & options .orig_head -> object .oid ;
1317
+ ropts .head_msg = head_msg .buf ;
1334
1318
ropts .branch = options .head_name ;
1335
1319
ropts .flags = RESET_HEAD_HARD ;
1336
- ropts .default_reflog_action = DEFAULT_REFLOG_ACTION ;
1337
1320
if (reset_head (the_repository , & ropts ) < 0 )
1338
1321
die (_ ("could not move back to %s" ),
1339
1322
oid_to_hex (& options .orig_head -> object .oid ));
@@ -1359,17 +1342,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1359
1342
goto cleanup ;
1360
1343
}
1361
1344
case ACTION_EDIT_TODO :
1362
- options .action = "edit-todo" ;
1363
1345
options .dont_finish_rebase = 1 ;
1364
1346
goto run_rebase ;
1365
1347
case ACTION_SHOW_CURRENT_PATCH :
1366
- options .action = "show-current-patch" ;
1367
1348
options .dont_finish_rebase = 1 ;
1368
1349
goto run_rebase ;
1369
1350
case ACTION_NONE :
1370
1351
break ;
1371
1352
default :
1372
- BUG ("action: %d" , action );
1353
+ BUG ("action: %d" , options . action );
1373
1354
}
1374
1355
1375
1356
/* Make sure no rebase is in progress */
@@ -1393,7 +1374,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1393
1374
}
1394
1375
1395
1376
if ((options .flags & REBASE_INTERACTIVE_EXPLICIT ) ||
1396
- (action != ACTION_NONE ) ||
1377
+ (options . action != ACTION_NONE ) ||
1397
1378
(exec .nr > 0 ) ||
1398
1379
options .autosquash ) {
1399
1380
allow_preemptive_ff = 0 ;
@@ -1804,7 +1785,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1804
1785
printf (_ ("First, rewinding head to replay your work on top of "
1805
1786
"it...\n" ));
1806
1787
1807
- strbuf_addf (& msg , "%s: checkout %s" ,
1788
+ strbuf_addf (& msg , "%s (start) : checkout %s" ,
1808
1789
getenv (GIT_REFLOG_ACTION_ENVIRONMENT ), options .onto_name );
1809
1790
ropts .oid = & options .onto -> object .oid ;
1810
1791
ropts .orig_head = & options .orig_head -> object .oid ,
@@ -1820,19 +1801,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1820
1801
* If the onto is a proper descendant of the tip of the branch, then
1821
1802
* we just fast-forwarded.
1822
1803
*/
1823
- strbuf_reset (& msg );
1824
1804
if (oideq (& branch_base , & options .orig_head -> object .oid )) {
1825
1805
printf (_ ("Fast-forwarded %s to %s.\n" ),
1826
1806
branch_name , options .onto_name );
1827
- strbuf_addf (& msg , "rebase finished: %s onto %s" ,
1828
- options .head_name ? options .head_name : "detached HEAD" ,
1829
- oid_to_hex (& options .onto -> object .oid ));
1830
- memset (& ropts , 0 , sizeof (ropts ));
1831
- ropts .branch = options .head_name ;
1832
- ropts .flags = RESET_HEAD_REFS_ONLY ;
1833
- ropts .head_msg = msg .buf ;
1834
- reset_head (the_repository , & ropts );
1835
- strbuf_release (& msg );
1807
+ move_to_original_branch (& options );
1836
1808
ret = finish_rebase (& options );
1837
1809
goto cleanup ;
1838
1810
}
@@ -1847,7 +1819,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1847
1819
options .revisions = revisions .buf ;
1848
1820
1849
1821
run_rebase :
1850
- ret = run_specific_rebase (& options , action );
1822
+ ret = run_specific_rebase (& options );
1851
1823
1852
1824
cleanup :
1853
1825
strbuf_release (& buf );
0 commit comments