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>

Johannes Schindelin committed Sep 9, 2016 at 16:37 UTC 0d9c6dc9ec316c5b117ee53b44d346349bd8b818
1 file changed +10 -5
sequencer.c
+10 -5
@@ -640,18 +640,21 @@ static int prepare_revs(struct replay_opts *opts)
640 return 0;
641 }
642
643 -static void read_and_refresh_cache(struct replay_opts *opts)
643 +static int read_and_refresh_cache(struct replay_opts *opts)
644 {
645 static struct lock_file index_lock;
646 int index_fd = hold_locked_index(&index_lock, 0);
647 if (read_index_preload(&the_index, NULL) < 0)
648 - die(_("git %s: failed to read the index"), action_name(opts));
648 + return error(_("git %s: failed to read the index"),
649 + action_name(opts));
650 refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
651 if (the_index.cache_changed && index_fd >= 0) {
652 if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
652 - die(_("git %s: failed to refresh the index"), action_name(opts));
653 + return error(_("git %s: failed to refresh the index"),
654 + action_name(opts));
655 }
656 rollback_lock_file(&index_lock);
657 + return 0;
658 }
659
660 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)
984 if (opts->allow_ff)
985 assert(!(opts->signoff || opts->no_commit ||
986 opts->record_origin || opts->edit));
984 - read_and_refresh_cache(opts);
987 + if (read_and_refresh_cache(opts))
988 + return -1;
989
990 for (cur = todo_list; cur; cur = cur->next) {
991 save_todo(cur, opts);
@@ -1045,7 +1049,8 @@ int sequencer_pick_revisions(struct replay_opts *opts)
1049 if (opts->subcommand == REPLAY_NONE)
1050 assert(opts->revs);
1051
1048 - read_and_refresh_cache(opts);
1052 + if (read_and_refresh_cache(opts))
1053 + return -1;
1054
1055 /*
1056 * Decide what to do depending on the arguments; a fresh