diff options
author | Alban Gruin <alban.gruin@gmail.com> | 2019-03-05 20:18:03 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-03-07 09:17:57 +0900 |
commit | a930eb03a8299b5b29284dd9e3c253c38187167a (patch) | |
tree | 701fad4abf3ec0445d84a33158c85bf61d0d3ea0 /rebase-interactive.c | |
parent | af1fc3adc5bf0d831ee3c1c8e86c1b7ce59e070e (diff) | |
download | git-a930eb03a8299b5b29284dd9e3c253c38187167a.tar.gz |
rebase-interactive: rewrite edit_todo_list() to handle the initial edit
edit_todo_list() is changed to work on a todo_list, and to handle the
initial edition of the todo list (ie. making a backup of the todo
list).
It does not check for dropped commits yet, as todo_list_check() does not
take the commits that have already been processed by the rebase (ie. the
todo list is edited in the middle of a rebase session).
Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'rebase-interactive.c')
-rw-r--r-- | rebase-interactive.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/rebase-interactive.c b/rebase-interactive.c index 807f8370db..aa18ae82b7 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -87,35 +87,40 @@ void append_todo_help(unsigned keep_empty, int command_count, } } -int edit_todo_list(struct repository *r, unsigned flags) +int edit_todo_list(struct repository *r, struct todo_list *todo_list, + struct todo_list *new_todo, const char *shortrevisions, + const char *shortonto, unsigned flags) { const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - int res = 0; - - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); - - strbuf_stripspace(&todo_list.buf, 1); - todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); - if (todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, - flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) { - todo_list_release(&todo_list); - return -1; - } + unsigned initial = shortrevisions && shortonto; - strbuf_reset(&todo_list.buf); - if (launch_sequence_editor(todo_file, &todo_list.buf, NULL)) { - todo_list_release(&todo_list); - return -1; - } + /* If the user is editing the todo list, we first try to parse + * it. If there is an error, we do not return, because the user + * might want to fix it in the first place. */ + if (!initial) + todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list); - if (!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) - res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, - flags & ~(TODO_LIST_SHORTEN_IDS)); + if (todo_list_write_to_file(r, todo_list, todo_file, shortrevisions, shortonto, + -1, flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) + return error_errno(_("could not write '%s'"), todo_file); - todo_list_release(&todo_list); - return res; + if (initial && copy_file(rebase_path_todo_backup(), todo_file, 0666)) + return error(_("could not copy '%s' to '%s'."), todo_file, + rebase_path_todo_backup()); + + if (launch_sequence_editor(todo_file, &new_todo->buf, NULL)) + return -2; + + strbuf_stripspace(&new_todo->buf, 1); + if (initial && new_todo->buf.len == 0) + return -3; + + /* For the initial edit, the todo list gets parsed in + * complete_action(). */ + if (!initial) + return todo_list_parse_insn_buffer(r, new_todo->buf.buf, new_todo); + + return 0; } define_commit_slab(commit_seen, unsigned char); |