Git fork

rebase -i: pass struct replay_opts to parse_insn_line()

This new parameter will be used in the next commit. As adding the
parameter requires quite a few changes to plumb it through the call
chain these are separated into their own commit to avoid cluttering up
the next commit with incidental changes.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Phillip Wood and committed by
Junio C Hamano
0c26738a 19981dae

+44 -29
+11 -6
builtin/rebase.c
··· 194 194 return replay; 195 195 } 196 196 197 - static int edit_todo_file(unsigned flags) 197 + static int edit_todo_file(unsigned flags, struct replay_opts *opts) 198 198 { 199 199 const char *todo_file = rebase_path_todo(); 200 200 struct todo_list todo_list = TODO_LIST_INIT, ··· 205 205 return error_errno(_("could not read '%s'."), todo_file); 206 206 207 207 strbuf_stripspace(&todo_list.buf, comment_line_str); 208 - res = edit_todo_list(the_repository, &todo_list, &new_todo, NULL, NULL, flags); 208 + res = edit_todo_list(the_repository, opts, &todo_list, &new_todo, 209 + NULL, NULL, flags); 209 210 if (!res && todo_list_write_to_file(the_repository, &new_todo, todo_file, 210 211 NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS))) 211 212 res = error_errno(_("could not write '%s'"), todo_file); ··· 296 297 error(_("could not generate todo list")); 297 298 else { 298 299 discard_index(&the_index); 299 - if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf, 300 - &todo_list)) 300 + if (todo_list_parse_insn_buffer(the_repository, &replay, 301 + todo_list.buf.buf, &todo_list)) 301 302 BUG("unusable todo list"); 302 303 303 304 ret = complete_action(the_repository, &replay, flags, ··· 352 353 replay_opts_release(&replay_opts); 353 354 break; 354 355 } 355 - case ACTION_EDIT_TODO: 356 - ret = edit_todo_file(flags); 356 + case ACTION_EDIT_TODO: { 357 + struct replay_opts replay_opts = get_replay_opts(opts); 358 + 359 + ret = edit_todo_file(flags, &replay_opts); 360 + replay_opts_release(&replay_opts); 357 361 break; 362 + } 358 363 case ACTION_SHOW_CURRENT_PATCH: { 359 364 struct child_process cmd = CHILD_PROCESS_INIT; 360 365
+13 -8
rebase-interactive.c
··· 101 101 strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str); 102 102 } 103 103 104 - int edit_todo_list(struct repository *r, struct todo_list *todo_list, 105 - struct todo_list *new_todo, const char *shortrevisions, 106 - const char *shortonto, unsigned flags) 104 + int edit_todo_list(struct repository *r, struct replay_opts *opts, 105 + struct todo_list *todo_list, struct todo_list *new_todo, 106 + const char *shortrevisions, const char *shortonto, 107 + unsigned flags) 107 108 { 108 109 const char *todo_file = rebase_path_todo(), 109 110 *todo_backup = rebase_path_todo_backup(); ··· 114 115 * it. If there is an error, we do not return, because the user 115 116 * might want to fix it in the first place. */ 116 117 if (!initial) 117 - incorrect = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list) | 118 + incorrect = todo_list_parse_insn_buffer(r, opts, 119 + todo_list->buf.buf, 120 + todo_list) | 118 121 file_exists(rebase_path_dropped()); 119 122 120 123 if (todo_list_write_to_file(r, todo_list, todo_file, shortrevisions, shortonto, ··· 134 137 if (initial && new_todo->buf.len == 0) 135 138 return -3; 136 139 137 - if (todo_list_parse_insn_buffer(r, new_todo->buf.buf, new_todo)) { 140 + if (todo_list_parse_insn_buffer(r, opts, new_todo->buf.buf, new_todo)) { 138 141 fprintf(stderr, _(edit_todo_list_advice)); 139 142 return -4; 140 143 } 141 144 142 145 if (incorrect) { 143 - if (todo_list_check_against_backup(r, new_todo)) { 146 + if (todo_list_check_against_backup(r, opts, new_todo)) { 144 147 write_file(rebase_path_dropped(), "%s", ""); 145 148 return -4; 146 149 } ··· 228 231 return res; 229 232 } 230 233 231 - int todo_list_check_against_backup(struct repository *r, struct todo_list *todo_list) 234 + int todo_list_check_against_backup(struct repository *r, 235 + struct replay_opts *opts, 236 + struct todo_list *todo_list) 232 237 { 233 238 struct todo_list backup = TODO_LIST_INIT; 234 239 int res = 0; 235 240 236 241 if (strbuf_read_file(&backup.buf, rebase_path_todo_backup(), 0) > 0) { 237 - todo_list_parse_insn_buffer(r, backup.buf.buf, &backup); 242 + todo_list_parse_insn_buffer(r, opts, backup.buf.buf, &backup); 238 243 res = todo_list_check(&backup, todo_list); 239 244 } 240 245
+6 -3
rebase-interactive.h
··· 3 3 4 4 struct strbuf; 5 5 struct repository; 6 + struct replay_opts; 6 7 struct todo_list; 7 8 8 9 void append_todo_help(int command_count, 9 10 const char *shortrevisions, const char *shortonto, 10 11 struct strbuf *buf); 11 - int edit_todo_list(struct repository *r, struct todo_list *todo_list, 12 - struct todo_list *new_todo, const char *shortrevisions, 13 - const char *shortonto, unsigned flags); 12 + int edit_todo_list(struct repository *r, struct replay_opts *opts, 13 + struct todo_list *todo_list, struct todo_list *new_todo, 14 + const char *shortrevisions, const char *shortonto, 15 + unsigned flags); 14 16 15 17 int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo); 16 18 int todo_list_check_against_backup(struct repository *r, 19 + struct replay_opts *opts, 17 20 struct todo_list *todo_list); 18 21 19 22 #endif
+12 -10
sequencer.c
··· 2573 2573 return 0; 2574 2574 } 2575 2575 2576 - static int parse_insn_line(struct repository *r, struct todo_item *item, 2577 - const char *buf, const char *bol, char *eol) 2576 + static int parse_insn_line(struct repository *r, struct replay_opts *opts UNUSED, 2577 + struct todo_item *item, const char *buf, 2578 + const char *bol, char *eol) 2578 2579 { 2579 2580 struct object_id commit_oid; 2580 2581 char *end_of_object_name; ··· 2708 2709 return ret; 2709 2710 } 2710 2711 2711 - int todo_list_parse_insn_buffer(struct repository *r, char *buf, 2712 - struct todo_list *todo_list) 2712 + int todo_list_parse_insn_buffer(struct repository *r, struct replay_opts *opts, 2713 + char *buf, struct todo_list *todo_list) 2713 2714 { 2714 2715 struct todo_item *item; 2715 2716 char *p = buf, *next_p; ··· 2727 2728 2728 2729 item = append_new_todo(todo_list); 2729 2730 item->offset_in_buf = p - todo_list->buf.buf; 2730 - if (parse_insn_line(r, item, buf, p, eol)) { 2731 + if (parse_insn_line(r, opts, item, buf, p, eol)) { 2731 2732 res = error(_("invalid line %d: %.*s"), 2732 2733 i, (int)(eol - p), p); 2733 2734 item->command = TODO_COMMENT + 1; ··· 2875 2876 if (strbuf_read_file_or_whine(&todo_list->buf, todo_file) < 0) 2876 2877 return -1; 2877 2878 2878 - res = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list); 2879 + res = todo_list_parse_insn_buffer(r, opts, todo_list->buf.buf, todo_list); 2879 2880 if (res) { 2880 2881 if (is_rebase_i(opts)) 2881 2882 return error(_("please fix this using " ··· 2905 2906 struct todo_list done = TODO_LIST_INIT; 2906 2907 2907 2908 if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 && 2908 - !todo_list_parse_insn_buffer(r, done.buf.buf, &done)) 2909 + !todo_list_parse_insn_buffer(r, opts, done.buf.buf, &done)) 2909 2910 todo_list->done_nr = count_commands(&done); 2910 2911 else 2911 2912 todo_list->done_nr = 0; ··· 5251 5252 goto release_todo_list; 5252 5253 5253 5254 if (file_exists(rebase_path_dropped())) { 5254 - if ((res = todo_list_check_against_backup(r, &todo_list))) 5255 + if ((res = todo_list_check_against_backup(r, opts, 5256 + &todo_list))) 5255 5257 goto release_todo_list; 5256 5258 5257 5259 unlink(rebase_path_dropped()); ··· 6294 6296 return error(_("nothing to do")); 6295 6297 } 6296 6298 6297 - res = edit_todo_list(r, todo_list, &new_todo, shortrevisions, 6299 + res = edit_todo_list(r, opts, todo_list, &new_todo, shortrevisions, 6298 6300 shortonto, flags); 6299 6301 if (res == -1) 6300 6302 return -1; ··· 6322 6324 strbuf_release(&buf2); 6323 6325 /* Nothing is done yet, and we're reparsing, so let's reset the count */ 6324 6326 new_todo.total_nr = 0; 6325 - if (todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo) < 0) 6327 + if (todo_list_parse_insn_buffer(r, opts, new_todo.buf.buf, &new_todo) < 0) 6326 6328 BUG("invalid todo list after expanding IDs:\n%s", 6327 6329 new_todo.buf.buf); 6328 6330
+2 -2
sequencer.h
··· 137 137 .buf = STRBUF_INIT, \ 138 138 } 139 139 140 - int todo_list_parse_insn_buffer(struct repository *r, char *buf, 141 - struct todo_list *todo_list); 140 + int todo_list_parse_insn_buffer(struct repository *r, struct replay_opts *opts, 141 + char *buf, struct todo_list *todo_list); 142 142 int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list, 143 143 const char *file, const char *shortrevisions, 144 144 const char *shortonto, int num, unsigned flags);