Skip to content

Commit cf84c41

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 05b7930 commit cf84c41

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.
@@ -1383,6 +1393,7 @@ static int read_populate_todo(struct todo_list *todo_list,
13831393

13841394
if (is_rebase_i(opts)) {
13851395
struct todo_list done = TODO_LIST_INIT;
1396+
FILE *f = fopen(rebase_path_msgtotal(), "w");
13861397

13871398
if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
13881399
!parse_insn_buffer(done.buf.buf, &done))
@@ -1392,8 +1403,12 @@ static int read_populate_todo(struct todo_list *todo_list,
13921403

13931404
todo_list->total_nr = todo_list->done_nr
13941405
+ count_commands(todo_list);
1395-
13961406
todo_list_release(&done);
1407+
1408+
if (f) {
1409+
fprintf(f, "%d\n", todo_list->total_nr);
1410+
fclose(f);
1411+
}
13971412
}
13981413

13991414
return 0;
@@ -1946,11 +1961,20 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
19461961
if (save_todo(todo_list, opts))
19471962
return -1;
19481963
if (is_rebase_i(opts)) {
1949-
if (item->command != TODO_COMMENT)
1964+
if (item->command != TODO_COMMENT) {
1965+
FILE *f = fopen(rebase_path_msgnum(), "w");
1966+
1967+
todo_list->done_nr++;
1968+
1969+
if (f) {
1970+
fprintf(f, "%d\n", todo_list->done_nr);
1971+
fclose(f);
1972+
}
19501973
fprintf(stderr, "Rebasing (%d/%d)%s",
1951-
++(todo_list->done_nr),
1974+
todo_list->done_nr,
19521975
todo_list->total_nr,
19531976
opts->verbose ? "\n" : "\r");
1977+
}
19541978
unlink(rebase_path_message());
19551979
unlink(rebase_path_author_script());
19561980
unlink(rebase_path_stopped_sha());

0 commit comments

Comments
 (0)