sequencer (rebase -i): show the progress
The interactive rebase keeps the user informed about its progress. If the sequencer wants to do the grunt work of the interactive rebase, it also needs to show that progress. 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:35 UTC
968492e44c08f40cbfec083c22e05984f84c2353
1 file changed
+32
sequencer.c
+32
@@ -1181,6 +1181,7 @@ struct todo_list {
1181
struct strbuf buf;
1182
struct todo_item *items;
1183
int nr, alloc, current;
1184
+ int done_nr, total_nr;
1185
};
1186
1187
#define TODO_LIST_INIT { STRBUF_INIT }
@@ -1297,6 +1298,17 @@ static int parse_insn_buffer(char *buf, struct todo_list *todo_list)
1298
return res;
1299
}
1300
1301
+static int count_commands(struct todo_list *todo_list)
1302
+{
1303
+ int count = 0, i;
1304
+
1305
+ for (i = 0; i < todo_list->nr; i++)
1306
+ if (todo_list->items[i].command != TODO_COMMENT)
1307
+ count++;
1308
+
1309
+ return count;
1310
+}
1311
+
1312
static int read_populate_todo(struct todo_list *todo_list,
1313
struct replay_opts *opts)
1314
{
@@ -1339,6 +1351,21 @@ static int read_populate_todo(struct todo_list *todo_list,
1351
return error(_("cannot revert during a cherry-pick."));
1352
}
1353
1354
+ if (is_rebase_i(opts)) {
1355
+ struct todo_list done = TODO_LIST_INIT;
1356
+
1357
+ if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
1358
+ !parse_insn_buffer(done.buf.buf, &done))
1359
+ todo_list->done_nr = count_commands(&done);
1360
+ else
1361
+ todo_list->done_nr = 0;
1362
+
1363
+ todo_list->total_nr = todo_list->done_nr
1364
+ + count_commands(todo_list);
1365
+
1366
+ todo_list_release(&done);
1367
+ }
1368
+
1369
return 0;
1370
}
1371
@@ -1920,6 +1947,11 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
1947
if (save_todo(todo_list, opts))
1948
return -1;
1949
if (is_rebase_i(opts)) {
1950
+ if (item->command != TODO_COMMENT)
1951
+ fprintf(stderr, "Rebasing (%d/%d)%s",
1952
+ ++(todo_list->done_nr),
1953
+ todo_list->total_nr,
1954
+ opts->verbose ? "\n" : "\r");
1955
unlink(rebase_path_message());
1956
unlink(rebase_path_author_script());
1957
unlink(rebase_path_stopped_sha());