cocci: apply "pending" index-compatibility to some "builtin/*.c"
Apply "index-compatibility.pending.cocci" rule to "builtin/*", but
exclude those where we conflict with in-flight changes.
As a result some of them end up using only "the_index", so let's have
them use the more narrow "USE_THE_INDEX_VARIABLE" rather than
"USE_THE_INDEX_COMPATIBILITY_MACROS".
Manual changes not made by coccinelle, that were squashed in:
* Whitespace-wrap argument lists for repo_hold_locked_index(),
repo_read_index_preload() and repo_refresh_and_write_index(), in cases
where the line became too long after the transformation.
* Change "refresh_cache()" to "refresh_index()" in a comment in
"builtin/update-index.c".
* For those whose call was followed by perror("<macro-name>"), change
it to perror("<function-name>"), referring to the new function.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committedNov 19, 2022 at 14:07 UTC07047d68294769d5e8700fc200ac326a21d04f8e
30 files changed+213-202
builtin/add.c
+4-4
index 23f9f0e08b..76277df326 100644--- a/builtin/add.c+++ b/builtin/add.c@@ -3,7 +3,7 @@ * * Copyright (C) 2006 Linus Torvalds */-#define USE_THE_INDEX_COMPATIBILITY_MACROS+#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "builtin.h"@@ -312,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 */- if (read_cache() < 0)+ if (repo_read_index(the_repository) < 0) die(_("Could not read the index")); repo_init_revisions(the_repository, &rev, prefix);@@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); 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@@ -587,7 +587,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) (!(addremove || take_worktree_changes) ? 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_in_unpopulated_submodule(&the_index, prefix);
builtin/am.c
+11-10
index f362a1c29f..30c9b3a9cd 100644--- a/builtin/am.c+++ b/builtin/am.c@@ -1519,8 +1519,8 @@ static int run_apply(const struct am_state *state, const char *index_file) if (index_file) { /* Reload index as apply_all_patches() will have modified it. */- discard_cache();- read_cache_from(index_file);+ discard_index(&the_index);+ read_index_from(&the_index, index_file, get_git_dir()); } 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)) return error("could not build fake ancestor");- discard_cache();- read_cache_from(index_path);+ discard_index(&the_index);+ read_index_from(&the_index, index_path, get_git_dir()); 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."));@@ -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..."));- discard_cache();- read_cache();+ discard_index(&the_index);+ repo_read_index(the_repository); /* * 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"));- 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")); if (repo_index_has_changes(the_repository, NULL, &sb)) {@@ -1967,9 +1968,9 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset) if (parse_tree(head) || parse_tree(remote)) 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)); opts.head_idx = 1;@@ -2007,7 +2008,7 @@ static int merge_tree(struct tree *tree) if (parse_tree(tree)) 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)); opts.head_idx = 1;
index 2191256965..ab776061c7 100644--- a/builtin/check-ignore.c+++ b/builtin/check-ignore.c@@ -1,4 +1,4 @@-#define USE_THE_INDEX_COMPATIBILITY_MACROS+#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.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")); /* 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")); setup_standard_excludes(&dir);
index 3fd303f560..3fa29a08ee 100644--- a/builtin/checkout.c+++ b/builtin/checkout.c@@ -1,4 +1,4 @@-#define USE_THE_INDEX_COMPATIBILITY_MACROS+#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "advice.h" #include "blob.h"@@ -148,7 +148,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base, * entry in place. Whether it is UPTODATE or not, checkout_entry will * 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) { struct cache_entry *old = the_index.cache[pos]; if (ce->ce_mode == old->ce_mode &&@@ -529,7 +529,7 @@ static int checkout_paths(const struct checkout_opts *opts, } 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")); if (opts->source_tree)@@ -741,8 +741,8 @@ static int merge_working_tree(const struct checkout_opts *opts, struct lock_file lock_file = LOCK_INIT; struct tree *new_tree;- hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);- if (read_cache_preload(NULL) < 0)+ repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);+ if (repo_read_index_preload(the_repository, NULL, 0) < 0) return error(_("index file corrupt")); resolve_undo_clear_index(&the_index);@@ -762,7 +762,7 @@ static int merge_working_tree(const struct checkout_opts *opts, struct unpack_trees_options topts; const struct object_id *old_commit_oid;- refresh_cache(REFRESH_QUIET);+ refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL); if (unmerged_index(&the_index)) { error(_("you need to resolve your current index first"));
builtin/clean.c
+2-2
index 7084e685f6..b2701a2815 100644--- a/builtin/clean.c+++ b/builtin/clean.c@@ -6,7 +6,7 @@ * Based on git-clean.sh by Pavel Roskin */-#define USE_THE_INDEX_COMPATIBILITY_MACROS+#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.h" #include "config.h"@@ -1012,7 +1012,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0;- if (read_cache() < 0)+ if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");
builtin/clone.c
+2-2
index 0e4348686b..f518bb2dc1 100644--- a/builtin/clone.c+++ b/builtin/clone.c@@ -8,7 +8,7 @@ * 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 "config.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 */ 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); opts.update = 1;
builtin/commit.c
+22-18
index abbed75027..06b1330346 100644--- a/builtin/commit.c+++ b/builtin/commit.c@@ -316,7 +316,7 @@ static void create_base_index(const struct commit *current_head) struct tree_desc t; if (!current_head) {- discard_cache();+ discard_index(&the_index); return; }@@ -343,7 +343,7 @@ static void refresh_cache_or_die(int refresh_flags) * refresh_flags contains REFRESH_QUIET, so the only errors * 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"); }@@ -382,12 +382,13 @@ static const char *prepare_index(const char **argv, const char *prefix, (!amend || (fixup_message && strcmp(fixup_prefix, "amend")))))) 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")); if (interactive) { 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);@@ -410,8 +411,9 @@ static const char *prepare_index(const char **argv, const char *prefix, unsetenv(INDEX_ENVIRONMENT); FREE_AND_NULL(old_index_env);- discard_cache();- read_cache_from(get_lock_file_path(&index_lock));+ discard_index(&the_index);+ read_index_from(&the_index, get_lock_file_path(&index_lock),+ get_git_dir()); if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) { if (reopen_lock_file(&index_lock) < 0) 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. */ 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); refresh_cache_or_die(refresh_flags); update_main_cache_tree(WRITE_TREE_SILENT);@@ -459,7 +462,8 @@ static const char *prepare_index(const char **argv, const char *prefix, * We still need to refresh the index here. */ 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); if (the_index.cache_changed || !cache_tree_fully_valid(the_index.cache_tree))@@ -505,13 +509,13 @@ static const char *prepare_index(const char **argv, const char *prefix, if (list_paths(&partial, !current_head ? NULL : "HEAD", &pathspec)) exit(1);- discard_cache();- if (read_cache() < 0)+ discard_index(&the_index);+ if (repo_read_index(the_repository) < 0) 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);- refresh_cache(REFRESH_QUIET);+ refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL); update_main_cache_tree(WRITE_TREE_SILENT); if (write_locked_index(&the_index, &index_lock, 0)) 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); 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)) die(_("unable to write temporary index file"));- discard_cache();+ discard_index(&the_index); ret = get_lock_file_path(&false_lock);- read_cache_from(ret);+ read_index_from(&the_index, ret, get_git_dir()); out: string_list_clear(&partial, 0); clear_pathspec(&pathspec);@@ -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 * 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)) { error(_("Error building trees"));@@ -1556,7 +1560,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) &s.pathspec, NULL, NULL); if (use_optional_locks())- fd = hold_locked_index(&index_lock, 0);+ fd = repo_hold_locked_index(the_repository, &index_lock, 0); else fd = -1;
index cd47675e37..d207bd909b 100644--- a/builtin/fsck.c+++ b/builtin/fsck.c@@ -1,4 +1,4 @@-#define USE_THE_INDEX_COMPATIBILITY_MACROS+#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.h" #include "repository.h"@@ -958,7 +958,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) if (keep_cache_objects) { verify_index_checksum = 1; verify_ce_order = 1;- read_cache();+ repo_read_index(the_repository); /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index); for (i = 0; i < the_index.cache_nr; i++) {
builtin/merge-index.c
+3-3
index a334c513c9..452f833ac4 100644--- a/builtin/merge-index.c+++ b/builtin/merge-index.c@@ -1,4 +1,4 @@-#define USE_THE_INDEX_COMPATIBILITY_MACROS+#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "run-command.h"@@ -47,7 +47,7 @@ static int merge_entry(int pos, 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@@ -82,7 +82,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) if (argc < 3) usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])");- read_cache();+ repo_read_index(the_repository); /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index);
builtin/merge-ours.c
+1-2
index 3583cff71c..284eb48609 100644--- a/builtin/merge-ours.c+++ b/builtin/merge-ours.c@@ -7,7 +7,6 @@ * * Pretend we resolved the heads, but declare our tree trumps everybody else. */-#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "git-compat-util.h" #include "builtin.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 * through. */- if (read_cache() < 0)+ if (repo_read_index(the_repository) < 0) die_errno("read_cache failed"); if (index_differs_from(the_repository, "HEAD", NULL, 0)) return 2;
builtin/merge.c
+12-7
index 27218ee93c..dd474371a2 100644--- a/builtin/merge.c+++ b/builtin/merge.c@@ -318,7 +318,7 @@ static int save_state(struct object_id *stash) int rc = -1; 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) repo_update_index_if_able(the_repository, &lock_file); rollback_lock_file(&lock_file);@@ -716,7 +716,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, { 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.")); if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree") ||@@ -750,7 +752,8 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, for (j = common; j; j = j->next) 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")) clean = merge_ort_recursive(&o, head, remoteheads->item, reversed, &result);@@ -859,9 +862,9 @@ static void prepare_to_commit(struct commit_list *remoteheads) * the editor and after we invoke run_status above. */ 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); if (squash) BUG("the control must not reach here under --squash");@@ -910,7 +913,9 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads) struct object_id result_tree, result_commit; 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.")); write_tree_trivial(&result_tree);@@ -1602,7 +1607,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) * We are not doing octopus, not fast-forward, and have * only one common. */- refresh_cache(REFRESH_QUIET);+ refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL); if (allow_trivial && fast_forward != FF_ONLY) { /* * Must first ensure that index matches HEAD before
builtin/mv.c
+8-8
index 883cf3ff12..19790ce38f 100644--- a/builtin/mv.c+++ b/builtin/mv.c@@ -106,7 +106,7 @@ static int index_range_of_same_dir(const char *src, int length, const char *src_w_slash = add_slash(src); 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) die(_("%.*s is in index"), len_w_slash, src_w_slash);@@ -136,7 +136,7 @@ static int empty_dir_has_sparse_contents(const char *name) const char *with_slash = add_slash(name); 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; if (pos < 0) {@@ -189,8 +189,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (--argc < 1) usage_with_options(builtin_mv_usage, builtin_mv_options);- hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);- if (read_cache() < 0)+ repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);+ if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); 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; const struct cache_entry *ce;- pos = cache_name_pos(src, length);+ pos = index_name_pos(&the_index, src, length); if (pos < 0) { const char *src_w_slash = add_slash(src); if (!path_in_sparse_checkout(src_w_slash, &the_index) &&@@ -278,7 +278,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) goto act_on_entry; } /* 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; goto act_on_entry; }@@ -303,7 +303,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) dir_check: if (S_ISDIR(st.st_mode)) { 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) { prepare_move_submodule(src, first,@@ -468,7 +468,7 @@ remove_entry: if (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR)) continue;- pos = cache_name_pos(src, strlen(src));+ pos = index_name_pos(&the_index, src, strlen(src)); assert(pos >= 0); if (!(mode & SPARSE) && !lstat(src, &st)) sparse_and_dirty = ie_modified(&the_index,
index 5d855fd8f5..1384008fe0 100644--- a/builtin/rebase.c+++ b/builtin/rebase.c@@ -4,7 +4,7 @@ * Copyright (c) 2018 Pratik Karki */-#define USE_THE_INDEX_COMPATIBILITY_MACROS+#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "run-command.h" #include "exec-cmd.h"@@ -292,7 +292,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) if (ret) error(_("could not generate todo list")); else {- discard_cache();+ discard_index(&the_index); if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf, &todo_list)) BUG("unusable todo list");@@ -1268,7 +1268,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (get_oid("HEAD", &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) die(_("could not read index")); refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,
builtin/reset.c
+5-4
index 75e061f5dc..1fa86edb4c 100644--- a/builtin/reset.c+++ b/builtin/reset.c@@ -7,7 +7,7 @@ * * 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 "config.h" #include "lockfile.h"@@ -160,7 +160,7 @@ static void update_index_from_diff(struct diff_queue_struct *q, * if this entry is outside the sparse cone - this is necessary * 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(the_index.cache[pos])) || (pos < 0 && !path_in_sparse_checkout(one->path, &the_index))) ce->ce_flags |= CE_SKIP_WORKTREE;@@ -423,7 +423,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0;- if (read_cache() < 0)+ if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); /* Soft reset does not touch the index file nor the working tree@@ -434,7 +434,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (reset_type != SOFT) { 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) { int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN; if (read_from_tree(&pathspec, &oid, intent_to_add))
builtin/rev-parse.c
+2-2
index 8f61050bde..d4c81352a6 100644--- a/builtin/rev-parse.c+++ b/builtin/rev-parse.c@@ -3,7 +3,7 @@ * * Copyright (C) Linus Torvalds, 2005 */-#define USE_THE_INDEX_COMPATIBILITY_MACROS+#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "commit.h"@@ -997,7 +997,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--shared-index-path")) {- if (read_cache() < 0)+ if (repo_read_index(the_repository) < 0) die(_("Could not read the index")); if (the_index.split_index) { const struct object_id *oid = &the_index.split_index->base_oid;
builtin/rm.c
+4-4
index 2b23eb2543..40b7990de1 100644--- a/builtin/rm.c+++ b/builtin/rm.c@@ -72,7 +72,7 @@ static void submodules_absorb_gitdir_if_needed(void) int pos; const struct cache_entry *ce;- pos = cache_name_pos(name, strlen(name));+ pos = index_name_pos(&the_index, name, strlen(name)); if (pos < 0) { pos = get_ours_cache_pos(name, pos); if (pos < 0)@@ -117,7 +117,7 @@ static int check_local_mod(struct object_id *head, int index_only) int local_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) { /* * Skip unmerged entries except for populated submodules@@ -291,9 +291,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); 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")); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);
builtin/stash.c
+19-16
index c251419af7..62e36718d3 100644--- a/builtin/stash.c+++ b/builtin/stash.c@@ -261,11 +261,11 @@ static int reset_tree(struct object_id *i_tree, int update, int reset) struct tree *tree; struct lock_file lock_file = LOCK_INIT;- read_cache_preload(NULL);- if (refresh_cache(REFRESH_QUIET))+ repo_read_index_preload(the_repository, NULL, 0);+ if (refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL)) 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));@@ -523,8 +523,9 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, struct tree *head, *merge, *merge_base; struct lock_file lock = LOCK_INIT;- read_cache_preload(NULL);- if (refresh_and_write_cache(REFRESH_QUIET, 0, 0))+ repo_read_index_preload(the_repository, NULL, 0);+ if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,+ NULL, NULL, NULL)) return -1; 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. " "Try without --index."));- discard_cache();- read_cache();+ discard_index(&the_index);+ repo_read_index(the_repository); if (write_cache_as_tree(&index_tree, 0, NULL)) return error(_("could not save index tree")); reset_head();- discard_cache();- read_cache();+ discard_index(&the_index);+ repo_read_index(the_repository); } }@@ -1082,7 +1083,7 @@ static int check_changes_tracked_files(const struct pathspec *ps) if (get_oid("HEAD", &dummy)) return -1;- if (read_cache() < 0)+ if (repo_read_index(the_repository) < 0) return -1; 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_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; 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");- read_cache_preload(NULL);- if (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0) {+ repo_read_index_preload(the_repository, NULL, 0);+ if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,+ NULL, NULL, NULL) < 0) { ret = -1; goto done; }@@ -1513,7 +1515,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q goto done; }- read_cache_preload(NULL);+ repo_read_index_preload(the_repository, NULL, 0); if (!include_untracked && ps->nr) { int i; char *ps_matched = xcalloc(ps->nr, 1);@@ -1533,7 +1535,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q 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; goto done; }@@ -1590,7 +1593,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q goto done; } }- discard_cache();+ discard_index(&the_index); if (ps->nr) { struct child_process cp_add = CHILD_PROCESS_INIT; struct child_process cp_diff = CHILD_PROCESS_INIT;
builtin/submodule--helper.c
+7-7
index 808865a5e3..ebe86e6817 100644--- a/builtin/submodule--helper.c+++ b/builtin/submodule--helper.c@@ -1,4 +1,4 @@-#define USE_THE_INDEX_COMPATIBILITY_MACROS+#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "repository.h" #include "cache.h"@@ -196,7 +196,7 @@ static int module_list_compute(const char **argv, if (pathspec->nr) ps_matched = xcalloc(pathspec->nr, 1);- if (read_cache() < 0)+ if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); for (i = 0; i < the_index.cache_nr; i++) {@@ -1109,13 +1109,13 @@ static int compute_summary_module_list(struct object_id *head_oid, if (!info->cached) { if (diff_cmd == DIFF_INDEX) setup_work_tree();- if (read_cache_preload(&rev.diffopt.pathspec) < 0) {- perror("read_cache_preload");+ if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {+ perror("repo_read_index_preload"); ret = -1; goto cleanup; }- } else if (read_cache() < 0) {- perror("read_cache");+ } else if (repo_read_index(the_repository) < 0) {+ perror("repo_read_cache"); ret = -1; goto cleanup; }@@ -3240,7 +3240,7 @@ static void die_on_index_match(const char *path, int force) const char *args[] = { path, NULL }; 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")); if (ps.nr) {
builtin/update-index.c
+10-9
index fec3da05ab..82d5902cc8 100644--- a/builtin/update-index.c+++ b/builtin/update-index.c@@ -237,7 +237,7 @@ done: static int mark_ce_flags(const char *path, int flag, int mark) { int namelen = strlen(path);- int pos = cache_name_pos(path, namelen);+ int pos = index_name_pos(&the_index, path, namelen); if (0 <= pos) { mark_fsmonitor_invalid(&the_index, the_index.cache[pos]); if (mark)@@ -331,7 +331,7 @@ 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) { 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 */ if (pos >= 0) {@@ -441,7 +441,7 @@ static void chmod_path(char flip, const char *path) int pos; struct cache_entry *ce;- pos = cache_name_pos(path, strlen(path));+ pos = index_name_pos(&the_index, path, strlen(path)); if (pos < 0) goto fail; ce = the_index.cache[pos];@@ -638,7 +638,7 @@ static int unresolve_one(const char *path) struct cache_entry *ce_2 = NULL, *ce_3 = NULL; /* 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) { /* already merged */ pos = unmerge_index_entry_at(&the_index, pos);@@ -802,15 +802,16 @@ struct refresh_params { static int refresh(struct refresh_params *o, unsigned int flag) { setup_work_tree();- read_cache();- *o->has_errors |= refresh_cache(o->flags | flag);+ repo_read_index(the_repository);+ *o->has_errors |= refresh_index(&the_index, o->flags | flag, NULL,+ NULL, NULL); if (has_racy_timestamp(&the_index)) { /* * Even if nothing else has changed, updating the file * increases the chance that racy timestamps become * non-racy, helping future run-time performance. * 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. */ the_index.cache_changed |= SOMETHING_CHANGED;@@ -1109,11 +1110,11 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) the_repository->settings.command_requires_full_index = 0; /* 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) lock_error = errno;- entries = read_cache();+ entries = repo_read_index(the_repository); if (entries < 0) die("cache corrupted");