Skip to content

Commit e1ff0a3

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent fb4a846 commit e1ff0a3

File tree

16 files changed

+49
-50
lines changed

16 files changed

+49
-50
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4019,7 +4019,7 @@ static int read_apply_cache(struct apply_state *state)
40194019
return read_index_from(state->repo->index, state->index_file,
40204020
get_git_dir());
40214021
else
4022-
return read_index(state->repo->index);
4022+
return repo_read_index(state->repo);
40234023
}
40244024

40254025
/* This function tries to read the object name from the current index */

blame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
188188
unsigned mode;
189189
struct strbuf msg = STRBUF_INIT;
190190

191-
read_index(r->index);
191+
repo_read_index(r);
192192
time(&now);
193193
commit = alloc_commit_node(r);
194194
commit->object.parsed = 1;
@@ -270,7 +270,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
270270
* want to run "diff-index --cached".
271271
*/
272272
discard_index(r->index);
273-
read_index(r->index);
273+
repo_read_index(r);
274274

275275
len = strlen(path);
276276
if (!mode) {

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
22782278
/* Ensure a valid committer ident can be constructed */
22792279
git_committer_info(IDENT_STRICT);
22802280

2281-
if (read_index_preload(&the_index, NULL, 0) < 0)
2281+
if (repo_read_index_preload(the_repository, NULL, 0) < 0)
22822282
die(_("failed to read the index"));
22832283

22842284
if (in_progress) {

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13671367
if (status_format != STATUS_FORMAT_PORCELAIN &&
13681368
status_format != STATUS_FORMAT_PORCELAIN_V2)
13691369
progress_flag = REFRESH_PROGRESS;
1370-
read_index(&the_index);
1370+
repo_read_index(the_repository);
13711371
refresh_index(&the_index,
13721372
REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,
13731373
&s.pathspec, NULL, NULL);

builtin/diff-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
165165

166166
if (opt->diffopt.detect_rename) {
167167
if (!the_index.cache)
168-
read_index(&the_index);
168+
repo_read_index(the_repository);
169169
opt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;
170170
}
171171
while (fgets(line, sizeof(line), stdin)) {

builtin/rebase.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ static int reset_head(struct object_id *oid, const char *action,
576576
if (!detach_head)
577577
unpack_tree_opts.reset = 1;
578578

579-
if (read_index_unmerged(the_repository->index) < 0) {
579+
if (repo_read_index_unmerged(the_repository) < 0) {
580580
ret = error(_("could not read index"));
581581
goto leave_reset_head;
582582
}
@@ -1015,7 +1015,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10151015
die(_("Cannot read HEAD"));
10161016

10171017
fd = hold_locked_index(&lock_file, 0);
1018-
if (read_index(the_repository->index) < 0)
1018+
if (repo_read_index(the_repository) < 0)
10191019
die(_("could not read index"));
10201020
refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,
10211021
NULL);
@@ -1368,7 +1368,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13681368
get_fork_point(options.upstream_name, head);
13691369
}
13701370

1371-
if (read_index(the_repository->index) < 0)
1371+
if (repo_read_index(the_repository) < 0)
13721372
die(_("could not read index"));
13731373

13741374
if (options.autostash) {
@@ -1423,7 +1423,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14231423
putchar('\n');
14241424

14251425
if (discard_index(the_repository->index) < 0 ||
1426-
read_index(the_repository->index) < 0)
1426+
repo_read_index(the_repository) < 0)
14271427
die(_("could not read index"));
14281428
}
14291429
}

cache.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ void validate_cache_entries(const struct index_state *istate);
408408
#define active_cache_changed (the_index.cache_changed)
409409
#define active_cache_tree (the_index.cache_tree)
410410

411-
#define read_cache() read_index(&the_index)
411+
#define read_cache() repo_read_index(the_repository)
412412
#define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))
413-
#define read_cache_preload(pathspec) read_index_preload(&the_index, (pathspec), 0)
413+
#define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)
414414
#define is_cache_unborn() is_index_unborn(&the_index)
415-
#define read_cache_unmerged() read_index_unmerged(&the_index)
415+
#define read_cache_unmerged() repo_read_index_unmerged(the_repository)
416416
#define discard_cache() discard_index(&the_index)
417417
#define unmerged_cache() unmerged_index(&the_index)
418418
#define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))
@@ -661,19 +661,14 @@ extern int daemonize(void);
661661

662662
/* Initialize and use the cache information */
663663
struct lock_file;
664-
extern int read_index(struct index_state *);
665664
extern void preload_index(struct index_state *index,
666665
const struct pathspec *pathspec,
667666
unsigned int refresh_flags);
668-
extern int read_index_preload(struct index_state *,
669-
const struct pathspec *pathspec,
670-
unsigned int refresh_flags);
671667
extern int do_read_index(struct index_state *istate, const char *path,
672668
int must_exist); /* for testting only! */
673669
extern int read_index_from(struct index_state *, const char *path,
674670
const char *gitdir);
675671
extern int is_index_unborn(struct index_state *);
676-
extern int read_index_unmerged(struct index_state *);
677672

678673
/* For use with `write_locked_index()`. */
679674
#define COMMIT_LOCK (1 << 0)

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3576,7 +3576,7 @@ int merge_recursive(struct merge_options *o,
35763576

35773577
discard_cache();
35783578
if (!o->call_depth)
3579-
read_cache();
3579+
repo_read_index(the_repository);
35803580

35813581
o->ancestor = "merged common ancestors";
35823582
clean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),

merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int try_merge_command(struct repository *r,
3737
argv_array_clear(&args);
3838

3939
discard_index(r->index);
40-
if (read_index(r->index) < 0)
40+
if (repo_read_index(r) < 0)
4141
die(_("failed to read the cache"));
4242
resolve_undo_clear_index(r->index);
4343

preload-index.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "config.h"
99
#include "progress.h"
1010
#include "thread-utils.h"
11+
#include "repository.h"
1112

1213
/*
1314
* Mostly randomly chosen maximum thread counts: we
@@ -146,12 +147,12 @@ void preload_index(struct index_state *index,
146147
trace_performance_leave("preload index");
147148
}
148149

149-
int read_index_preload(struct index_state *index,
150-
const struct pathspec *pathspec,
151-
unsigned int refresh_flags)
150+
int repo_read_index_preload(struct repository *repo,
151+
const struct pathspec *pathspec,
152+
unsigned int refresh_flags)
152153
{
153-
int retval = read_index(index);
154+
int retval = repo_read_index(repo);
154155

155-
preload_index(index, pathspec, refresh_flags);
156+
preload_index(repo->index, pathspec, refresh_flags);
156157
return retval;
157158
}

0 commit comments

Comments
 (0)