summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2021-09-23 15:26:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-09-24 15:56:27 (GMT)
commitdfa8bae5a20ead0737413fec5c7bb754fe538abe (patch)
tree2acb6bf0415e2f03e99a485dba1e1d1996b586dd
parent225bc32a989d7a22fa6addafd4ce7dcd04675dbf (diff)
downloadgit-dfa8bae5a20ead0737413fec5c7bb754fe538abe.zip
git-dfa8bae5a20ead0737413fec5c7bb754fe538abe.tar.gz
git-dfa8bae5a20ead0737413fec5c7bb754fe538abe.tar.bz2
sequencer.c: factor out a function
This code is heavily indented and obscures the high level logic within the loop. Let's move it to its own function before modifying it in the next commit. Note that there is a subtle change in behavior if the todo list cannot be reread. Previously todo_list->current was incremented before returning, now it returns immediately. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--sequencer.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/sequencer.c b/sequencer.c
index 7f07cd0..a248c88 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4254,6 +4254,27 @@ static int stopped_at_head(struct repository *r)
}
+static int reread_todo_if_changed(struct repository *r,
+ struct todo_list *todo_list,
+ struct replay_opts *opts)
+{
+ struct stat st;
+
+ if (stat(get_todo_path(opts), &st)) {
+ return error_errno(_("could not stat '%s'"),
+ get_todo_path(opts));
+ } else if (match_stat_data(&todo_list->stat, &st)) {
+ /* Reread the todo file if it has changed. */
+ todo_list_release(todo_list);
+ if (read_populate_todo(r, todo_list, opts))
+ return -1; /* message was printed */
+ /* `current` will be incremented on return */
+ todo_list->current = -1;
+ }
+
+ return 0;
+}
+
static const char rescheduled_advice[] =
N_("Could not execute the todo command\n"
"\n"
@@ -4433,20 +4454,9 @@ static int pick_commits(struct repository *r,
item->commit,
arg, item->arg_len,
opts, res, 0);
- } else if (is_rebase_i(opts) && check_todo && !res) {
- struct stat st;
-
- if (stat(get_todo_path(opts), &st)) {
- res = error_errno(_("could not stat '%s'"),
- get_todo_path(opts));
- } else if (match_stat_data(&todo_list->stat, &st)) {
- /* Reread the todo file if it has changed. */
- todo_list_release(todo_list);
- if (read_populate_todo(r, todo_list, opts))
- res = -1; /* message was printed */
- /* `current` will be incremented below */
- todo_list->current = -1;
- }
+ } else if (is_rebase_i(opts) && check_todo && !res &&
+ reread_todo_if_changed(r, todo_list, opts)) {
+ return -1;
}
todo_list->current++;