sequencer: make sequencer_make_script() write its script to a strbuf

This makes sequencer_make_script() write its script to a strbuf (ie. the
buffer of a todo_list) instead of a FILE.  This reduce the amount of
read/write made by rebase interactive.

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:56 +01:00
committed by Junio C Hamano
parent f2a04904be
commit d358fc286d
3 changed files with 28 additions and 31 deletions

View File

@ -71,7 +71,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
const char *head_hash = NULL;
char *revisions = NULL, *shortrevisions = NULL;
struct argv_array make_script_args = ARGV_ARRAY_INIT;
FILE *todo_list;
FILE *todo_list_file;
struct todo_list todo_list = TODO_LIST_INIT;
if (prepare_branch_to_be_rebased(opts, switch_to))
return -1;
@ -93,8 +94,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
if (!upstream && squash_onto)
write_file(path_squash_onto(), "%s\n", squash_onto);
todo_list = fopen(rebase_path_todo(), "w");
if (!todo_list) {
todo_list_file = fopen(rebase_path_todo(), "w");
if (!todo_list_file) {
free(revisions);
free(shortrevisions);
@ -105,10 +106,11 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
if (restrict_revision)
argv_array_push(&make_script_args, restrict_revision);
ret = sequencer_make_script(the_repository, todo_list,
ret = sequencer_make_script(the_repository, &todo_list.buf,
make_script_args.argc, make_script_args.argv,
flags);
fclose(todo_list);
fputs(todo_list.buf.buf, todo_list_file);
fclose(todo_list_file);
if (ret)
error(_("could not generate todo list"));
@ -121,6 +123,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
free(revisions);
free(shortrevisions);
todo_list_release(&todo_list);
argv_array_clear(&make_script_args);
return ret;