+ strbuf_reset(&todo_list->buf);
+ strbuf_add(&todo_list->buf, buf.buf, buf.len);
+ strbuf_release(&buf);
+
+ if (todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list))
+ BUG("unusable todo list");
+}
+
+int transform_todo_file(struct repository *r, unsigned flags)
+{
+ const char *todo_file = rebase_path_todo();
+ struct todo_list todo_list = TODO_LIST_INIT;
+ int res;
+
+ if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
+ return error_errno(_("could not read '%s'."), todo_file);
+
+ if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {
+ todo_list_release(&todo_list);
+ return error(_("unusable todo list: '%s'"), todo_file);
+ }
+
+ todo_list_transform(r, &todo_list, flags);
+
+ res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0);