Skip to content

Commit 1da5874

Browse files
agrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2602762 commit 1da5874

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed

rebase-interactive.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
#include "commit-slab.h"
77
#include "config.h"
88

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+
915
enum missing_commit_check_level {
1016
MISSING_COMMIT_CHECK_IGNORE = 0,
1117
MISSING_COMMIT_CHECK_WARN,
@@ -189,3 +195,32 @@ int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo)
189195
clear_commit_seen(&commit_seen);
190196
return res;
191197
}
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
1313
const char *shortonto, unsigned flags);
1414
int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo);
1515

16+
int check_todo_list_from_file(struct repository *r);
17+
1618
#endif

sequencer.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4991,35 +4991,6 @@ N_("You can fix this with 'git rebase --edit-todo' "
49914991
"Or you can abort the rebase with 'git rebase"
49924992
" --abort'.\n");
49934993

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-
50234994
/* skip picking commits whose parents are unchanged */
50244995
static int skip_unnecessary_picks(struct repository *r,
50254996
struct todo_list *todo_list,

sequencer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
155155

156156
void todo_list_add_exec_commands(struct todo_list *todo_list,
157157
struct string_list *commands);
158-
int check_todo_list_from_file(struct repository *r);
159158
int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
160159
const char *shortrevisions, const char *onto_name,
161160
struct commit *onto, const char *orig_head, struct string_list *commands,

0 commit comments

Comments
 (0)