@@ -4562,27 +4562,18 @@ int sequencer_add_exec_commands(struct repository *r,
4562
4562
return i ;
4563
4563
}
4564
4564
4565
- int transform_todos (struct repository * r , unsigned flags )
4565
+ void todo_list_transform (struct repository * r , struct todo_list * todo_list ,
4566
+ unsigned flags )
4566
4567
{
4567
- const char * todo_file = rebase_path_todo ();
4568
- struct todo_list todo_list = TODO_LIST_INIT ;
4569
4568
struct strbuf buf = STRBUF_INIT ;
4570
4569
struct todo_item * item ;
4571
4570
int i ;
4572
4571
4573
- if (strbuf_read_file (& todo_list .buf , todo_file , 0 ) < 0 )
4574
- return error (_ ("could not read '%s'." ), todo_file );
4575
-
4576
- if (todo_list_parse_insn_buffer (r , todo_list .buf .buf , & todo_list )) {
4577
- todo_list_release (& todo_list );
4578
- return error (_ ("unusable todo list: '%s'" ), todo_file );
4579
- }
4580
-
4581
- for (item = todo_list .items , i = 0 ; i < todo_list .nr ; i ++ , item ++ ) {
4572
+ for (item = todo_list -> items , i = 0 ; i < todo_list -> nr ; i ++ , item ++ ) {
4582
4573
/* if the item is not a command write it and continue */
4583
4574
if (item -> command >= TODO_COMMENT ) {
4584
4575
strbuf_addf (& buf , "%.*s\n" , item -> arg_len ,
4585
- todo_item_get_arg (& todo_list , item ));
4576
+ todo_item_get_arg (todo_list , item ));
4586
4577
continue ;
4587
4578
}
4588
4579
@@ -4613,12 +4604,39 @@ int transform_todos(struct repository *r, unsigned flags)
4613
4604
strbuf_addch (& buf , '\n' );
4614
4605
else
4615
4606
strbuf_addf (& buf , " %.*s\n" , item -> arg_len ,
4616
- todo_item_get_arg (& todo_list , item ));
4607
+ todo_item_get_arg (todo_list , item ));
4617
4608
}
4618
4609
4619
- i = write_message (buf .buf , buf .len , todo_file , 0 );
4610
+ strbuf_reset (& todo_list -> buf );
4611
+ strbuf_add (& todo_list -> buf , buf .buf , buf .len );
4612
+ strbuf_release (& buf );
4613
+
4614
+ if (todo_list_parse_insn_buffer (r , todo_list -> buf .buf , todo_list ))
4615
+ BUG ("unusable todo list" );
4616
+ }
4617
+
4618
+ int transform_todo_file (struct repository * r , unsigned flags )
4619
+ {
4620
+ const char * todo_file = rebase_path_todo ();
4621
+ struct todo_list todo_list = TODO_LIST_INIT ;
4622
+ int res ;
4623
+
4624
+ if (strbuf_read_file (& todo_list .buf , todo_file , 0 ) < 0 )
4625
+ return error_errno (_ ("could not read '%s'." ), todo_file );
4626
+
4627
+ if (todo_list_parse_insn_buffer (r , todo_list .buf .buf , & todo_list )) {
4628
+ todo_list_release (& todo_list );
4629
+ return error (_ ("unusable todo list: '%s'" ), todo_file );
4630
+ }
4631
+
4632
+ todo_list_transform (r , & todo_list , flags );
4633
+
4634
+ res = write_message (todo_list .buf .buf , todo_list .buf .len , todo_file , 0 );
4620
4635
todo_list_release (& todo_list );
4621
- return i ;
4636
+
4637
+ if (res )
4638
+ return error_errno (_ ("could not write '%s'." ), todo_file );
4639
+ return 0 ;
4622
4640
}
4623
4641
4624
4642
enum missing_commit_check_level get_missing_commit_check_level (void )
@@ -4880,7 +4898,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
4880
4898
return error (_ ("could not copy '%s' to '%s'." ), todo_file ,
4881
4899
rebase_path_todo_backup ());
4882
4900
4883
- if (transform_todos (r , flags | TODO_LIST_SHORTEN_IDS ))
4901
+ if (transform_todo_file (r , flags | TODO_LIST_SHORTEN_IDS ))
4884
4902
return error (_ ("could not transform the todo list" ));
4885
4903
4886
4904
strbuf_reset (buf );
@@ -4909,7 +4927,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
4909
4927
return -1 ;
4910
4928
}
4911
4929
4912
- if (transform_todos (r , flags & ~(TODO_LIST_SHORTEN_IDS )))
4930
+ if (transform_todo_file (r , flags & ~(TODO_LIST_SHORTEN_IDS )))
4913
4931
return error (_ ("could not transform the todo list" ));
4914
4932
4915
4933
if (opts -> allow_ff && skip_unnecessary_picks (r , & oid ))
0 commit comments