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
This commit is contained in:
commit
5a5ea9763c
47
sequencer.c
47
sequencer.c
@ -2693,7 +2693,6 @@ static int read_populate_todo(struct repository *r,
|
|||||||
struct todo_list *todo_list,
|
struct todo_list *todo_list,
|
||||||
struct replay_opts *opts)
|
struct replay_opts *opts)
|
||||||
{
|
{
|
||||||
struct stat st;
|
|
||||||
const char *todo_file = get_todo_path(opts);
|
const char *todo_file = get_todo_path(opts);
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@ -2701,11 +2700,6 @@ static int read_populate_todo(struct repository *r,
|
|||||||
if (strbuf_read_file_or_whine(&todo_list->buf, todo_file) < 0)
|
if (strbuf_read_file_or_whine(&todo_list->buf, todo_file) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
res = stat(todo_file, &st);
|
|
||||||
if (res)
|
|
||||||
return error(_("could not stat '%s'"), todo_file);
|
|
||||||
fill_stat_data(&todo_list->stat, &st);
|
|
||||||
|
|
||||||
res = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list);
|
res = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list);
|
||||||
if (res) {
|
if (res) {
|
||||||
if (is_rebase_i(opts))
|
if (is_rebase_i(opts))
|
||||||
@ -4284,6 +4278,30 @@ 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)
|
||||||
|
{
|
||||||
|
int offset;
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
||||||
|
if (strbuf_read_file_or_whine(&buf, get_todo_path(opts)) < 0)
|
||||||
|
return -1;
|
||||||
|
offset = get_item_line_offset(todo_list, todo_list->current + 1);
|
||||||
|
if (buf.len != todo_list->buf.len - offset ||
|
||||||
|
memcmp(buf.buf, todo_list->buf.buf + offset, buf.len)) {
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
strbuf_release(&buf);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const char rescheduled_advice[] =
|
static const char rescheduled_advice[] =
|
||||||
N_("Could not execute the todo command\n"
|
N_("Could not execute the todo command\n"
|
||||||
"\n"
|
"\n"
|
||||||
@ -4462,20 +4480,9 @@ static int pick_commits(struct repository *r,
|
|||||||
item->commit,
|
item->commit,
|
||||||
arg, item->arg_len,
|
arg, item->arg_len,
|
||||||
opts, res, 0);
|
opts, res, 0);
|
||||||
} else if (is_rebase_i(opts) && check_todo && !res) {
|
} else if (is_rebase_i(opts) && check_todo && !res &&
|
||||||
struct stat st;
|
reread_todo_if_changed(r, todo_list, opts)) {
|
||||||
|
return -1;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
todo_list->current++;
|
todo_list->current++;
|
||||||
|
@ -116,7 +116,6 @@ struct todo_list {
|
|||||||
struct todo_item *items;
|
struct todo_item *items;
|
||||||
int nr, alloc, current;
|
int nr, alloc, current;
|
||||||
int done_nr, total_nr;
|
int done_nr, total_nr;
|
||||||
struct stat_data stat;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TODO_LIST_INIT { STRBUF_INIT }
|
#define TODO_LIST_INIT { STRBUF_INIT }
|
||||||
|
Loading…
Reference in New Issue
Block a user