Skip to content

Commit 1ba204d

Browse files
agrngitster
authored andcommitted
rebase--interactive: move sequencer_add_exec_commands()
As sequencer_add_exec_commands() is only needed inside of rebase--interactive.c for `rebase -p', it is moved there from sequencer.c. The parameter r (repository) is dropped along the way. Signed-off-by: Alban Gruin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 94bcad7 commit 1ba204d

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

builtin/rebase--interactive.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ static GIT_PATH_FUNC(path_state_dir, "rebase-merge/")
1313
static GIT_PATH_FUNC(path_squash_onto, "rebase-merge/squash-onto")
1414
static GIT_PATH_FUNC(path_interactive, "rebase-merge/interactive")
1515

16+
static int add_exec_commands(struct string_list *commands)
17+
{
18+
const char *todo_file = rebase_path_todo();
19+
struct todo_list todo_list = TODO_LIST_INIT;
20+
int res;
21+
22+
if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
23+
return error_errno(_("could not read '%s'."), todo_file);
24+
25+
if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf,
26+
&todo_list)) {
27+
todo_list_release(&todo_list);
28+
return error(_("unusable todo list: '%s'"), todo_file);
29+
}
30+
31+
todo_list_add_exec_commands(&todo_list, commands);
32+
res = todo_list_write_to_file(the_repository, &todo_list,
33+
todo_file, NULL, NULL, -1, 0);
34+
todo_list_release(&todo_list);
35+
36+
if (res)
37+
return error_errno(_("could not write '%s'."), todo_file);
38+
return 0;
39+
}
40+
1641
static int get_revision_ranges(const char *upstream, const char *onto,
1742
const char **head_hash,
1843
char **revisions, char **shortrevisions)
@@ -266,7 +291,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
266291
ret = rearrange_squash_in_todo_file(the_repository);
267292
break;
268293
case ADD_EXEC:
269-
ret = sequencer_add_exec_commands(the_repository, &commands);
294+
ret = add_exec_commands(&commands);
270295
break;
271296
default:
272297
BUG("invalid command '%d'", command);

sequencer.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4500,8 +4500,8 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
45004500
* Add commands after pick and (series of) squash/fixup commands
45014501
* in the todo list.
45024502
*/
4503-
static void todo_list_add_exec_commands(struct todo_list *todo_list,
4504-
struct string_list *commands)
4503+
void todo_list_add_exec_commands(struct todo_list *todo_list,
4504+
struct string_list *commands)
45054505
{
45064506
struct strbuf *buf = &todo_list->buf;
45074507
size_t base_offset = buf->len;
@@ -4567,30 +4567,6 @@ static void todo_list_add_exec_commands(struct todo_list *todo_list,
45674567
todo_list->alloc = alloc;
45684568
}
45694569

4570-
int sequencer_add_exec_commands(struct repository *r,
4571-
struct string_list *commands)
4572-
{
4573-
const char *todo_file = rebase_path_todo();
4574-
struct todo_list todo_list = TODO_LIST_INIT;
4575-
int res;
4576-
4577-
if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
4578-
return error_errno(_("could not read '%s'."), todo_file);
4579-
4580-
if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {
4581-
todo_list_release(&todo_list);
4582-
return error(_("unusable todo list: '%s'"), todo_file);
4583-
}
4584-
4585-
todo_list_add_exec_commands(&todo_list, commands);
4586-
res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, 0);
4587-
todo_list_release(&todo_list);
4588-
4589-
if (res)
4590-
return error_errno(_("could not write '%s'."), todo_file);
4591-
return 0;
4592-
}
4593-
45944570
static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_list,
45954571
struct strbuf *buf, int num, unsigned flags)
45964572
{

sequencer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ int sequencer_remove_state(struct replay_opts *opts);
145145
int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
146146
const char **argv, unsigned flags);
147147

148-
int sequencer_add_exec_commands(struct repository *r,
149-
struct string_list *commands);
150148
int transform_todo_file(struct repository *r, unsigned flags);
149+
void todo_list_add_exec_commands(struct todo_list *todo_list,
150+
struct string_list *commands);
151151
int check_todo_list_from_file(struct repository *r);
152152
int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
153153
const char *shortrevisions, const char *onto_name,

0 commit comments

Comments
 (0)