Skip to content

Commit 0c26738

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 19981da commit 0c26738

File tree

5 files changed

+44
-29
lines changed

5 files changed

+44
-29
lines changed

builtin/rebase.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
194194
return replay;
195195
}
196196

197-
static int edit_todo_file(unsigned flags)
197+
static int edit_todo_file(unsigned flags, struct replay_opts *opts)
198198
{
199199
const char *todo_file = rebase_path_todo();
200200
struct todo_list todo_list = TODO_LIST_INIT,
@@ -205,7 +205,8 @@ static int edit_todo_file(unsigned flags)
205205
return error_errno(_("could not read '%s'."), todo_file);
206206

207207
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);
209210
if (!res && todo_list_write_to_file(the_repository, &new_todo, todo_file,
210211
NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS)))
211212
res = error_errno(_("could not write '%s'"), todo_file);
@@ -296,8 +297,8 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
296297
error(_("could not generate todo list"));
297298
else {
298299
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))
301302
BUG("unusable todo list");
302303

303304
ret = complete_action(the_repository, &replay, flags,
@@ -352,9 +353,13 @@ static int run_sequencer_rebase(struct rebase_options *opts)
352353
replay_opts_release(&replay_opts);
353354
break;
354355
}
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);
357361
break;
362+
}
358363
case ACTION_SHOW_CURRENT_PATCH: {
359364
struct child_process cmd = CHILD_PROCESS_INIT;
360365

rebase-interactive.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ void append_todo_help(int command_count,
101101
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
102102
}
103103

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)
107108
{
108109
const char *todo_file = rebase_path_todo(),
109110
*todo_backup = rebase_path_todo_backup();
@@ -114,7 +115,9 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
114115
* it. If there is an error, we do not return, because the user
115116
* might want to fix it in the first place. */
116117
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) |
118121
file_exists(rebase_path_dropped());
119122

120123
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,
134137
if (initial && new_todo->buf.len == 0)
135138
return -3;
136139

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)) {
138141
fprintf(stderr, _(edit_todo_list_advice));
139142
return -4;
140143
}
141144

142145
if (incorrect) {
143-
if (todo_list_check_against_backup(r, new_todo)) {
146+
if (todo_list_check_against_backup(r, opts, new_todo)) {
144147
write_file(rebase_path_dropped(), "%s", "");
145148
return -4;
146149
}
@@ -228,13 +231,15 @@ int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo)
228231
return res;
229232
}
230233

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)
232237
{
233238
struct todo_list backup = TODO_LIST_INIT;
234239
int res = 0;
235240

236241
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);
238243
res = todo_list_check(&backup, todo_list);
239244
}
240245

rebase-interactive.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33

44
struct strbuf;
55
struct repository;
6+
struct replay_opts;
67
struct todo_list;
78

89
void append_todo_help(int command_count,
910
const char *shortrevisions, const char *shortonto,
1011
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);
1416

1517
int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo);
1618
int todo_list_check_against_backup(struct repository *r,
19+
struct replay_opts *opts,
1720
struct todo_list *todo_list);
1821

1922
#endif

sequencer.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,8 +2573,9 @@ static int check_label_or_ref_arg(enum todo_command command, const char *arg)
25732573
return 0;
25742574
}
25752575

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)
25782579
{
25792580
struct object_id commit_oid;
25802581
char *end_of_object_name;
@@ -2708,8 +2709,8 @@ int sequencer_get_last_command(struct repository *r UNUSED, enum replay_action *
27082709
return ret;
27092710
}
27102711

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)
27132714
{
27142715
struct todo_item *item;
27152716
char *p = buf, *next_p;
@@ -2727,7 +2728,7 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf,
27272728

27282729
item = append_new_todo(todo_list);
27292730
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)) {
27312732
res = error(_("invalid line %d: %.*s"),
27322733
i, (int)(eol - p), p);
27332734
item->command = TODO_COMMENT + 1;
@@ -2875,7 +2876,7 @@ static int read_populate_todo(struct repository *r,
28752876
if (strbuf_read_file_or_whine(&todo_list->buf, todo_file) < 0)
28762877
return -1;
28772878

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);
28792880
if (res) {
28802881
if (is_rebase_i(opts))
28812882
return error(_("please fix this using "
@@ -2905,7 +2906,7 @@ static int read_populate_todo(struct repository *r,
29052906
struct todo_list done = TODO_LIST_INIT;
29062907

29072908
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))
29092910
todo_list->done_nr = count_commands(&done);
29102911
else
29112912
todo_list->done_nr = 0;
@@ -5251,7 +5252,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
52515252
goto release_todo_list;
52525253

52535254
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)))
52555257
goto release_todo_list;
52565258

52575259
unlink(rebase_path_dropped());
@@ -6294,7 +6296,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
62946296
return error(_("nothing to do"));
62956297
}
62966298

6297-
res = edit_todo_list(r, todo_list, &new_todo, shortrevisions,
6299+
res = edit_todo_list(r, opts, todo_list, &new_todo, shortrevisions,
62986300
shortonto, flags);
62996301
if (res == -1)
63006302
return -1;
@@ -6322,7 +6324,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
63226324
strbuf_release(&buf2);
63236325
/* Nothing is done yet, and we're reparsing, so let's reset the count */
63246326
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)
63266328
BUG("invalid todo list after expanding IDs:\n%s",
63276329
new_todo.buf.buf);
63286330

sequencer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ struct todo_list {
137137
.buf = STRBUF_INIT, \
138138
}
139139

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);
142142
int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list,
143143
const char *file, const char *shortrevisions,
144144
const char *shortonto, int num, unsigned flags);

0 commit comments

Comments
 (0)