Skip to content

Commit 479efdc

Browse files
committed
sequencer (rebase -i): write the progress into files
For the benefit of e.g. the shell prompt, the interactive rebase not only displays the progress for the user to see, but also writes it into the msgnum/end files in the state directory. Teach the sequencer this new trick. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 3207457 commit 479efdc

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

sequencer.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ static GIT_PATH_FUNC(rebase_path_todo, "rebase-merge/git-rebase-todo")
4444
* actions.
4545
*/
4646
static GIT_PATH_FUNC(rebase_path_done, "rebase-merge/done")
47+
/*
48+
* The file to keep track of how many commands were already processed (e.g.
49+
* for the prompt).
50+
*/
51+
static GIT_PATH_FUNC(rebase_path_msgnum, "rebase-merge/msgnum");
52+
/*
53+
* The file to keep track of how many commands are to be processed in total
54+
* (e.g. for the prompt).
55+
*/
56+
static GIT_PATH_FUNC(rebase_path_msgtotal, "rebase-merge/end");
4757
/*
4858
* The commit message that is planned to be used for any changes that
4959
* need to be committed following a user interaction.
@@ -1370,17 +1380,22 @@ static int read_populate_todo(struct todo_list *todo_list,
13701380

13711381
if (is_rebase_i(opts)) {
13721382
struct todo_list done = TODO_LIST_INIT;
1383+
FILE *f = fopen(rebase_path_msgtotal(), "w");
13731384

13741385
if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
13751386
!parse_insn_buffer(done.buf.buf, &done))
13761387
todo_list->done_nr = count_commands(&done);
13771388
else
13781389
todo_list->done_nr = 0;
1390+
todo_list_release(&done);
13791391

13801392
todo_list->total_nr = todo_list->done_nr
13811393
+ count_commands(todo_list);
13821394

1383-
todo_list_release(&done);
1395+
if (f) {
1396+
fprintf(f, "%d\n", todo_list->total_nr);
1397+
fclose(f);
1398+
}
13841399
}
13851400

13861401
return 0;
@@ -1928,11 +1943,20 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
19281943
if (save_todo(todo_list, opts))
19291944
return -1;
19301945
if (is_rebase_i(opts)) {
1931-
if (item->command != TODO_COMMENT)
1946+
if (item->command != TODO_COMMENT) {
1947+
FILE *f = fopen(rebase_path_msgnum(), "w");
1948+
1949+
todo_list->done_nr++;
1950+
1951+
if (f) {
1952+
fprintf(f, "%d\n", todo_list->done_nr);
1953+
fclose(f);
1954+
}
19321955
fprintf(stderr, "Rebasing (%d/%d)%s",
1933-
++(todo_list->done_nr),
1956+
todo_list->done_nr,
19341957
todo_list->total_nr,
19351958
opts->verbose ? "\n" : "\r");
1959+
}
19361960
unlink(rebase_path_message());
19371961
unlink(rebase_path_author_script());
19381962
unlink(rebase_path_stopped_sha());

0 commit comments

Comments
 (0)