Skip to content

Commit 9f8edcd

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 83df07d commit 9f8edcd

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.
@@ -1382,17 +1392,22 @@ static int read_populate_todo(struct todo_list *todo_list,
13821392

13831393
if (is_rebase_i(opts)) {
13841394
struct todo_list done = TODO_LIST_INIT;
1395+
FILE *f = fopen(rebase_path_msgtotal(), "w");
13851396

13861397
if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
13871398
!parse_insn_buffer(done.buf.buf, &done))
13881399
todo_list->done_nr = count_commands(&done);
13891400
else
13901401
todo_list->done_nr = 0;
1402+
todo_list_release(&done);
13911403

13921404
todo_list->total_nr = todo_list->done_nr
13931405
+ count_commands(todo_list);
13941406

1395-
todo_list_release(&done);
1407+
if (f) {
1408+
fprintf(f, "%d\n", todo_list->total_nr);
1409+
fclose(f);
1410+
}
13961411
}
13971412

13981413
return 0;
@@ -1931,11 +1946,20 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
19311946
if (save_todo(todo_list, opts))
19321947
return -1;
19331948
if (is_rebase_i(opts)) {
1934-
if (item->command != TODO_COMMENT)
1949+
if (item->command != TODO_COMMENT) {
1950+
FILE *f = fopen(rebase_path_msgnum(), "w");
1951+
1952+
todo_list->done_nr++;
1953+
1954+
if (f) {
1955+
fprintf(f, "%d\n", todo_list->done_nr);
1956+
fclose(f);
1957+
}
19351958
fprintf(stderr, "Rebasing (%d/%d)%s",
1936-
++(todo_list->done_nr),
1959+
todo_list->done_nr,
19371960
todo_list->total_nr,
19381961
opts->verbose ? "\n" : "\r");
1962+
}
19391963
unlink(rebase_path_message());
19401964
unlink(rebase_path_author_script());
19411965
unlink(rebase_path_stopped_sha());

0 commit comments

Comments
 (0)