Skip to content

Commit 5d94d54

Browse files
agrngitster
authored andcommitted
sequencer: make the todo_list structure public
This makes the structures todo_list and todo_item, and the functions todo_list_release() and parse_insn_buffer(), accessible outside of sequencer.c. Signed-off-by: Alban Gruin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2b71595 commit 5d94d54

File tree

2 files changed

+62
-57
lines changed

2 files changed

+62
-57
lines changed

sequencer.c

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,32 +1510,6 @@ static int allow_empty(struct repository *r,
15101510
return 1;
15111511
}
15121512

1513-
/*
1514-
* Note that ordering matters in this enum. Not only must it match the mapping
1515-
* below, it is also divided into several sections that matter. When adding
1516-
* new commands, make sure you add it in the right section.
1517-
*/
1518-
enum todo_command {
1519-
/* commands that handle commits */
1520-
TODO_PICK = 0,
1521-
TODO_REVERT,
1522-
TODO_EDIT,
1523-
TODO_REWORD,
1524-
TODO_FIXUP,
1525-
TODO_SQUASH,
1526-
/* commands that do something else than handling a single commit */
1527-
TODO_EXEC,
1528-
TODO_BREAK,
1529-
TODO_LABEL,
1530-
TODO_RESET,
1531-
TODO_MERGE,
1532-
/* commands that do nothing but are counted for reporting progress */
1533-
TODO_NOOP,
1534-
TODO_DROP,
1535-
/* comments (not counted for reporting progress) */
1536-
TODO_COMMENT
1537-
};
1538-
15391513
static struct {
15401514
char c;
15411515
const char *str;
@@ -2012,26 +1986,7 @@ enum todo_item_flags {
20121986
TODO_EDIT_MERGE_MSG = 1
20131987
};
20141988

2015-
struct todo_item {
2016-
enum todo_command command;
2017-
struct commit *commit;
2018-
unsigned int flags;
2019-
const char *arg;
2020-
int arg_len;
2021-
size_t offset_in_buf;
2022-
};
2023-
2024-
struct todo_list {
2025-
struct strbuf buf;
2026-
struct todo_item *items;
2027-
int nr, alloc, current;
2028-
int done_nr, total_nr;
2029-
struct stat_data stat;
2030-
};
2031-
2032-
#define TODO_LIST_INIT { STRBUF_INIT }
2033-
2034-
static void todo_list_release(struct todo_list *todo_list)
1989+
void todo_list_release(struct todo_list *todo_list)
20351990
{
20361991
strbuf_release(&todo_list->buf);
20371992
FREE_AND_NULL(todo_list->items);
@@ -2134,8 +2089,8 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
21342089
return !item->commit;
21352090
}
21362091

2137-
static int parse_insn_buffer(struct repository *r, char *buf,
2138-
struct todo_list *todo_list)
2092+
int todo_list_parse_insn_buffer(struct repository *r, char *buf,
2093+
struct todo_list *todo_list)
21392094
{
21402095
struct todo_item *item;
21412096
char *p = buf, *next_p;
@@ -2234,7 +2189,7 @@ static int read_populate_todo(struct repository *r,
22342189
return error(_("could not stat '%s'"), todo_file);
22352190
fill_stat_data(&todo_list->stat, &st);
22362191

2237-
res = parse_insn_buffer(r, todo_list->buf.buf, todo_list);
2192+
res = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list);
22382193
if (res) {
22392194
if (is_rebase_i(opts))
22402195
return error(_("please fix this using "
@@ -2265,7 +2220,7 @@ static int read_populate_todo(struct repository *r,
22652220
FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w");
22662221

22672222
if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
2268-
!parse_insn_buffer(r, done.buf.buf, &done))
2223+
!todo_list_parse_insn_buffer(r, done.buf.buf, &done))
22692224
todo_list->done_nr = count_commands(&done);
22702225
else
22712226
todo_list->done_nr = 0;
@@ -4556,7 +4511,7 @@ int sequencer_add_exec_commands(struct repository *r,
45564511
if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
45574512
return error(_("could not read '%s'."), todo_file);
45584513

4559-
if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {
4514+
if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {
45604515
todo_list_release(&todo_list);
45614516
return error(_("unusable todo list: '%s'"), todo_file);
45624517
}
@@ -4612,7 +4567,7 @@ int transform_todos(struct repository *r, unsigned flags)
46124567
if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
46134568
return error(_("could not read '%s'."), todo_file);
46144569

4615-
if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {
4570+
if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {
46164571
todo_list_release(&todo_list);
46174572
return error(_("unusable todo list: '%s'"), todo_file);
46184573
}
@@ -4698,7 +4653,7 @@ int check_todo_list(struct repository *r)
46984653
goto leave_check;
46994654
}
47004655
advise_to_edit_todo = res =
4701-
parse_insn_buffer(r, todo_list.buf.buf, &todo_list);
4656+
todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list);
47024657

47034658
if (res || check_level == MISSING_COMMIT_CHECK_IGNORE)
47044659
goto leave_check;
@@ -4717,7 +4672,7 @@ int check_todo_list(struct repository *r)
47174672
goto leave_check;
47184673
}
47194674
strbuf_release(&todo_file);
4720-
res = !!parse_insn_buffer(r, todo_list.buf.buf, &todo_list);
4675+
res = !!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list);
47214676

47224677
/* Find commits in git-rebase-todo.backup yet unseen */
47234678
for (i = todo_list.nr - 1; i >= 0; i--) {
@@ -4799,7 +4754,7 @@ static int skip_unnecessary_picks(struct repository *r, struct object_id *output
47994754

48004755
if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
48014756
return -1;
4802-
if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {
4757+
if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {
48034758
todo_list_release(&todo_list);
48044759
return -1;
48054760
}
@@ -4887,7 +4842,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
48874842
if (strbuf_read_file(buf, todo_file, 0) < 0)
48884843
return error_errno(_("could not read '%s'."), todo_file);
48894844

4890-
if (parse_insn_buffer(r, buf->buf, &todo_list)) {
4845+
if (todo_list_parse_insn_buffer(r, buf->buf, &todo_list)) {
48914846
todo_list_release(&todo_list);
48924847
return error(_("unusable todo list: '%s'"), todo_file);
48934848
}
@@ -4995,7 +4950,7 @@ int rearrange_squash(struct repository *r)
49954950

49964951
if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
49974952
return -1;
4998-
if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {
4953+
if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {
49994954
todo_list_release(&todo_list);
50004955
return -1;
50014956
}

sequencer.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,56 @@ enum missing_commit_check_level {
7373
int write_message(const void *buf, size_t len, const char *filename,
7474
int append_eol);
7575

76+
/*
77+
* Note that ordering matters in this enum. Not only must it match the mapping
78+
* of todo_command_info (in sequencer.c), it is also divided into several
79+
* sections that matter. When adding new commands, make sure you add it in the
80+
* right section.
81+
*/
82+
enum todo_command {
83+
/* commands that handle commits */
84+
TODO_PICK = 0,
85+
TODO_REVERT,
86+
TODO_EDIT,
87+
TODO_REWORD,
88+
TODO_FIXUP,
89+
TODO_SQUASH,
90+
/* commands that do something else than handling a single commit */
91+
TODO_EXEC,
92+
TODO_BREAK,
93+
TODO_LABEL,
94+
TODO_RESET,
95+
TODO_MERGE,
96+
/* commands that do nothing but are counted for reporting progress */
97+
TODO_NOOP,
98+
TODO_DROP,
99+
/* comments (not counted for reporting progress) */
100+
TODO_COMMENT
101+
};
102+
103+
struct todo_item {
104+
enum todo_command command;
105+
struct commit *commit;
106+
unsigned int flags;
107+
const char *arg;
108+
int arg_len;
109+
size_t offset_in_buf;
110+
};
111+
112+
struct todo_list {
113+
struct strbuf buf;
114+
struct todo_item *items;
115+
int nr, alloc, current;
116+
int done_nr, total_nr;
117+
struct stat_data stat;
118+
};
119+
120+
#define TODO_LIST_INIT { STRBUF_INIT }
121+
122+
int todo_list_parse_insn_buffer(struct repository *r, char *buf,
123+
struct todo_list *todo_list);
124+
void todo_list_release(struct todo_list *todo_list);
125+
76126
/* Call this to setup defaults before parsing command line options */
77127
void sequencer_init_config(struct replay_opts *opts);
78128
int sequencer_pick_revisions(struct repository *repo,

0 commit comments

Comments
 (0)