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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 2, 2017 at 16:36 UTC ef80069a037e5c5180a67eadedc375e184a28dbb
1 file changed +27 -3
sequencer.c
+27 -3
@@ -46,6 +46,16 @@ static GIT_PATH_FUNC(rebase_path_todo, "rebase-merge/git-rebase-todo")
46 * actions.
47 */
48 static GIT_PATH_FUNC(rebase_path_done, "rebase-merge/done")
49 +/*
50 + * The file to keep track of how many commands were already processed (e.g.
51 + * for the prompt).
52 + */
53 +static GIT_PATH_FUNC(rebase_path_msgnum, "rebase-merge/msgnum");
54 +/*
55 + * The file to keep track of how many commands are to be processed in total
56 + * (e.g. for the prompt).
57 + */
58 +static GIT_PATH_FUNC(rebase_path_msgtotal, "rebase-merge/end");
59 /*
60 * The commit message that is planned to be used for any changes that
61 * need to be committed following a user interaction.
@@ -1353,6 +1363,7 @@ static int read_populate_todo(struct todo_list *todo_list,
1363
1364 if (is_rebase_i(opts)) {
1365 struct todo_list done = TODO_LIST_INIT;
1366 + FILE *f = fopen(rebase_path_msgtotal(), "w");
1367
1368 if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
1369 !parse_insn_buffer(done.buf.buf, &done))
@@ -1362,8 +1373,12 @@ static int read_populate_todo(struct todo_list *todo_list,
1373
1374 todo_list->total_nr = todo_list->done_nr
1375 + count_commands(todo_list);
1365 -
1376 todo_list_release(&done);
1377 +
1378 + if (f) {
1379 + fprintf(f, "%d\n", todo_list->total_nr);
1380 + fclose(f);
1381 + }
1382 }
1383
1384 return 0;
@@ -1947,11 +1962,20 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
1962 if (save_todo(todo_list, opts))
1963 return -1;
1964 if (is_rebase_i(opts)) {
1950 - if (item->command != TODO_COMMENT)
1965 + if (item->command != TODO_COMMENT) {
1966 + FILE *f = fopen(rebase_path_msgnum(), "w");
1967 +
1968 + todo_list->done_nr++;
1969 +
1970 + if (f) {
1971 + fprintf(f, "%d\n", todo_list->done_nr);
1972 + fclose(f);
1973 + }
1974 fprintf(stderr, "Rebasing (%d/%d)%s",
1952 - ++(todo_list->done_nr),
1975 + todo_list->done_nr,
1976 todo_list->total_nr,
1977 opts->verbose ? "\n" : "\r");
1978 + }
1979 unlink(rebase_path_message());
1980 unlink(rebase_path_author_script());
1981 unlink(rebase_path_stopped_sha());