28
28
#include "sequencer.h"
29
29
#include "rebase-interactive.h"
30
30
31
+ #define DEFAULT_REFLOG_ACTION "rebase"
32
+
31
33
static char const * const builtin_rebase_usage [] = {
32
34
N_ ("git rebase [-i] [options] [--exec <cmd>] "
33
35
"[--onto <newbase> | --keep-base] [<upstream> [<branch>]]" ),
@@ -772,9 +774,10 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
772
774
#define RESET_HEAD_REFS_ONLY (1<<3)
773
775
#define RESET_ORIG_HEAD (1<<4)
774
776
775
- static int reset_head (struct object_id * oid , const char * action ,
777
+ static int reset_head (struct repository * r , struct object_id * oid , const char * action ,
776
778
const char * switch_to_branch , unsigned flags ,
777
- const char * reflog_orig_head , const char * reflog_head )
779
+ const char * reflog_orig_head , const char * reflog_head ,
780
+ const char * default_reflog_action )
778
781
{
779
782
unsigned detach_head = flags & RESET_HEAD_DETACH ;
780
783
unsigned reset_hard = flags & RESET_HEAD_HARD ;
@@ -796,7 +799,7 @@ static int reset_head(struct object_id *oid, const char *action,
796
799
if (switch_to_branch && !starts_with (switch_to_branch , "refs/" ))
797
800
BUG ("Not a fully qualified branch: '%s'" , switch_to_branch );
798
801
799
- if (!refs_only && hold_locked_index ( & lock , LOCK_REPORT_ON_ERROR ) < 0 ) {
802
+ if (!refs_only && repo_hold_locked_index ( r , & lock , LOCK_REPORT_ON_ERROR ) < 0 ) {
800
803
ret = -1 ;
801
804
goto leave_reset_head ;
802
805
}
@@ -815,26 +818,26 @@ static int reset_head(struct object_id *oid, const char *action,
815
818
memset (& unpack_tree_opts , 0 , sizeof (unpack_tree_opts ));
816
819
setup_unpack_trees_porcelain (& unpack_tree_opts , action );
817
820
unpack_tree_opts .head_idx = 1 ;
818
- unpack_tree_opts .src_index = the_repository -> index ;
819
- unpack_tree_opts .dst_index = the_repository -> index ;
821
+ unpack_tree_opts .src_index = r -> index ;
822
+ unpack_tree_opts .dst_index = r -> index ;
820
823
unpack_tree_opts .fn = reset_hard ? oneway_merge : twoway_merge ;
821
824
unpack_tree_opts .update = 1 ;
822
825
unpack_tree_opts .merge = 1 ;
823
826
if (!detach_head )
824
827
unpack_tree_opts .reset = 1 ;
825
828
826
- if (repo_read_index_unmerged (the_repository ) < 0 ) {
829
+ if (repo_read_index_unmerged (r ) < 0 ) {
827
830
ret = error (_ ("could not read index" ));
828
831
goto leave_reset_head ;
829
832
}
830
833
831
- if (!reset_hard && !fill_tree_descriptor (the_repository , & desc [nr ++ ], & head_oid )) {
834
+ if (!reset_hard && !fill_tree_descriptor (r , & desc [nr ++ ], & head_oid )) {
832
835
ret = error (_ ("failed to find tree of %s" ),
833
836
oid_to_hex (& head_oid ));
834
837
goto leave_reset_head ;
835
838
}
836
839
837
- if (!fill_tree_descriptor (the_repository , & desc [nr ++ ], oid )) {
840
+ if (!fill_tree_descriptor (r , & desc [nr ++ ], oid )) {
838
841
ret = error (_ ("failed to find tree of %s" ), oid_to_hex (oid ));
839
842
goto leave_reset_head ;
840
843
}
@@ -845,16 +848,16 @@ static int reset_head(struct object_id *oid, const char *action,
845
848
}
846
849
847
850
tree = parse_tree_indirect (oid );
848
- prime_cache_tree (the_repository , the_repository -> index , tree );
851
+ prime_cache_tree (r , r -> index , tree );
849
852
850
- if (write_locked_index (the_repository -> index , & lock , COMMIT_LOCK ) < 0 ) {
853
+ if (write_locked_index (r -> index , & lock , COMMIT_LOCK ) < 0 ) {
851
854
ret = error (_ ("could not write index" ));
852
855
goto leave_reset_head ;
853
856
}
854
857
855
858
reset_head_refs :
856
859
reflog_action = getenv (GIT_REFLOG_ACTION_ENVIRONMENT );
857
- strbuf_addf (& msg , "%s: " , reflog_action ? reflog_action : "rebase" );
860
+ strbuf_addf (& msg , "%s: " , reflog_action ? reflog_action : default_reflog_action );
858
861
prefix_len = msg .len ;
859
862
860
863
if (update_orig_head ) {
@@ -916,8 +919,10 @@ static int move_to_original_branch(struct rebase_options *opts)
916
919
opts -> head_name , oid_to_hex (& opts -> onto -> object .oid ));
917
920
strbuf_addf (& head_reflog , "rebase finished: returning to %s" ,
918
921
opts -> head_name );
919
- ret = reset_head (NULL , "" , opts -> head_name , RESET_HEAD_REFS_ONLY ,
920
- orig_head_reflog .buf , head_reflog .buf );
922
+ ret = reset_head (the_repository , NULL , "" , opts -> head_name ,
923
+ RESET_HEAD_REFS_ONLY ,
924
+ orig_head_reflog .buf , head_reflog .buf ,
925
+ DEFAULT_REFLOG_ACTION );
921
926
922
927
strbuf_release (& orig_head_reflog );
923
928
strbuf_release (& head_reflog );
@@ -1005,8 +1010,9 @@ static int run_am(struct rebase_options *opts)
1005
1010
free (rebased_patches );
1006
1011
argv_array_clear (& am .args );
1007
1012
1008
- reset_head (& opts -> orig_head , "checkout" , opts -> head_name , 0 ,
1009
- "HEAD" , NULL );
1013
+ reset_head (the_repository , & opts -> orig_head , "checkout" ,
1014
+ opts -> head_name , 0 ,
1015
+ "HEAD" , NULL , DEFAULT_REFLOG_ACTION );
1010
1016
error (_ ("\ngit encountered an error while preparing the "
1011
1017
"patches to replay\n"
1012
1018
"these revisions:\n"
@@ -1661,8 +1667,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1661
1667
rerere_clear (the_repository , & merge_rr );
1662
1668
string_list_clear (& merge_rr , 1 );
1663
1669
1664
- if (reset_head (NULL , "reset" , NULL , RESET_HEAD_HARD ,
1665
- NULL , NULL ) < 0 )
1670
+ if (reset_head (the_repository , NULL , "reset" , NULL , RESET_HEAD_HARD ,
1671
+ NULL , NULL , DEFAULT_REFLOG_ACTION ) < 0 )
1666
1672
die (_ ("could not discard worktree changes" ));
1667
1673
remove_branch_state (the_repository , 0 );
1668
1674
if (read_basic_state (& options ))
@@ -1679,9 +1685,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1679
1685
1680
1686
if (read_basic_state (& options ))
1681
1687
exit (1 );
1682
- if (reset_head (& options .orig_head , "reset" ,
1688
+ if (reset_head (the_repository , & options .orig_head , "reset" ,
1683
1689
options .head_name , RESET_HEAD_HARD ,
1684
- NULL , NULL ) < 0 )
1690
+ NULL , NULL , DEFAULT_REFLOG_ACTION ) < 0 )
1685
1691
die (_ ("could not move back to %s" ),
1686
1692
oid_to_hex (& options .orig_head ));
1687
1693
remove_branch_state (the_repository , 0 );
@@ -2073,8 +2079,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
2073
2079
options .state_dir );
2074
2080
write_file (autostash , "%s" , oid_to_hex (& oid ));
2075
2081
printf (_ ("Created autostash: %s\n" ), buf .buf );
2076
- if (reset_head (NULL , "reset --hard" ,
2077
- NULL , RESET_HEAD_HARD , NULL , NULL ) < 0 )
2082
+ if (reset_head (the_repository , NULL , "reset --hard" ,
2083
+ NULL , RESET_HEAD_HARD , NULL , NULL ,
2084
+ DEFAULT_REFLOG_ACTION ) < 0 )
2078
2085
die (_ ("could not reset --hard" ));
2079
2086
2080
2087
if (discard_index (the_repository -> index ) < 0 ||
@@ -2114,10 +2121,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
2114
2121
strbuf_addf (& buf , "%s: checkout %s" ,
2115
2122
getenv (GIT_REFLOG_ACTION_ENVIRONMENT ),
2116
2123
options .switch_to );
2117
- if (reset_head (& options .orig_head , "checkout" ,
2124
+ if (reset_head (the_repository ,
2125
+ & options .orig_head , "checkout" ,
2118
2126
options .head_name ,
2119
2127
RESET_HEAD_RUN_POST_CHECKOUT_HOOK ,
2120
- NULL , buf .buf ) < 0 ) {
2128
+ NULL , buf .buf ,
2129
+ DEFAULT_REFLOG_ACTION ) < 0 ) {
2121
2130
ret = !!error (_ ("could not switch to "
2122
2131
"%s" ),
2123
2132
options .switch_to );
@@ -2189,10 +2198,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
2189
2198
2190
2199
strbuf_addf (& msg , "%s: checkout %s" ,
2191
2200
getenv (GIT_REFLOG_ACTION_ENVIRONMENT ), options .onto_name );
2192
- if (reset_head (& options .onto -> object .oid , "checkout" , NULL ,
2201
+ if (reset_head (the_repository , & options .onto -> object .oid , "checkout" , NULL ,
2193
2202
RESET_HEAD_DETACH | RESET_ORIG_HEAD |
2194
2203
RESET_HEAD_RUN_POST_CHECKOUT_HOOK ,
2195
- NULL , msg .buf ))
2204
+ NULL , msg .buf , DEFAULT_REFLOG_ACTION ))
2196
2205
die (_ ("Could not detach HEAD" ));
2197
2206
strbuf_release (& msg );
2198
2207
@@ -2207,8 +2216,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
2207
2216
strbuf_addf (& msg , "rebase finished: %s onto %s" ,
2208
2217
options .head_name ? options .head_name : "detached HEAD" ,
2209
2218
oid_to_hex (& options .onto -> object .oid ));
2210
- reset_head (NULL , "Fast-forwarded" , options .head_name ,
2211
- RESET_HEAD_REFS_ONLY , "HEAD" , msg .buf );
2219
+ reset_head (the_repository , NULL , "Fast-forwarded" , options .head_name ,
2220
+ RESET_HEAD_REFS_ONLY , "HEAD" , msg .buf ,
2221
+ DEFAULT_REFLOG_ACTION );
2212
2222
strbuf_release (& msg );
2213
2223
ret = !!finish_rebase (& options );
2214
2224
goto cleanup ;
0 commit comments