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 <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alban Gruin committed Dec 29, 2018 at 17:03 UTC 5d94d54564fb0dea1f3caf2f1dacb7701f4be25c
2 files changed +62 -57
sequencer.c
+12 -57
@@ -1510,32 +1510,6 @@ static int allow_empty(struct repository *r,
1510 return 1;
1511 }
1512
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 -
1513 static struct {
1514 char c;
1515 const char *str;
@@ -2012,26 +1986,7 @@ enum todo_item_flags {
1986 TODO_EDIT_MERGE_MSG = 1
1987 };
1988
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)
1990 {
1991 strbuf_release(&todo_list->buf);
1992 FREE_AND_NULL(todo_list->items);
@@ -2134,8 +2089,8 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
2089 return !item->commit;
2090 }
2091
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)
2094 {
2095 struct todo_item *item;
2096 char *p = buf, *next_p;
@@ -2234,7 +2189,7 @@ static int read_populate_todo(struct repository *r,
2189 return error(_("could not stat '%s'"), todo_file);
2190 fill_stat_data(&todo_list->stat, &st);
2191
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);
2193 if (res) {
2194 if (is_rebase_i(opts))
2195 return error(_("please fix this using "
@@ -2265,7 +2220,7 @@ static int read_populate_todo(struct repository *r,
2220 FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w");
2221
2222 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))
2224 todo_list->done_nr = count_commands(&done);
2225 else
2226 todo_list->done_nr = 0;
@@ -4556,7 +4511,7 @@ int sequencer_add_exec_commands(struct repository *r,
4511 if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
4512 return error(_("could not read '%s'."), todo_file);
4513
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)) {
4515 todo_list_release(&todo_list);
4516 return error(_("unusable todo list: '%s'"), todo_file);
4517 }
@@ -4612,7 +4567,7 @@ int transform_todos(struct repository *r, unsigned flags)
4567 if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
4568 return error(_("could not read '%s'."), todo_file);
4569
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)) {
4571 todo_list_release(&todo_list);
4572 return error(_("unusable todo list: '%s'"), todo_file);
4573 }
@@ -4698,7 +4653,7 @@ int check_todo_list(struct repository *r)
4653 goto leave_check;
4654 }
4655 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);
4657
4658 if (res || check_level == MISSING_COMMIT_CHECK_IGNORE)
4659 goto leave_check;
@@ -4717,7 +4672,7 @@ int check_todo_list(struct repository *r)
4672 goto leave_check;
4673 }
4674 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);
4676
4677 /* Find commits in git-rebase-todo.backup yet unseen */
4678 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
4754
4755 if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
4756 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) {
4758 todo_list_release(&todo_list);
4759 return -1;
4760 }
@@ -4887,7 +4842,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
4842 if (strbuf_read_file(buf, todo_file, 0) < 0)
4843 return error_errno(_("could not read '%s'."), todo_file);
4844
4890 - if (parse_insn_buffer(r, buf->buf, &todo_list)) {
4845 + if (todo_list_parse_insn_buffer(r, buf->buf, &todo_list)) {
4846 todo_list_release(&todo_list);
4847 return error(_("unusable todo list: '%s'"), todo_file);
4848 }
@@ -4995,7 +4950,7 @@ int rearrange_squash(struct repository *r)
4950
4951 if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
4952 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) {
4954 todo_list_release(&todo_list);
4955 return -1;
4956 }
sequencer.h
+50
@@ -73,6 +73,56 @@ enum missing_commit_check_level {
73 int write_message(const void *buf, size_t len, const char *filename,
74 int append_eol);
75
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 +
126 /* Call this to setup defaults before parsing command line options */
127 void sequencer_init_config(struct replay_opts *opts);
128 int sequencer_pick_revisions(struct repository *repo,