sequencer: refactor rearrange_squash() to work on a todo_list

This refactors rearrange_squash() to work on a todo_list to avoid
redundant reads and writes.  The function is renamed
todo_list_rearrange_squash().

The old version created a new buffer, which was directly written to the
disk.  This new version creates a new item list by just copying items
from the old item list, without creating a new buffer.  This eliminates
the need to reparse the todo list, but this also means its buffer cannot
be directly written to the disk.

As rebase -p still need to check the todo list from the disk, a new
function is introduced, rearrange_squash_in_todo_file().

complete_action() still uses rearrange_squash_in_todo_file() for now.
This will be changed in a future commit.

Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Alban Gruin
2019-03-05 20:17:55 +01:00
committed by Junio C Hamano
parent 683153a438
commit f2a04904be
3 changed files with 49 additions and 47 deletions

View File

@ -268,7 +268,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
ret = check_todo_list_from_file(the_repository);
break;
case REARRANGE_SQUASH:
ret = rearrange_squash(the_repository);
ret = rearrange_squash_in_todo_file(the_repository);
break;
case ADD_EXEC:
ret = sequencer_add_exec_commands(the_repository, &commands);