read-cache.c: kill read_index()
read_index() shares the same problem as hold_locked_index(): it assumes $GIT_DIR/index. Move all call sites to repo_read_index() instead. read_index_preload() and read_index_unmerged() are also killed as a consequence. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
fb4a8464a6
commit
e1ff0a32e4
2
apply.c
2
apply.c
@ -4019,7 +4019,7 @@ static int read_apply_cache(struct apply_state *state)
|
||||
return read_index_from(state->repo->index, state->index_file,
|
||||
get_git_dir());
|
||||
else
|
||||
return read_index(state->repo->index);
|
||||
return repo_read_index(state->repo);
|
||||
}
|
||||
|
||||
/* This function tries to read the object name from the current index */
|
||||
|
4
blame.c
4
blame.c
@ -188,7 +188,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
|
||||
unsigned mode;
|
||||
struct strbuf msg = STRBUF_INIT;
|
||||
|
||||
read_index(r->index);
|
||||
repo_read_index(r);
|
||||
time(&now);
|
||||
commit = alloc_commit_node(r);
|
||||
commit->object.parsed = 1;
|
||||
@ -270,7 +270,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
|
||||
* want to run "diff-index --cached".
|
||||
*/
|
||||
discard_index(r->index);
|
||||
read_index(r->index);
|
||||
repo_read_index(r);
|
||||
|
||||
len = strlen(path);
|
||||
if (!mode) {
|
||||
|
@ -2278,7 +2278,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
|
||||
/* Ensure a valid committer ident can be constructed */
|
||||
git_committer_info(IDENT_STRICT);
|
||||
|
||||
if (read_index_preload(&the_index, NULL, 0) < 0)
|
||||
if (repo_read_index_preload(the_repository, NULL, 0) < 0)
|
||||
die(_("failed to read the index"));
|
||||
|
||||
if (in_progress) {
|
||||
|
@ -1367,7 +1367,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
|
||||
if (status_format != STATUS_FORMAT_PORCELAIN &&
|
||||
status_format != STATUS_FORMAT_PORCELAIN_V2)
|
||||
progress_flag = REFRESH_PROGRESS;
|
||||
read_index(&the_index);
|
||||
repo_read_index(the_repository);
|
||||
refresh_index(&the_index,
|
||||
REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,
|
||||
&s.pathspec, NULL, NULL);
|
||||
|
@ -165,7 +165,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
|
||||
|
||||
if (opt->diffopt.detect_rename) {
|
||||
if (!the_index.cache)
|
||||
read_index(&the_index);
|
||||
repo_read_index(the_repository);
|
||||
opt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;
|
||||
}
|
||||
while (fgets(line, sizeof(line), stdin)) {
|
||||
|
@ -576,7 +576,7 @@ static int reset_head(struct object_id *oid, const char *action,
|
||||
if (!detach_head)
|
||||
unpack_tree_opts.reset = 1;
|
||||
|
||||
if (read_index_unmerged(the_repository->index) < 0) {
|
||||
if (repo_read_index_unmerged(the_repository) < 0) {
|
||||
ret = error(_("could not read index"));
|
||||
goto leave_reset_head;
|
||||
}
|
||||
@ -1015,7 +1015,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
die(_("Cannot read HEAD"));
|
||||
|
||||
fd = hold_locked_index(&lock_file, 0);
|
||||
if (read_index(the_repository->index) < 0)
|
||||
if (repo_read_index(the_repository) < 0)
|
||||
die(_("could not read index"));
|
||||
refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,
|
||||
NULL);
|
||||
@ -1368,7 +1368,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
get_fork_point(options.upstream_name, head);
|
||||
}
|
||||
|
||||
if (read_index(the_repository->index) < 0)
|
||||
if (repo_read_index(the_repository) < 0)
|
||||
die(_("could not read index"));
|
||||
|
||||
if (options.autostash) {
|
||||
@ -1423,7 +1423,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
putchar('\n');
|
||||
|
||||
if (discard_index(the_repository->index) < 0 ||
|
||||
read_index(the_repository->index) < 0)
|
||||
repo_read_index(the_repository) < 0)
|
||||
die(_("could not read index"));
|
||||
}
|
||||
}
|
||||
|
11
cache.h
11
cache.h
@ -408,11 +408,11 @@ void validate_cache_entries(const struct index_state *istate);
|
||||
#define active_cache_changed (the_index.cache_changed)
|
||||
#define active_cache_tree (the_index.cache_tree)
|
||||
|
||||
#define read_cache() read_index(&the_index)
|
||||
#define read_cache() repo_read_index(the_repository)
|
||||
#define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))
|
||||
#define read_cache_preload(pathspec) read_index_preload(&the_index, (pathspec), 0)
|
||||
#define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)
|
||||
#define is_cache_unborn() is_index_unborn(&the_index)
|
||||
#define read_cache_unmerged() read_index_unmerged(&the_index)
|
||||
#define read_cache_unmerged() repo_read_index_unmerged(the_repository)
|
||||
#define discard_cache() discard_index(&the_index)
|
||||
#define unmerged_cache() unmerged_index(&the_index)
|
||||
#define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))
|
||||
@ -661,19 +661,14 @@ extern int daemonize(void);
|
||||
|
||||
/* Initialize and use the cache information */
|
||||
struct lock_file;
|
||||
extern int read_index(struct index_state *);
|
||||
extern void preload_index(struct index_state *index,
|
||||
const struct pathspec *pathspec,
|
||||
unsigned int refresh_flags);
|
||||
extern int read_index_preload(struct index_state *,
|
||||
const struct pathspec *pathspec,
|
||||
unsigned int refresh_flags);
|
||||
extern int do_read_index(struct index_state *istate, const char *path,
|
||||
int must_exist); /* for testting only! */
|
||||
extern int read_index_from(struct index_state *, const char *path,
|
||||
const char *gitdir);
|
||||
extern int is_index_unborn(struct index_state *);
|
||||
extern int read_index_unmerged(struct index_state *);
|
||||
|
||||
/* For use with `write_locked_index()`. */
|
||||
#define COMMIT_LOCK (1 << 0)
|
||||
|
@ -3576,7 +3576,7 @@ int merge_recursive(struct merge_options *o,
|
||||
|
||||
discard_cache();
|
||||
if (!o->call_depth)
|
||||
read_cache();
|
||||
repo_read_index(the_repository);
|
||||
|
||||
o->ancestor = "merged common ancestors";
|
||||
clean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),
|
||||
|
2
merge.c
2
merge.c
@ -37,7 +37,7 @@ int try_merge_command(struct repository *r,
|
||||
argv_array_clear(&args);
|
||||
|
||||
discard_index(r->index);
|
||||
if (read_index(r->index) < 0)
|
||||
if (repo_read_index(r) < 0)
|
||||
die(_("failed to read the cache"));
|
||||
resolve_undo_clear_index(r->index);
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "config.h"
|
||||
#include "progress.h"
|
||||
#include "thread-utils.h"
|
||||
#include "repository.h"
|
||||
|
||||
/*
|
||||
* Mostly randomly chosen maximum thread counts: we
|
||||
@ -146,12 +147,12 @@ void preload_index(struct index_state *index,
|
||||
trace_performance_leave("preload index");
|
||||
}
|
||||
|
||||
int read_index_preload(struct index_state *index,
|
||||
const struct pathspec *pathspec,
|
||||
unsigned int refresh_flags)
|
||||
int repo_read_index_preload(struct repository *repo,
|
||||
const struct pathspec *pathspec,
|
||||
unsigned int refresh_flags)
|
||||
{
|
||||
int retval = read_index(index);
|
||||
int retval = repo_read_index(repo);
|
||||
|
||||
preload_index(index, pathspec, refresh_flags);
|
||||
preload_index(repo->index, pathspec, refresh_flags);
|
||||
return retval;
|
||||
}
|
||||
|
11
read-cache.c
11
read-cache.c
@ -1733,11 +1733,6 @@ static int read_index_extension(struct index_state *istate,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read_index(struct index_state *istate)
|
||||
{
|
||||
return read_index_from(istate, get_index_file(), get_git_dir());
|
||||
}
|
||||
|
||||
static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
|
||||
unsigned int version,
|
||||
struct ondisk_cache_entry *ondisk,
|
||||
@ -3218,12 +3213,14 @@ out:
|
||||
* state can call this and check its return value, instead of calling
|
||||
* read_cache().
|
||||
*/
|
||||
int read_index_unmerged(struct index_state *istate)
|
||||
int repo_read_index_unmerged(struct repository *repo)
|
||||
{
|
||||
struct index_state *istate;
|
||||
int i;
|
||||
int unmerged = 0;
|
||||
|
||||
read_index(istate);
|
||||
repo_read_index(repo);
|
||||
istate = repo->index;
|
||||
for (i = 0; i < istate->cache_nr; i++) {
|
||||
struct cache_entry *ce = istate->cache[i];
|
||||
struct cache_entry *new_ce;
|
||||
|
@ -7,6 +7,7 @@ struct config_set;
|
||||
struct git_hash_algo;
|
||||
struct index_state;
|
||||
struct lock_file;
|
||||
struct pathspec;
|
||||
struct raw_object_store;
|
||||
struct submodule_cache;
|
||||
|
||||
@ -135,4 +136,9 @@ int repo_hold_locked_index(struct repository *repo,
|
||||
struct lock_file *lf,
|
||||
int flags);
|
||||
|
||||
int repo_read_index_preload(struct repository *,
|
||||
const struct pathspec *pathspec,
|
||||
unsigned refresh_flags);
|
||||
int repo_read_index_unmerged(struct repository *);
|
||||
|
||||
#endif /* REPOSITORY_H */
|
||||
|
6
rerere.c
6
rerere.c
@ -561,7 +561,7 @@ static int find_conflict(struct repository *r, struct string_list *conflict)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (read_index(r->index) < 0)
|
||||
if (repo_read_index(r) < 0)
|
||||
return error(_("index file corrupt"));
|
||||
|
||||
for (i = 0; i < r->index->cache_nr;) {
|
||||
@ -595,7 +595,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr)
|
||||
|
||||
if (setup_rerere(r, merge_rr, RERERE_READONLY))
|
||||
return 0;
|
||||
if (read_index(r->index) < 0)
|
||||
if (repo_read_index(r) < 0)
|
||||
return error(_("index file corrupt"));
|
||||
|
||||
for (i = 0; i < r->index->cache_nr;) {
|
||||
@ -1107,7 +1107,7 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec)
|
||||
struct string_list conflict = STRING_LIST_INIT_DUP;
|
||||
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
||||
|
||||
if (read_index(r->index) < 0)
|
||||
if (repo_read_index(r) < 0)
|
||||
return error(_("index file corrupt"));
|
||||
|
||||
fd = setup_rerere(r, &merge_rr, RERERE_NOAUTOUPDATE);
|
||||
|
@ -1384,7 +1384,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
|
||||
{
|
||||
struct worktree **worktrees, **p;
|
||||
|
||||
read_index(revs->repo->index);
|
||||
repo_read_index(revs->repo);
|
||||
do_add_index_objects_to_pending(revs, revs->repo->index, flags);
|
||||
|
||||
if (revs->single_worktree)
|
||||
@ -1530,7 +1530,7 @@ static void prepare_show_merge(struct rev_info *revs)
|
||||
head->object.flags |= SYMMETRIC_LEFT;
|
||||
|
||||
if (!istate->cache_nr)
|
||||
read_index(istate);
|
||||
repo_read_index(revs->repo);
|
||||
for (i = 0; i < istate->cache_nr; i++) {
|
||||
const struct cache_entry *ce = istate->cache[i];
|
||||
if (!ce_stage(ce))
|
||||
|
20
sequencer.c
20
sequencer.c
@ -446,9 +446,9 @@ static struct tree *empty_tree(struct repository *r)
|
||||
return lookup_tree(r, the_hash_algo->empty_tree);
|
||||
}
|
||||
|
||||
static int error_dirty_index(struct index_state *istate, struct replay_opts *opts)
|
||||
static int error_dirty_index(struct repository *repo, struct replay_opts *opts)
|
||||
{
|
||||
if (read_index_unmerged(istate))
|
||||
if (repo_read_index_unmerged(repo))
|
||||
return error_resolve_conflict(_(action_name(opts)));
|
||||
|
||||
error(_("your local changes would be overwritten by %s."),
|
||||
@ -483,7 +483,7 @@ static int fast_forward_to(struct repository *r,
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
|
||||
read_index(r->index);
|
||||
repo_read_index(r);
|
||||
if (checkout_fast_forward(r, from, to, 1))
|
||||
return -1; /* the callee should have complained already */
|
||||
|
||||
@ -543,7 +543,7 @@ static int do_recursive_merge(struct repository *r,
|
||||
if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)
|
||||
return -1;
|
||||
|
||||
read_index(r->index);
|
||||
repo_read_index(r);
|
||||
|
||||
init_merge_options(&o);
|
||||
o.ancestor = base ? base_label : "(empty tree)";
|
||||
@ -1766,7 +1766,7 @@ static int do_pick_commit(struct repository *r,
|
||||
oidcpy(&head, the_hash_algo->empty_tree);
|
||||
if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
|
||||
NULL, 0))
|
||||
return error_dirty_index(r->index, opts);
|
||||
return error_dirty_index(r, opts);
|
||||
}
|
||||
discard_index(r->index);
|
||||
|
||||
@ -2854,7 +2854,7 @@ static int do_exec(struct repository *r, const char *command_line)
|
||||
child_env.argv);
|
||||
|
||||
/* force re-reading of the cache */
|
||||
if (discard_index(r->index) < 0 || read_index(r->index) < 0)
|
||||
if (discard_index(r->index) < 0 || repo_read_index(r) < 0)
|
||||
return error(_("could not read index"));
|
||||
|
||||
dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1);
|
||||
@ -3023,7 +3023,7 @@ static int do_reset(struct repository *r,
|
||||
unpack_tree_opts.merge = 1;
|
||||
unpack_tree_opts.update = 1;
|
||||
|
||||
if (read_index_unmerged(r->index)) {
|
||||
if (repo_read_index_unmerged(r)) {
|
||||
rollback_lock_file(&lock);
|
||||
strbuf_release(&ref_name);
|
||||
return error_resolve_conflict(_(action_name(opts)));
|
||||
@ -3277,7 +3277,7 @@ static int do_merge(struct repository *r,
|
||||
|
||||
/* force re-reading of the cache */
|
||||
if (!ret && (discard_index(r->index) < 0 ||
|
||||
read_index(r->index) < 0))
|
||||
repo_read_index(r) < 0))
|
||||
ret = error(_("could not read index"));
|
||||
goto leave_merge;
|
||||
}
|
||||
@ -3299,7 +3299,7 @@ static int do_merge(struct repository *r,
|
||||
commit_list_insert(j->item, &reversed);
|
||||
free_commit_list(bases);
|
||||
|
||||
read_index(r->index);
|
||||
repo_read_index(r);
|
||||
init_merge_options(&o);
|
||||
o.branch1 = "HEAD";
|
||||
o.branch2 = ref_name.buf;
|
||||
@ -3972,7 +3972,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
|
||||
goto release_todo_list;
|
||||
}
|
||||
if (index_differs_from(r, "HEAD", NULL, 0)) {
|
||||
res = error_dirty_index(r->index, opts);
|
||||
res = error_dirty_index(r, opts);
|
||||
goto release_todo_list;
|
||||
}
|
||||
todo_list.current++;
|
||||
|
@ -1723,9 +1723,9 @@ static int get_oid_with_context_1(const char *name,
|
||||
if (flags & GET_OID_RECORD_PATH)
|
||||
oc->path = xstrdup(cp);
|
||||
|
||||
if (!active_cache)
|
||||
read_cache();
|
||||
pos = cache_name_pos(cp, namelen);
|
||||
if (!the_index.cache)
|
||||
repo_read_index(the_repository);
|
||||
pos = index_name_pos(&the_index, cp, namelen);
|
||||
if (pos < 0)
|
||||
pos = -pos - 1;
|
||||
while (pos < active_nr) {
|
||||
|
Loading…
Reference in New Issue
Block a user