sequencer: introduce todo_list_write_to_file()

This introduces a new function to recreate the text of a todo list from
its commands and write it to a file.  This will be useful as the next
few commits will change the use of the buffer in struct todo_list so it
will no longer be a mirror of the file on disk.

This functionality already exists in todo_list_transform(), but this
function was made to replace the buffer of a todo list, which is not
what we want here.  Thus, the part of todo_list_transform() that
replaces the buffer is dropped, and the function is renamed
todo_list_to_strbuf().  It is called by todo_list_write_to_file() to
fill the buffer to write to the disk.

todo_list_write_to_file() can also take care of appending the help text
to the buffer before writing it to the disk, or to write only the first
n items of the list.  This feature will be used by
skip_unnecessary_picks(), which has to write done commands in a file.

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-01-29 16:01:48 +01:00
committed by Junio C Hamano
parent cbef27d61c
commit 616d7740cf
2 changed files with 48 additions and 24 deletions

View File

@ -121,8 +121,9 @@ struct todo_list {
int todo_list_parse_insn_buffer(struct repository *r, char *buf,
struct todo_list *todo_list);
void todo_list_transform(struct repository *r, struct todo_list *todo_list,
unsigned flags);
int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list,
const char *file, const char *shortrevisions,
const char *shortonto, int num, unsigned flags);
void todo_list_release(struct todo_list *todo_list);
const char *todo_item_get_arg(struct todo_list *todo_list,
struct todo_item *item);
@ -145,8 +146,10 @@ int sequencer_remove_state(struct replay_opts *opts);
* commits should be rebased onto the new base, this flag needs to be passed.
*/
#define TODO_LIST_REBASE_COUSINS (1U << 4)
int sequencer_make_script(struct repository *repo, FILE *out,
int argc, const char **argv,
#define TODO_LIST_APPEND_TODO_HELP (1U << 5)
int sequencer_make_script(struct repository *r, FILE *out, int argc,
const char **argv,
unsigned flags);
int sequencer_add_exec_commands(struct repository *r, const char *command);