sequencer: move the code writing total_nr on the disk to a new function
The total number of commands can be used to show the progression of the rebasing in a shell. It is written to the disk by read_populate_todo() when the todo list is loaded from sequencer_continue() or pick_commits(), but not by complete_action(). This moves the part writing total_nr to a new function so it can be called from complete_action(). Signed-off-by: Alban Gruin <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alban Gruin committed
Nov 24, 2019 at 18:43 UTC
3f34f2d8a4da82ddda48a591cbb091f24a5f3e58
1 file changed
+11
-5
sequencer.c
+11
-5
@@ -2342,6 +2342,16 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose)
2342
sequencer_remove_state(&opts);
2343
}
2344
2345
+static void todo_list_write_total_nr(struct todo_list *todo_list)
2346
+{
2347
+ FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w");
2348
+
2349
+ if (f) {
2350
+ fprintf(f, "%d\n", todo_list->total_nr);
2351
+ fclose(f);
2352
+ }
2353
+}
2354
+
2355
static int read_populate_todo(struct repository *r,
2356
struct todo_list *todo_list,
2357
struct replay_opts *opts)
@@ -2387,7 +2397,6 @@ static int read_populate_todo(struct repository *r,
2397
2398
if (is_rebase_i(opts)) {
2399
struct todo_list done = TODO_LIST_INIT;
2390
- FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w");
2400
2401
if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
2402
!todo_list_parse_insn_buffer(r, done.buf.buf, &done))
@@ -2399,10 +2408,7 @@ static int read_populate_todo(struct repository *r,
2408
+ count_commands(todo_list);
2409
todo_list_release(&done);
2410
2402
- if (f) {
2403
- fprintf(f, "%d\n", todo_list->total_nr);
2404
- fclose(f);
2405
- }
2411
+ todo_list_write_total_nr(todo_list);
2412
}
2413
2414
return 0;