Merge branch 'ab/fewer-the-index-macros'

Progress on removing 'the_index' convenience wrappers.

* ab/fewer-the-index-macros:
  cocci: apply "pending" index-compatibility to some "builtin/*.c"
  cache.h & test-tool.h: add & use "USE_THE_INDEX_VARIABLE"
  {builtin/*,repository}.c: add & use "USE_THE_INDEX_VARIABLE"
  cocci: apply "pending" index-compatibility to "t/helper/*.c"
  cocci & cache.h: apply variable section of "pending" index-compatibility
  cocci & cache.h: apply a selection of "pending" index-compatibility
  cocci: add a index-compatibility.pending.cocci
  read-cache API & users: make discard_index() return void
  cocci & cache.h: remove rarely used "the_index" compat macros
  builtin/{grep,log}.: don't define "USE_THE_INDEX_COMPATIBILITY_MACROS"
  cache.h: remove unused "the_index" compat macros
This commit is contained in:
Junio C Hamano 2022-11-28 12:13:46 +09:00
commit 041df69edd
51 changed files with 532 additions and 366 deletions

View File

@ -530,8 +530,8 @@ static int get_modified_files(struct repository *r,
struct collection_status s = { 0 }; struct collection_status s = { 0 };
int i; int i;
if (discard_index(r->index) < 0 || discard_index(r->index);
repo_read_index_preload(r, ps, 0) < 0) if (repo_read_index_preload(r, ps, 0) < 0)
return error(_("could not read index")); return error(_("could not read index"));
prefix_item_list_clear(files); prefix_item_list_clear(files);
@ -1156,8 +1156,8 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
_("staged"), _("unstaged"), _("path")); _("staged"), _("unstaged"), _("path"));
opts.list_opts.header = header.buf; opts.list_opts.header = header.buf;
if (discard_index(r->index) < 0 || discard_index(r->index);
repo_read_index(r) < 0 || if (repo_read_index(r) < 0 ||
repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1, repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
NULL, NULL, NULL) < 0) NULL, NULL, NULL) < 0)
warning(_("could not refresh index")); warning(_("could not refresh index"));

View File

@ -1750,7 +1750,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
s.mode = &patch_mode_add; s.mode = &patch_mode_add;
s.revision = revision; s.revision = revision;
if (discard_index(r->index) < 0 || repo_read_index(r) < 0 || discard_index(r->index);
if (repo_read_index(r) < 0 ||
(!s.mode->index_only && (!s.mode->index_only &&
repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1, repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
NULL, NULL, NULL) < 0) || NULL, NULL, NULL) < 0) ||

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2006 Linus Torvalds * Copyright (C) 2006 Linus Torvalds
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"
@ -42,8 +42,8 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
{ {
int i, ret = 0; int i, ret = 0;
for (i = 0; i < active_nr; i++) { for (i = 0; i < the_index.cache_nr; i++) {
struct cache_entry *ce = active_cache[i]; struct cache_entry *ce = the_index.cache[i];
int err; int err;
if (!include_sparse && if (!include_sparse &&
@ -55,7 +55,7 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
continue; continue;
if (!show_only) if (!show_only)
err = chmod_cache_entry(ce, flip); err = chmod_index_entry(&the_index, ce, flip);
else else
err = S_ISREG(ce->ce_mode) ? 0 : -1; err = S_ISREG(ce->ce_mode) ? 0 : -1;
@ -159,8 +159,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
{ {
int i, retval = 0; int i, retval = 0;
for (i = 0; i < active_nr; i++) { for (i = 0; i < the_index.cache_nr; i++) {
struct cache_entry *ce = active_cache[i]; struct cache_entry *ce = the_index.cache[i];
if (!include_sparse && if (!include_sparse &&
(ce_skip_worktree(ce) || (ce_skip_worktree(ce) ||
@ -172,7 +172,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
continue; /* do not touch non blobs */ continue; /* do not touch non blobs */
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL)) if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
continue; continue;
retval |= add_file_to_cache(ce->name, flags | ADD_CACHE_RENORMALIZE); retval |= add_file_to_index(&the_index, ce->name,
flags | ADD_CACHE_RENORMALIZE);
} }
return retval; return retval;
@ -311,7 +312,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die(_("Could not read the index")); die(_("Could not read the index"));
repo_init_revisions(the_repository, &rev, prefix); repo_init_revisions(the_repository, &rev, prefix);
@ -543,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
prepare_repo_settings(the_repository); prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0; the_repository->settings.command_requires_full_index = 0;
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
/* /*
* Check the "pathspec '%s' did not match any files" block * Check the "pathspec '%s' did not match any files" block
@ -586,7 +587,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
(!(addremove || take_worktree_changes) (!(addremove || take_worktree_changes)
? ADD_CACHE_IGNORE_REMOVAL : 0)); ? ADD_CACHE_IGNORE_REMOVAL : 0));
if (read_cache_preload(&pathspec) < 0) if (repo_read_index_preload(the_repository, &pathspec, 0) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
die_in_unpopulated_submodule(&the_index, prefix); die_in_unpopulated_submodule(&the_index, prefix);

View File

@ -1519,8 +1519,8 @@ static int run_apply(const struct am_state *state, const char *index_file)
if (index_file) { if (index_file) {
/* Reload index as apply_all_patches() will have modified it. */ /* Reload index as apply_all_patches() will have modified it. */
discard_cache(); discard_index(&the_index);
read_cache_from(index_file); read_index_from(&the_index, index_file, get_git_dir());
} }
return 0; return 0;
@ -1562,8 +1562,8 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
if (build_fake_ancestor(state, index_path)) if (build_fake_ancestor(state, index_path))
return error("could not build fake ancestor"); return error("could not build fake ancestor");
discard_cache(); discard_index(&the_index);
read_cache_from(index_path); read_index_from(&the_index, index_path, get_git_dir());
if (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL)) if (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))
return error(_("Repository lacks necessary blobs to fall back on 3-way merge.")); return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
@ -1596,8 +1596,8 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
say(state, stdout, _("Falling back to patching base and 3-way merge...")); say(state, stdout, _("Falling back to patching base and 3-way merge..."));
discard_cache(); discard_index(&the_index);
read_cache(); repo_read_index(the_repository);
/* /*
* This is not so wrong. Depending on which base we picked, orig_tree * This is not so wrong. Depending on which base we picked, orig_tree
@ -1781,7 +1781,8 @@ static void am_run(struct am_state *state, int resume)
unlink(am_path(state, "dirtyindex")); unlink(am_path(state, "dirtyindex"));
if (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0) if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
NULL, NULL, NULL) < 0)
die(_("unable to write index file")); die(_("unable to write index file"));
if (repo_index_has_changes(the_repository, NULL, &sb)) { if (repo_index_has_changes(the_repository, NULL, &sb)) {
@ -1930,7 +1931,7 @@ static void am_resolve(struct am_state *state, int allow_empty)
} }
} }
if (unmerged_cache()) { if (unmerged_index(&the_index)) {
printf_ln(_("You still have unmerged paths in your index.\n" printf_ln(_("You still have unmerged paths in your index.\n"
"You should 'git add' each file with resolved conflicts to mark them as such.\n" "You should 'git add' each file with resolved conflicts to mark them as such.\n"
"You might run `git rm` on a file to accept \"deleted by them\" for it.")); "You might run `git rm` on a file to accept \"deleted by them\" for it."));
@ -1967,9 +1968,9 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
if (parse_tree(head) || parse_tree(remote)) if (parse_tree(head) || parse_tree(remote))
return -1; return -1;
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
refresh_cache(REFRESH_QUIET); refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.head_idx = 1; opts.head_idx = 1;
@ -2007,7 +2008,7 @@ static int merge_tree(struct tree *tree)
if (parse_tree(tree)) if (parse_tree(tree))
return -1; return -1;
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.head_idx = 1; opts.head_idx = 1;
@ -2045,7 +2046,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
if (!remote_tree) if (!remote_tree)
return error(_("Could not parse object '%s'."), oid_to_hex(remote)); return error(_("Could not parse object '%s'."), oid_to_hex(remote));
read_cache_unmerged(); repo_read_index_unmerged(the_repository);
if (fast_forward_to(head_tree, head_tree, 1)) if (fast_forward_to(head_tree, head_tree, 1))
return -1; return -1;

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"

View File

@ -1,4 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
@ -115,7 +115,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, check_attr_options, argc = parse_options(argc, argv, prefix, check_attr_options,
check_attr_usage, PARSE_OPT_KEEP_DASHDASH); check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
if (read_cache() < 0) { if (repo_read_index(the_repository) < 0) {
die("invalid cache"); die("invalid cache");
} }

View File

@ -1,4 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
@ -179,7 +179,7 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)
die(_("--non-matching is only valid with --verbose")); die(_("--non-matching is only valid with --verbose"));
/* read_cache() is only necessary so we can watch out for submodules. */ /* read_cache() is only necessary so we can watch out for submodules. */
if (!no_index && read_cache() < 0) if (!no_index && repo_read_index(the_repository) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
setup_standard_excludes(&dir); setup_standard_excludes(&dir);

View File

@ -4,7 +4,7 @@
* Copyright (C) 2005 Linus Torvalds * Copyright (C) 2005 Linus Torvalds
* *
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "config.h" #include "config.h"
#include "dir.h" #include "dir.h"
@ -65,7 +65,7 @@ static void write_tempfile_record(const char *name, const char *prefix)
static int checkout_file(const char *name, const char *prefix) static int checkout_file(const char *name, const char *prefix)
{ {
int namelen = strlen(name); int namelen = strlen(name);
int pos = cache_name_pos(name, namelen); int pos = index_name_pos(&the_index, name, namelen);
int has_same_name = 0; int has_same_name = 0;
int is_file = 0; int is_file = 0;
int is_skipped = 1; int is_skipped = 1;
@ -75,8 +75,8 @@ static int checkout_file(const char *name, const char *prefix)
if (pos < 0) if (pos < 0)
pos = -pos - 1; pos = -pos - 1;
while (pos < active_nr) { while (pos < the_index.cache_nr) {
struct cache_entry *ce = active_cache[pos]; struct cache_entry *ce = the_index.cache[pos];
if (ce_namelen(ce) != namelen || if (ce_namelen(ce) != namelen ||
memcmp(ce->name, name, namelen)) memcmp(ce->name, name, namelen))
break; break;
@ -136,8 +136,8 @@ static int checkout_all(const char *prefix, int prefix_length)
int i, errs = 0; int i, errs = 0;
struct cache_entry *last_ce = NULL; struct cache_entry *last_ce = NULL;
for (i = 0; i < active_nr ; i++) { for (i = 0; i < the_index.cache_nr ; i++) {
struct cache_entry *ce = active_cache[i]; struct cache_entry *ce = the_index.cache[i];
if (S_ISSPARSEDIR(ce->ce_mode)) { if (S_ISSPARSEDIR(ce->ce_mode)) {
if (!ce_skip_worktree(ce)) if (!ce_skip_worktree(ce))
@ -151,7 +151,7 @@ static int checkout_all(const char *prefix, int prefix_length)
*/ */
if (ignore_skip_worktree) { if (ignore_skip_worktree) {
ensure_full_index(&the_index); ensure_full_index(&the_index);
ce = active_cache[i]; ce = the_index.cache[i];
} }
} }
@ -249,7 +249,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
prepare_repo_settings(the_repository); prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0; the_repository->settings.command_requires_full_index = 0;
if (read_cache() < 0) { if (repo_read_index(the_repository) < 0) {
die("invalid cache"); die("invalid cache");
} }
@ -270,7 +270,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
if (index_opt && !state.base_dir_len && !to_tempfile) { if (index_opt && !state.base_dir_len && !to_tempfile) {
state.refresh_cache = 1; state.refresh_cache = 1;
state.istate = &the_index; state.istate = &the_index;
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file,
LOCK_DIE_ON_ERROR);
} }
get_parallel_checkout_configs(&pc_workers, &pc_threshold); get_parallel_checkout_configs(&pc_workers, &pc_threshold);

View File

@ -1,4 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "advice.h" #include "advice.h"
#include "blob.h" #include "blob.h"
@ -148,9 +148,9 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
* entry in place. Whether it is UPTODATE or not, checkout_entry will * entry in place. Whether it is UPTODATE or not, checkout_entry will
* do the right thing. * do the right thing.
*/ */
pos = cache_name_pos(ce->name, ce->ce_namelen); pos = index_name_pos(&the_index, ce->name, ce->ce_namelen);
if (pos >= 0) { if (pos >= 0) {
struct cache_entry *old = active_cache[pos]; struct cache_entry *old = the_index.cache[pos];
if (ce->ce_mode == old->ce_mode && if (ce->ce_mode == old->ce_mode &&
!ce_intent_to_add(old) && !ce_intent_to_add(old) &&
oideq(&ce->oid, &old->oid)) { oideq(&ce->oid, &old->oid)) {
@ -160,7 +160,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
} }
} }
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); add_index_entry(&the_index, ce,
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
return 0; return 0;
} }
@ -178,8 +179,8 @@ static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
static int skip_same_name(const struct cache_entry *ce, int pos) static int skip_same_name(const struct cache_entry *ce, int pos)
{ {
while (++pos < active_nr && while (++pos < the_index.cache_nr &&
!strcmp(active_cache[pos]->name, ce->name)) !strcmp(the_index.cache[pos]->name, ce->name))
; /* skip */ ; /* skip */
return pos; return pos;
} }
@ -187,9 +188,9 @@ static int skip_same_name(const struct cache_entry *ce, int pos)
static int check_stage(int stage, const struct cache_entry *ce, int pos, static int check_stage(int stage, const struct cache_entry *ce, int pos,
int overlay_mode) int overlay_mode)
{ {
while (pos < active_nr && while (pos < the_index.cache_nr &&
!strcmp(active_cache[pos]->name, ce->name)) { !strcmp(the_index.cache[pos]->name, ce->name)) {
if (ce_stage(active_cache[pos]) == stage) if (ce_stage(the_index.cache[pos]) == stage)
return 0; return 0;
pos++; pos++;
} }
@ -206,8 +207,8 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
unsigned seen = 0; unsigned seen = 0;
const char *name = ce->name; const char *name = ce->name;
while (pos < active_nr) { while (pos < the_index.cache_nr) {
ce = active_cache[pos]; ce = the_index.cache[pos];
if (strcmp(name, ce->name)) if (strcmp(name, ce->name))
break; break;
seen |= (1 << ce_stage(ce)); seen |= (1 << ce_stage(ce));
@ -223,10 +224,10 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
const struct checkout *state, int *nr_checkouts, const struct checkout *state, int *nr_checkouts,
int overlay_mode) int overlay_mode)
{ {
while (pos < active_nr && while (pos < the_index.cache_nr &&
!strcmp(active_cache[pos]->name, ce->name)) { !strcmp(the_index.cache[pos]->name, ce->name)) {
if (ce_stage(active_cache[pos]) == stage) if (ce_stage(the_index.cache[pos]) == stage)
return checkout_entry(active_cache[pos], state, return checkout_entry(the_index.cache[pos], state,
NULL, nr_checkouts); NULL, nr_checkouts);
pos++; pos++;
} }
@ -243,7 +244,7 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
static int checkout_merged(int pos, const struct checkout *state, static int checkout_merged(int pos, const struct checkout *state,
int *nr_checkouts, struct mem_pool *ce_mem_pool) int *nr_checkouts, struct mem_pool *ce_mem_pool)
{ {
struct cache_entry *ce = active_cache[pos]; struct cache_entry *ce = the_index.cache[pos];
const char *path = ce->name; const char *path = ce->name;
mmfile_t ancestor, ours, theirs; mmfile_t ancestor, ours, theirs;
enum ll_merge_result merge_status; enum ll_merge_result merge_status;
@ -256,7 +257,7 @@ static int checkout_merged(int pos, const struct checkout *state,
int renormalize = 0; int renormalize = 0;
memset(threeway, 0, sizeof(threeway)); memset(threeway, 0, sizeof(threeway));
while (pos < active_nr) { while (pos < the_index.cache_nr) {
int stage; int stage;
stage = ce_stage(ce); stage = ce_stage(ce);
if (!stage || strcmp(path, ce->name)) if (!stage || strcmp(path, ce->name))
@ -265,7 +266,7 @@ static int checkout_merged(int pos, const struct checkout *state,
if (stage == 2) if (stage == 2)
mode = create_ce_mode(ce->ce_mode); mode = create_ce_mode(ce->ce_mode);
pos++; pos++;
ce = active_cache[pos]; ce = the_index.cache[pos];
} }
if (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2])) if (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))
return error(_("path '%s' does not have necessary versions"), path); return error(_("path '%s' does not have necessary versions"), path);
@ -391,8 +392,8 @@ static int checkout_worktree(const struct checkout_opts *opts,
if (pc_workers > 1) if (pc_workers > 1)
init_parallel_checkout(); init_parallel_checkout();
for (pos = 0; pos < active_nr; pos++) { for (pos = 0; pos < the_index.cache_nr; pos++) {
struct cache_entry *ce = active_cache[pos]; struct cache_entry *ce = the_index.cache[pos];
if (ce->ce_flags & CE_MATCHED) { if (ce->ce_flags & CE_MATCHED) {
if (!ce_stage(ce)) { if (!ce_stage(ce)) {
errs |= checkout_entry(ce, &state, errs |= checkout_entry(ce, &state,
@ -528,7 +529,7 @@ static int checkout_paths(const struct checkout_opts *opts,
} }
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
if (read_cache_preload(&opts->pathspec) < 0) if (repo_read_index_preload(the_repository, &opts->pathspec, 0) < 0)
return error(_("index file corrupt")); return error(_("index file corrupt"));
if (opts->source_tree) if (opts->source_tree)
@ -540,13 +541,13 @@ static int checkout_paths(const struct checkout_opts *opts,
* Make sure all pathspecs participated in locating the paths * Make sure all pathspecs participated in locating the paths
* to be checked out. * to be checked out.
*/ */
for (pos = 0; pos < active_nr; pos++) for (pos = 0; pos < the_index.cache_nr; pos++)
if (opts->overlay_mode) if (opts->overlay_mode)
mark_ce_for_checkout_overlay(active_cache[pos], mark_ce_for_checkout_overlay(the_index.cache[pos],
ps_matched, ps_matched,
opts); opts);
else else
mark_ce_for_checkout_no_overlay(active_cache[pos], mark_ce_for_checkout_no_overlay(the_index.cache[pos],
ps_matched, ps_matched,
opts); opts);
@ -561,8 +562,8 @@ static int checkout_paths(const struct checkout_opts *opts,
unmerge_marked_index(&the_index); unmerge_marked_index(&the_index);
/* Any unmerged paths? */ /* Any unmerged paths? */
for (pos = 0; pos < active_nr; pos++) { for (pos = 0; pos < the_index.cache_nr; pos++) {
const struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = the_index.cache[pos];
if (ce->ce_flags & CE_MATCHED) { if (ce->ce_flags & CE_MATCHED) {
if (!ce_stage(ce)) if (!ce_stage(ce))
continue; continue;
@ -722,7 +723,7 @@ static void init_topts(struct unpack_trees_options *topts, int merge,
setup_unpack_trees_porcelain(topts, "checkout"); setup_unpack_trees_porcelain(topts, "checkout");
topts->initial_checkout = is_cache_unborn(); topts->initial_checkout = is_index_unborn(&the_index);
topts->update = 1; topts->update = 1;
topts->merge = 1; topts->merge = 1;
topts->quiet = merge && old_commit; topts->quiet = merge && old_commit;
@ -740,11 +741,11 @@ static int merge_working_tree(const struct checkout_opts *opts,
struct lock_file lock_file = LOCK_INIT; struct lock_file lock_file = LOCK_INIT;
struct tree *new_tree; struct tree *new_tree;
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
if (read_cache_preload(NULL) < 0) if (repo_read_index_preload(the_repository, NULL, 0) < 0)
return error(_("index file corrupt")); return error(_("index file corrupt"));
resolve_undo_clear(); resolve_undo_clear_index(&the_index);
if (opts->new_orphan_branch && opts->orphan_from_empty_tree) { if (opts->new_orphan_branch && opts->orphan_from_empty_tree) {
if (new_branch_info->commit) if (new_branch_info->commit)
BUG("'switch --orphan' should never accept a commit as starting point"); BUG("'switch --orphan' should never accept a commit as starting point");
@ -761,9 +762,9 @@ static int merge_working_tree(const struct checkout_opts *opts,
struct unpack_trees_options topts; struct unpack_trees_options topts;
const struct object_id *old_commit_oid; const struct object_id *old_commit_oid;
refresh_cache(REFRESH_QUIET); refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
if (unmerged_cache()) { if (unmerged_index(&the_index)) {
error(_("you need to resolve your current index first")); error(_("you need to resolve your current index first"));
return 1; return 1;
} }
@ -867,7 +868,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
} }
} }
if (!cache_tree_fully_valid(active_cache_tree)) if (!cache_tree_fully_valid(the_index.cache_tree))
cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR); cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))

View File

@ -6,7 +6,7 @@
* Based on git-clean.sh by Pavel Roskin * Based on git-clean.sh by Pavel Roskin
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
@ -1012,7 +1012,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
prepare_repo_settings(the_repository); prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0; the_repository->settings.command_requires_full_index = 0;
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option"); pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");
@ -1031,7 +1031,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
struct stat st; struct stat st;
const char *rel; const char *rel;
if (!cache_name_is_other(ent->name, ent->len)) if (!index_name_is_other(&the_index, ent->name, ent->len))
continue; continue;
if (lstat(ent->name, &st)) if (lstat(ent->name, &st))

View File

@ -8,7 +8,7 @@
* Clone a repository into a different directory that does not yet exist. * Clone a repository into a different directory that does not yet exist.
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"
@ -703,7 +703,7 @@ static int checkout(int submodule_progress, int filter_submodules)
/* We need to be in the new work tree for the checkout */ /* We need to be in the new work tree for the checkout */
setup_work_tree(); setup_work_tree();
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
memset(&opts, 0, sizeof opts); memset(&opts, 0, sizeof opts);
opts.update = 1; opts.update = 1;

View File

@ -272,8 +272,8 @@ static int list_paths(struct string_list *list, const char *with_tree,
/* TODO: audit for interaction with sparse-index. */ /* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index); ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++) { for (i = 0; i < the_index.cache_nr; i++) {
const struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = the_index.cache[i];
struct string_list_item *item; struct string_list_item *item;
if (ce->ce_flags & CE_UPDATE) if (ce->ce_flags & CE_UPDATE)
@ -302,10 +302,10 @@ static void add_remove_files(struct string_list *list)
continue; continue;
if (!lstat(p->string, &st)) { if (!lstat(p->string, &st)) {
if (add_to_cache(p->string, &st, 0)) if (add_to_index(&the_index, p->string, &st, 0))
die(_("updating files failed")); die(_("updating files failed"));
} else } else
remove_file_from_cache(p->string); remove_file_from_index(&the_index, p->string);
} }
} }
@ -316,7 +316,7 @@ static void create_base_index(const struct commit *current_head)
struct tree_desc t; struct tree_desc t;
if (!current_head) { if (!current_head) {
discard_cache(); discard_index(&the_index);
return; return;
} }
@ -343,7 +343,7 @@ static void refresh_cache_or_die(int refresh_flags)
* refresh_flags contains REFRESH_QUIET, so the only errors * refresh_flags contains REFRESH_QUIET, so the only errors
* are for unmerged entries. * are for unmerged entries.
*/ */
if (refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN)) if (refresh_index(&the_index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))
die_resolve_conflict("commit"); die_resolve_conflict("commit");
} }
@ -382,12 +382,13 @@ static const char *prepare_index(const char **argv, const char *prefix,
(!amend || (fixup_message && strcmp(fixup_prefix, "amend")))))) (!amend || (fixup_message && strcmp(fixup_prefix, "amend"))))))
die(_("No paths with --include/--only does not make sense.")); die(_("No paths with --include/--only does not make sense."));
if (read_cache_preload(&pathspec) < 0) if (repo_read_index_preload(the_repository, &pathspec, 0) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
if (interactive) { if (interactive) {
char *old_index_env = NULL, *old_repo_index_file; char *old_index_env = NULL, *old_repo_index_file;
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &index_lock,
LOCK_DIE_ON_ERROR);
refresh_cache_or_die(refresh_flags); refresh_cache_or_die(refresh_flags);
@ -410,8 +411,9 @@ static const char *prepare_index(const char **argv, const char *prefix,
unsetenv(INDEX_ENVIRONMENT); unsetenv(INDEX_ENVIRONMENT);
FREE_AND_NULL(old_index_env); FREE_AND_NULL(old_index_env);
discard_cache(); discard_index(&the_index);
read_cache_from(get_lock_file_path(&index_lock)); read_index_from(&the_index, get_lock_file_path(&index_lock),
get_git_dir());
if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) { if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
if (reopen_lock_file(&index_lock) < 0) if (reopen_lock_file(&index_lock) < 0)
die(_("unable to write index file")); die(_("unable to write index file"));
@ -438,7 +440,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
* (B) on failure, rollback the real index. * (B) on failure, rollback the real index.
*/ */
if (all || (also && pathspec.nr)) { if (all || (also && pathspec.nr)) {
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &index_lock,
LOCK_DIE_ON_ERROR);
add_files_to_cache(also ? prefix : NULL, &pathspec, 0); add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
refresh_cache_or_die(refresh_flags); refresh_cache_or_die(refresh_flags);
update_main_cache_tree(WRITE_TREE_SILENT); update_main_cache_tree(WRITE_TREE_SILENT);
@ -459,10 +462,11 @@ static const char *prepare_index(const char **argv, const char *prefix,
* We still need to refresh the index here. * We still need to refresh the index here.
*/ */
if (!only && !pathspec.nr) { if (!only && !pathspec.nr) {
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &index_lock,
LOCK_DIE_ON_ERROR);
refresh_cache_or_die(refresh_flags); refresh_cache_or_die(refresh_flags);
if (active_cache_changed if (the_index.cache_changed
|| !cache_tree_fully_valid(active_cache_tree)) || !cache_tree_fully_valid(the_index.cache_tree))
update_main_cache_tree(WRITE_TREE_SILENT); update_main_cache_tree(WRITE_TREE_SILENT);
if (write_locked_index(&the_index, &index_lock, if (write_locked_index(&the_index, &index_lock,
COMMIT_LOCK | SKIP_IF_UNCHANGED)) COMMIT_LOCK | SKIP_IF_UNCHANGED))
@ -505,13 +509,13 @@ static const char *prepare_index(const char **argv, const char *prefix,
if (list_paths(&partial, !current_head ? NULL : "HEAD", &pathspec)) if (list_paths(&partial, !current_head ? NULL : "HEAD", &pathspec))
exit(1); exit(1);
discard_cache(); discard_index(&the_index);
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die(_("cannot read the index")); die(_("cannot read the index"));
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
add_remove_files(&partial); add_remove_files(&partial);
refresh_cache(REFRESH_QUIET); refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
update_main_cache_tree(WRITE_TREE_SILENT); update_main_cache_tree(WRITE_TREE_SILENT);
if (write_locked_index(&the_index, &index_lock, 0)) if (write_locked_index(&the_index, &index_lock, 0))
die(_("unable to write new_index file")); die(_("unable to write new_index file"));
@ -523,14 +527,14 @@ static const char *prepare_index(const char **argv, const char *prefix,
create_base_index(current_head); create_base_index(current_head);
add_remove_files(&partial); add_remove_files(&partial);
refresh_cache(REFRESH_QUIET); refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
if (write_locked_index(&the_index, &false_lock, 0)) if (write_locked_index(&the_index, &false_lock, 0))
die(_("unable to write temporary index file")); die(_("unable to write temporary index file"));
discard_cache(); discard_index(&the_index);
ret = get_lock_file_path(&false_lock); ret = get_lock_file_path(&false_lock);
read_cache_from(ret); read_index_from(&the_index, ret, get_git_dir());
out: out:
string_list_clear(&partial, 0); string_list_clear(&partial, 0);
clear_pathspec(&pathspec); clear_pathspec(&pathspec);
@ -998,10 +1002,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
/* TODO: audit for interaction with sparse-index. */ /* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index); ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++) for (i = 0; i < the_index.cache_nr; i++)
if (ce_intent_to_add(active_cache[i])) if (ce_intent_to_add(the_index.cache[i]))
ita_nr++; ita_nr++;
committable = active_nr - ita_nr > 0; committable = the_index.cache_nr - ita_nr > 0;
} else { } else {
/* /*
* Unless the user did explicitly request a submodule * Unless the user did explicitly request a submodule
@ -1068,9 +1072,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
* and could have updated it. We must do this before we invoke * and could have updated it. We must do this before we invoke
* the editor and after we invoke run_status above. * the editor and after we invoke run_status above.
*/ */
discard_cache(); discard_index(&the_index);
} }
read_cache_from(index_file); read_index_from(&the_index, index_file, get_git_dir());
if (update_main_cache_tree(0)) { if (update_main_cache_tree(0)) {
error(_("Error building trees")); error(_("Error building trees"));
@ -1556,7 +1560,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
&s.pathspec, NULL, NULL); &s.pathspec, NULL, NULL);
if (use_optional_locks()) if (use_optional_locks())
fd = hold_locked_index(&index_lock, 0); fd = repo_hold_locked_index(the_repository, &index_lock, 0);
else else
fd = -1; fd = -1;
@ -1823,7 +1827,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
append_merge_tag_headers(parents, &tail); append_merge_tag_headers(parents, &tail);
} }
if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid, if (commit_tree_extended(sb.buf, sb.len, &the_index.cache_tree->oid,
parents, &oid, author_ident.buf, NULL, parents, &oid, author_ident.buf, NULL,
sign_commit, extra)) { sign_commit, extra)) {
rollback_index_files(); rollback_index_files();

View File

@ -1,4 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"
@ -653,10 +653,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
int fd, result; int fd, result;
setup_work_tree(); setup_work_tree();
read_cache(); repo_read_index(the_repository);
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
NULL, NULL, NULL); NULL, NULL, NULL);
fd = hold_locked_index(&index_lock, 0); fd = repo_hold_locked_index(the_repository,
&index_lock, 0);
if (0 <= fd) if (0 <= fd)
repo_update_index_if_able(the_repository, &index_lock); repo_update_index_if_able(the_repository, &index_lock);

View File

@ -3,7 +3,6 @@
* *
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "diff.h" #include "diff.h"
@ -76,8 +75,8 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
(rev.diffopt.output_format & DIFF_FORMAT_PATCH)) (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
diff_merges_set_dense_combined_if_unset(&rev); diff_merges_set_dense_combined_if_unset(&rev);
if (read_cache_preload(&rev.diffopt.pathspec) < 0) { if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
perror("read_cache_preload"); perror("repo_read_index_preload");
result = -1; result = -1;
goto cleanup; goto cleanup;
} }

View File

@ -1,4 +1,3 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "diff.h" #include "diff.h"
@ -62,12 +61,12 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
usage(diff_cache_usage); usage(diff_cache_usage);
if (!(option & DIFF_INDEX_CACHED)) { if (!(option & DIFF_INDEX_CACHED)) {
setup_work_tree(); setup_work_tree();
if (read_cache_preload(&rev.diffopt.pathspec) < 0) { if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
perror("read_cache_preload"); perror("repo_read_index_preload");
return -1; return -1;
} }
} else if (read_cache() < 0) { } else if (repo_read_index(the_repository) < 0) {
perror("read_cache"); perror("repo_read_index");
return -1; return -1;
} }
result = run_diff_index(&rev, option); result = run_diff_index(&rev, option);

View File

@ -1,4 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "diff.h" #include "diff.h"
@ -120,7 +120,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
repo_init_revisions(the_repository, opt, prefix); repo_init_revisions(the_repository, opt, prefix);
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
opt->abbrev = 0; opt->abbrev = 0;
opt->diff = 1; opt->diff = 1;

View File

@ -3,7 +3,7 @@
* *
* Copyright (c) 2006 Junio C Hamano * Copyright (c) 2006 Junio C Hamano
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "ewah/ewok.h" #include "ewah/ewok.h"
@ -157,12 +157,13 @@ static int builtin_diff_index(struct rev_info *revs,
usage(builtin_diff_usage); usage(builtin_diff_usage);
if (!(option & DIFF_INDEX_CACHED)) { if (!(option & DIFF_INDEX_CACHED)) {
setup_work_tree(); setup_work_tree();
if (read_cache_preload(&revs->diffopt.pathspec) < 0) { if (repo_read_index_preload(the_repository,
perror("read_cache_preload"); &revs->diffopt.pathspec, 0) < 0) {
perror("repo_read_index_preload");
return -1; return -1;
} }
} else if (read_cache() < 0) { } else if (repo_read_index(the_repository) < 0) {
perror("read_cache"); perror("repo_read_cache");
return -1; return -1;
} }
return run_diff_index(revs, option); return run_diff_index(revs, option);
@ -239,12 +240,13 @@ static void refresh_index_quietly(void)
struct lock_file lock_file = LOCK_INIT; struct lock_file lock_file = LOCK_INIT;
int fd; int fd;
fd = hold_locked_index(&lock_file, 0); fd = repo_hold_locked_index(the_repository, &lock_file, 0);
if (fd < 0) if (fd < 0)
return; return;
discard_cache(); discard_index(&the_index);
read_cache(); repo_read_index(the_repository);
refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL,
NULL);
repo_update_index_if_able(the_repository, &lock_file); repo_update_index_if_able(the_repository, &lock_file);
} }
@ -279,8 +281,9 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
diff_merges_set_dense_combined_if_unset(revs); diff_merges_set_dense_combined_if_unset(revs);
setup_work_tree(); setup_work_tree();
if (read_cache_preload(&revs->diffopt.pathspec) < 0) { if (repo_read_index_preload(the_repository, &revs->diffopt.pathspec,
perror("read_cache_preload"); 0) < 0) {
perror("repo_read_index_preload");
return -1; return -1;
} }
return run_diff_files(revs, options); return run_diff_files(revs, options);

View File

@ -11,7 +11,7 @@
* *
* Copyright (C) 2016 Johannes Schindelin * Copyright (C) 2016 Johannes Schindelin
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"

View File

@ -1,4 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "repository.h" #include "repository.h"
@ -958,29 +958,29 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
if (keep_cache_objects) { if (keep_cache_objects) {
verify_index_checksum = 1; verify_index_checksum = 1;
verify_ce_order = 1; verify_ce_order = 1;
read_cache(); repo_read_index(the_repository);
/* TODO: audit for interaction with sparse-index. */ /* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index); ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++) { for (i = 0; i < the_index.cache_nr; i++) {
unsigned int mode; unsigned int mode;
struct blob *blob; struct blob *blob;
struct object *obj; struct object *obj;
mode = active_cache[i]->ce_mode; mode = the_index.cache[i]->ce_mode;
if (S_ISGITLINK(mode)) if (S_ISGITLINK(mode))
continue; continue;
blob = lookup_blob(the_repository, blob = lookup_blob(the_repository,
&active_cache[i]->oid); &the_index.cache[i]->oid);
if (!blob) if (!blob)
continue; continue;
obj = &blob->object; obj = &blob->object;
obj->flags |= USED; obj->flags |= USED;
fsck_put_object_name(&fsck_walk_options, &obj->oid, fsck_put_object_name(&fsck_walk_options, &obj->oid,
":%s", active_cache[i]->name); ":%s", the_index.cache[i]->name);
mark_object_reachable(obj); mark_object_reachable(obj);
} }
if (active_cache_tree) if (the_index.cache_tree)
fsck_cache_tree(active_cache_tree); fsck_cache_tree(the_index.cache_tree);
fsck_resolve_undo(&the_index); fsck_resolve_undo(&the_index);
} }

View File

@ -3,7 +3,6 @@
* *
* Copyright (c) 2006 Junio C Hamano * Copyright (c) 2006 Junio C Hamano
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "repository.h" #include "repository.h"
#include "config.h" #include "config.h"

View File

@ -4,7 +4,6 @@
* (C) Copyright 2006 Linus Torvalds * (C) Copyright 2006 Linus Torvalds
* 2006 Junio Hamano * 2006 Junio Hamano
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "refs.h" #include "refs.h"

View File

@ -1,4 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "run-command.h" #include "run-command.h"
@ -14,11 +14,11 @@ static int merge_entry(int pos, const char *path)
char ownbuf[4][60]; char ownbuf[4][60];
struct child_process cmd = CHILD_PROCESS_INIT; struct child_process cmd = CHILD_PROCESS_INIT;
if (pos >= active_nr) if (pos >= the_index.cache_nr)
die("git merge-index: %s not in the cache", path); die("git merge-index: %s not in the cache", path);
found = 0; found = 0;
do { do {
const struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = the_index.cache[pos];
int stage = ce_stage(ce); int stage = ce_stage(ce);
if (strcmp(ce->name, path)) if (strcmp(ce->name, path))
@ -28,7 +28,7 @@ static int merge_entry(int pos, const char *path)
xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode); xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
arguments[stage] = hexbuf[stage]; arguments[stage] = hexbuf[stage];
arguments[stage + 4] = ownbuf[stage]; arguments[stage + 4] = ownbuf[stage];
} while (++pos < active_nr); } while (++pos < the_index.cache_nr);
if (!found) if (!found)
die("git merge-index: %s not in the cache", path); die("git merge-index: %s not in the cache", path);
@ -47,7 +47,7 @@ static int merge_entry(int pos, const char *path)
static void merge_one_path(const char *path) static void merge_one_path(const char *path)
{ {
int pos = cache_name_pos(path, strlen(path)); int pos = index_name_pos(&the_index, path, strlen(path));
/* /*
* If it already exists in the cache as stage0, it's * If it already exists in the cache as stage0, it's
@ -62,8 +62,8 @@ static void merge_all(void)
int i; int i;
/* TODO: audit for interaction with sparse-index. */ /* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index); ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++) { for (i = 0; i < the_index.cache_nr; i++) {
const struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = the_index.cache[i];
if (!ce_stage(ce)) if (!ce_stage(ce))
continue; continue;
i += merge_entry(i, ce->name)-1; i += merge_entry(i, ce->name)-1;
@ -82,7 +82,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix)
if (argc < 3) if (argc < 3)
usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])"); usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])");
read_cache(); repo_read_index(the_repository);
/* TODO: audit for interaction with sparse-index. */ /* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index); ensure_full_index(&the_index);

View File

@ -7,7 +7,6 @@
* *
* Pretend we resolved the heads, but declare our tree trumps everybody else. * Pretend we resolved the heads, but declare our tree trumps everybody else.
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "git-compat-util.h" #include "git-compat-util.h"
#include "builtin.h" #include "builtin.h"
#include "diff.h" #include "diff.h"
@ -25,7 +24,7 @@ int cmd_merge_ours(int argc, const char **argv, const char *prefix)
* commit. The index must match HEAD, or this merge cannot go * commit. The index must match HEAD, or this merge cannot go
* through. * through.
*/ */
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die_errno("read_cache failed"); die_errno("read_cache failed");
if (index_differs_from(the_repository, "HEAD", NULL, 0)) if (index_differs_from(the_repository, "HEAD", NULL, 0))
return 2; return 2;

View File

@ -1,4 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "tree-walk.h" #include "tree-walk.h"
#include "xdiff-interface.h" #include "xdiff-interface.h"

View File

@ -318,7 +318,7 @@ static int save_state(struct object_id *stash)
int rc = -1; int rc = -1;
fd = repo_hold_locked_index(the_repository, &lock_file, 0); fd = repo_hold_locked_index(the_repository, &lock_file, 0);
refresh_cache(REFRESH_QUIET); refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
if (0 <= fd) if (0 <= fd)
repo_update_index_if_able(the_repository, &lock_file); repo_update_index_if_able(the_repository, &lock_file);
rollback_lock_file(&lock_file); rollback_lock_file(&lock_file);
@ -390,7 +390,8 @@ static void restore_state(const struct object_id *head,
run_command(&cmd); run_command(&cmd);
refresh_cache: refresh_cache:
if (discard_cache() < 0 || read_cache() < 0) discard_cache();
if (read_cache() < 0)
die(_("could not read index")); die(_("could not read index"));
} }
@ -693,7 +694,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
if (!trees[nr_trees++]) if (!trees[nr_trees++])
return -1; return -1;
opts.fn = threeway_merge; opts.fn = threeway_merge;
cache_tree_free(&active_cache_tree); cache_tree_free(&the_index.cache_tree);
for (i = 0; i < nr_trees; i++) { for (i = 0; i < nr_trees; i++) {
parse_tree(trees[i]); parse_tree(trees[i]);
init_tree_desc(t+i, trees[i]->buffer, trees[i]->size); init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
@ -715,7 +716,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
{ {
const char *head_arg = "HEAD"; const char *head_arg = "HEAD";
if (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0) if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET,
SKIP_IF_UNCHANGED, 0, NULL, NULL,
NULL) < 0)
return error(_("Unable to write index.")); return error(_("Unable to write index."));
if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree") || if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree") ||
@ -749,7 +752,8 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
for (j = common; j; j = j->next) for (j = common; j; j = j->next)
commit_list_insert(j->item, &reversed); commit_list_insert(j->item, &reversed);
hold_locked_index(&lock, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock,
LOCK_DIE_ON_ERROR);
if (!strcmp(strategy, "ort")) if (!strcmp(strategy, "ort"))
clean = merge_ort_recursive(&o, head, remoteheads->item, clean = merge_ort_recursive(&o, head, remoteheads->item,
reversed, &result); reversed, &result);
@ -783,8 +787,8 @@ static int count_unmerged_entries(void)
{ {
int i, ret = 0; int i, ret = 0;
for (i = 0; i < active_nr; i++) for (i = 0; i < the_index.cache_nr; i++)
if (ce_stage(active_cache[i])) if (ce_stage(the_index.cache[i]))
ret++; ret++;
return ret; return ret;
@ -858,9 +862,9 @@ static void prepare_to_commit(struct commit_list *remoteheads)
* the editor and after we invoke run_status above. * the editor and after we invoke run_status above.
*/ */
if (invoked_hook) if (invoked_hook)
discard_cache(); discard_index(&the_index);
} }
read_cache_from(index_file); read_index_from(&the_index, index_file, get_git_dir());
strbuf_addbuf(&msg, &merge_msg); strbuf_addbuf(&msg, &merge_msg);
if (squash) if (squash)
BUG("the control must not reach here under --squash"); BUG("the control must not reach here under --squash");
@ -909,7 +913,9 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
struct object_id result_tree, result_commit; struct object_id result_tree, result_commit;
struct commit_list *parents, **pptr = &parents; struct commit_list *parents, **pptr = &parents;
if (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0) if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET,
SKIP_IF_UNCHANGED, 0, NULL, NULL,
NULL) < 0)
return error(_("Unable to write index.")); return error(_("Unable to write index."));
write_tree_trivial(&result_tree); write_tree_trivial(&result_tree);
@ -1375,7 +1381,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
goto done; goto done;
} }
if (read_cache_unmerged()) if (repo_read_index_unmerged(the_repository))
die_resolve_conflict("merge"); die_resolve_conflict("merge");
if (file_exists(git_path_merge_head(the_repository))) { if (file_exists(git_path_merge_head(the_repository))) {
@ -1396,7 +1402,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
else else
die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).")); die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)."));
} }
resolve_undo_clear(); resolve_undo_clear_index(&the_index);
if (option_edit < 0) if (option_edit < 0)
option_edit = default_edit_option(); option_edit = default_edit_option();
@ -1601,7 +1607,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* We are not doing octopus, not fast-forward, and have * We are not doing octopus, not fast-forward, and have
* only one common. * only one common.
*/ */
refresh_cache(REFRESH_QUIET); refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
if (allow_trivial && fast_forward != FF_ONLY) { if (allow_trivial && fast_forward != FF_ONLY) {
/* /*
* Must first ensure that index matches HEAD before * Must first ensure that index matches HEAD before

View File

@ -87,7 +87,7 @@ static void prepare_move_submodule(const char *src, int first,
const char **submodule_gitfile) const char **submodule_gitfile)
{ {
struct strbuf submodule_dotgit = STRBUF_INIT; struct strbuf submodule_dotgit = STRBUF_INIT;
if (!S_ISGITLINK(active_cache[first]->ce_mode)) if (!S_ISGITLINK(the_index.cache[first]->ce_mode))
die(_("Directory %s is in index and no submodule?"), src); die(_("Directory %s is in index and no submodule?"), src);
if (!is_staging_gitmodules_ok(&the_index)) if (!is_staging_gitmodules_ok(&the_index))
die(_("Please stage your changes to .gitmodules or stash them to proceed")); die(_("Please stage your changes to .gitmodules or stash them to proceed"));
@ -106,13 +106,13 @@ static int index_range_of_same_dir(const char *src, int length,
const char *src_w_slash = add_slash(src); const char *src_w_slash = add_slash(src);
int first, last, len_w_slash = length + 1; int first, last, len_w_slash = length + 1;
first = cache_name_pos(src_w_slash, len_w_slash); first = index_name_pos(&the_index, src_w_slash, len_w_slash);
if (first >= 0) if (first >= 0)
die(_("%.*s is in index"), len_w_slash, src_w_slash); die(_("%.*s is in index"), len_w_slash, src_w_slash);
first = -1 - first; first = -1 - first;
for (last = first; last < active_nr; last++) { for (last = first; last < the_index.cache_nr; last++) {
const char *path = active_cache[last]->name; const char *path = the_index.cache[last]->name;
if (strncmp(path, src_w_slash, len_w_slash)) if (strncmp(path, src_w_slash, len_w_slash))
break; break;
} }
@ -136,14 +136,14 @@ static int empty_dir_has_sparse_contents(const char *name)
const char *with_slash = add_slash(name); const char *with_slash = add_slash(name);
int length = strlen(with_slash); int length = strlen(with_slash);
int pos = cache_name_pos(with_slash, length); int pos = index_name_pos(&the_index, with_slash, length);
const struct cache_entry *ce; const struct cache_entry *ce;
if (pos < 0) { if (pos < 0) {
pos = -pos - 1; pos = -pos - 1;
if (pos >= the_index.cache_nr) if (pos >= the_index.cache_nr)
goto free_return; goto free_return;
ce = active_cache[pos]; ce = the_index.cache[pos];
if (strncmp(with_slash, ce->name, length)) if (strncmp(with_slash, ce->name, length))
goto free_return; goto free_return;
if (ce_skip_worktree(ce)) if (ce_skip_worktree(ce))
@ -189,8 +189,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
if (--argc < 1) if (--argc < 1)
usage_with_options(builtin_mv_usage, builtin_mv_options); usage_with_options(builtin_mv_usage, builtin_mv_options);
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
source = internal_prefix_pathspec(prefix, argv, argc, 0); source = internal_prefix_pathspec(prefix, argv, argc, 0);
@ -255,7 +255,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
int pos; int pos;
const struct cache_entry *ce; const struct cache_entry *ce;
pos = cache_name_pos(src, length); pos = index_name_pos(&the_index, src, length);
if (pos < 0) { if (pos < 0) {
const char *src_w_slash = add_slash(src); const char *src_w_slash = add_slash(src);
if (!path_in_sparse_checkout(src_w_slash, &the_index) && if (!path_in_sparse_checkout(src_w_slash, &the_index) &&
@ -268,7 +268,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
bad = _("bad source"); bad = _("bad source");
goto act_on_entry; goto act_on_entry;
} }
ce = active_cache[pos]; ce = the_index.cache[pos];
if (!ce_skip_worktree(ce)) { if (!ce_skip_worktree(ce)) {
bad = _("bad source"); bad = _("bad source");
goto act_on_entry; goto act_on_entry;
@ -278,7 +278,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
goto act_on_entry; goto act_on_entry;
} }
/* Check if dst exists in index */ /* Check if dst exists in index */
if (cache_name_pos(dst, strlen(dst)) < 0) { if (index_name_pos(&the_index, dst, strlen(dst)) < 0) {
modes[i] |= SPARSE; modes[i] |= SPARSE;
goto act_on_entry; goto act_on_entry;
} }
@ -303,7 +303,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
dir_check: dir_check:
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
int j, dst_len, n; int j, dst_len, n;
int first = cache_name_pos(src, length), last; int first = index_name_pos(&the_index, src, length), last;
if (first >= 0) { if (first >= 0) {
prepare_move_submodule(src, first, prepare_move_submodule(src, first,
@ -331,7 +331,7 @@ dir_check:
dst_len = strlen(dst); dst_len = strlen(dst);
for (j = 0; j < last - first; j++) { for (j = 0; j < last - first; j++) {
const struct cache_entry *ce = active_cache[first + j]; const struct cache_entry *ce = the_index.cache[first + j];
const char *path = ce->name; const char *path = ce->name;
source[argc + j] = path; source[argc + j] = path;
destination[argc + j] = destination[argc + j] =
@ -343,7 +343,7 @@ dir_check:
argc += last - first; argc += last - first;
goto act_on_entry; goto act_on_entry;
} }
if (!(ce = cache_file_exists(src, length, 0))) { if (!(ce = index_file_exists(&the_index, src, length, 0))) {
bad = _("not under version control"); bad = _("not under version control");
goto act_on_entry; goto act_on_entry;
} }
@ -468,11 +468,14 @@ remove_entry:
if (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR)) if (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR))
continue; continue;
pos = cache_name_pos(src, strlen(src)); pos = index_name_pos(&the_index, src, strlen(src));
assert(pos >= 0); assert(pos >= 0);
if (!(mode & SPARSE) && !lstat(src, &st)) if (!(mode & SPARSE) && !lstat(src, &st))
sparse_and_dirty = ce_modified(active_cache[pos], &st, 0); sparse_and_dirty = ie_modified(&the_index,
rename_cache_entry_at(pos, dst); the_index.cache[pos],
&st,
0);
rename_index_entry_at(&the_index, pos, dst);
if (ignore_sparse && if (ignore_sparse &&
core_apply_sparse_checkout && core_apply_sparse_checkout &&
@ -487,7 +490,7 @@ remove_entry:
path_in_sparse_checkout(dst, &the_index)) { path_in_sparse_checkout(dst, &the_index)) {
/* from out-of-cone to in-cone */ /* from out-of-cone to in-cone */
int dst_pos = cache_name_pos(dst, strlen(dst)); int dst_pos = cache_name_pos(dst, strlen(dst));
struct cache_entry *dst_ce = active_cache[dst_pos]; struct cache_entry *dst_ce = the_index.cache[dst_pos];
dst_ce->ce_flags &= ~CE_SKIP_WORKTREE; dst_ce->ce_flags &= ~CE_SKIP_WORKTREE;
@ -498,7 +501,7 @@ remove_entry:
!path_in_sparse_checkout(dst, &the_index)) { !path_in_sparse_checkout(dst, &the_index)) {
/* from in-cone to out-of-cone */ /* from in-cone to out-of-cone */
int dst_pos = cache_name_pos(dst, strlen(dst)); int dst_pos = cache_name_pos(dst, strlen(dst));
struct cache_entry *dst_ce = active_cache[dst_pos]; struct cache_entry *dst_ce = the_index.cache[dst_pos];
/* /*
* if src is clean, it will suffice to remove it * if src is clean, it will suffice to remove it

View File

@ -5,7 +5,7 @@
* *
* Fetch one or more remote refs and merge it/them into the current HEAD. * Fetch one or more remote refs and merge it/them into the current HEAD.
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "builtin.h" #include "builtin.h"
@ -1030,7 +1030,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
if (opt_rebase < 0) if (opt_rebase < 0)
opt_rebase = config_get_rebase(&rebase_unspecified); opt_rebase = config_get_rebase(&rebase_unspecified);
if (read_cache_unmerged()) if (repo_read_index_unmerged(the_repository))
die_resolve_conflict("pull"); die_resolve_conflict("pull");
if (file_exists(git_path_merge_head(the_repository))) if (file_exists(git_path_merge_head(the_repository)))
@ -1043,7 +1043,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
if (opt_autostash == -1) if (opt_autostash == -1)
opt_autostash = config_autostash; opt_autostash = config_autostash;
if (is_null_oid(&orig_head) && !is_cache_unborn()) if (is_null_oid(&orig_head) && !is_index_unborn(&the_index))
die(_("Updating an unborn branch with changes added to the index.")); die(_("Updating an unborn branch with changes added to the index."));
if (!opt_autostash) if (!opt_autostash)

View File

@ -4,7 +4,7 @@
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"
@ -176,7 +176,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
prepare_repo_settings(the_repository); prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0; the_repository->settings.command_requires_full_index = 0;
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
/* /*
* NEEDSWORK * NEEDSWORK
@ -188,11 +188,11 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
*/ */
if (opts.reset || opts.merge || opts.prefix) { if (opts.reset || opts.merge || opts.prefix) {
if (read_cache_unmerged() && (opts.prefix || opts.merge)) if (repo_read_index_unmerged(the_repository) && (opts.prefix || opts.merge))
die(_("You need to resolve your current index first")); die(_("You need to resolve your current index first"));
stage = opts.merge = 1; stage = opts.merge = 1;
} }
resolve_undo_clear(); resolve_undo_clear_index(&the_index);
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
const char *arg = argv[i]; const char *arg = argv[i];
@ -232,7 +232,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
break; break;
case 2: case 2:
opts.fn = twoway_merge; opts.fn = twoway_merge;
opts.initial_checkout = is_cache_unborn(); opts.initial_checkout = is_index_unborn(&the_index);
break; break;
case 3: case 3:
default: default:
@ -253,7 +253,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
if (nr_trees == 1 && !opts.prefix) if (nr_trees == 1 && !opts.prefix)
opts.skip_cache_tree_update = 1; opts.skip_cache_tree_update = 1;
cache_tree_free(&active_cache_tree); cache_tree_free(&the_index.cache_tree);
for (i = 0; i < nr_trees; i++) { for (i = 0; i < nr_trees; i++) {
struct tree *tree = trees[i]; struct tree *tree = trees[i];
parse_tree(tree); parse_tree(tree);

View File

@ -4,7 +4,7 @@
* Copyright (c) 2018 Pratik Karki * Copyright (c) 2018 Pratik Karki
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "run-command.h" #include "run-command.h"
#include "exec-cmd.h" #include "exec-cmd.h"
@ -292,7 +292,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
if (ret) if (ret)
error(_("could not generate todo list")); error(_("could not generate todo list"));
else { else {
discard_cache(); discard_index(&the_index);
if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf, if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf,
&todo_list)) &todo_list))
BUG("unusable todo list"); BUG("unusable todo list");
@ -1270,7 +1270,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
if (get_oid("HEAD", &head)) if (get_oid("HEAD", &head))
die(_("Cannot read HEAD")); die(_("Cannot read HEAD"));
fd = hold_locked_index(&lock_file, 0); fd = repo_hold_locked_index(the_repository, &lock_file, 0);
if (repo_read_index(the_repository) < 0) if (repo_read_index(the_repository) < 0)
die(_("could not read index")); die(_("could not read index"));
refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,

View File

@ -7,7 +7,7 @@
* *
* Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"
@ -84,7 +84,7 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t
BUG("invalid reset_type passed to reset_index"); BUG("invalid reset_type passed to reset_index");
} }
read_cache_unmerged(); repo_read_index_unmerged(the_repository);
if (reset_type == KEEP) { if (reset_type == KEEP) {
struct object_id head_oid; struct object_id head_oid;
@ -145,7 +145,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
struct cache_entry *ce; struct cache_entry *ce;
if (!is_in_reset_tree && !intent_to_add) { if (!is_in_reset_tree && !intent_to_add) {
remove_file_from_cache(one->path); remove_file_from_index(&the_index, one->path);
continue; continue;
} }
@ -160,8 +160,8 @@ static void update_index_from_diff(struct diff_queue_struct *q,
* if this entry is outside the sparse cone - this is necessary * if this entry is outside the sparse cone - this is necessary
* to properly construct the reset sparse directory. * to properly construct the reset sparse directory.
*/ */
pos = cache_name_pos(one->path, strlen(one->path)); pos = index_name_pos(&the_index, one->path, strlen(one->path));
if ((pos >= 0 && ce_skip_worktree(active_cache[pos])) || if ((pos >= 0 && ce_skip_worktree(the_index.cache[pos])) ||
(pos < 0 && !path_in_sparse_checkout(one->path, &the_index))) (pos < 0 && !path_in_sparse_checkout(one->path, &the_index)))
ce->ce_flags |= CE_SKIP_WORKTREE; ce->ce_flags |= CE_SKIP_WORKTREE;
@ -172,7 +172,8 @@ static void update_index_from_diff(struct diff_queue_struct *q,
ce->ce_flags |= CE_INTENT_TO_ADD; ce->ce_flags |= CE_INTENT_TO_ADD;
set_object_name_for_intent_to_add_entry(ce); set_object_name_for_intent_to_add_entry(ce);
} }
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); add_index_entry(&the_index, ce,
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
} }
} }
@ -220,7 +221,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,
static void die_if_unmerged_cache(int reset_type) static void die_if_unmerged_cache(int reset_type)
{ {
if (is_merge() || unmerged_cache()) if (is_merge() || unmerged_index(&the_index))
die(_("Cannot do a %s reset in the middle of a merge."), die(_("Cannot do a %s reset in the middle of a merge."),
_(reset_type_names[reset_type])); _(reset_type_names[reset_type]));
@ -422,7 +423,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
prepare_repo_settings(the_repository); prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0; the_repository->settings.command_requires_full_index = 0;
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
/* Soft reset does not touch the index file nor the working tree /* Soft reset does not touch the index file nor the working tree
@ -433,7 +434,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
if (reset_type != SOFT) { if (reset_type != SOFT) {
struct lock_file lock = LOCK_INIT; struct lock_file lock = LOCK_INIT;
hold_locked_index(&lock, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock,
LOCK_DIE_ON_ERROR);
if (reset_type == MIXED) { if (reset_type == MIXED) {
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN; int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
if (read_from_tree(&pathspec, &oid, intent_to_add)) if (read_from_tree(&pathspec, &oid, intent_to_add))

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) Linus Torvalds, 2005 * Copyright (C) Linus Torvalds, 2005
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
#include "commit.h" #include "commit.h"
@ -1007,7 +1007,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue; continue;
} }
if (!strcmp(arg, "--shared-index-path")) { if (!strcmp(arg, "--shared-index-path")) {
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die(_("Could not read the index")); die(_("Could not read the index"));
if (the_index.split_index) { if (the_index.split_index) {
const struct object_id *oid = &the_index.split_index->base_oid; const struct object_id *oid = &the_index.split_index->base_oid;

View File

@ -35,8 +35,8 @@ static int get_ours_cache_pos(const char *path, int pos)
{ {
int i = -pos - 1; int i = -pos - 1;
while ((i < active_nr) && !strcmp(active_cache[i]->name, path)) { while ((i < the_index.cache_nr) && !strcmp(the_index.cache[i]->name, path)) {
if (ce_stage(active_cache[i]) == 2) if (ce_stage(the_index.cache[i]) == 2)
return i; return i;
i++; i++;
} }
@ -72,13 +72,13 @@ static void submodules_absorb_gitdir_if_needed(void)
int pos; int pos;
const struct cache_entry *ce; const struct cache_entry *ce;
pos = cache_name_pos(name, strlen(name)); pos = index_name_pos(&the_index, name, strlen(name));
if (pos < 0) { if (pos < 0) {
pos = get_ours_cache_pos(name, pos); pos = get_ours_cache_pos(name, pos);
if (pos < 0) if (pos < 0)
continue; continue;
} }
ce = active_cache[pos]; ce = the_index.cache[pos];
if (!S_ISGITLINK(ce->ce_mode) || if (!S_ISGITLINK(ce->ce_mode) ||
!file_exists(ce->name) || !file_exists(ce->name) ||
@ -116,7 +116,7 @@ static int check_local_mod(struct object_id *head, int index_only)
int local_changes = 0; int local_changes = 0;
int staged_changes = 0; int staged_changes = 0;
pos = cache_name_pos(name, strlen(name)); pos = index_name_pos(&the_index, name, strlen(name));
if (pos < 0) { if (pos < 0) {
/* /*
* Skip unmerged entries except for populated submodules * Skip unmerged entries except for populated submodules
@ -126,11 +126,11 @@ static int check_local_mod(struct object_id *head, int index_only)
if (pos < 0) if (pos < 0)
continue; continue;
if (!S_ISGITLINK(active_cache[pos]->ce_mode) || if (!S_ISGITLINK(the_index.cache[pos]->ce_mode) ||
is_empty_dir(name)) is_empty_dir(name))
continue; continue;
} }
ce = active_cache[pos]; ce = the_index.cache[pos];
if (lstat(ce->name, &st) < 0) { if (lstat(ce->name, &st) < 0) {
if (!is_missing_file_error(errno)) if (!is_missing_file_error(errno))
@ -167,7 +167,7 @@ static int check_local_mod(struct object_id *head, int index_only)
* Is the index different from the file in the work tree? * Is the index different from the file in the work tree?
* If it's a submodule, is its work tree modified? * If it's a submodule, is its work tree modified?
*/ */
if (ce_match_stat(ce, &st, 0) || if (ie_match_stat(&the_index, ce, &st, 0) ||
(S_ISGITLINK(ce->ce_mode) && (S_ISGITLINK(ce->ce_mode) &&
bad_to_remove_submodule(ce->name, bad_to_remove_submodule(ce->name,
SUBMODULE_REMOVAL_DIE_ON_ERROR | SUBMODULE_REMOVAL_DIE_ON_ERROR |
@ -290,9 +290,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
prepare_repo_settings(the_repository); prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0; the_repository->settings.command_requires_full_index = 0;
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);
@ -302,8 +302,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
if (pathspec_needs_expanded_index(&the_index, &pathspec)) if (pathspec_needs_expanded_index(&the_index, &pathspec))
ensure_full_index(&the_index); ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++) { for (i = 0; i < the_index.cache_nr; i++) {
const struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = the_index.cache[i];
if (!include_sparse && if (!include_sparse &&
(ce_skip_worktree(ce) || (ce_skip_worktree(ce) ||
@ -385,7 +385,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
if (!quiet) if (!quiet)
printf("rm '%s'\n", path); printf("rm '%s'\n", path);
if (remove_file_from_cache(path)) if (remove_file_from_index(&the_index, path))
die(_("git rm: unable to remove %s"), path); die(_("git rm: unable to remove %s"), path);
} }

View File

@ -261,11 +261,11 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
struct tree *tree; struct tree *tree;
struct lock_file lock_file = LOCK_INIT; struct lock_file lock_file = LOCK_INIT;
read_cache_preload(NULL); repo_read_index_preload(the_repository, NULL, 0);
if (refresh_cache(REFRESH_QUIET)) if (refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL))
return -1; return -1;
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
@ -454,10 +454,10 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)
* path, but left it out of the working tree, then clear the * path, but left it out of the working tree, then clear the
* SKIP_WORKTREE bit and write it to the working tree. * SKIP_WORKTREE bit and write it to the working tree.
*/ */
if (pos >= 0 && ce_skip_worktree(active_cache[pos])) { if (pos >= 0 && ce_skip_worktree(the_index.cache[pos])) {
struct stat st; struct stat st;
ce = active_cache[pos]; ce = the_index.cache[pos];
if (!lstat(ce->name, &st)) { if (!lstat(ce->name, &st)) {
/* Conflicting path present; relocate it */ /* Conflicting path present; relocate it */
struct strbuf new_path = STRBUF_INIT; struct strbuf new_path = STRBUF_INIT;
@ -523,8 +523,9 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
struct tree *head, *merge, *merge_base; struct tree *head, *merge, *merge_base;
struct lock_file lock = LOCK_INIT; struct lock_file lock = LOCK_INIT;
read_cache_preload(NULL); repo_read_index_preload(the_repository, NULL, 0);
if (refresh_and_write_cache(REFRESH_QUIET, 0, 0)) if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
NULL, NULL, NULL))
return -1; return -1;
if (write_cache_as_tree(&c_tree, 0, NULL)) if (write_cache_as_tree(&c_tree, 0, NULL))
@ -549,14 +550,14 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
return error(_("conflicts in index. " return error(_("conflicts in index. "
"Try without --index.")); "Try without --index."));
discard_cache(); discard_index(&the_index);
read_cache(); repo_read_index(the_repository);
if (write_cache_as_tree(&index_tree, 0, NULL)) if (write_cache_as_tree(&index_tree, 0, NULL))
return error(_("could not save index tree")); return error(_("could not save index tree"));
reset_head(); reset_head();
discard_cache(); discard_index(&the_index);
read_cache(); repo_read_index(the_repository);
} }
} }
@ -1082,7 +1083,7 @@ static int check_changes_tracked_files(const struct pathspec *ps)
if (get_oid("HEAD", &dummy)) if (get_oid("HEAD", &dummy))
return -1; return -1;
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
return -1; return -1;
init_revisions(&rev, NULL); init_revisions(&rev, NULL);
@ -1286,7 +1287,7 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps
rev.diffopt.format_callback = add_diff_to_buf; rev.diffopt.format_callback = add_diff_to_buf;
rev.diffopt.format_callback_data = &diff_output; rev.diffopt.format_callback_data = &diff_output;
if (read_cache_preload(&rev.diffopt.pathspec) < 0) { if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
ret = -1; ret = -1;
goto done; goto done;
} }
@ -1344,8 +1345,9 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
prepare_fallback_ident("git stash", "git@stash"); prepare_fallback_ident("git stash", "git@stash");
read_cache_preload(NULL); repo_read_index_preload(the_repository, NULL, 0);
if (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0) { if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
NULL, NULL, NULL) < 0) {
ret = -1; ret = -1;
goto done; goto done;
} }
@ -1513,15 +1515,15 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
goto done; goto done;
} }
read_cache_preload(NULL); repo_read_index_preload(the_repository, NULL, 0);
if (!include_untracked && ps->nr) { if (!include_untracked && ps->nr) {
int i; int i;
char *ps_matched = xcalloc(ps->nr, 1); char *ps_matched = xcalloc(ps->nr, 1);
/* TODO: audit for interaction with sparse-index. */ /* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index); ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++) for (i = 0; i < the_index.cache_nr; i++)
ce_path_match(&the_index, active_cache[i], ps, ce_path_match(&the_index, the_index.cache[i], ps,
ps_matched); ps_matched);
if (report_path_error(ps_matched, ps)) { if (report_path_error(ps_matched, ps)) {
@ -1533,7 +1535,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
free(ps_matched); free(ps_matched);
} }
if (refresh_and_write_cache(REFRESH_QUIET, 0, 0)) { if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
NULL, NULL, NULL)) {
ret = -1; ret = -1;
goto done; goto done;
} }
@ -1590,7 +1593,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
goto done; goto done;
} }
} }
discard_cache(); discard_index(&the_index);
if (ps->nr) { if (ps->nr) {
struct child_process cp_add = CHILD_PROCESS_INIT; struct child_process cp_add = CHILD_PROCESS_INIT;
struct child_process cp_diff = CHILD_PROCESS_INIT; struct child_process cp_diff = CHILD_PROCESS_INIT;

View File

@ -1,4 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "builtin.h" #include "builtin.h"
#include "repository.h" #include "repository.h"
#include "cache.h" #include "cache.h"
@ -196,11 +196,11 @@ static int module_list_compute(const char **argv,
if (pathspec->nr) if (pathspec->nr)
ps_matched = xcalloc(pathspec->nr, 1); ps_matched = xcalloc(pathspec->nr, 1);
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
for (i = 0; i < active_nr; i++) { for (i = 0; i < the_index.cache_nr; i++) {
const struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = the_index.cache[i];
if (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce), if (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),
0, ps_matched, 1) || 0, ps_matched, 1) ||
@ -209,8 +209,8 @@ static int module_list_compute(const char **argv,
ALLOC_GROW(list->entries, list->nr + 1, list->alloc); ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
list->entries[list->nr++] = ce; list->entries[list->nr++] = ce;
while (i + 1 < active_nr && while (i + 1 < the_index.cache_nr &&
!strcmp(ce->name, active_cache[i + 1]->name)) !strcmp(ce->name, the_index.cache[i + 1]->name))
/* /*
* Skip entries with the same name in different stages * Skip entries with the same name in different stages
* to make sure an entry is returned only once. * to make sure an entry is returned only once.
@ -1110,13 +1110,13 @@ static int compute_summary_module_list(struct object_id *head_oid,
if (!info->cached) { if (!info->cached) {
if (diff_cmd == DIFF_INDEX) if (diff_cmd == DIFF_INDEX)
setup_work_tree(); setup_work_tree();
if (read_cache_preload(&rev.diffopt.pathspec) < 0) { if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
perror("read_cache_preload"); perror("repo_read_index_preload");
ret = -1; ret = -1;
goto cleanup; goto cleanup;
} }
} else if (read_cache() < 0) { } else if (repo_read_index(the_repository) < 0) {
perror("read_cache"); perror("repo_read_cache");
ret = -1; ret = -1;
goto cleanup; goto cleanup;
} }
@ -3187,7 +3187,7 @@ static void die_on_index_match(const char *path, int force)
const char *args[] = { path, NULL }; const char *args[] = { path, NULL };
parse_pathspec(&ps, 0, PATHSPEC_PREFER_CWD, NULL, args); parse_pathspec(&ps, 0, PATHSPEC_PREFER_CWD, NULL, args);
if (read_cache_preload(NULL) < 0) if (repo_read_index_preload(the_repository, NULL, 0) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
if (ps.nr) { if (ps.nr) {
@ -3202,15 +3202,15 @@ static void die_on_index_match(const char *path, int force)
* need to check ps_matched[0] to know if a cache * need to check ps_matched[0] to know if a cache
* entry matched. * entry matched.
*/ */
for (i = 0; i < active_nr; i++) { for (i = 0; i < the_index.cache_nr; i++) {
ce_path_match(&the_index, active_cache[i], &ps, ce_path_match(&the_index, the_index.cache[i], &ps,
ps_matched); ps_matched);
if (ps_matched[0]) { if (ps_matched[0]) {
if (!force) if (!force)
die(_("'%s' already exists in the index"), die(_("'%s' already exists in the index"),
path); path);
if (!S_ISGITLINK(active_cache[i]->ce_mode)) if (!S_ISGITLINK(the_index.cache[i]->ce_mode))
die(_("'%s' already exists in the index " die(_("'%s' already exists in the index "
"and is not a submodule"), path); "and is not a submodule"), path);
break; break;

View File

@ -237,16 +237,16 @@ done:
static int mark_ce_flags(const char *path, int flag, int mark) static int mark_ce_flags(const char *path, int flag, int mark)
{ {
int namelen = strlen(path); int namelen = strlen(path);
int pos = cache_name_pos(path, namelen); int pos = index_name_pos(&the_index, path, namelen);
if (0 <= pos) { if (0 <= pos) {
mark_fsmonitor_invalid(&the_index, active_cache[pos]); mark_fsmonitor_invalid(&the_index, the_index.cache[pos]);
if (mark) if (mark)
active_cache[pos]->ce_flags |= flag; the_index.cache[pos]->ce_flags |= flag;
else else
active_cache[pos]->ce_flags &= ~flag; the_index.cache[pos]->ce_flags &= ~flag;
active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE; the_index.cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
cache_tree_invalidate_path(&the_index, path); cache_tree_invalidate_path(&the_index, path);
active_cache_changed |= CE_ENTRY_CHANGED; the_index.cache_changed |= CE_ENTRY_CHANGED;
return 0; return 0;
} }
return -1; return -1;
@ -256,7 +256,7 @@ static int remove_one_path(const char *path)
{ {
if (!allow_remove) if (!allow_remove)
return error("%s: does not exist and --remove not passed", path); return error("%s: does not exist and --remove not passed", path);
if (remove_file_from_cache(path)) if (remove_file_from_index(&the_index, path))
return error("%s: cannot remove from the index", path); return error("%s: cannot remove from the index", path);
return 0; return 0;
} }
@ -281,7 +281,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
struct cache_entry *ce; struct cache_entry *ce;
/* Was the old index entry already up-to-date? */ /* Was the old index entry already up-to-date? */
if (old && !ce_stage(old) && !ce_match_stat(old, st, 0)) if (old && !ce_stage(old) && !ie_match_stat(&the_index, old, st, 0))
return 0; return 0;
ce = make_empty_cache_entry(&the_index, len); ce = make_empty_cache_entry(&the_index, len);
@ -298,7 +298,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
} }
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0; option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0; option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
if (add_cache_entry(ce, option)) { if (add_index_entry(&the_index, ce, option)) {
discard_cache_entry(ce); discard_cache_entry(ce);
return error("%s: cannot add to the index - missing --add option?", path); return error("%s: cannot add to the index - missing --add option?", path);
} }
@ -331,11 +331,11 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
static int process_directory(const char *path, int len, struct stat *st) static int process_directory(const char *path, int len, struct stat *st)
{ {
struct object_id oid; struct object_id oid;
int pos = cache_name_pos(path, len); int pos = index_name_pos(&the_index, path, len);
/* Exact match: file or existing gitlink */ /* Exact match: file or existing gitlink */
if (pos >= 0) { if (pos >= 0) {
const struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = the_index.cache[pos];
if (S_ISGITLINK(ce->ce_mode)) { if (S_ISGITLINK(ce->ce_mode)) {
/* Do nothing to the index if there is no HEAD! */ /* Do nothing to the index if there is no HEAD! */
@ -350,8 +350,8 @@ static int process_directory(const char *path, int len, struct stat *st)
/* Inexact match: is there perhaps a subdirectory match? */ /* Inexact match: is there perhaps a subdirectory match? */
pos = -pos-1; pos = -pos-1;
while (pos < active_nr) { while (pos < the_index.cache_nr) {
const struct cache_entry *ce = active_cache[pos++]; const struct cache_entry *ce = the_index.cache[pos++];
if (strncmp(ce->name, path, len)) if (strncmp(ce->name, path, len))
break; break;
@ -382,7 +382,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
return error("'%s' is beyond a symbolic link", path); return error("'%s' is beyond a symbolic link", path);
pos = cache_name_pos(path, len); pos = cache_name_pos(path, len);
ce = pos < 0 ? NULL : active_cache[pos]; ce = pos < 0 ? NULL : the_index.cache[pos];
if (ce && ce_skip_worktree(ce)) { if (ce && ce_skip_worktree(ce)) {
/* /*
* working directory version is assumed "good" * working directory version is assumed "good"
@ -390,7 +390,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
* On the other hand, removing it from index should work * On the other hand, removing it from index should work
*/ */
if (!ignore_skip_worktree_entries && allow_remove && if (!ignore_skip_worktree_entries && allow_remove &&
remove_file_from_cache(path)) remove_file_from_index(&the_index, path))
return error("%s: cannot remove from the index", path); return error("%s: cannot remove from the index", path);
return 0; return 0;
} }
@ -429,7 +429,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,
ce->ce_flags |= CE_VALID; ce->ce_flags |= CE_VALID;
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0; option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0; option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
if (add_cache_entry(ce, option)) if (add_index_entry(&the_index, ce, option))
return error("%s: cannot add to the index - missing --add option?", return error("%s: cannot add to the index - missing --add option?",
path); path);
report("add '%s'", path); report("add '%s'", path);
@ -441,11 +441,11 @@ static void chmod_path(char flip, const char *path)
int pos; int pos;
struct cache_entry *ce; struct cache_entry *ce;
pos = cache_name_pos(path, strlen(path)); pos = index_name_pos(&the_index, path, strlen(path));
if (pos < 0) if (pos < 0)
goto fail; goto fail;
ce = active_cache[pos]; ce = the_index.cache[pos];
if (chmod_cache_entry(ce, flip) < 0) if (chmod_index_entry(&the_index, ce, flip) < 0)
goto fail; goto fail;
report("chmod %cx '%s'", flip, path); report("chmod %cx '%s'", flip, path);
@ -488,7 +488,7 @@ static void update_one(const char *path)
} }
if (force_remove) { if (force_remove) {
if (remove_file_from_cache(path)) if (remove_file_from_index(&the_index, path))
die("git update-index: unable to remove %s", path); die("git update-index: unable to remove %s", path);
report("remove '%s'", path); report("remove '%s'", path);
return; return;
@ -571,7 +571,7 @@ static void read_index_info(int nul_term_line)
if (!mode) { if (!mode) {
/* mode == 0 means there is no such path -- remove */ /* mode == 0 means there is no such path -- remove */
if (remove_file_from_cache(path_name)) if (remove_file_from_index(&the_index, path_name))
die("git update-index: unable to remove %s", die("git update-index: unable to remove %s",
ptr); ptr);
} }
@ -638,12 +638,12 @@ static int unresolve_one(const char *path)
struct cache_entry *ce_2 = NULL, *ce_3 = NULL; struct cache_entry *ce_2 = NULL, *ce_3 = NULL;
/* See if there is such entry in the index. */ /* See if there is such entry in the index. */
pos = cache_name_pos(path, namelen); pos = index_name_pos(&the_index, path, namelen);
if (0 <= pos) { if (0 <= pos) {
/* already merged */ /* already merged */
pos = unmerge_cache_entry_at(pos); pos = unmerge_index_entry_at(&the_index, pos);
if (pos < active_nr) { if (pos < the_index.cache_nr) {
const struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = the_index.cache[pos];
if (ce_stage(ce) && if (ce_stage(ce) &&
ce_namelen(ce) == namelen && ce_namelen(ce) == namelen &&
!memcmp(ce->name, path, namelen)) !memcmp(ce->name, path, namelen))
@ -656,8 +656,8 @@ static int unresolve_one(const char *path)
* want to do anything in the former case. * want to do anything in the former case.
*/ */
pos = -pos-1; pos = -pos-1;
if (pos < active_nr) { if (pos < the_index.cache_nr) {
const struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = the_index.cache[pos];
if (ce_namelen(ce) == namelen && if (ce_namelen(ce) == namelen &&
!memcmp(ce->name, path, namelen)) { !memcmp(ce->name, path, namelen)) {
fprintf(stderr, fprintf(stderr,
@ -686,13 +686,13 @@ static int unresolve_one(const char *path)
goto free_return; goto free_return;
} }
remove_file_from_cache(path); remove_file_from_index(&the_index, path);
if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) { if (add_index_entry(&the_index, ce_2, ADD_CACHE_OK_TO_ADD)) {
error("%s: cannot add our version to the index.", path); error("%s: cannot add our version to the index.", path);
ret = -1; ret = -1;
goto free_return; goto free_return;
} }
if (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD)) if (!add_index_entry(&the_index, ce_3, ADD_CACHE_OK_TO_ADD))
return 0; return 0;
error("%s: cannot add their version to the index.", path); error("%s: cannot add their version to the index.", path);
ret = -1; ret = -1;
@ -752,8 +752,8 @@ static int do_reupdate(const char **paths,
*/ */
has_head = 0; has_head = 0;
redo: redo:
for (pos = 0; pos < active_nr; pos++) { for (pos = 0; pos < the_index.cache_nr; pos++) {
const struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = the_index.cache[pos];
struct cache_entry *old = NULL; struct cache_entry *old = NULL;
int save_nr; int save_nr;
char *path; char *path;
@ -782,12 +782,12 @@ static int do_reupdate(const char **paths,
* path anymore, in which case, under 'allow_remove', * path anymore, in which case, under 'allow_remove',
* or worse yet 'allow_replace', active_nr may decrease. * or worse yet 'allow_replace', active_nr may decrease.
*/ */
save_nr = active_nr; save_nr = the_index.cache_nr;
path = xstrdup(ce->name); path = xstrdup(ce->name);
update_one(path); update_one(path);
free(path); free(path);
discard_cache_entry(old); discard_cache_entry(old);
if (save_nr != active_nr) if (save_nr != the_index.cache_nr)
goto redo; goto redo;
} }
clear_pathspec(&pathspec); clear_pathspec(&pathspec);
@ -802,18 +802,19 @@ struct refresh_params {
static int refresh(struct refresh_params *o, unsigned int flag) static int refresh(struct refresh_params *o, unsigned int flag)
{ {
setup_work_tree(); setup_work_tree();
read_cache(); repo_read_index(the_repository);
*o->has_errors |= refresh_cache(o->flags | flag); *o->has_errors |= refresh_index(&the_index, o->flags | flag, NULL,
NULL, NULL);
if (has_racy_timestamp(&the_index)) { if (has_racy_timestamp(&the_index)) {
/* /*
* Even if nothing else has changed, updating the file * Even if nothing else has changed, updating the file
* increases the chance that racy timestamps become * increases the chance that racy timestamps become
* non-racy, helping future run-time performance. * non-racy, helping future run-time performance.
* We do that even in case of "errors" returned by * We do that even in case of "errors" returned by
* refresh_cache() as these are no actual errors. * refresh_index() as these are no actual errors.
* cmd_status() does the same. * cmd_status() does the same.
*/ */
active_cache_changed |= SOMETHING_CHANGED; the_index.cache_changed |= SOMETHING_CHANGED;
} }
return 0; return 0;
} }
@ -850,7 +851,7 @@ static int resolve_undo_clear_callback(const struct option *opt,
{ {
BUG_ON_OPT_NEG(unset); BUG_ON_OPT_NEG(unset);
BUG_ON_OPT_ARG(arg); BUG_ON_OPT_ARG(arg);
resolve_undo_clear(); resolve_undo_clear_index(&the_index);
return 0; return 0;
} }
@ -951,7 +952,7 @@ static enum parse_opt_result unresolve_callback(
*has_errors = do_unresolve(ctx->argc, ctx->argv, *has_errors = do_unresolve(ctx->argc, ctx->argv,
prefix, prefix ? strlen(prefix) : 0); prefix, prefix ? strlen(prefix) : 0);
if (*has_errors) if (*has_errors)
active_cache_changed = 0; the_index.cache_changed = 0;
ctx->argv += ctx->argc - 1; ctx->argv += ctx->argc - 1;
ctx->argc = 1; ctx->argc = 1;
@ -972,7 +973,7 @@ static enum parse_opt_result reupdate_callback(
setup_work_tree(); setup_work_tree();
*has_errors = do_reupdate(ctx->argv + 1, prefix); *has_errors = do_reupdate(ctx->argv + 1, prefix);
if (*has_errors) if (*has_errors)
active_cache_changed = 0; the_index.cache_changed = 0;
ctx->argv += ctx->argc - 1; ctx->argv += ctx->argc - 1;
ctx->argc = 1; ctx->argc = 1;
@ -1109,11 +1110,11 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
the_repository->settings.command_requires_full_index = 0; the_repository->settings.command_requires_full_index = 0;
/* we will diagnose later if it turns out that we need to update it */ /* we will diagnose later if it turns out that we need to update it */
newfd = hold_locked_index(&lock_file, 0); newfd = repo_hold_locked_index(the_repository, &lock_file, 0);
if (newfd < 0) if (newfd < 0)
lock_error = errno; lock_error = errno;
entries = read_cache(); entries = repo_read_index(the_repository);
if (entries < 0) if (entries < 0)
die("cache corrupted"); die("cache corrupted");
@ -1178,7 +1179,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
INDEX_FORMAT_LB, INDEX_FORMAT_UB); INDEX_FORMAT_LB, INDEX_FORMAT_UB);
if (the_index.version != preferred_index_format) if (the_index.version != preferred_index_format)
active_cache_changed |= SOMETHING_CHANGED; the_index.cache_changed |= SOMETHING_CHANGED;
the_index.version = preferred_index_format; the_index.version = preferred_index_format;
} }
@ -1290,7 +1291,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
report(_("fsmonitor disabled")); report(_("fsmonitor disabled"));
} }
if (active_cache_changed || force_write) { if (the_index.cache_changed || force_write) {
if (newfd < 0) { if (newfd < 0) {
if (refresh_args.flags & REFRESH_QUIET) if (refresh_args.flags & REFRESH_QUIET)
exit(128); exit(128);

36
cache.h
View File

@ -433,42 +433,18 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *);
void prefetch_cache_entries(const struct index_state *istate, void prefetch_cache_entries(const struct index_state *istate,
must_prefetch_predicate must_prefetch); must_prefetch_predicate must_prefetch);
#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS #if defined(USE_THE_INDEX_COMPATIBILITY_MACROS) || defined(USE_THE_INDEX_VARIABLE)
extern struct index_state the_index; extern struct index_state the_index;
#define active_cache (the_index.cache) #ifndef USE_THE_INDEX_VARIABLE
#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
#define active_nr (the_index.cache_nr) #define active_nr (the_index.cache_nr)
#define active_alloc (the_index.cache_alloc)
#define active_cache_changed (the_index.cache_changed)
#define active_cache_tree (the_index.cache_tree)
#define read_cache() repo_read_index(the_repository) #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) repo_read_index_preload(the_repository, (pathspec), 0)
#define is_cache_unborn() is_index_unborn(&the_index)
#define read_cache_unmerged() repo_read_index_unmerged(the_repository)
#define discard_cache() discard_index(&the_index) #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)) #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))
#define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option)) #endif
#define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name)) #endif
#define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos))
#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags))
#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags))
#define chmod_cache_entry(ce, flip) chmod_index_entry(&the_index, (ce), (flip))
#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
#define refresh_and_write_cache(refresh_flags, write_flags, gentle) repo_refresh_and_write_index(the_repository, (refresh_flags), (write_flags), (gentle), NULL, NULL, NULL)
#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
#define cache_dir_exists(name, namelen) index_dir_exists(&the_index, (name), (namelen))
#define cache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))
#define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))
#define resolve_undo_clear() resolve_undo_clear_index(&the_index)
#define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)
#define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)
#define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))
#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))
#endif #endif
#define TYPE_BITS 3 #define TYPE_BITS 3
@ -789,7 +765,7 @@ void ensure_full_index(struct index_state *istate);
*/ */
int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags); int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
int discard_index(struct index_state *); void discard_index(struct index_state *);
void move_index_extensions(struct index_state *dst, struct index_state *src); void move_index_extensions(struct index_state *dst, struct index_state *src);
int unmerged_index(const struct index_state *); int unmerged_index(const struct index_state *);

View File

@ -0,0 +1,135 @@
// the_index.* variables
@@
@@
(
- active_cache
+ the_index.cache
|
- active_cache_changed
+ the_index.cache_changed
|
- active_cache_tree
+ the_index.cache_tree
)
@@
identifier f != prepare_to_commit;
@@
f(...) {<...
- active_nr
+ the_index.cache_nr
...>}
// "the_repository" simple cases
@@
@@
(
- read_cache_unmerged
+ repo_read_index_unmerged
|
- hold_locked_index
+ repo_hold_locked_index
)
(
+ the_repository,
...)
// "the_repository" special-cases
@@
@@
(
- read_cache_preload
+ repo_read_index_preload
)
(
+ the_repository,
...
+ , 0
)
// "the_index" simple cases
@@
@@
(
- is_cache_unborn
+ is_index_unborn
|
- unmerged_cache
+ unmerged_index
|
- rename_cache_entry_at
+ rename_index_entry_at
|
- chmod_cache_entry
+ chmod_index_entry
|
- cache_file_exists
+ index_file_exists
|
- cache_name_is_other
+ index_name_is_other
|
- unmerge_cache_entry_at
+ unmerge_index_entry_at
|
- add_to_cache
+ add_to_index
|
- add_file_to_cache
+ add_file_to_index
|
- add_cache_entry
+ add_index_entry
|
- remove_file_from_cache
+ remove_file_from_index
|
- ce_match_stat
+ ie_match_stat
|
- ce_modified
+ ie_modified
|
- resolve_undo_clear
+ resolve_undo_clear_index
)
(
+ &the_index,
...)
@@
@@
(
- refresh_and_write_cache
+ repo_refresh_and_write_index
)
(
+ the_repository,
...
+ , NULL, NULL, NULL
)
// "the_index" special-cases
@@
@@
(
- read_cache_from
+ read_index_from
)
(
+ &the_index,
...
+ , get_git_dir()
)
@@
@@
(
- refresh_cache
+ refresh_index
)
(
+ &the_index,
...
+ , NULL, NULL, NULL
)

View File

@ -0,0 +1,24 @@
// "the_repository" simple cases
@@
@@
(
- read_cache
+ repo_read_index
)
(
+ the_repository,
...)
// "the_index" simple cases
@@
@@
(
- discard_cache
+ discard_index
|
- cache_name_pos
+ index_name_pos
)
(
+ &the_index,
...)

View File

@ -2531,7 +2531,7 @@ int is_index_unborn(struct index_state *istate)
return (!istate->cache_nr && !istate->timestamp.sec); return (!istate->cache_nr && !istate->timestamp.sec);
} }
int discard_index(struct index_state *istate) void discard_index(struct index_state *istate)
{ {
/* /*
* Cache entries in istate->cache[] should have been allocated * Cache entries in istate->cache[] should have been allocated
@ -2562,8 +2562,6 @@ int discard_index(struct index_state *istate)
mem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries()); mem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries());
FREE_AND_NULL(istate->ce_mem_pool); FREE_AND_NULL(istate->ce_mem_pool);
} }
return 0;
} }
/* /*

View File

@ -2,7 +2,7 @@
* not really _using_ the compat macros, just make sure the_index * not really _using_ the compat macros, just make sure the_index
* declaration matches the definition in this file. * declaration matches the definition in this file.
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "cache.h" #include "cache.h"
#include "repository.h" #include "repository.h"
#include "object-store.h" #include "object-store.h"

View File

@ -3567,7 +3567,8 @@ static int do_exec(struct repository *r, const char *command_line)
status = run_command(&cmd); status = run_command(&cmd);
/* force re-reading of the cache */ /* force re-reading of the cache */
if (discard_index(r->index) < 0 || repo_read_index(r) < 0) discard_index(r->index);
if (repo_read_index(r) < 0)
return error(_("could not read index")); return error(_("could not read index"));
dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1); dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1);
@ -4046,9 +4047,11 @@ static int do_merge(struct repository *r,
ret = run_command(&cmd); ret = run_command(&cmd);
/* force re-reading of the cache */ /* force re-reading of the cache */
if (!ret && (discard_index(r->index) < 0 || if (!ret) {
repo_read_index(r) < 0)) discard_index(r->index);
ret = error(_("could not read index")); if (repo_read_index(r) < 0)
ret = error(_("could not read index"));
}
goto leave_merge; goto leave_merge;
} }
@ -4421,8 +4424,8 @@ void create_autostash(struct repository *r, const char *path)
printf(_("Created autostash: %s\n"), buf.buf); printf(_("Created autostash: %s\n"), buf.buf);
if (reset_head(r, &ropts) < 0) if (reset_head(r, &ropts) < 0)
die(_("could not reset --hard")); die(_("could not reset --hard"));
if (discard_index(r->index) < 0 || discard_index(r->index);
repo_read_index(r) < 0) if (repo_read_index(r) < 0)
die(_("could not read index")); die(_("could not read index"));
} }
strbuf_release(&buf); strbuf_release(&buf);

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "tree.h" #include "tree.h"
@ -30,7 +31,7 @@ int cmd__cache_tree(int argc, const char **argv)
argc = parse_options(argc, argv, NULL, options, test_cache_tree_usage, 0); argc = parse_options(argc, argv, NULL, options, test_cache_tree_usage, 0);
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die(_("unable to read index file")); die(_("unable to read index file"));
oidcpy(&oid, &the_index.cache_tree->oid); oidcpy(&oid, &the_index.cache_tree->oid);

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "tree.h" #include "tree.h"
@ -62,12 +63,12 @@ int cmd__dump_cache_tree(int ac, const char **av)
int ret; int ret;
setup_git_directory(); setup_git_directory();
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die("unable to read index file"); die("unable to read index file");
istate = the_index; istate = the_index;
istate.cache_tree = another; istate.cache_tree = another;
cache_tree_update(&istate, WRITE_TREE_DRY_RUN); cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
ret = dump_cache_tree(active_cache_tree, another, ""); ret = dump_cache_tree(the_index.cache_tree, another, "");
cache_tree_free(&another); cache_tree_free(&another);
return ret; return ret;

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "split-index.h" #include "split-index.h"

View File

@ -1,4 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "dir.h" #include "dir.h"
@ -51,7 +51,7 @@ int cmd__dump_untracked_cache(int ac, const char **av)
xsetenv("GIT_CONFIG_VALUE_0", "keep", 1); xsetenv("GIT_CONFIG_VALUE_0", "keep", 1);
setup_git_directory(); setup_git_directory();
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die("unable to read index file"); die("unable to read index file");
uc = the_index.untracked; uc = the_index.untracked;
if (!uc) { if (!uc) {

View File

@ -10,7 +10,7 @@
* refactoring is the better route). * refactoring is the better route).
*/ */
#define USE_THE_INDEX_COMPATIBILITY_MACROS #define USE_THE_INDEX_VARIABLE
#include "test-tool.h" #include "test-tool.h"
#include "cache-tree.h" #include "cache-tree.h"
@ -123,7 +123,7 @@ int cmd__fast_rebase(int argc, const char **argv)
die(_("Cannot read HEAD")); die(_("Cannot read HEAD"));
assert(oideq(&onto->object.oid, &head)); assert(oideq(&onto->object.oid, &head));
hold_locked_index(&lock, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);
if (repo_read_index(the_repository) < 0) if (repo_read_index(the_repository) < 0)
BUG("Could not read index"); BUG("Could not read index");

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "parse-options.h" #include "parse-options.h"
@ -32,7 +33,7 @@ static void dump_run(void)
struct dir_entry *dir; struct dir_entry *dir;
struct cache_entry *ce; struct cache_entry *ce;
read_cache(); repo_read_index(the_repository);
if (single) { if (single) {
test_lazy_init_name_hash(&the_index, 0); test_lazy_init_name_hash(&the_index, 0);
} else { } else {
@ -49,7 +50,7 @@ static void dump_run(void)
ent /* member name */) ent /* member name */)
printf("name %08x %s\n", ce->ent.hash, ce->name); printf("name %08x %s\n", ce->ent.hash, ce->name);
discard_cache(); discard_index(&the_index);
} }
/* /*
@ -66,7 +67,7 @@ static uint64_t time_runs(int try_threaded)
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
t0 = getnanotime(); t0 = getnanotime();
read_cache(); repo_read_index(the_repository);
t1 = getnanotime(); t1 = getnanotime();
nr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded); nr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded);
t2 = getnanotime(); t2 = getnanotime();
@ -89,7 +90,7 @@ static uint64_t time_runs(int try_threaded)
the_index.cache_nr); the_index.cache_nr);
fflush(stdout); fflush(stdout);
discard_cache(); discard_index(&the_index);
} }
avg = sum / count; avg = sum / count;
@ -113,9 +114,9 @@ static void analyze_run(void)
int i; int i;
int nr; int nr;
read_cache(); repo_read_index(the_repository);
cache_nr_limit = the_index.cache_nr; cache_nr_limit = the_index.cache_nr;
discard_cache(); discard_index(&the_index);
nr = analyze; nr = analyze;
while (1) { while (1) {
@ -128,23 +129,23 @@ static void analyze_run(void)
nr = cache_nr_limit; nr = cache_nr_limit;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
read_cache(); repo_read_index(the_repository);
the_index.cache_nr = nr; /* cheap truncate of index */ the_index.cache_nr = nr; /* cheap truncate of index */
t1s = getnanotime(); t1s = getnanotime();
test_lazy_init_name_hash(&the_index, 0); test_lazy_init_name_hash(&the_index, 0);
t2s = getnanotime(); t2s = getnanotime();
sum_single += (t2s - t1s); sum_single += (t2s - t1s);
the_index.cache_nr = cache_nr_limit; the_index.cache_nr = cache_nr_limit;
discard_cache(); discard_index(&the_index);
read_cache(); repo_read_index(the_repository);
the_index.cache_nr = nr; /* cheap truncate of index */ the_index.cache_nr = nr; /* cheap truncate of index */
t1m = getnanotime(); t1m = getnanotime();
nr_threads_used = test_lazy_init_name_hash(&the_index, 1); nr_threads_used = test_lazy_init_name_hash(&the_index, 1);
t2m = getnanotime(); t2m = getnanotime();
sum_multi += (t2m - t1m); sum_multi += (t2m - t1m);
the_index.cache_nr = cache_nr_limit; the_index.cache_nr = cache_nr_limit;
discard_cache(); discard_index(&the_index);
if (!nr_threads_used) if (!nr_threads_used)
printf(" [size %8d] [single %f] non-threaded code path used\n", printf(" [size %8d] [single %f] non-threaded code path used\n",

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "config.h" #include "config.h"
@ -20,7 +21,7 @@ int cmd__read_cache(int argc, const char **argv)
git_config(git_default_config, NULL); git_config(git_default_config, NULL);
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
read_cache(); repo_read_index(the_repository);
if (name) { if (name) {
int pos; int pos;
@ -33,7 +34,7 @@ int cmd__read_cache(int argc, const char **argv)
ce_uptodate(the_index.cache[pos]) ? "" : " not"); ce_uptodate(the_index.cache[pos]) ? "" : " not");
write_file(name, "%d\n", i); write_file(name, "%d\n", i);
} }
discard_cache(); discard_index(&the_index);
} }
return 0; return 0;
} }

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "lockfile.h" #include "lockfile.h"
@ -9,11 +10,11 @@ int cmd__scrap_cache_tree(int ac, const char **av)
struct lock_file index_lock = LOCK_INIT; struct lock_file index_lock = LOCK_INIT;
setup_git_directory(); setup_git_directory();
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
if (read_cache() < 0) if (repo_read_index(the_repository) < 0)
die("unable to read index file"); die("unable to read index file");
cache_tree_free(&active_cache_tree); cache_tree_free(&the_index.cache_tree);
active_cache_tree = NULL; the_index.cache_tree = NULL;
if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
die("unable to write index file"); die("unable to write index file");
return 0; return 0;

View File

@ -1,7 +1,6 @@
#ifndef TEST_TOOL_H #ifndef TEST_TOOL_H
#define TEST_TOOL_H #define TEST_TOOL_H
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "git-compat-util.h" #include "git-compat-util.h"
int cmd__advise_if_enabled(int argc, const char **argv); int cmd__advise_if_enabled(int argc, const char **argv);

View File

@ -1,3 +1,4 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "lockfile.h" #include "lockfile.h"
@ -9,9 +10,10 @@ int cmd__write_cache(int argc, const char **argv)
if (argc == 2) if (argc == 2)
cnt = strtol(argv[1], NULL, 0); cnt = strtol(argv[1], NULL, 0);
setup_git_directory(); setup_git_directory();
read_cache(); repo_read_index(the_repository);
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); repo_hold_locked_index(the_repository, &index_lock,
LOCK_DIE_ON_ERROR);
if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
die("unable to write index file"); die("unable to write index file");
} }