]> git.ipfire.org Git - thirdparty/git.git/commit
rebase -r: fix the total number shown in the progress
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Sat, 13 May 2023 08:11:26 +0000 (08:11 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 May 2023 04:44:50 +0000 (21:44 -0700)
commit170eea9750e1bca7a35b5d27def9ee77df92fdf1
tree8d1ca44d44b34556f5974c44db68723386c65d04
parentfa5103dd8913366b031ad8daa11f27e9452638be
rebase -r: fix the total number shown in the progress

For regular, non-`--rebase-merges` runs, there is very little work to do
for the parser when determining the total number of commands in a rebase
script: it is simply the number of lines after stripping the commented
lines and then trimming the trailing empty line, if any.

The `--rebase-merges` mode complicates things by introducing empty lines
and comments in the middle of the script. These should _not_ be counted
as commands, and indeed, when an interactive rebase is interrupted and
subsequently resumed, the total number of commands can magically shrink,
sometimes dramatically.

The reason for this strange behavior is that empty lines _are_ counted
in `edit_todo_list()` (but not the comments, as they are stripped via
`strbuf_stripspace(..., 1)`, which is a bug.

Let's fix this so that the correct total number is shown from the
get-go, by carefully adjusting it according to what's in the rebase
script. Extra care needs to be taken in case the user edits the script:
the number of commands might be different after the user edited than
beforehand.

Note: Even though commented lines are skipped in `edit_todo_list()`, we
still need to handle `TODO_COMMENT` items by decrementing the
already-incremented `total_nr` again: empty lines are also marked as
`TODO_COMMENT`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3430-rebase-merges.sh