]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer: move check_todo_list_from_file() to rebase-interactive.c
authorAlban Gruin <alban.gruin@gmail.com>
Tue, 28 Jan 2020 21:12:45 +0000 (22:12 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Jan 2020 22:13:41 +0000 (14:13 -0800)
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>
rebase-interactive.c
rebase-interactive.h
sequencer.c
sequencer.h

index 1259adc8ea1afd51f062c18c972ef4acefeef496..45f29c28a84f40c10447656262aa23a38557cbc6 100644 (file)
@@ -6,6 +6,12 @@
 #include "commit-slab.h"
 #include "config.h"
 
+static const char edit_todo_list_advice[] =
+N_("You can fix this with 'git rebase --edit-todo' "
+"and then run 'git rebase --continue'.\n"
+"Or you can abort the rebase with 'git rebase"
+" --abort'.\n");
+
 enum missing_commit_check_level {
        MISSING_COMMIT_CHECK_IGNORE = 0,
        MISSING_COMMIT_CHECK_WARN,
@@ -189,3 +195,32 @@ leave_check:
        clear_commit_seen(&commit_seen);
        return res;
 }
+
+int check_todo_list_from_file(struct repository *r)
+{
+       struct todo_list old_todo = TODO_LIST_INIT, new_todo = TODO_LIST_INIT;
+       int res = 0;
+
+       if (strbuf_read_file(&new_todo.buf, rebase_path_todo(), 0) < 0) {
+               res = error(_("could not read '%s'."), rebase_path_todo());
+               goto out;
+       }
+
+       if (strbuf_read_file(&old_todo.buf, rebase_path_todo_backup(), 0) < 0) {
+               res = error(_("could not read '%s'."), rebase_path_todo_backup());
+               goto out;
+       }
+
+       res = todo_list_parse_insn_buffer(r, old_todo.buf.buf, &old_todo);
+       if (!res)
+               res = todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo);
+       if (!res)
+               res = todo_list_check(&old_todo, &new_todo);
+       if (res)
+               fprintf(stderr, _(edit_todo_list_advice));
+out:
+       todo_list_release(&old_todo);
+       todo_list_release(&new_todo);
+
+       return res;
+}
index 44dbb06311a84168d8a5970267a14ade85671a98..5f41bf5a287adcd8ab7b6c6757a3694c5d4afa81 100644 (file)
@@ -13,4 +13,6 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
                   const char *shortonto, unsigned flags);
 int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo);
 
+int check_todo_list_from_file(struct repository *r);
+
 #endif
index 5f69b47e32456b0b0eace0bddeeae48233dbd325..9365fc3e5a02dcaa1ba56eabb2091cdb2e372c33 100644 (file)
@@ -4991,35 +4991,6 @@ N_("You can fix this with 'git rebase --edit-todo' "
 "Or you can abort the rebase with 'git rebase"
 " --abort'.\n");
 
-int check_todo_list_from_file(struct repository *r)
-{
-       struct todo_list old_todo = TODO_LIST_INIT, new_todo = TODO_LIST_INIT;
-       int res = 0;
-
-       if (strbuf_read_file_or_whine(&new_todo.buf, rebase_path_todo()) < 0) {
-               res = -1;
-               goto out;
-       }
-
-       if (strbuf_read_file_or_whine(&old_todo.buf, rebase_path_todo_backup()) < 0) {
-               res = -1;
-               goto out;
-       }
-
-       res = todo_list_parse_insn_buffer(r, old_todo.buf.buf, &old_todo);
-       if (!res)
-               res = todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo);
-       if (!res)
-               res = todo_list_check(&old_todo, &new_todo);
-       if (res)
-               fprintf(stderr, _(edit_todo_list_advice));
-out:
-       todo_list_release(&old_todo);
-       todo_list_release(&new_todo);
-
-       return res;
-}
-
 /* skip picking commits whose parents are unchanged */
 static int skip_unnecessary_picks(struct repository *r,
                                  struct todo_list *todo_list,
index 9f9ae291e3c4ad8bc30abc3c68e18e413df9b6f6..5d4df0807c4640f9498b116f4ca694c2559ae321 100644 (file)
@@ -155,7 +155,6 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
 
 void todo_list_add_exec_commands(struct todo_list *todo_list,
                                 struct string_list *commands);
-int check_todo_list_from_file(struct repository *r);
 int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
                    const char *shortrevisions, const char *onto_name,
                    struct commit *onto, const char *orig_head, struct string_list *commands,