зеркало из https://github.com/microsoft/git.git
sequencer: lib'ify read_and_refresh_cache()
Instead of dying there, let the caller high up in the callchain notice the error and handle it (by dying, still). There are two call sites of read_and_refresh_cache(), one of which is pick_commits(), whose callers were already prepared to do the right thing given an "error" return from it by an earlier patch, so the conversion is safe. The other one, sequencer_pick_revisions() was also prepared to relay an error return back to its caller in all remaining cases in an earlier patch. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
c3e8618c1f
Коммит
0d9c6dc9ec
15
sequencer.c
15
sequencer.c
|
@ -640,18 +640,21 @@ static int prepare_revs(struct replay_opts *opts)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_and_refresh_cache(struct replay_opts *opts)
|
static int read_and_refresh_cache(struct replay_opts *opts)
|
||||||
{
|
{
|
||||||
static struct lock_file index_lock;
|
static struct lock_file index_lock;
|
||||||
int index_fd = hold_locked_index(&index_lock, 0);
|
int index_fd = hold_locked_index(&index_lock, 0);
|
||||||
if (read_index_preload(&the_index, NULL) < 0)
|
if (read_index_preload(&the_index, NULL) < 0)
|
||||||
die(_("git %s: failed to read the index"), action_name(opts));
|
return error(_("git %s: failed to read the index"),
|
||||||
|
action_name(opts));
|
||||||
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
|
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
|
||||||
if (the_index.cache_changed && index_fd >= 0) {
|
if (the_index.cache_changed && index_fd >= 0) {
|
||||||
if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
|
if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
|
||||||
die(_("git %s: failed to refresh the index"), action_name(opts));
|
return error(_("git %s: failed to refresh the index"),
|
||||||
|
action_name(opts));
|
||||||
}
|
}
|
||||||
rollback_lock_file(&index_lock);
|
rollback_lock_file(&index_lock);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
|
static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
|
||||||
|
@ -981,7 +984,8 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)
|
||||||
if (opts->allow_ff)
|
if (opts->allow_ff)
|
||||||
assert(!(opts->signoff || opts->no_commit ||
|
assert(!(opts->signoff || opts->no_commit ||
|
||||||
opts->record_origin || opts->edit));
|
opts->record_origin || opts->edit));
|
||||||
read_and_refresh_cache(opts);
|
if (read_and_refresh_cache(opts))
|
||||||
|
return -1;
|
||||||
|
|
||||||
for (cur = todo_list; cur; cur = cur->next) {
|
for (cur = todo_list; cur; cur = cur->next) {
|
||||||
save_todo(cur, opts);
|
save_todo(cur, opts);
|
||||||
|
@ -1045,7 +1049,8 @@ int sequencer_pick_revisions(struct replay_opts *opts)
|
||||||
if (opts->subcommand == REPLAY_NONE)
|
if (opts->subcommand == REPLAY_NONE)
|
||||||
assert(opts->revs);
|
assert(opts->revs);
|
||||||
|
|
||||||
read_and_refresh_cache(opts);
|
if (read_and_refresh_cache(opts))
|
||||||
|
return -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decide what to do depending on the arguments; a fresh
|
* Decide what to do depending on the arguments; a fresh
|
||||||
|
|
Загрузка…
Ссылка в новой задаче