This replaces all patterns of "if (read_cached() < 0) die(some-msg);" with repo_read_index_or_die; this changes the output of the error message. However as all error messages before were translated, these are for human consumption, so a change in error message is not bad; in fact it makes Git more consistent. Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> --- builtin/add.c | 4 ++-- builtin/commit.c | 9 +++++---- builtin/rev-parse.c | 4 ++-- merge.c | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index e4751c198c1..910f619b7d5 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -19,6 +19,7 @@ #include "bulk-checkin.h" #include "argv-array.h" #include "submodule.h" +#include "repository.h" static const char * const builtin_add_usage[] = { N_("git add [<options>] [--] <pathspec>..."), @@ -229,8 +230,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix) git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ - if (read_cache() < 0) - die(_("Could not read the index")); + repo_read_index_or_die(the_repository); init_revisions(&rev, prefix); rev.diffopt.context = 7; diff --git a/builtin/commit.c b/builtin/commit.c index 5571d4a3e2b..9ebfb4db415 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -32,6 +32,8 @@ #include "column.h" #include "sequencer.h" #include "mailmap.h" +#include "sigchain.h" +#include "repository.h" static const char * const builtin_commit_usage[] = { N_("git commit [<options>] [--] <pathspec>..."), @@ -428,8 +430,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix exit(1); discard_cache(); - if (read_cache() < 0) - die(_("cannot read the index")); + repo_read_index_or_die(the_repository); hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); add_remove_files(&partial); @@ -853,8 +854,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, struct object_id oid; const char *parent = "HEAD"; - if (!active_nr && read_cache() < 0) - die(_("Cannot read index")); + if (!active_nr) + repo_read_index_or_die(the_repository); if (amend) parent = "HEAD^1"; diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 36b20877828..37f29fd850d 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -14,6 +14,7 @@ #include "revision.h" #include "split-index.h" #include "submodule.h" +#include "repository.h" #define DO_REVS 1 #define DO_NOREV 2 @@ -884,8 +885,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--shared-index-path")) { - if (read_cache() < 0) - die(_("Could not read the index")); + repo_read_index_or_die(the_repository); if (the_index.split_index) { const unsigned char *sha1 = the_index.split_index->base_sha1; const char *path = git_path("sharedindex.%s", sha1_to_hex(sha1)); diff --git a/merge.c b/merge.c index f06a4773d4f..654d049e80d 100644 --- a/merge.c +++ b/merge.c @@ -8,6 +8,7 @@ #include "tree-walk.h" #include "unpack-trees.h" #include "dir.h" +#include "repository.h" static const char *merge_argument(struct commit *commit) { @@ -70,8 +71,7 @@ int try_merge_command(const char *strategy, size_t xopts_nr, argv_array_clear(&args); discard_cache(); - if (read_cache() < 0) - die(_("failed to read the cache")); + repo_read_index_or_die(the_repository); resolve_undo_clear(); return ret; -- 2.17.0.582.gccdcbd54c44.dirty