| 104 | } |
| 105 | |
| 106 | int edit_todo_list(struct repository *r, struct replay_opts *opts, |
| 107 | struct todo_list *todo_list, struct todo_list *new_todo, |
| 108 | const char *shortrevisions, const char *shortonto, |
| 109 | unsigned flags) |
| 110 | { |
| 111 | const char *todo_file = rebase_path_todo(), |
| 112 | *todo_backup = rebase_path_todo_backup(); |
| 113 | unsigned initial = shortrevisions && shortonto; |
| 114 | int incorrect = 0; |
| 115 | |
| 116 | /* If the user is editing the todo list, we first try to parse |
| 117 | * it. If there is an error, we do not return, because the user |
| 118 | * might want to fix it in the first place. */ |
| 119 | if (!initial) |
| 120 | incorrect = todo_list_parse_insn_buffer(r, opts, |
| 121 | todo_list->buf.buf, |
| 122 | todo_list) | |
| 123 | file_exists(rebase_path_dropped()); |
| 124 | |
| 125 | if (todo_list_write_to_file(r, todo_list, todo_file, shortrevisions, shortonto, |
| 126 | -1, flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) |
| 127 | return error_errno(_("could not write '%s'"), todo_file); |
| 128 | |
| 129 | if (!incorrect && |
| 130 | todo_list_write_to_file(r, todo_list, todo_backup, |
| 131 | shortrevisions, shortonto, -1, |
| 132 | (flags | TODO_LIST_APPEND_TODO_HELP) & ~TODO_LIST_SHORTEN_IDS) < 0) |
| 133 | return error(_("could not write '%s'."), rebase_path_todo_backup()); |
| 134 | |
| 135 | if (launch_sequence_editor(todo_file, &new_todo->buf, NULL)) |
| 136 | return -2; |
| 137 | |
| 138 | strbuf_stripspace(&new_todo->buf, comment_line_str); |
| 139 | if (initial && new_todo->buf.len == 0) |
| 140 | return -3; |
| 141 | |
| 142 | if (todo_list_parse_insn_buffer(r, opts, new_todo->buf.buf, new_todo)) { |
| 143 | fprintf(stderr, _(edit_todo_list_advice)); |
| 144 | return -4; |
| 145 | } |
| 146 | |
| 147 | if (incorrect) { |
| 148 | if (todo_list_check_against_backup(r, opts, new_todo)) { |
| 149 | write_file(rebase_path_dropped(), "%s", ""); |
| 150 | return -4; |
| 151 | } |
| 152 | |
| 153 | if (incorrect > 0) |
| 154 | unlink(rebase_path_dropped()); |
| 155 | } else if (todo_list_check(todo_list, new_todo)) { |
| 156 | write_file(rebase_path_dropped(), "%s", ""); |
| 157 | return -4; |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * See if branches need to be added or removed from the update-refs |
| 162 | * file based on the new todo list. |
| 163 | */ |
no test coverage detected