sequencer: changes in parse_insn_buffer()
authorAlban Gruin <alban.gruin@gmail.com>
Sat, 29 Dec 2018 16:03:58 +0000 (17:03 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Jan 2019 21:22:09 +0000 (13:22 -0800)
This clears the number of items of a todo_list before parsing it to
allow to parse the same list multiple times without issues. As its
items are not dynamically allocated, or don’t need to allocate memory,
no additionnal memory management is required here.

Furthermore, if a line is invalid, the type of the corresponding
command is set to a garbage value, and its argument is defined properly.
This will allow to recreate the text of a todo list from its commands,
even if one of them is incorrect.

Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
index b68bca0bef927f0ebb2d8762f658946be7107fcb..d605199a54becef7888ad94d7799b5b54b244fc2 100644 (file)
@@ -2141,6 +2141,8 @@ static int parse_insn_buffer(struct repository *r, char *buf,
        char *p = buf, *next_p;
        int i, res = 0, fixup_okay = file_exists(rebase_path_done());
 
+       todo_list->current = todo_list->nr = 0;
+
        for (i = 1; *p; i++, p = next_p) {
                char *eol = strchrnul(p, '\n');
 
@@ -2154,7 +2156,10 @@ static int parse_insn_buffer(struct repository *r, char *buf,
                if (parse_insn_line(r, item, p, eol)) {
                        res = error(_("invalid line %d: %.*s"),
                                i, (int)(eol - p), p);
-                       item->command = TODO_NOOP;
+                       item->command = TODO_COMMENT + 1;
+                       item->arg = p;
+                       item->arg_len = (int)(eol - p);
+                       item->commit = NULL;
                }
 
                if (fixup_okay)