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>
Phillip Wood committed
May 30, 2024 at 13:43 UTC
0c26738aa4a8256b40a46476c2433c03a562124f
5 files changed
+44
-29
builtin/rebase.c
+11
-6
@@ -194,7 +194,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
194
return replay;
195
}
196
197
-static int edit_todo_file(unsigned flags)
197
+static int edit_todo_file(unsigned flags, struct replay_opts *opts)
198
{
199
const char *todo_file = rebase_path_todo();
200
struct todo_list todo_list = TODO_LIST_INIT,
@@ -205,7 +205,8 @@ static int edit_todo_file(unsigned flags)
205
return error_errno(_("could not read '%s'."), todo_file);
206
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);
210
if (!res && todo_list_write_to_file(the_repository, &new_todo, todo_file,
211
NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS)))
212
res = error_errno(_("could not write '%s'"), todo_file);
@@ -296,8 +297,8 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
297
error(_("could not generate todo list"));
298
else {
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))
302
BUG("unusable todo list");
303
304
ret = complete_action(the_repository, &replay, flags,
@@ -352,9 +353,13 @@ static int run_sequencer_rebase(struct rebase_options *opts)
353
replay_opts_release(&replay_opts);
354
break;
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);
361
break;
362
+ }
363
case ACTION_SHOW_CURRENT_PATCH: {
364
struct child_process cmd = CHILD_PROCESS_INIT;
365
rebase-interactive.c
+13
-8
@@ -101,9 +101,10 @@ void append_todo_help(int command_count,
101
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
102
}
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)
108
{
109
const char *todo_file = rebase_path_todo(),
110
*todo_backup = rebase_path_todo_backup();
@@ -114,7 +115,9 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
115
* it. If there is an error, we do not return, because the user
116
* might want to fix it in the first place. */
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) |
121
file_exists(rebase_path_dropped());
122
123
if (todo_list_write_to_file(r, todo_list, todo_file, shortrevisions, shortonto,
@@ -134,13 +137,13 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
137
if (initial && new_todo->buf.len == 0)
138
return -3;
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)) {
141
fprintf(stderr, _(edit_todo_list_advice));
142
return -4;
143
}
144
145
if (incorrect) {
143
- if (todo_list_check_against_backup(r, new_todo)) {
146
+ if (todo_list_check_against_backup(r, opts, new_todo)) {
147
write_file(rebase_path_dropped(), "%s", "");
148
return -4;
149
}
@@ -228,13 +231,15 @@ leave_check:
231
return res;
232
}
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)
237
{
238
struct todo_list backup = TODO_LIST_INIT;
239
int res = 0;
240
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);
243
res = todo_list_check(&backup, todo_list);
244
}
245
rebase-interactive.h
+6
-3
@@ -3,17 +3,20 @@
3
4
struct strbuf;
5
struct repository;
6
+struct replay_opts;
7
struct todo_list;
8
9
void append_todo_help(int command_count,
10
const char *shortrevisions, const char *shortonto,
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);
16
17
int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo);
18
int todo_list_check_against_backup(struct repository *r,
19
+ struct replay_opts *opts,
20
struct todo_list *todo_list);
21
22
#endif
sequencer.c
+12
-10
@@ -2573,8 +2573,9 @@ static int check_label_or_ref_arg(enum todo_command command, const char *arg)
2573
return 0;
2574
}
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)
2579
{
2580
struct object_id commit_oid;
2581
char *end_of_object_name;
@@ -2708,8 +2709,8 @@ int sequencer_get_last_command(struct repository *r UNUSED, enum replay_action *
2709
return ret;
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)
2714
{
2715
struct todo_item *item;
2716
char *p = buf, *next_p;
@@ -2727,7 +2728,7 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf,
2728
2729
item = append_new_todo(todo_list);
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)) {
2732
res = error(_("invalid line %d: %.*s"),
2733
i, (int)(eol - p), p);
2734
item->command = TODO_COMMENT + 1;
@@ -2875,7 +2876,7 @@ static int read_populate_todo(struct repository *r,
2876
if (strbuf_read_file_or_whine(&todo_list->buf, todo_file) < 0)
2877
return -1;
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);
2880
if (res) {
2881
if (is_rebase_i(opts))
2882
return error(_("please fix this using "
@@ -2905,7 +2906,7 @@ static int read_populate_todo(struct repository *r,
2906
struct todo_list done = TODO_LIST_INIT;
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))
2910
todo_list->done_nr = count_commands(&done);
2911
else
2912
todo_list->done_nr = 0;
@@ -5251,7 +5252,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
5252
goto release_todo_list;
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)))
5257
goto release_todo_list;
5258
5259
unlink(rebase_path_dropped());
@@ -6294,7 +6296,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
6296
return error(_("nothing to do"));
6297
}
6298
6297
- res = edit_todo_list(r, todo_list, &new_todo, shortrevisions,
6299
+ res = edit_todo_list(r, opts, todo_list, &new_todo, shortrevisions,
6300
shortonto, flags);
6301
if (res == -1)
6302
return -1;
@@ -6322,7 +6324,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
6324
strbuf_release(&buf2);
6325
/* Nothing is done yet, and we're reparsing, so let's reset the count */
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)
6328
BUG("invalid todo list after expanding IDs:\n%s",
6329
new_todo.buf.buf);
6330
sequencer.h
+2
-2
@@ -137,8 +137,8 @@ struct todo_list {
137
.buf = STRBUF_INIT, \
138
}
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
int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list,
143
const char *file, const char *shortrevisions,
144
const char *shortonto, int num, unsigned flags);