@matheusbsbs / matheus-bagliano / commits / 1da5874c1b
Fork 0

sequencer: move check_todo_list_from_file() to rebase-interactive.c

The message contained in `edit_todo_list_advice' (sequencer.c) is printed after the initial edit of the todo list if it can't be parsed or if commits were dropped. This is done either in complete_action() for `rebase -i', or in check_todo_list_from_file() for `rebase -p'. Since we want to add this check when editing the list, we also want to use this message from edit_todo_list() (rebase-interactive.c). To this end, check_todo_list_from_file() is moved to rebase-interactive.c, and `edit_todo_list_advice' is copied there. In the next commit, complete_action() will stop using it, and `edit_todo_list_advice' will be removed from sequencer.c. Signed-off-by: Alban Gruin <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alban Gruin committed Jan 28, 2020 at 22:12 UTC 1da5874c1b283862f8252a2f5f2f8d4afe86346a
4 files changed +37 -30
rebase-interactive.c
+35
@@ -6,6 +6,12 @@
6 #include "commit-slab.h"
7 #include "config.h"
8
9 +static const char edit_todo_list_advice[] =
10 +N_("You can fix this with 'git rebase --edit-todo' "
11 +"and then run 'git rebase --continue'.\n"
12 +"Or you can abort the rebase with 'git rebase"
13 +" --abort'.\n");
14 +
15 enum missing_commit_check_level {
16 MISSING_COMMIT_CHECK_IGNORE = 0,
17 MISSING_COMMIT_CHECK_WARN,
@@ -189,3 +195,32 @@ leave_check:
195 clear_commit_seen(&commit_seen);
196 return res;
197 }
198 +
199 +int check_todo_list_from_file(struct repository *r)
200 +{
201 + struct todo_list old_todo = TODO_LIST_INIT, new_todo = TODO_LIST_INIT;
202 + int res = 0;
203 +
204 + if (strbuf_read_file(&new_todo.buf, rebase_path_todo(), 0) < 0) {
205 + res = error(_("could not read '%s'."), rebase_path_todo());
206 + goto out;
207 + }
208 +
209 + if (strbuf_read_file(&old_todo.buf, rebase_path_todo_backup(), 0) < 0) {
210 + res = error(_("could not read '%s'."), rebase_path_todo_backup());
211 + goto out;
212 + }
213 +
214 + res = todo_list_parse_insn_buffer(r, old_todo.buf.buf, &old_todo);
215 + if (!res)
216 + res = todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo);
217 + if (!res)
218 + res = todo_list_check(&old_todo, &new_todo);
219 + if (res)
220 + fprintf(stderr, _(edit_todo_list_advice));
221 +out:
222 + todo_list_release(&old_todo);
223 + todo_list_release(&new_todo);
224 +
225 + return res;
226 +}
rebase-interactive.h
+2
@@ -13,4 +13,6 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
13 const char *shortonto, unsigned flags);
14 int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo);
15
16 +int check_todo_list_from_file(struct repository *r);
17 +
18 #endif
sequencer.c
-29
@@ -4991,35 +4991,6 @@ N_("You can fix this with 'git rebase --edit-todo' "
4991 "Or you can abort the rebase with 'git rebase"
4992 " --abort'.\n");
4993
4994 -int check_todo_list_from_file(struct repository *r)
4995 -{
4996 - struct todo_list old_todo = TODO_LIST_INIT, new_todo = TODO_LIST_INIT;
4997 - int res = 0;
4998 -
4999 - if (strbuf_read_file_or_whine(&new_todo.buf, rebase_path_todo()) < 0) {
5000 - res = -1;
5001 - goto out;
5002 - }
5003 -
5004 - if (strbuf_read_file_or_whine(&old_todo.buf, rebase_path_todo_backup()) < 0) {
5005 - res = -1;
5006 - goto out;
5007 - }
5008 -
5009 - res = todo_list_parse_insn_buffer(r, old_todo.buf.buf, &old_todo);
5010 - if (!res)
5011 - res = todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo);
5012 - if (!res)
5013 - res = todo_list_check(&old_todo, &new_todo);
5014 - if (res)
5015 - fprintf(stderr, _(edit_todo_list_advice));
5016 -out:
5017 - todo_list_release(&old_todo);
5018 - todo_list_release(&new_todo);
5019 -
5020 - return res;
5021 -}
5022 -
4994 /* skip picking commits whose parents are unchanged */
4995 static int skip_unnecessary_picks(struct repository *r,
4996 struct todo_list *todo_list,
sequencer.h
-1
@@ -155,7 +155,6 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
155
156 void todo_list_add_exec_commands(struct todo_list *todo_list,
157 struct string_list *commands);
158 -int check_todo_list_from_file(struct repository *r);
158 int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
159 const char *shortrevisions, const char *onto_name,
160 struct commit *onto, const char *orig_head, struct string_list *commands,