@@ -6426,104 +6426,12 @@ static int todo_list_add_update_ref_commands(struct todo_list *todo_list)
64266426 return 0 ;
64276427}
64286428
6429- int complete_action (struct repository * r , struct replay_opts * opts , unsigned flags ,
6430- const char * shortrevisions , const char * onto_name ,
6431- struct commit * onto , const struct object_id * orig_head ,
6432- struct string_list * commands , unsigned autosquash ,
6433- unsigned update_refs ,
6434- struct todo_list * todo_list )
6435- {
6436- char shortonto [GIT_MAX_HEXSZ + 1 ];
6437- const char * todo_file = rebase_path_todo ();
6438- struct todo_list new_todo = TODO_LIST_INIT ;
6439- struct strbuf * buf = & todo_list -> buf , buf2 = STRBUF_INIT ;
6440- struct object_id oid = onto -> object .oid ;
6441- int res ;
6442-
6443- repo_find_unique_abbrev_r (r , shortonto , & oid ,
6444- DEFAULT_ABBREV );
6445-
6446- if (buf -> len == 0 ) {
6447- struct todo_item * item = append_new_todo (todo_list );
6448- item -> command = TODO_NOOP ;
6449- item -> commit = NULL ;
6450- item -> arg_len = item -> arg_offset = item -> flags = item -> offset_in_buf = 0 ;
6451- }
6452-
6453- if (update_refs && todo_list_add_update_ref_commands (todo_list ))
6454- return -1 ;
6455-
6456- if (autosquash && todo_list_rearrange_squash (todo_list ))
6457- return -1 ;
6458-
6459- if (commands -> nr )
6460- todo_list_add_exec_commands (todo_list , commands );
6461-
6462- if (count_commands (todo_list ) == 0 ) {
6463- apply_autostash (rebase_path_autostash ());
6464- sequencer_remove_state (opts );
6465-
6466- return error (_ ("nothing to do" ));
6467- }
6468-
6469- res = edit_todo_list (r , opts , todo_list , & new_todo , shortrevisions ,
6470- shortonto , flags );
6471- if (res == -1 )
6472- return -1 ;
6473- else if (res == -2 ) {
6474- apply_autostash (rebase_path_autostash ());
6475- sequencer_remove_state (opts );
6476-
6477- return -1 ;
6478- } else if (res == -3 ) {
6479- apply_autostash (rebase_path_autostash ());
6480- sequencer_remove_state (opts );
6481- todo_list_release (& new_todo );
6482-
6483- return error (_ ("nothing to do" ));
6484- } else if (res == -4 ) {
6485- checkout_onto (r , opts , onto_name , & onto -> object .oid , orig_head );
6486- todo_list_release (& new_todo );
6487-
6488- return -1 ;
6489- }
6490-
6491- /* Expand the commit IDs */
6492- todo_list_to_strbuf (r , & new_todo , & buf2 , -1 , 0 );
6493- strbuf_swap (& new_todo .buf , & buf2 );
6494- strbuf_release (& buf2 );
6495- /* Nothing is done yet, and we're reparsing, so let's reset the count */
6496- new_todo .total_nr = 0 ;
6497- if (todo_list_parse_insn_buffer (r , opts , new_todo .buf .buf , & new_todo ) < 0 )
6498- BUG ("invalid todo list after expanding IDs:\n%s" ,
6499- new_todo .buf .buf );
6500-
6501- if (opts -> allow_ff && skip_unnecessary_picks (r , & new_todo , & oid )) {
6502- todo_list_release (& new_todo );
6503- return error (_ ("could not skip unnecessary pick commands" ));
6504- }
6505-
6506- if (todo_list_write_to_file (r , & new_todo , todo_file , NULL , NULL , -1 ,
6507- flags & ~(TODO_LIST_SHORTEN_IDS ))) {
6508- todo_list_release (& new_todo );
6509- return error_errno (_ ("could not write '%s'" ), todo_file );
6510- }
6511-
6512- res = -1 ;
6513-
6514- if (checkout_onto (r , opts , onto_name , & oid , orig_head ))
6515- goto cleanup ;
6516-
6517- if (require_clean_work_tree (r , "rebase" , NULL , 1 , 1 ))
6518- goto cleanup ;
6519-
6520- todo_list_write_total_nr (& new_todo );
6521- res = pick_commits (r , & new_todo , opts );
6522-
6523- cleanup :
6524- todo_list_release (& new_todo );
6429+ define_commit_slab (commit_todo_item , struct todo_item * );
65256430
6526- return res ;
6431+ static int skip_fixupish (const char * subject , const char * * p ) {
6432+ return skip_prefix (subject , "fixup! " , p ) ||
6433+ skip_prefix (subject , "amend! " , p ) ||
6434+ skip_prefix (subject , "squash! " , p );
65276435}
65286436
65296437struct subject2item_entry {
@@ -6545,14 +6453,6 @@ static int subject2item_cmp(const void *fndata UNUSED,
65456453 return key ? strcmp (a -> subject , key ) : strcmp (a -> subject , b -> subject );
65466454}
65476455
6548- define_commit_slab (commit_todo_item , struct todo_item * );
6549-
6550- static int skip_fixupish (const char * subject , const char * * p ) {
6551- return skip_prefix (subject , "fixup! " , p ) ||
6552- skip_prefix (subject , "amend! " , p ) ||
6553- skip_prefix (subject , "squash! " , p );
6554- }
6555-
65566456/*
65576457 * Rearrange the todo list that has both "pick commit-id msg" and "pick
65586458 * commit-id fixup!/squash! msg" in it so that the latter is put immediately
@@ -6562,7 +6462,7 @@ static int skip_fixupish(const char *subject, const char **p) {
65626462 * message will have to be retrieved from the commit (as the oneline in the
65636463 * script cannot be trusted) in order to normalize the autosquash arrangement.
65646464 */
6565- int todo_list_rearrange_squash (struct todo_list * todo_list )
6465+ static int todo_list_rearrange_squash (struct todo_list * todo_list )
65666466{
65676467 struct hashmap subject2item ;
65686468 int rearranged = 0 , * next , * tail , i , nr = 0 ;
@@ -6714,6 +6614,106 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
67146614 return 0 ;
67156615}
67166616
6617+ int complete_action (struct repository * r , struct replay_opts * opts , unsigned flags ,
6618+ const char * shortrevisions , const char * onto_name ,
6619+ struct commit * onto , const struct object_id * orig_head ,
6620+ struct string_list * commands , unsigned autosquash ,
6621+ unsigned update_refs ,
6622+ struct todo_list * todo_list )
6623+ {
6624+ char shortonto [GIT_MAX_HEXSZ + 1 ];
6625+ const char * todo_file = rebase_path_todo ();
6626+ struct todo_list new_todo = TODO_LIST_INIT ;
6627+ struct strbuf * buf = & todo_list -> buf , buf2 = STRBUF_INIT ;
6628+ struct object_id oid = onto -> object .oid ;
6629+ int res ;
6630+
6631+ repo_find_unique_abbrev_r (r , shortonto , & oid ,
6632+ DEFAULT_ABBREV );
6633+
6634+ if (buf -> len == 0 ) {
6635+ struct todo_item * item = append_new_todo (todo_list );
6636+ item -> command = TODO_NOOP ;
6637+ item -> commit = NULL ;
6638+ item -> arg_len = item -> arg_offset = item -> flags = item -> offset_in_buf = 0 ;
6639+ }
6640+
6641+ if (update_refs && todo_list_add_update_ref_commands (todo_list ))
6642+ return -1 ;
6643+
6644+ if (autosquash && todo_list_rearrange_squash (todo_list ))
6645+ return -1 ;
6646+
6647+ if (commands -> nr )
6648+ todo_list_add_exec_commands (todo_list , commands );
6649+
6650+ if (count_commands (todo_list ) == 0 ) {
6651+ apply_autostash (rebase_path_autostash ());
6652+ sequencer_remove_state (opts );
6653+
6654+ return error (_ ("nothing to do" ));
6655+ }
6656+
6657+ res = edit_todo_list (r , opts , todo_list , & new_todo , shortrevisions ,
6658+ shortonto , flags );
6659+ if (res == -1 )
6660+ return -1 ;
6661+ else if (res == -2 ) {
6662+ apply_autostash (rebase_path_autostash ());
6663+ sequencer_remove_state (opts );
6664+
6665+ return -1 ;
6666+ } else if (res == -3 ) {
6667+ apply_autostash (rebase_path_autostash ());
6668+ sequencer_remove_state (opts );
6669+ todo_list_release (& new_todo );
6670+
6671+ return error (_ ("nothing to do" ));
6672+ } else if (res == -4 ) {
6673+ checkout_onto (r , opts , onto_name , & onto -> object .oid , orig_head );
6674+ todo_list_release (& new_todo );
6675+
6676+ return -1 ;
6677+ }
6678+
6679+ /* Expand the commit IDs */
6680+ todo_list_to_strbuf (r , & new_todo , & buf2 , -1 , 0 );
6681+ strbuf_swap (& new_todo .buf , & buf2 );
6682+ strbuf_release (& buf2 );
6683+ /* Nothing is done yet, and we're reparsing, so let's reset the count */
6684+ new_todo .total_nr = 0 ;
6685+ if (todo_list_parse_insn_buffer (r , opts , new_todo .buf .buf , & new_todo ) < 0 )
6686+ BUG ("invalid todo list after expanding IDs:\n%s" ,
6687+ new_todo .buf .buf );
6688+
6689+ if (opts -> allow_ff && skip_unnecessary_picks (r , & new_todo , & oid )) {
6690+ todo_list_release (& new_todo );
6691+ return error (_ ("could not skip unnecessary pick commands" ));
6692+ }
6693+
6694+ if (todo_list_write_to_file (r , & new_todo , todo_file , NULL , NULL , -1 ,
6695+ flags & ~(TODO_LIST_SHORTEN_IDS ))) {
6696+ todo_list_release (& new_todo );
6697+ return error_errno (_ ("could not write '%s'" ), todo_file );
6698+ }
6699+
6700+ res = -1 ;
6701+
6702+ if (checkout_onto (r , opts , onto_name , & oid , orig_head ))
6703+ goto cleanup ;
6704+
6705+ if (require_clean_work_tree (r , "rebase" , NULL , 1 , 1 ))
6706+ goto cleanup ;
6707+
6708+ todo_list_write_total_nr (& new_todo );
6709+ res = pick_commits (r , & new_todo , opts );
6710+
6711+ cleanup :
6712+ todo_list_release (& new_todo );
6713+
6714+ return res ;
6715+ }
6716+
67176717int sequencer_determine_whence (struct repository * r , enum commit_whence * whence )
67186718{
67196719 if (refs_ref_exists (get_main_ref_store (r ), "CHERRY_PICK_HEAD" )) {
0 commit comments