On 30/11/2018 19:06, Johannes Schindelin wrote:
Hi,
On Fri, 30 Nov 2018, Phillip Wood wrote:
diff --git a/sequencer.c b/sequencer.c
index 900899ef20..11692d0b98 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4394,24 +4394,29 @@ int sequencer_make_script(FILE *out, int argc, const
char **argv,
return 0;
}
-/*
- * Add commands after pick and (series of) squash/fixup commands
- * in the todo list.
- */
-int sequencer_add_exec_commands(const char *commands)
+static void todo_list_add_exec_commands(struct todo_list *todo_list,
+ struct string_list *commands)
{
- const char *todo_file = rebase_path_todo();
- struct todo_list todo_list = TODO_LIST_INIT;
- struct strbuf *buf = &todo_list.buf;
- size_t offset = 0, commands_len = strlen(commands);
- int i, insert;
+ struct strbuf *buf = &todo_list->buf;
+ const char *old_buf = buf->buf;
+ size_t base_length = buf->len;
+ int i, insert, nr = 0, alloc = 0;
+ struct todo_item *items = NULL, *base_items = NULL;
- if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
- return error(_("could not read '%s'."), todo_file);
+ for (i = 0; i < commands->nr; ++i) {
+ strbuf_addstr(buf, commands->items[i].string);
+ strbuf_addch(buf, '\n');
+ }
This could cause buf->buf to be reallocated in which case all the
todo_list_item.arg pointers will be invalidated.
I guess it is a good time for me to admit that the `arg` idea was not my
best. Maybe it would be good to convert that from a pointer to an offset,
e.g. `size_t arg_offset_in_buf;`? Or maybe we should just drop the
`_in_buf` suffix and clarify in a comment next to the declaration of the
fields that they are offsets in the strbuf?
I think that sounds sensible (though I haven't looked at how much work
it would be), having a comment and calling it arg_offset would be my
preference.
Best Wishes
Phillip
Ciao,
Dscho