Skip to content

Commit 3a70368

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 <johannes.schindelin@gmx.de>
1 parent dd0709c commit 3a70368

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

sequencer.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ static GIT_PATH_FUNC(git_path_rebase_todo, "rebase-merge/git-rebase-todo")
4343
* actions.
4444
*/
4545
static GIT_PATH_FUNC(git_path_rebase_done, "rebase-merge/done")
46+
/*
47+
* The file to keep track of how many commands were already processed (e.g.
48+
* for the prompt).
49+
*/
50+
static GIT_PATH_FUNC(msgnum, "rebase-merge/msgnum");
51+
/*
52+
* The file to keep track of how many commands are to be processed in total
53+
* (e.g. for the prompt).
54+
*/
55+
static GIT_PATH_FUNC(msgtotal, "rebase-merge/end");
4656
/*
4757
* The commit message that is planned to be used for any changes that
4858
* need to be committed following a user interaction.
@@ -1258,18 +1268,23 @@ static int read_populate_todo(struct todo_list *todo_list,
12581268

12591269
if (IS_REBASE_I()) {
12601270
struct todo_list done = TODO_LIST_INIT;
1271+
FILE *f = fopen(msgtotal(), "w");
12611272

12621273
if (strbuf_read_file(&done.buf,
12631274
git_path_rebase_done(), 0) > 0 &&
12641275
!parse_insn_buffer(done.buf.buf, &done, opts))
12651276
todo_list->done_nr = count_commands(&done);
12661277
else
12671278
todo_list->done_nr = 0;
1279+
todo_list_release(&done);
12681280

12691281
todo_list->total_nr = todo_list->done_nr
12701282
+ count_commands(todo_list);
12711283

1272-
todo_list_release(&done);
1284+
if (f) {
1285+
fprintf(f, "%d\n", todo_list->total_nr);
1286+
fclose(f);
1287+
}
12731288
}
12741289

12751290
return 0;
@@ -1748,11 +1763,20 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
17481763
if (save_todo(todo_list, opts))
17491764
return -1;
17501765
if (IS_REBASE_I()) {
1751-
if (item->command != TODO_COMMENT)
1766+
if (item->command != TODO_COMMENT) {
1767+
FILE *f = fopen(msgnum(), "w");
1768+
1769+
todo_list->done_nr++;
1770+
1771+
if (f) {
1772+
fprintf(f, "%d\n", todo_list->done_nr);
1773+
fclose(f);
1774+
}
17521775
fprintf(stderr, "Rebasing (%d/%d)%s",
1753-
++(todo_list->done_nr),
1776+
todo_list->done_nr,
17541777
todo_list->total_nr,
17551778
file_exists(git_path_rebase_verbose()) ? "\n" : "\r");
1779+
}
17561780
unlink(git_path_rebase_msg());
17571781
unlink(author_script());
17581782
unlink(stopped_sha());

0 commit comments

Comments
 (0)