Skip to content

Commit 5a5ea97

Browse files
committed
Merge branch 'pw/rebase-reread-todo-after-editing'
The code to re-read the edited todo list in "git rebase -i" was made more robust. * pw/rebase-reread-todo-after-editing: rebase: fix todo-list rereading sequencer.c: factor out a function
2 parents b39b0e1 + 2b88fe0 commit 5a5ea97

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

sequencer.c

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,19 +2693,13 @@ static int read_populate_todo(struct repository *r,
26932693
struct todo_list *todo_list,
26942694
struct replay_opts *opts)
26952695
{
2696-
struct stat st;
26972696
const char *todo_file = get_todo_path(opts);
26982697
int res;
26992698

27002699
strbuf_reset(&todo_list->buf);
27012700
if (strbuf_read_file_or_whine(&todo_list->buf, todo_file) < 0)
27022701
return -1;
27032702

2704-
res = stat(todo_file, &st);
2705-
if (res)
2706-
return error(_("could not stat '%s'"), todo_file);
2707-
fill_stat_data(&todo_list->stat, &st);
2708-
27092703
res = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list);
27102704
if (res) {
27112705
if (is_rebase_i(opts))
@@ -4284,6 +4278,30 @@ static int stopped_at_head(struct repository *r)
42844278

42854279
}
42864280

4281+
static int reread_todo_if_changed(struct repository *r,
4282+
struct todo_list *todo_list,
4283+
struct replay_opts *opts)
4284+
{
4285+
int offset;
4286+
struct strbuf buf = STRBUF_INIT;
4287+
4288+
if (strbuf_read_file_or_whine(&buf, get_todo_path(opts)) < 0)
4289+
return -1;
4290+
offset = get_item_line_offset(todo_list, todo_list->current + 1);
4291+
if (buf.len != todo_list->buf.len - offset ||
4292+
memcmp(buf.buf, todo_list->buf.buf + offset, buf.len)) {
4293+
/* Reread the todo file if it has changed. */
4294+
todo_list_release(todo_list);
4295+
if (read_populate_todo(r, todo_list, opts))
4296+
return -1; /* message was printed */
4297+
/* `current` will be incremented on return */
4298+
todo_list->current = -1;
4299+
}
4300+
strbuf_release(&buf);
4301+
4302+
return 0;
4303+
}
4304+
42874305
static const char rescheduled_advice[] =
42884306
N_("Could not execute the todo command\n"
42894307
"\n"
@@ -4462,20 +4480,9 @@ static int pick_commits(struct repository *r,
44624480
item->commit,
44634481
arg, item->arg_len,
44644482
opts, res, 0);
4465-
} else if (is_rebase_i(opts) && check_todo && !res) {
4466-
struct stat st;
4467-
4468-
if (stat(get_todo_path(opts), &st)) {
4469-
res = error_errno(_("could not stat '%s'"),
4470-
get_todo_path(opts));
4471-
} else if (match_stat_data(&todo_list->stat, &st)) {
4472-
/* Reread the todo file if it has changed. */
4473-
todo_list_release(todo_list);
4474-
if (read_populate_todo(r, todo_list, opts))
4475-
res = -1; /* message was printed */
4476-
/* `current` will be incremented below */
4477-
todo_list->current = -1;
4478-
}
4483+
} else if (is_rebase_i(opts) && check_todo && !res &&
4484+
reread_todo_if_changed(r, todo_list, opts)) {
4485+
return -1;
44794486
}
44804487

44814488
todo_list->current++;

sequencer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ struct todo_list {
116116
struct todo_item *items;
117117
int nr, alloc, current;
118118
int done_nr, total_nr;
119-
struct stat_data stat;
120119
};
121120

122121
#define TODO_LIST_INIT { STRBUF_INIT }

0 commit comments

Comments
 (0)