@@ -571,6 +571,7 @@ static int finish_rebase(struct rebase_options *opts)
571571static int move_to_original_branch (struct rebase_options * opts )
572572{
573573 struct strbuf orig_head_reflog = STRBUF_INIT , head_reflog = STRBUF_INIT ;
574+ struct reset_head_opts ropts = { 0 };
574575 int ret ;
575576
576577 if (!opts -> head_name )
@@ -583,9 +584,11 @@ static int move_to_original_branch(struct rebase_options *opts)
583584 opts -> head_name , oid_to_hex (& opts -> onto -> object .oid ));
584585 strbuf_addf (& head_reflog , "rebase finished: returning to %s" ,
585586 opts -> head_name );
586- ret = reset_head (the_repository , NULL , opts -> head_name ,
587- RESET_HEAD_REFS_ONLY ,
588- orig_head_reflog .buf , head_reflog .buf , NULL );
587+ ropts .branch = opts -> head_name ;
588+ ropts .flags = RESET_HEAD_REFS_ONLY ;
589+ ropts .orig_head_msg = orig_head_reflog .buf ;
590+ ropts .head_msg = head_reflog .buf ;
591+ ret = reset_head (the_repository , & ropts );
589592
590593 strbuf_release (& orig_head_reflog );
591594 strbuf_release (& head_reflog );
@@ -669,13 +672,15 @@ static int run_am(struct rebase_options *opts)
669672
670673 status = run_command (& format_patch );
671674 if (status ) {
675+ struct reset_head_opts ropts = { 0 };
672676 unlink (rebased_patches );
673677 free (rebased_patches );
674678 strvec_clear (& am .args );
675679
676- reset_head (the_repository , & opts -> orig_head ,
677- opts -> head_name , 0 ,
678- NULL , NULL , DEFAULT_REFLOG_ACTION );
680+ ropts .oid = & opts -> orig_head ;
681+ ropts .branch = opts -> head_name ;
682+ ropts .default_reflog_action = DEFAULT_REFLOG_ACTION ;
683+ reset_head (the_repository , & ropts );
679684 error (_ ("\ngit encountered an error while preparing the "
680685 "patches to replay\n"
681686 "these revisions:\n"
@@ -814,14 +819,17 @@ static int rebase_config(const char *var, const char *value, void *data)
814819static int checkout_up_to_date (struct rebase_options * options )
815820{
816821 struct strbuf buf = STRBUF_INIT ;
822+ struct reset_head_opts ropts = { 0 };
817823 int ret = 0 ;
818824
819825 strbuf_addf (& buf , "%s: checkout %s" ,
820826 getenv (GIT_REFLOG_ACTION_ENVIRONMENT ),
821827 options -> switch_to );
822- if (reset_head (the_repository , & options -> orig_head ,
823- options -> head_name , RESET_HEAD_RUN_POST_CHECKOUT_HOOK ,
824- NULL , buf .buf , NULL ) < 0 )
828+ ropts .oid = & options -> orig_head ;
829+ ropts .branch = options -> head_name ;
830+ ropts .flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK ;
831+ ropts .head_msg = buf .buf ;
832+ if (reset_head (the_repository , & ropts ) < 0 )
825833 ret = error (_ ("could not switch to %s" ), options -> switch_to );
826834 strbuf_release (& buf );
827835
@@ -1033,6 +1041,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10331041 int reschedule_failed_exec = -1 ;
10341042 int allow_preemptive_ff = 1 ;
10351043 int preserve_merges_selected = 0 ;
1044+ struct reset_head_opts ropts = { 0 };
10361045 struct option builtin_rebase_options [] = {
10371046 OPT_STRING (0 , "onto" , & options .onto_name ,
10381047 N_ ("revision" ),
@@ -1270,9 +1279,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12701279
12711280 rerere_clear (the_repository , & merge_rr );
12721281 string_list_clear (& merge_rr , 1 );
1273-
1274- if (reset_head (the_repository , NULL , NULL , RESET_HEAD_HARD ,
1275- NULL , NULL , NULL ) < 0 )
1282+ ropts .flags = RESET_HEAD_HARD ;
1283+ if (reset_head (the_repository , & ropts ) < 0 )
12761284 die (_ ("could not discard worktree changes" ));
12771285 remove_branch_state (the_repository , 0 );
12781286 if (read_basic_state (& options ))
@@ -1289,9 +1297,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12891297
12901298 if (read_basic_state (& options ))
12911299 exit (1 );
1292- if (reset_head (the_repository , & options .orig_head ,
1293- options .head_name , RESET_HEAD_HARD ,
1294- NULL , NULL , DEFAULT_REFLOG_ACTION ) < 0 )
1300+ ropts .oid = & options .orig_head ;
1301+ ropts .branch = options .head_name ;
1302+ ropts .flags = RESET_HEAD_HARD ;
1303+ ropts .default_reflog_action = DEFAULT_REFLOG_ACTION ;
1304+ if (reset_head (the_repository , & ropts ) < 0 )
12951305 die (_ ("could not move back to %s" ),
12961306 oid_to_hex (& options .orig_head ));
12971307 remove_branch_state (the_repository , 0 );
@@ -1758,10 +1768,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17581768
17591769 strbuf_addf (& msg , "%s: checkout %s" ,
17601770 getenv (GIT_REFLOG_ACTION_ENVIRONMENT ), options .onto_name );
1761- if (reset_head (the_repository , & options .onto -> object .oid , NULL ,
1762- RESET_HEAD_DETACH | RESET_ORIG_HEAD |
1763- RESET_HEAD_RUN_POST_CHECKOUT_HOOK ,
1764- NULL , msg .buf , DEFAULT_REFLOG_ACTION ))
1771+ ropts .oid = & options .onto -> object .oid ;
1772+ ropts .flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD |
1773+ RESET_HEAD_RUN_POST_CHECKOUT_HOOK ;
1774+ ropts .head_msg = msg .buf ;
1775+ ropts .default_reflog_action = DEFAULT_REFLOG_ACTION ;
1776+ if (reset_head (the_repository , & ropts ))
17651777 die (_ ("Could not detach HEAD" ));
17661778 strbuf_release (& msg );
17671779
@@ -1776,8 +1788,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17761788 strbuf_addf (& msg , "rebase finished: %s onto %s" ,
17771789 options .head_name ? options .head_name : "detached HEAD" ,
17781790 oid_to_hex (& options .onto -> object .oid ));
1779- reset_head (the_repository , NULL , options .head_name ,
1780- RESET_HEAD_REFS_ONLY , NULL , msg .buf , NULL );
1791+ memset (& ropts , 0 , sizeof (ropts ));
1792+ ropts .branch = options .head_name ;
1793+ ropts .flags = RESET_HEAD_REFS_ONLY ;
1794+ ropts .head_msg = msg .buf ;
1795+ reset_head (the_repository , & ropts );
17811796 strbuf_release (& msg );
17821797 ret = finish_rebase (& options );
17831798 goto cleanup ;
0 commit comments