{"thread":{"id":"58812","subject":"[PATCH 00/12] tree-wide: chip away at USE_THE_INDEX_COMPATIBILITY_MACROS","startedAt":"2022-11-18T11:31:14Z","lastAt":"2022-11-19T13:08:34Z","messageCount":32,"participants":["Ævar Arnfjörð Bjarmason","Phillip Wood","Taylor Blau"],"isPatch":true,"patchVersion":1,"patchTotal":12},"messages":[{"id":"467495","messageId":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":null,"subject":"[PATCH 00/12] tree-wide: chip away at USE_THE_INDEX_COMPATIBILITY_MACROS","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:30:54Z","receivedAt":"2022-11-18T11:31:14Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"As 3/12 here notes we've been undergoing a sloooow migration away from\nfunctions that provide \"the_index\" for you since 2007, with the last\nmajor move away from some of them being in 2019.\n\nThis series has a large diffstat, but should be disproportionately\neasy to review as I wrote almost none of the code: coccinelle did :)\n\nI.e. after some trivial cleanup in 1-2/12 the C code changes in 3/12\nare mostly generated from a new index-compatibility.cocci migration.\n\nThe commits that deviate from that are:\n\n * 04/12: Make a function that always returns \"0\" return \"void\"\n   instead.\n\n * 09-10/12: Add a \"USE_THE_INDEX_VARIABLE\", for those leftover users\n   that only need \"the_index\", but not the compatility macros.\n\n * 12/12: Manual follow-up to the cocci-applied 11/12.\n\nThe only exceptions to this are the changes to cache.h itself, and\nmoving things around in contrib/coccinelle/* as we can fully migrate\nsome things, so they move from a \"pending\" rule to a regular\ncoccinelle rule.\n\nAt the start of this the patch to migrate all of this would have been\n~2k lines, after it's down to below ~1k.\n\nI've carefully crafted this so that it doesn't have conflicts with\nanything that's in-flight, or is likely to develop such conflicts (but\nI could always get unlucky). If there are any the resolution should be\ntrivially validated by running the cocci rule on \"theirs\" and keeping\nthat version.\n\nBranch & passing CI at:\nhttps://github.com/avar/git/tree/avar/narrow-down-the-index-compatibilty-macros\n\nÆvar Arnfjörð Bjarmason (12):\n  cache.h: remove unused \"the_index\" compat macros\n  builtin/{grep,log}.: don't define \"USE_THE_INDEX_COMPATIBILITY_MACROS\"\n  cocci & cache.h: remove rarely used \"the_index\" compat macros\n  read-cache API & users: make discard_index() return void\n  cocci: add a index-compatibility.pending.cocci\n  cocci & cache.h: apply a selection of \"pending\" index-compatibility\n  cocci & cache.h: apply variable section of \"pending\"\n    index-compatibility\n  cocci: apply \"pending\" index-compatibility to \"t/helper/*.c\"\n  {builtin/*,repository}.c: add & use \"USE_THE_INDEX_VARIABLE\"\n  cache.h & test-tool.h: add & use \"USE_THE_INDEX_VARIABLE\"\n  cocci: apply \"pending\" index-compatibility to some \"builtin/*.c\"\n  builtin/*: remove or amend \"USE_THE_INDEX_COMPATIBILITY_MACROS\"\n\n add-interactive.c                             |  8 +-\n add-patch.c                                   |  3 +-\n builtin/add.c                                 | 21 ++---\n builtin/am.c                                  |  4 +-\n builtin/cat-file.c                            |  2 +-\n builtin/check-attr.c                          |  4 +-\n builtin/check-ignore.c                        |  4 +-\n builtin/checkout-index.c                      | 19 ++--\n builtin/checkout.c                            | 55 ++++++------\n builtin/clean.c                               |  6 +-\n builtin/clone.c                               |  4 +-\n builtin/commit.c                              | 20 ++---\n builtin/describe.c                            |  7 +-\n builtin/diff-files.c                          |  3 +-\n builtin/diff-index.c                          |  5 +-\n builtin/diff-tree.c                           |  4 +-\n builtin/difftool.c                            |  2 +-\n builtin/fsck.c                                | 16 ++--\n builtin/grep.c                                |  1 -\n builtin/log.c                                 |  1 -\n builtin/merge-index.c                         | 16 ++--\n builtin/merge-ours.c                          |  3 +-\n builtin/merge-tree.c                          |  2 +-\n builtin/merge.c                               | 13 +--\n builtin/mv.c                                  | 25 +++---\n builtin/pull.c                                |  6 +-\n builtin/read-tree.c                           |  6 +-\n builtin/rebase.c                              |  6 +-\n builtin/reset.c                               | 20 +++--\n builtin/rev-parse.c                           |  4 +-\n builtin/rm.c                                  | 18 ++--\n builtin/stash.c                               |  8 +-\n builtin/submodule--helper.c                   | 14 +--\n builtin/update-index.c                        | 72 +++++++--------\n cache.h                                       | 30 ++-----\n contrib/coccinelle/index-compatibility.cocci  | 87 +++++++++++++++++++\n .../index-compatibility.pending.cocci         | 78 +++++++++++++++++\n read-cache.c                                  |  4 +-\n repository.c                                  |  2 +-\n sequencer.c                                   | 15 ++--\n t/helper/test-dump-cache-tree.c               |  5 +-\n t/helper/test-dump-split-index.c              |  1 +\n t/helper/test-dump-untracked-cache.c          |  4 +-\n t/helper/test-fast-rebase.c                   |  4 +-\n t/helper/test-lazy-init-name-hash.c           | 21 ++---\n t/helper/test-read-cache.c                    |  5 +-\n t/helper/test-scrap-cache-tree.c              |  9 +-\n t/helper/test-write-cache.c                   |  6 +-\n 48 files changed, 417 insertions(+), 256 deletions(-)\n create mode 100644 contrib/coccinelle/index-compatibility.cocci\n create mode 100644 contrib/coccinelle/index-compatibility.pending.cocci\n\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467496","messageId":"patch-01.12-760b4ddf06a-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 01/12] cache.h: remove unused \"the_index\" compat macros","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:30:55Z","receivedAt":"2022-11-18T11:31:17Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The \"active_alloc\" macro added in 228e94f9357 (Move index-related\nvariables into a structure., 2007-04-01) has not been used since\n4aab5b46f44 (Make read-cache.c \"the_index\" free., 2007-04-01). Let's\nremove it.\n\nThe rest of these are likewise unused, so let's not keep them\naround. E.g. 12cd0bf9b02 (dir: stop using the index compatibility\nmacros, 2017-05-05) is the last use of \"cache_dir_exists\".\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n cache.h | 5 -----\n 1 file changed, 5 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 26ed03bd6de..29bb0ad2b41 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -438,7 +438,6 @@ extern struct index_state the_index;\n \n #define active_cache (the_index.cache)\n #define active_nr (the_index.cache_nr)\n-#define active_alloc (the_index.cache_alloc)\n #define active_cache_changed (the_index.cache_changed)\n #define active_cache_tree (the_index.cache_tree)\n \n@@ -452,7 +451,6 @@ extern struct index_state the_index;\n #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))\n #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))\n #define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))\n-#define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos))\n #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))\n #define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags))\n #define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags))\n@@ -461,13 +459,10 @@ extern struct index_state the_index;\n #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)\n #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))\n #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))\n-#define cache_dir_exists(name, namelen) index_dir_exists(&the_index, (name), (namelen))\n #define cache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))\n #define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))\n #define resolve_undo_clear() resolve_undo_clear_index(&the_index)\n #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)\n-#define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)\n-#define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))\n #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n \n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467497","messageId":"patch-02.12-9789509a902-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 02/12] builtin/{grep,log}.: don't define \"USE_THE_INDEX_COMPATIBILITY_MACROS\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:30:56Z","receivedAt":"2022-11-18T11:31:18Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Adding \"USE_THE_INDEX_COMPATIBILITY_MACROS\" to these two appears to\nhave been unnecessary from the start, as going back and compiling\nf8adbec9fea (cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch,\n2019-01-24) without that addition works.\n\nLet's not have these ask for the compatibility macros from cache.h\nthat they don't need.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/grep.c | 1 -\n builtin/log.c  | 1 -\n 2 files changed, 2 deletions(-)\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 5fa927d4e22..f7821c5fbba 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -3,7 +3,6 @@\n  *\n  * Copyright (c) 2006 Junio C Hamano\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"repository.h\"\n #include \"config.h\"\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 5eafcf26b49..89447a50838 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -4,7 +4,6 @@\n  * (C) Copyright 2006 Linus Torvalds\n  *\t\t 2006 Junio Hamano\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"refs.h\"\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467498","messageId":"patch-03.12-faa7757cb32-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 03/12] cocci & cache.h: remove rarely used \"the_index\" compat macros","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:30:57Z","receivedAt":"2022-11-18T11:31:26Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since 4aab5b46f44 (Make read-cache.c \"the_index\" free., 2007-04-01)\nwe've been undergoing a slow migration away from these macros, but\nhaven't made much progress since f8adbec9fea (cache.h: flip\nNO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24).\n\nLet's move forward a bit by changing the users of those macros that\nare rare enough that we can convert them in one go, and then remove\nthe compatibility shim.\n\nThe only manual change to the C code here is to \"cache.h\", the rest is\nall the result of applying the new \"index-compatibility.cocci\".\n\nEven though it's a one-off, let's keep the coccinelle rules for\nnow. We'll extend them in subsequent commits, and this will help\nanything that's in-flight or out-of-tree to migrate.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/add.c                                |  5 ++-\n builtin/am.c                                 |  4 +-\n builtin/checkout.c                           |  4 +-\n builtin/clean.c                              |  2 +-\n builtin/commit.c                             |  2 +-\n builtin/merge.c                              |  2 +-\n builtin/mv.c                                 |  4 +-\n builtin/pull.c                               |  4 +-\n builtin/read-tree.c                          |  4 +-\n builtin/reset.c                              |  4 +-\n builtin/update-index.c                       |  4 +-\n cache.h                                      | 10 -----\n contrib/coccinelle/index-compatibility.cocci | 45 ++++++++++++++++++++\n 13 files changed, 65 insertions(+), 29 deletions(-)\n create mode 100644 contrib/coccinelle/index-compatibility.cocci\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 626c71ec6aa..75be1d021ab 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -55,7 +55,7 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)\n \t\t\tcontinue;\n \n \t\tif (!show_only)\n-\t\t\terr = chmod_cache_entry(ce, flip);\n+\t\t\terr = chmod_index_entry(&the_index, ce, flip);\n \t\telse\n \t\t\terr = S_ISREG(ce->ce_mode) ? 0 : -1;\n \n@@ -172,7 +172,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)\n \t\t\tcontinue; /* do not touch non blobs */\n \t\tif (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))\n \t\t\tcontinue;\n-\t\tretval |= add_file_to_cache(ce->name, flags | ADD_CACHE_RENORMALIZE);\n+\t\tretval |= add_file_to_index(&the_index, ce->name,\n+\t\t\t\t\t    flags | ADD_CACHE_RENORMALIZE);\n \t}\n \n \treturn retval;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 20aea0d2487..f362a1c29fd 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1930,7 +1930,7 @@ static void am_resolve(struct am_state *state, int allow_empty)\n \t\t}\n \t}\n \n-\tif (unmerged_cache()) {\n+\tif (unmerged_index(&the_index)) {\n \t\tprintf_ln(_(\"You still have unmerged paths in your index.\\n\"\n \t\t\t\"You should 'git add' each file with resolved conflicts to mark them as such.\\n\"\n \t\t\t\"You might run `git rm` on a file to accept \\\"deleted by them\\\" for it.\"));\n@@ -2045,7 +2045,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem\n \tif (!remote_tree)\n \t\treturn error(_(\"Could not parse object '%s'.\"), oid_to_hex(remote));\n \n-\tread_cache_unmerged();\n+\trepo_read_index_unmerged(the_repository);\n \n \tif (fast_forward_to(head_tree, head_tree, 1))\n \t\treturn -1;\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 2a132392fbe..aa610b274e3 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -722,7 +722,7 @@ static void init_topts(struct unpack_trees_options *topts, int merge,\n \n \tsetup_unpack_trees_porcelain(topts, \"checkout\");\n \n-\ttopts->initial_checkout = is_cache_unborn();\n+\ttopts->initial_checkout = is_index_unborn(&the_index);\n \ttopts->update = 1;\n \ttopts->merge = 1;\n \ttopts->quiet = merge && old_commit;\n@@ -763,7 +763,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \n \t\trefresh_cache(REFRESH_QUIET);\n \n-\t\tif (unmerged_cache()) {\n+\t\tif (unmerged_index(&the_index)) {\n \t\t\terror(_(\"you need to resolve your current index first\"));\n \t\t\treturn 1;\n \t\t}\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex 40ff2c578de..7084e685f6f 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -1031,7 +1031,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \t\tstruct stat st;\n \t\tconst char *rel;\n \n-\t\tif (!cache_name_is_other(ent->name, ent->len))\n+\t\tif (!index_name_is_other(&the_index, ent->name, ent->len))\n \t\t\tcontinue;\n \n \t\tif (lstat(ent->name, &st))\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex e22bdf23f5f..985503d43a6 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -302,7 +302,7 @@ static void add_remove_files(struct string_list *list)\n \t\t\tcontinue;\n \n \t\tif (!lstat(p->string, &st)) {\n-\t\t\tif (add_to_cache(p->string, &st, 0))\n+\t\t\tif (add_to_index(&the_index, p->string, &st, 0))\n \t\t\t\tdie(_(\"updating files failed\"));\n \t\t} else\n \t\t\tremove_file_from_cache(p->string);\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex b3f75f55c8a..da11dfae19e 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1375,7 +1375,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\tgoto done;\n \t}\n \n-\tif (read_cache_unmerged())\n+\tif (repo_read_index_unmerged(the_repository))\n \t\tdie_resolve_conflict(\"merge\");\n \n \tif (file_exists(git_path_merge_head(the_repository))) {\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 3413ad1c9b1..df6157fd6b5 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -343,7 +343,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\targc += last - first;\n \t\t\tgoto act_on_entry;\n \t\t}\n-\t\tif (!(ce = cache_file_exists(src, length, 0))) {\n+\t\tif (!(ce = index_file_exists(&the_index, src, length, 0))) {\n \t\t\tbad = _(\"not under version control\");\n \t\t\tgoto act_on_entry;\n \t\t}\n@@ -472,7 +472,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tassert(pos >= 0);\n \t\tif (!(mode & SPARSE) && !lstat(src, &st))\n \t\t\tsparse_and_dirty = ce_modified(active_cache[pos], &st, 0);\n-\t\trename_cache_entry_at(pos, dst);\n+\t\trename_index_entry_at(&the_index, pos, dst);\n \n \t\tif (ignore_sparse &&\n \t\t    core_apply_sparse_checkout &&\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex b21edd767aa..4a2a6db2dce 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -1030,7 +1030,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \tif (opt_rebase < 0)\n \t\topt_rebase = config_get_rebase(&rebase_unspecified);\n \n-\tif (read_cache_unmerged())\n+\tif (repo_read_index_unmerged(the_repository))\n \t\tdie_resolve_conflict(\"pull\");\n \n \tif (file_exists(git_path_merge_head(the_repository)))\n@@ -1043,7 +1043,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \t\tif (opt_autostash == -1)\n \t\t\topt_autostash = config_autostash;\n \n-\t\tif (is_null_oid(&orig_head) && !is_cache_unborn())\n+\t\tif (is_null_oid(&orig_head) && !is_index_unborn(&the_index))\n \t\t\tdie(_(\"Updating an unborn branch with changes added to the index.\"));\n \n \t\tif (!opt_autostash)\ndiff --git a/builtin/read-tree.c b/builtin/read-tree.c\nindex f4cbe460b97..8a697a782fc 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -188,7 +188,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \t */\n \n \tif (opts.reset || opts.merge || opts.prefix) {\n-\t\tif (read_cache_unmerged() && (opts.prefix || opts.merge))\n+\t\tif (repo_read_index_unmerged(the_repository) && (opts.prefix || opts.merge))\n \t\t\tdie(_(\"You need to resolve your current index first\"));\n \t\tstage = opts.merge = 1;\n \t}\n@@ -232,7 +232,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \t\t\tbreak;\n \t\tcase 2:\n \t\t\topts.fn = twoway_merge;\n-\t\t\topts.initial_checkout = is_cache_unborn();\n+\t\t\topts.initial_checkout = is_index_unborn(&the_index);\n \t\t\tbreak;\n \t\tcase 3:\n \t\tdefault:\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex fdce6f8c856..ee874ee6d5b 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -82,7 +82,7 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t\n \t\tBUG(\"invalid reset_type passed to reset_index\");\n \t}\n \n-\tread_cache_unmerged();\n+\trepo_read_index_unmerged(the_repository);\n \n \tif (reset_type == KEEP) {\n \t\tstruct object_id head_oid;\n@@ -218,7 +218,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,\n \n static void die_if_unmerged_cache(int reset_type)\n {\n-\tif (is_merge() || unmerged_cache())\n+\tif (is_merge() || unmerged_index(&the_index))\n \t\tdie(_(\"Cannot do a %s reset in the middle of a merge.\"),\n \t\t    _(reset_type_names[reset_type]));\n \ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex 7b0c924d7d4..e1b2bb78e72 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -445,7 +445,7 @@ static void chmod_path(char flip, const char *path)\n \tif (pos < 0)\n \t\tgoto fail;\n \tce = active_cache[pos];\n-\tif (chmod_cache_entry(ce, flip) < 0)\n+\tif (chmod_index_entry(&the_index, ce, flip) < 0)\n \t\tgoto fail;\n \n \treport(\"chmod %cx '%s'\", flip, path);\n@@ -641,7 +641,7 @@ static int unresolve_one(const char *path)\n \tpos = cache_name_pos(path, namelen);\n \tif (0 <= pos) {\n \t\t/* already merged */\n-\t\tpos = unmerge_cache_entry_at(pos);\n+\t\tpos = unmerge_index_entry_at(&the_index, pos);\n \t\tif (pos < active_nr) {\n \t\t\tconst struct cache_entry *ce = active_cache[pos];\n \t\t\tif (ce_stage(ce) &&\ndiff --git a/cache.h b/cache.h\nindex 29bb0ad2b41..53dc4341717 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -444,25 +444,15 @@ extern struct index_state the_index;\n #define read_cache() repo_read_index(the_repository)\n #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))\n #define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)\n-#define is_cache_unborn() is_index_unborn(&the_index)\n-#define read_cache_unmerged() repo_read_index_unmerged(the_repository)\n #define discard_cache() discard_index(&the_index)\n-#define unmerged_cache() unmerged_index(&the_index)\n #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))\n #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))\n-#define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))\n #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))\n-#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags))\n-#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags))\n-#define chmod_cache_entry(ce, flip) chmod_index_entry(&the_index, (ce), (flip))\n #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)\n #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)\n #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))\n #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))\n-#define cache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))\n-#define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))\n #define resolve_undo_clear() resolve_undo_clear_index(&the_index)\n-#define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)\n #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n \ndiff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci\nnew file mode 100644\nindex 00000000000..04207c409e1\n--- /dev/null\n+++ b/contrib/coccinelle/index-compatibility.cocci\n@@ -0,0 +1,45 @@\n+// \"the_repository\" simple cases\n+@@\n+@@\n+(\n+- read_cache_unmerged\n++ repo_read_index_unmerged\n+)\n+  (\n++ the_repository,\n+  ...)\n+\n+// \"the_index\" simple cases\n+@@\n+@@\n+(\n+- is_cache_unborn\n++ is_index_unborn\n+|\n+- unmerged_cache\n++ unmerged_index\n+|\n+- rename_cache_entry_at\n++ rename_index_entry_at\n+|\n+- chmod_cache_entry\n++ chmod_index_entry\n+|\n+- cache_file_exists\n++ index_file_exists\n+|\n+- cache_name_is_other\n++ index_name_is_other\n+|\n+- unmerge_cache_entry_at\n++ unmerge_index_entry_at\n+|\n+- add_to_cache\n++ add_to_index\n+|\n+- add_file_to_cache\n++ add_file_to_index\n+)\n+  (\n++ &the_index,\n+  ...)\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467499","messageId":"patch-04.12-362a14a0539-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 04/12] read-cache API & users: make discard_index() return void","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:30:58Z","receivedAt":"2022-11-18T11:31:29Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The discard_index() function has not returned non-zero since\n7a51ed66f65 (Make on-disk index representation separate from in-core\none, 2008-01-14), but we've had various code in-tree still acting as\nthough that might be the case.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n add-interactive.c |  8 ++++----\n add-patch.c       |  3 ++-\n builtin/merge.c   |  3 ++-\n cache.h           |  2 +-\n read-cache.c      |  4 +---\n sequencer.c       | 15 +++++++++------\n 6 files changed, 19 insertions(+), 16 deletions(-)\n\ndiff --git a/add-interactive.c b/add-interactive.c\nindex ecc5ae1b249..ae1839c04a7 100644\n--- a/add-interactive.c\n+++ b/add-interactive.c\n@@ -530,8 +530,8 @@ static int get_modified_files(struct repository *r,\n \tstruct collection_status s = { 0 };\n \tint i;\n \n-\tif (discard_index(r->index) < 0 ||\n-\t    repo_read_index_preload(r, ps, 0) < 0)\n+\tdiscard_index(r->index);\n+\tif (repo_read_index_preload(r, ps, 0) < 0)\n \t\treturn error(_(\"could not read index\"));\n \n \tprefix_item_list_clear(files);\n@@ -1156,8 +1156,8 @@ int run_add_i(struct repository *r, const struct pathspec *ps)\n \t\t    _(\"staged\"), _(\"unstaged\"), _(\"path\"));\n \topts.list_opts.header = header.buf;\n \n-\tif (discard_index(r->index) < 0 ||\n-\t    repo_read_index(r) < 0 ||\n+\tdiscard_index(r->index);\n+\tif (repo_read_index(r) < 0 ||\n \t    repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,\n \t\t\t\t\t NULL, NULL, NULL) < 0)\n \t\twarning(_(\"could not refresh index\"));\ndiff --git a/add-patch.c b/add-patch.c\nindex 33ecd8398a1..a86a92e1646 100644\n--- a/add-patch.c\n+++ b/add-patch.c\n@@ -1750,7 +1750,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode,\n \t\ts.mode = &patch_mode_add;\n \ts.revision = revision;\n \n-\tif (discard_index(r->index) < 0 || repo_read_index(r) < 0 ||\n+\tdiscard_index(r->index);\n+\tif (repo_read_index(r) < 0 ||\n \t    (!s.mode->index_only &&\n \t     repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,\n \t\t\t\t\t  NULL, NULL, NULL) < 0) ||\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex da11dfae19e..89fdac24e40 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -390,7 +390,8 @@ static void restore_state(const struct object_id *head,\n \trun_command(&cmd);\n \n refresh_cache:\n-\tif (discard_cache() < 0 || read_cache() < 0)\n+\tdiscard_cache();\n+\tif (read_cache() < 0)\n \t\tdie(_(\"could not read index\"));\n }\n \ndiff --git a/cache.h b/cache.h\nindex 53dc4341717..489e9e1925b 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -774,7 +774,7 @@ void ensure_full_index(struct index_state *istate);\n  */\n int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);\n \n-int discard_index(struct index_state *);\n+void discard_index(struct index_state *);\n void move_index_extensions(struct index_state *dst, struct index_state *src);\n int unmerged_index(const struct index_state *);\n \ndiff --git a/read-cache.c b/read-cache.c\nindex 32024029274..46f5e497b14 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2531,7 +2531,7 @@ int is_index_unborn(struct index_state *istate)\n \treturn (!istate->cache_nr && !istate->timestamp.sec);\n }\n \n-int discard_index(struct index_state *istate)\n+void discard_index(struct index_state *istate)\n {\n \t/*\n \t * Cache entries in istate->cache[] should have been allocated\n@@ -2562,8 +2562,6 @@ int discard_index(struct index_state *istate)\n \t\tmem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries());\n \t\tFREE_AND_NULL(istate->ce_mem_pool);\n \t}\n-\n-\treturn 0;\n }\n \n /*\ndiff --git a/sequencer.c b/sequencer.c\nindex f0f1af4d478..58ad2a77565 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -3564,7 +3564,8 @@ static int do_exec(struct repository *r, const char *command_line)\n \tstatus = run_command(&cmd);\n \n \t/* force re-reading of the cache */\n-\tif (discard_index(r->index) < 0 || repo_read_index(r) < 0)\n+\tdiscard_index(r->index);\n+\tif (repo_read_index(r) < 0)\n \t\treturn error(_(\"could not read index\"));\n \n \tdirty = require_clean_work_tree(r, \"rebase\", NULL, 1, 1);\n@@ -4028,9 +4029,11 @@ static int do_merge(struct repository *r,\n \t\tret = run_command(&cmd);\n \n \t\t/* force re-reading of the cache */\n-\t\tif (!ret && (discard_index(r->index) < 0 ||\n-\t\t\t     repo_read_index(r) < 0))\n-\t\t\tret = error(_(\"could not read index\"));\n+\t\tif (!ret) {\n+\t\t\tdiscard_index(r->index);\n+\t\t\tif (repo_read_index(r) < 0)\n+\t\t\t\tret = error(_(\"could not read index\"));\n+\t\t}\n \t\tgoto leave_merge;\n \t}\n \n@@ -4400,8 +4403,8 @@ void create_autostash(struct repository *r, const char *path)\n \t\tprintf(_(\"Created autostash: %s\\n\"), buf.buf);\n \t\tif (reset_head(r, &ropts) < 0)\n \t\t\tdie(_(\"could not reset --hard\"));\n-\t\tif (discard_index(r->index) < 0 ||\n-\t\t\trepo_read_index(r) < 0)\n+\t\tdiscard_index(r->index);\n+\t\tif (repo_read_index(r) < 0)\n \t\t\tdie(_(\"could not read index\"));\n \t}\n \tstrbuf_release(&buf);\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467500","messageId":"patch-05.12-14bf6e7188c-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 05/12] cocci: add a index-compatibility.pending.cocci","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:30:59Z","receivedAt":"2022-11-18T11:31:32Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add a coccinelle rule which covers the rest of the macros guarded by\n\"USE_THE_INDEX_COMPATIBILITY_MACROS\" cache.h. If the result of this\nwere applied it can be reduced down to just:\n\n\t#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n\textern struct index_state the_index;\n\t#endif\n\nBut that patch is just under 2000 lines, so let's first add this as a\n\"pending\", and then incrementally pick changes from it in subsequent\ncommits. In doing that we'll migrate rules from this\n\"index-compatibility.pending.cocci\" to the \"index-compatibility.cocci\"\ncreated in a preceding commit.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .../index-compatibility.pending.cocci         | 110 ++++++++++++++++++\n 1 file changed, 110 insertions(+)\n create mode 100644 contrib/coccinelle/index-compatibility.pending.cocci\n\ndiff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci\nnew file mode 100644\nindex 00000000000..6e96de0f638\n--- /dev/null\n+++ b/contrib/coccinelle/index-compatibility.pending.cocci\n@@ -0,0 +1,110 @@\n+// the_index.* variables\n+@@\n+@@\n+(\n+- active_cache\n++ the_index.cache\n+|\n+- active_nr\n++ the_index.cache_nr\n+|\n+- active_cache_changed\n++ the_index.cache_changed\n+|\n+- active_cache_tree\n++ the_index.cache_tree\n+)\n+\n+// \"the_repository\" simple cases\n+@@\n+@@\n+(\n+- read_cache\n++ repo_read_index\n+|\n+- hold_locked_index\n++ repo_hold_locked_index\n+)\n+  (\n++ the_repository,\n+  ...)\n+\n+// \"the_index\" simple cases\n+@@\n+@@\n+(\n+- discard_cache\n++ discard_index\n+|\n+- cache_name_pos\n++ index_name_pos\n+|\n+- add_cache_entry\n++ add_index_entry\n+|\n+- remove_file_from_cache\n++ remove_file_from_index\n+|\n+- ce_match_stat\n++ ie_match_stat\n+|\n+- ce_modified\n++ ie_modified\n+|\n+- resolve_undo_clear\n++ resolve_undo_clear_index\n+)\n+  (\n++ &the_index,\n+  ...)\n+\n+// \"the_repository\" special-cases\n+@@\n+@@\n+(\n+- read_cache_preload\n++ repo_read_index_preload\n+)\n+  (\n++ the_repository,\n+  ...\n++ , 0\n+  )\n+\n+@@\n+@@\n+(\n+- refresh_and_write_cache\n++ repo_refresh_and_write_index\n+)\n+  (\n++ the_repository,\n+  ...\n++ , NULL, NULL, NULL\n+  )\n+\n+\n+// \"the_index\" special-cases\n+@@\n+@@\n+(\n+- read_cache_from\n++ read_index_from\n+)\n+  (\n++ &the_index,\n+  ...\n++ , get_git_dir()\n+  )\n+\n+@@\n+@@\n+(\n+- refresh_cache\n++ refresh_index\n+)\n+  (\n++ &the_index,\n+  ...\n++ , NULL, NULL, NULL\n+  )\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467501","messageId":"patch-06.12-dbf14ed23e6-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 06/12] cocci & cache.h: apply a selection of \"pending\" index-compatibility","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:31:00Z","receivedAt":"2022-11-18T11:31:34Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Apply a selection of rules in \"index-compatibility.pending.cocci\"\ntree-wide, and in doing so migrate them to\n\"index-compatibility.cocci\".\n\nAs in preceding commits the only manual changes here are the macro\nremovals in \"cache.h\", and the update to the '*.cocci\" rules. The rest\nof the C code changes are the result of applying those updated rules.\n\nMove rules for some rarely used cache compatibility macros from\n\"index-compatibility.pending.cocci\" to \"index-compatibility.cocci\" and\napply them.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/checkout.c                            |  5 +++--\n builtin/commit.c                              |  2 +-\n builtin/merge.c                               |  2 +-\n builtin/mv.c                                  |  4 +++-\n builtin/read-tree.c                           |  2 +-\n builtin/reset.c                               |  5 +++--\n builtin/rm.c                                  |  4 ++--\n builtin/update-index.c                        | 22 +++++++++----------\n cache.h                                       |  5 -----\n contrib/coccinelle/index-compatibility.cocci  | 15 +++++++++++++\n .../index-compatibility.pending.cocci         | 15 -------------\n 11 files changed, 40 insertions(+), 41 deletions(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex aa610b274e3..afbd71764a3 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -160,7 +160,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \t\t}\n \t}\n \n-\tadd_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n+\tadd_index_entry(&the_index, ce,\n+\t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \treturn 0;\n }\n \n@@ -744,7 +745,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \tif (read_cache_preload(NULL) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \tif (opts->new_orphan_branch && opts->orphan_from_empty_tree) {\n \t\tif (new_branch_info->commit)\n \t\t\tBUG(\"'switch --orphan' should never accept a commit as starting point\");\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 985503d43a6..10a827b1f4a 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -305,7 +305,7 @@ static void add_remove_files(struct string_list *list)\n \t\t\tif (add_to_index(&the_index, p->string, &st, 0))\n \t\t\t\tdie(_(\"updating files failed\"));\n \t\t} else\n-\t\t\tremove_file_from_cache(p->string);\n+\t\t\tremove_file_from_index(&the_index, p->string);\n \t}\n }\n \ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 89fdac24e40..2046992d75a 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1397,7 +1397,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\telse\n \t\t\tdie(_(\"You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\"));\n \t}\n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \n \tif (option_edit < 0)\n \t\toption_edit = default_edit_option();\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex df6157fd6b5..6f94c3b9238 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -471,7 +471,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tpos = cache_name_pos(src, strlen(src));\n \t\tassert(pos >= 0);\n \t\tif (!(mode & SPARSE) && !lstat(src, &st))\n-\t\t\tsparse_and_dirty = ce_modified(active_cache[pos], &st, 0);\n+\t\t\tsparse_and_dirty = ie_modified(&the_index,\n+\t\t\t\t\t\t       active_cache[pos], &st,\n+\t\t\t\t\t\t       0);\n \t\trename_index_entry_at(&the_index, pos, dst);\n \n \t\tif (ignore_sparse &&\ndiff --git a/builtin/read-tree.c b/builtin/read-tree.c\nindex 8a697a782fc..5a05cbe02c7 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -192,7 +192,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \t\t\tdie(_(\"You need to resolve your current index first\"));\n \t\tstage = opts.merge = 1;\n \t}\n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \n \tfor (i = 0; i < argc; i++) {\n \t\tconst char *arg = argv[i];\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex ee874ee6d5b..d38fb7d13fa 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -143,7 +143,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,\n \t\tstruct cache_entry *ce;\n \n \t\tif (!is_in_reset_tree && !intent_to_add) {\n-\t\t\tremove_file_from_cache(one->path);\n+\t\t\tremove_file_from_index(&the_index, one->path);\n \t\t\tcontinue;\n \t\t}\n \n@@ -170,7 +170,8 @@ static void update_index_from_diff(struct diff_queue_struct *q,\n \t\t\tce->ce_flags |= CE_INTENT_TO_ADD;\n \t\t\tset_object_name_for_intent_to_add_entry(ce);\n \t\t}\n-\t\tadd_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n+\t\tadd_index_entry(&the_index, ce,\n+\t\t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \t}\n }\n \ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex f0d025a4e23..c717cdc97f5 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -168,7 +168,7 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\t * Is the index different from the file in the work tree?\n \t\t * If it's a submodule, is its work tree modified?\n \t\t */\n-\t\tif (ce_match_stat(ce, &st, 0) ||\n+\t\tif (ie_match_stat(&the_index, ce, &st, 0) ||\n \t\t    (S_ISGITLINK(ce->ce_mode) &&\n \t\t     bad_to_remove_submodule(ce->name,\n \t\t\t\tSUBMODULE_REMOVAL_DIE_ON_ERROR |\n@@ -386,7 +386,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\tif (!quiet)\n \t\t\tprintf(\"rm '%s'\\n\", path);\n \n-\t\tif (remove_file_from_cache(path))\n+\t\tif (remove_file_from_index(&the_index, path))\n \t\t\tdie(_(\"git rm: unable to remove %s\"), path);\n \t}\n \ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex e1b2bb78e72..533ba66df05 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -256,7 +256,7 @@ static int remove_one_path(const char *path)\n {\n \tif (!allow_remove)\n \t\treturn error(\"%s: does not exist and --remove not passed\", path);\n-\tif (remove_file_from_cache(path))\n+\tif (remove_file_from_index(&the_index, path))\n \t\treturn error(\"%s: cannot remove from the index\", path);\n \treturn 0;\n }\n@@ -281,7 +281,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len\n \tstruct cache_entry *ce;\n \n \t/* Was the old index entry already up-to-date? */\n-\tif (old && !ce_stage(old) && !ce_match_stat(old, st, 0))\n+\tif (old && !ce_stage(old) && !ie_match_stat(&the_index, old, st, 0))\n \t\treturn 0;\n \n \tce = make_empty_cache_entry(&the_index, len);\n@@ -298,7 +298,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len\n \t}\n \toption = allow_add ? ADD_CACHE_OK_TO_ADD : 0;\n \toption |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;\n-\tif (add_cache_entry(ce, option)) {\n+\tif (add_index_entry(&the_index, ce, option)) {\n \t\tdiscard_cache_entry(ce);\n \t\treturn error(\"%s: cannot add to the index - missing --add option?\", path);\n \t}\n@@ -390,7 +390,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)\n \t\t * On the other hand, removing it from index should work\n \t\t */\n \t\tif (!ignore_skip_worktree_entries && allow_remove &&\n-\t\t    remove_file_from_cache(path))\n+\t\t    remove_file_from_index(&the_index, path))\n \t\t\treturn error(\"%s: cannot remove from the index\", path);\n \t\treturn 0;\n \t}\n@@ -429,7 +429,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,\n \t\tce->ce_flags |= CE_VALID;\n \toption = allow_add ? ADD_CACHE_OK_TO_ADD : 0;\n \toption |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;\n-\tif (add_cache_entry(ce, option))\n+\tif (add_index_entry(&the_index, ce, option))\n \t\treturn error(\"%s: cannot add to the index - missing --add option?\",\n \t\t\t     path);\n \treport(\"add '%s'\", path);\n@@ -488,7 +488,7 @@ static void update_one(const char *path)\n \t}\n \n \tif (force_remove) {\n-\t\tif (remove_file_from_cache(path))\n+\t\tif (remove_file_from_index(&the_index, path))\n \t\t\tdie(\"git update-index: unable to remove %s\", path);\n \t\treport(\"remove '%s'\", path);\n \t\treturn;\n@@ -571,7 +571,7 @@ static void read_index_info(int nul_term_line)\n \n \t\tif (!mode) {\n \t\t\t/* mode == 0 means there is no such path -- remove */\n-\t\t\tif (remove_file_from_cache(path_name))\n+\t\t\tif (remove_file_from_index(&the_index, path_name))\n \t\t\t\tdie(\"git update-index: unable to remove %s\",\n \t\t\t\t    ptr);\n \t\t}\n@@ -686,13 +686,13 @@ static int unresolve_one(const char *path)\n \t\tgoto free_return;\n \t}\n \n-\tremove_file_from_cache(path);\n-\tif (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) {\n+\tremove_file_from_index(&the_index, path);\n+\tif (add_index_entry(&the_index, ce_2, ADD_CACHE_OK_TO_ADD)) {\n \t\terror(\"%s: cannot add our version to the index.\", path);\n \t\tret = -1;\n \t\tgoto free_return;\n \t}\n-\tif (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD))\n+\tif (!add_index_entry(&the_index, ce_3, ADD_CACHE_OK_TO_ADD))\n \t\treturn 0;\n \terror(\"%s: cannot add their version to the index.\", path);\n \tret = -1;\n@@ -850,7 +850,7 @@ static int resolve_undo_clear_callback(const struct option *opt,\n {\n \tBUG_ON_OPT_NEG(unset);\n \tBUG_ON_OPT_ARG(arg);\n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \treturn 0;\n }\n \ndiff --git a/cache.h b/cache.h\nindex 489e9e1925b..79b8d479710 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -446,13 +446,8 @@ extern struct index_state the_index;\n #define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)\n #define discard_cache() discard_index(&the_index)\n #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))\n-#define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))\n-#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))\n #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)\n #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)\n-#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))\n-#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))\n-#define resolve_undo_clear() resolve_undo_clear_index(&the_index)\n #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n \ndiff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci\nindex 04207c409e1..89c18986160 100644\n--- a/contrib/coccinelle/index-compatibility.cocci\n+++ b/contrib/coccinelle/index-compatibility.cocci\n@@ -39,6 +39,21 @@\n |\n - add_file_to_cache\n + add_file_to_index\n+|\n+- add_cache_entry\n++ add_index_entry\n+|\n+- remove_file_from_cache\n++ remove_file_from_index\n+|\n+- ce_match_stat\n++ ie_match_stat\n+|\n+- ce_modified\n++ ie_modified\n+|\n+- resolve_undo_clear\n++ resolve_undo_clear_index\n )\n   (\n + &the_index,\ndiff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci\nindex 6e96de0f638..cf1ea57d700 100644\n--- a/contrib/coccinelle/index-compatibility.pending.cocci\n+++ b/contrib/coccinelle/index-compatibility.pending.cocci\n@@ -38,21 +38,6 @@\n |\n - cache_name_pos\n + index_name_pos\n-|\n-- add_cache_entry\n-+ add_index_entry\n-|\n-- remove_file_from_cache\n-+ remove_file_from_index\n-|\n-- ce_match_stat\n-+ ie_match_stat\n-|\n-- ce_modified\n-+ ie_modified\n-|\n-- resolve_undo_clear\n-+ resolve_undo_clear_index\n )\n   (\n + &the_index,\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467502","messageId":"patch-07.12-bf507c79d07-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 07/12] cocci & cache.h: apply variable section of \"pending\" index-compatibility","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:31:01Z","receivedAt":"2022-11-18T11:31:36Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Mostly apply the part of \"index-compatibility.pending.cocci\" that\nrenames the global variables like \"active_nr\", which are a shorthand\nto referencing (in that case) a struct member as \"the_index.cache_nr\".\n\nIn doing so move more of \"index-compatibility.pending.cocci\" to\n\"index-compatibility.cocci\".\n\nIn the case of \"active_cache_tree\" we'd have a textual conflict with\n\"vd/skip-cache-tree-update\" in \"next\"[1], and in the case of\n\"active_nr\" with \"ab/various-leak-fixes\" in \"seen\". Let's exclude\nthose specific cases while moving the rule over from \"pending\".\n\n1. dc5d40f5bc4 (read-tree: use 'skip_cache_tree_update' option,\n   2022-11-10)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/add.c                                 |  8 ++--\n builtin/checkout-index.c                      | 10 ++--\n builtin/checkout.c                            | 46 +++++++++----------\n builtin/commit.c                              | 16 +++----\n builtin/fsck.c                                | 12 ++---\n builtin/merge-index.c                         | 10 ++--\n builtin/merge.c                               |  6 +--\n builtin/mv.c                                  | 19 ++++----\n builtin/reset.c                               |  2 +-\n builtin/rm.c                                  | 14 +++---\n builtin/stash.c                               |  8 ++--\n builtin/submodule--helper.c                   | 14 +++---\n builtin/update-index.c                        | 46 +++++++++----------\n cache.h                                       |  2 -\n contrib/coccinelle/index-compatibility.cocci  | 27 +++++++++++\n .../index-compatibility.pending.cocci         | 17 -------\n t/helper/test-dump-cache-tree.c               |  2 +-\n t/helper/test-scrap-cache-tree.c              |  4 +-\n 18 files changed, 136 insertions(+), 127 deletions(-)\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 75be1d021ab..23f9f0e08bb 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -42,8 +42,8 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)\n {\n \tint i, ret = 0;\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \t\tint err;\n \n \t\tif (!include_sparse &&\n@@ -159,8 +159,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)\n {\n \tint i, retval = 0;\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \n \t\tif (!include_sparse &&\n \t\t    (ce_skip_worktree(ce) ||\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex 97e06e8c52c..c2aee450c40 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -75,8 +75,8 @@ static int checkout_file(const char *name, const char *prefix)\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n \n-\twhile (pos < active_nr) {\n-\t\tstruct cache_entry *ce = active_cache[pos];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tstruct cache_entry *ce = the_index.cache[pos];\n \t\tif (ce_namelen(ce) != namelen ||\n \t\t    memcmp(ce->name, name, namelen))\n \t\t\tbreak;\n@@ -136,8 +136,8 @@ static int checkout_all(const char *prefix, int prefix_length)\n \tint i, errs = 0;\n \tstruct cache_entry *last_ce = NULL;\n \n-\tfor (i = 0; i < active_nr ; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr ; i++) {\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \n \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n \t\t\tif (!ce_skip_worktree(ce))\n@@ -151,7 +151,7 @@ static int checkout_all(const char *prefix, int prefix_length)\n \t\t\t */\n \t\t\tif (ignore_skip_worktree) {\n \t\t\t\tensure_full_index(&the_index);\n-\t\t\t\tce = active_cache[i];\n+\t\t\t\tce = the_index.cache[i];\n \t\t\t}\n \t\t}\n \ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex afbd71764a3..3fd303f5604 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -150,7 +150,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \t */\n \tpos = cache_name_pos(ce->name, ce->ce_namelen);\n \tif (pos >= 0) {\n-\t\tstruct cache_entry *old = active_cache[pos];\n+\t\tstruct cache_entry *old = the_index.cache[pos];\n \t\tif (ce->ce_mode == old->ce_mode &&\n \t\t    !ce_intent_to_add(old) &&\n \t\t    oideq(&ce->oid, &old->oid)) {\n@@ -179,8 +179,8 @@ static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)\n \n static int skip_same_name(const struct cache_entry *ce, int pos)\n {\n-\twhile (++pos < active_nr &&\n-\t       !strcmp(active_cache[pos]->name, ce->name))\n+\twhile (++pos < the_index.cache_nr &&\n+\t       !strcmp(the_index.cache[pos]->name, ce->name))\n \t\t; /* skip */\n \treturn pos;\n }\n@@ -188,9 +188,9 @@ static int skip_same_name(const struct cache_entry *ce, int pos)\n static int check_stage(int stage, const struct cache_entry *ce, int pos,\n \t\t       int overlay_mode)\n {\n-\twhile (pos < active_nr &&\n-\t       !strcmp(active_cache[pos]->name, ce->name)) {\n-\t\tif (ce_stage(active_cache[pos]) == stage)\n+\twhile (pos < the_index.cache_nr &&\n+\t       !strcmp(the_index.cache[pos]->name, ce->name)) {\n+\t\tif (ce_stage(the_index.cache[pos]) == stage)\n \t\t\treturn 0;\n \t\tpos++;\n \t}\n@@ -207,8 +207,8 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)\n \tunsigned seen = 0;\n \tconst char *name = ce->name;\n \n-\twhile (pos < active_nr) {\n-\t\tce = active_cache[pos];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tce = the_index.cache[pos];\n \t\tif (strcmp(name, ce->name))\n \t\t\tbreak;\n \t\tseen |= (1 << ce_stage(ce));\n@@ -224,10 +224,10 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,\n \t\t\t  const struct checkout *state, int *nr_checkouts,\n \t\t\t  int overlay_mode)\n {\n-\twhile (pos < active_nr &&\n-\t       !strcmp(active_cache[pos]->name, ce->name)) {\n-\t\tif (ce_stage(active_cache[pos]) == stage)\n-\t\t\treturn checkout_entry(active_cache[pos], state,\n+\twhile (pos < the_index.cache_nr &&\n+\t       !strcmp(the_index.cache[pos]->name, ce->name)) {\n+\t\tif (ce_stage(the_index.cache[pos]) == stage)\n+\t\t\treturn checkout_entry(the_index.cache[pos], state,\n \t\t\t\t\t      NULL, nr_checkouts);\n \t\tpos++;\n \t}\n@@ -244,7 +244,7 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,\n static int checkout_merged(int pos, const struct checkout *state,\n \t\t\t   int *nr_checkouts, struct mem_pool *ce_mem_pool)\n {\n-\tstruct cache_entry *ce = active_cache[pos];\n+\tstruct cache_entry *ce = the_index.cache[pos];\n \tconst char *path = ce->name;\n \tmmfile_t ancestor, ours, theirs;\n \tenum ll_merge_result merge_status;\n@@ -257,7 +257,7 @@ static int checkout_merged(int pos, const struct checkout *state,\n \tint renormalize = 0;\n \n \tmemset(threeway, 0, sizeof(threeway));\n-\twhile (pos < active_nr) {\n+\twhile (pos < the_index.cache_nr) {\n \t\tint stage;\n \t\tstage = ce_stage(ce);\n \t\tif (!stage || strcmp(path, ce->name))\n@@ -266,7 +266,7 @@ static int checkout_merged(int pos, const struct checkout *state,\n \t\tif (stage == 2)\n \t\t\tmode = create_ce_mode(ce->ce_mode);\n \t\tpos++;\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \t}\n \tif (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))\n \t\treturn error(_(\"path '%s' does not have necessary versions\"), path);\n@@ -392,8 +392,8 @@ static int checkout_worktree(const struct checkout_opts *opts,\n \tif (pc_workers > 1)\n \t\tinit_parallel_checkout();\n \n-\tfor (pos = 0; pos < active_nr; pos++) {\n-\t\tstruct cache_entry *ce = active_cache[pos];\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n+\t\tstruct cache_entry *ce = the_index.cache[pos];\n \t\tif (ce->ce_flags & CE_MATCHED) {\n \t\t\tif (!ce_stage(ce)) {\n \t\t\t\terrs |= checkout_entry(ce, &state,\n@@ -541,13 +541,13 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t * Make sure all pathspecs participated in locating the paths\n \t * to be checked out.\n \t */\n-\tfor (pos = 0; pos < active_nr; pos++)\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++)\n \t\tif (opts->overlay_mode)\n-\t\t\tmark_ce_for_checkout_overlay(active_cache[pos],\n+\t\t\tmark_ce_for_checkout_overlay(the_index.cache[pos],\n \t\t\t\t\t\t     ps_matched,\n \t\t\t\t\t\t     opts);\n \t\telse\n-\t\t\tmark_ce_for_checkout_no_overlay(active_cache[pos],\n+\t\t\tmark_ce_for_checkout_no_overlay(the_index.cache[pos],\n \t\t\t\t\t\t\tps_matched,\n \t\t\t\t\t\t\topts);\n \n@@ -562,8 +562,8 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t\tunmerge_marked_index(&the_index);\n \n \t/* Any unmerged paths? */\n-\tfor (pos = 0; pos < active_nr; pos++) {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tif (ce->ce_flags & CE_MATCHED) {\n \t\t\tif (!ce_stage(ce))\n \t\t\t\tcontinue;\n@@ -868,7 +868,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \t\t}\n \t}\n \n-\tif (!cache_tree_fully_valid(active_cache_tree))\n+\tif (!cache_tree_fully_valid(the_index.cache_tree))\n \t\tcache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n \n \tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 10a827b1f4a..abbed750276 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -272,8 +272,8 @@ static int list_paths(struct string_list *list, const char *with_tree,\n \n \t/* TODO: audit for interaction with sparse-index. */\n \tensure_full_index(&the_index);\n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \t\tstruct string_list_item *item;\n \n \t\tif (ce->ce_flags & CE_UPDATE)\n@@ -461,8 +461,8 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \tif (!only && !pathspec.nr) {\n \t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n \t\trefresh_cache_or_die(refresh_flags);\n-\t\tif (active_cache_changed\n-\t\t    || !cache_tree_fully_valid(active_cache_tree))\n+\t\tif (the_index.cache_changed\n+\t\t    || !cache_tree_fully_valid(the_index.cache_tree))\n \t\t\tupdate_main_cache_tree(WRITE_TREE_SILENT);\n \t\tif (write_locked_index(&the_index, &index_lock,\n \t\t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n@@ -998,10 +998,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \n \t\t\t/* TODO: audit for interaction with sparse-index. */\n \t\t\tensure_full_index(&the_index);\n-\t\t\tfor (i = 0; i < active_nr; i++)\n-\t\t\t\tif (ce_intent_to_add(active_cache[i]))\n+\t\t\tfor (i = 0; i < the_index.cache_nr; i++)\n+\t\t\t\tif (ce_intent_to_add(the_index.cache[i]))\n \t\t\t\t\tita_nr++;\n-\t\t\tcommittable = active_nr - ita_nr > 0;\n+\t\t\tcommittable = the_index.cache_nr - ita_nr > 0;\n \t\t} else {\n \t\t\t/*\n \t\t\t * Unless the user did explicitly request a submodule\n@@ -1823,7 +1823,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tappend_merge_tag_headers(parents, &tail);\n \t}\n \n-\tif (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,\n+\tif (commit_tree_extended(sb.buf, sb.len, &the_index.cache_tree->oid,\n \t\t\t\t parents, &oid, author_ident.buf, NULL,\n \t\t\t\t sign_commit, extra)) {\n \t\trollback_index_files();\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 7436e1a68ef..cd47675e371 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -961,26 +961,26 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\tread_cache();\n \t\t/* TODO: audit for interaction with sparse-index. */\n \t\tensure_full_index(&the_index);\n-\t\tfor (i = 0; i < active_nr; i++) {\n+\t\tfor (i = 0; i < the_index.cache_nr; i++) {\n \t\t\tunsigned int mode;\n \t\t\tstruct blob *blob;\n \t\t\tstruct object *obj;\n \n-\t\t\tmode = active_cache[i]->ce_mode;\n+\t\t\tmode = the_index.cache[i]->ce_mode;\n \t\t\tif (S_ISGITLINK(mode))\n \t\t\t\tcontinue;\n \t\t\tblob = lookup_blob(the_repository,\n-\t\t\t\t\t   &active_cache[i]->oid);\n+\t\t\t\t\t   &the_index.cache[i]->oid);\n \t\t\tif (!blob)\n \t\t\t\tcontinue;\n \t\t\tobj = &blob->object;\n \t\t\tobj->flags |= USED;\n \t\t\tfsck_put_object_name(&fsck_walk_options, &obj->oid,\n-\t\t\t\t\t     \":%s\", active_cache[i]->name);\n+\t\t\t\t\t     \":%s\", the_index.cache[i]->name);\n \t\t\tmark_object_reachable(obj);\n \t\t}\n-\t\tif (active_cache_tree)\n-\t\t\tfsck_cache_tree(active_cache_tree);\n+\t\tif (the_index.cache_tree)\n+\t\t\tfsck_cache_tree(the_index.cache_tree);\n \t\tfsck_resolve_undo(&the_index);\n \t}\n \ndiff --git a/builtin/merge-index.c b/builtin/merge-index.c\nindex 012f52bd007..a334c513c9d 100644\n--- a/builtin/merge-index.c\n+++ b/builtin/merge-index.c\n@@ -14,11 +14,11 @@ static int merge_entry(int pos, const char *path)\n \tchar ownbuf[4][60];\n \tstruct child_process cmd = CHILD_PROCESS_INIT;\n \n-\tif (pos >= active_nr)\n+\tif (pos >= the_index.cache_nr)\n \t\tdie(\"git merge-index: %s not in the cache\", path);\n \tfound = 0;\n \tdo {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tint stage = ce_stage(ce);\n \n \t\tif (strcmp(ce->name, path))\n@@ -28,7 +28,7 @@ static int merge_entry(int pos, const char *path)\n \t\txsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), \"%o\", ce->ce_mode);\n \t\targuments[stage] = hexbuf[stage];\n \t\targuments[stage + 4] = ownbuf[stage];\n-\t} while (++pos < active_nr);\n+\t} while (++pos < the_index.cache_nr);\n \tif (!found)\n \t\tdie(\"git merge-index: %s not in the cache\", path);\n \n@@ -62,8 +62,8 @@ static void merge_all(void)\n \tint i;\n \t/* TODO: audit for interaction with sparse-index. */\n \tensure_full_index(&the_index);\n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \t\ti += merge_entry(i, ce->name)-1;\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 2046992d75a..27218ee93c9 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -694,7 +694,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,\n \tif (!trees[nr_trees++])\n \t\treturn -1;\n \topts.fn = threeway_merge;\n-\tcache_tree_free(&active_cache_tree);\n+\tcache_tree_free(&the_index.cache_tree);\n \tfor (i = 0; i < nr_trees; i++) {\n \t\tparse_tree(trees[i]);\n \t\tinit_tree_desc(t+i, trees[i]->buffer, trees[i]->size);\n@@ -784,8 +784,8 @@ static int count_unmerged_entries(void)\n {\n \tint i, ret = 0;\n \n-\tfor (i = 0; i < active_nr; i++)\n-\t\tif (ce_stage(active_cache[i]))\n+\tfor (i = 0; i < the_index.cache_nr; i++)\n+\t\tif (ce_stage(the_index.cache[i]))\n \t\t\tret++;\n \n \treturn ret;\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 6f94c3b9238..883cf3ff12b 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -87,7 +87,7 @@ static void prepare_move_submodule(const char *src, int first,\n \t\t\t\t   const char **submodule_gitfile)\n {\n \tstruct strbuf submodule_dotgit = STRBUF_INIT;\n-\tif (!S_ISGITLINK(active_cache[first]->ce_mode))\n+\tif (!S_ISGITLINK(the_index.cache[first]->ce_mode))\n \t\tdie(_(\"Directory %s is in index and no submodule?\"), src);\n \tif (!is_staging_gitmodules_ok(&the_index))\n \t\tdie(_(\"Please stage your changes to .gitmodules or stash them to proceed\"));\n@@ -111,8 +111,8 @@ static int index_range_of_same_dir(const char *src, int length,\n \t\tdie(_(\"%.*s is in index\"), len_w_slash, src_w_slash);\n \n \tfirst = -1 - first;\n-\tfor (last = first; last < active_nr; last++) {\n-\t\tconst char *path = active_cache[last]->name;\n+\tfor (last = first; last < the_index.cache_nr; last++) {\n+\t\tconst char *path = the_index.cache[last]->name;\n \t\tif (strncmp(path, src_w_slash, len_w_slash))\n \t\t\tbreak;\n \t}\n@@ -143,7 +143,7 @@ static int empty_dir_has_sparse_contents(const char *name)\n \t\tpos = -pos - 1;\n \t\tif (pos >= the_index.cache_nr)\n \t\t\tgoto free_return;\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \t\tif (strncmp(with_slash, ce->name, length))\n \t\t\tgoto free_return;\n \t\tif (ce_skip_worktree(ce))\n@@ -268,7 +268,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tbad = _(\"bad source\");\n \t\t\t\tgoto act_on_entry;\n \t\t\t}\n-\t\t\tce = active_cache[pos];\n+\t\t\tce = the_index.cache[pos];\n \t\t\tif (!ce_skip_worktree(ce)) {\n \t\t\t\tbad = _(\"bad source\");\n \t\t\t\tgoto act_on_entry;\n@@ -331,7 +331,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tdst_len = strlen(dst);\n \n \t\t\tfor (j = 0; j < last - first; j++) {\n-\t\t\t\tconst struct cache_entry *ce = active_cache[first + j];\n+\t\t\t\tconst struct cache_entry *ce = the_index.cache[first + j];\n \t\t\t\tconst char *path = ce->name;\n \t\t\t\tsource[argc + j] = path;\n \t\t\t\tdestination[argc + j] =\n@@ -472,7 +472,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tassert(pos >= 0);\n \t\tif (!(mode & SPARSE) && !lstat(src, &st))\n \t\t\tsparse_and_dirty = ie_modified(&the_index,\n-\t\t\t\t\t\t       active_cache[pos], &st,\n+\t\t\t\t\t\t       the_index.cache[pos],\n+\t\t\t\t\t\t       &st,\n \t\t\t\t\t\t       0);\n \t\trename_index_entry_at(&the_index, pos, dst);\n \n@@ -489,7 +490,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t    path_in_sparse_checkout(dst, &the_index)) {\n \t\t\t\t/* from out-of-cone to in-cone */\n \t\t\t\tint dst_pos = cache_name_pos(dst, strlen(dst));\n-\t\t\t\tstruct cache_entry *dst_ce = active_cache[dst_pos];\n+\t\t\t\tstruct cache_entry *dst_ce = the_index.cache[dst_pos];\n \n \t\t\t\tdst_ce->ce_flags &= ~CE_SKIP_WORKTREE;\n \n@@ -500,7 +501,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t\t   !path_in_sparse_checkout(dst, &the_index)) {\n \t\t\t\t/* from in-cone to out-of-cone */\n \t\t\t\tint dst_pos = cache_name_pos(dst, strlen(dst));\n-\t\t\t\tstruct cache_entry *dst_ce = active_cache[dst_pos];\n+\t\t\t\tstruct cache_entry *dst_ce = the_index.cache[dst_pos];\n \n \t\t\t\t/*\n \t\t\t\t * if src is clean, it will suffice to remove it\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex d38fb7d13fa..25ff76c17a3 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -159,7 +159,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,\n \t\t * to properly construct the reset sparse directory.\n \t\t */\n \t\tpos = cache_name_pos(one->path, strlen(one->path));\n-\t\tif ((pos >= 0 && ce_skip_worktree(active_cache[pos])) ||\n+\t\tif ((pos >= 0 && ce_skip_worktree(the_index.cache[pos])) ||\n \t\t    (pos < 0 && !path_in_sparse_checkout(one->path, &the_index)))\n \t\t\tce->ce_flags |= CE_SKIP_WORKTREE;\n \ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex c717cdc97f5..2b23eb25438 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -35,8 +35,8 @@ static int get_ours_cache_pos(const char *path, int pos)\n {\n \tint i = -pos - 1;\n \n-\twhile ((i < active_nr) && !strcmp(active_cache[i]->name, path)) {\n-\t\tif (ce_stage(active_cache[i]) == 2)\n+\twhile ((i < the_index.cache_nr) && !strcmp(the_index.cache[i]->name, path)) {\n+\t\tif (ce_stage(the_index.cache[i]) == 2)\n \t\t\treturn i;\n \t\ti++;\n \t}\n@@ -78,7 +78,7 @@ static void submodules_absorb_gitdir_if_needed(void)\n \t\t\tif (pos < 0)\n \t\t\t\tcontinue;\n \t\t}\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \n \t\tif (!S_ISGITLINK(ce->ce_mode) ||\n \t\t    !file_exists(ce->name) ||\n@@ -127,11 +127,11 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\t\tif (pos < 0)\n \t\t\t\tcontinue;\n \n-\t\t\tif (!S_ISGITLINK(active_cache[pos]->ce_mode) ||\n+\t\t\tif (!S_ISGITLINK(the_index.cache[pos]->ce_mode) ||\n \t\t\t    is_empty_dir(name))\n \t\t\t\tcontinue;\n \t\t}\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \n \t\tif (lstat(ce->name, &st) < 0) {\n \t\t\tif (!is_missing_file_error(errno))\n@@ -303,8 +303,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \tif (pathspec_needs_expanded_index(&the_index, &pathspec))\n \t\tensure_full_index(&the_index);\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \n \t\tif (!include_sparse &&\n \t\t    (ce_skip_worktree(ce) ||\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex bb5485b4095..c251419af7c 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -454,10 +454,10 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)\n \t\t * path, but left it out of the working tree, then clear the\n \t\t * SKIP_WORKTREE bit and write it to the working tree.\n \t\t */\n-\t\tif (pos >= 0 && ce_skip_worktree(active_cache[pos])) {\n+\t\tif (pos >= 0 && ce_skip_worktree(the_index.cache[pos])) {\n \t\t\tstruct stat st;\n \n-\t\t\tce = active_cache[pos];\n+\t\t\tce = the_index.cache[pos];\n \t\t\tif (!lstat(ce->name, &st)) {\n \t\t\t\t/* Conflicting path present; relocate it */\n \t\t\t\tstruct strbuf new_path = STRBUF_INIT;\n@@ -1520,8 +1520,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q\n \n \t\t/* TODO: audit for interaction with sparse-index. */\n \t\tensure_full_index(&the_index);\n-\t\tfor (i = 0; i < active_nr; i++)\n-\t\t\tce_path_match(&the_index, active_cache[i], ps,\n+\t\tfor (i = 0; i < the_index.cache_nr; i++)\n+\t\t\tce_path_match(&the_index, the_index.cache[i], ps,\n \t\t\t\t      ps_matched);\n \n \t\tif (report_path_error(ps_matched, ps)) {\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex a7683d35299..808865a5e31 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -199,8 +199,8 @@ static int module_list_compute(const char **argv,\n \tif (read_cache() < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \n \t\tif (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),\n \t\t\t\t    0, ps_matched, 1) ||\n@@ -209,8 +209,8 @@ static int module_list_compute(const char **argv,\n \n \t\tALLOC_GROW(list->entries, list->nr + 1, list->alloc);\n \t\tlist->entries[list->nr++] = ce;\n-\t\twhile (i + 1 < active_nr &&\n-\t\t       !strcmp(ce->name, active_cache[i + 1]->name))\n+\t\twhile (i + 1 < the_index.cache_nr &&\n+\t\t       !strcmp(ce->name, the_index.cache[i + 1]->name))\n \t\t\t/*\n \t\t\t * Skip entries with the same name in different stages\n \t\t\t * to make sure an entry is returned only once.\n@@ -3255,15 +3255,15 @@ static void die_on_index_match(const char *path, int force)\n \t\t * need to check ps_matched[0] to know if a cache\n \t\t * entry matched.\n \t\t */\n-\t\tfor (i = 0; i < active_nr; i++) {\n-\t\t\tce_path_match(&the_index, active_cache[i], &ps,\n+\t\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\t\tce_path_match(&the_index, the_index.cache[i], &ps,\n \t\t\t\t      ps_matched);\n \n \t\t\tif (ps_matched[0]) {\n \t\t\t\tif (!force)\n \t\t\t\t\tdie(_(\"'%s' already exists in the index\"),\n \t\t\t\t\t    path);\n-\t\t\t\tif (!S_ISGITLINK(active_cache[i]->ce_mode))\n+\t\t\t\tif (!S_ISGITLINK(the_index.cache[i]->ce_mode))\n \t\t\t\t\tdie(_(\"'%s' already exists in the index \"\n \t\t\t\t\t      \"and is not a submodule\"), path);\n \t\t\t\tbreak;\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex 533ba66df05..fec3da05abb 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -239,14 +239,14 @@ static int mark_ce_flags(const char *path, int flag, int mark)\n \tint namelen = strlen(path);\n \tint pos = cache_name_pos(path, namelen);\n \tif (0 <= pos) {\n-\t\tmark_fsmonitor_invalid(&the_index, active_cache[pos]);\n+\t\tmark_fsmonitor_invalid(&the_index, the_index.cache[pos]);\n \t\tif (mark)\n-\t\t\tactive_cache[pos]->ce_flags |= flag;\n+\t\t\tthe_index.cache[pos]->ce_flags |= flag;\n \t\telse\n-\t\t\tactive_cache[pos]->ce_flags &= ~flag;\n-\t\tactive_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;\n+\t\t\tthe_index.cache[pos]->ce_flags &= ~flag;\n+\t\tthe_index.cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;\n \t\tcache_tree_invalidate_path(&the_index, path);\n-\t\tactive_cache_changed |= CE_ENTRY_CHANGED;\n+\t\tthe_index.cache_changed |= CE_ENTRY_CHANGED;\n \t\treturn 0;\n \t}\n \treturn -1;\n@@ -335,7 +335,7 @@ static int process_directory(const char *path, int len, struct stat *st)\n \n \t/* Exact match: file or existing gitlink */\n \tif (pos >= 0) {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tif (S_ISGITLINK(ce->ce_mode)) {\n \n \t\t\t/* Do nothing to the index if there is no HEAD! */\n@@ -350,8 +350,8 @@ static int process_directory(const char *path, int len, struct stat *st)\n \n \t/* Inexact match: is there perhaps a subdirectory match? */\n \tpos = -pos-1;\n-\twhile (pos < active_nr) {\n-\t\tconst struct cache_entry *ce = active_cache[pos++];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tconst struct cache_entry *ce = the_index.cache[pos++];\n \n \t\tif (strncmp(ce->name, path, len))\n \t\t\tbreak;\n@@ -382,7 +382,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)\n \t\treturn error(\"'%s' is beyond a symbolic link\", path);\n \n \tpos = cache_name_pos(path, len);\n-\tce = pos < 0 ? NULL : active_cache[pos];\n+\tce = pos < 0 ? NULL : the_index.cache[pos];\n \tif (ce && ce_skip_worktree(ce)) {\n \t\t/*\n \t\t * working directory version is assumed \"good\"\n@@ -444,7 +444,7 @@ static void chmod_path(char flip, const char *path)\n \tpos = cache_name_pos(path, strlen(path));\n \tif (pos < 0)\n \t\tgoto fail;\n-\tce = active_cache[pos];\n+\tce = the_index.cache[pos];\n \tif (chmod_index_entry(&the_index, ce, flip) < 0)\n \t\tgoto fail;\n \n@@ -642,8 +642,8 @@ static int unresolve_one(const char *path)\n \tif (0 <= pos) {\n \t\t/* already merged */\n \t\tpos = unmerge_index_entry_at(&the_index, pos);\n-\t\tif (pos < active_nr) {\n-\t\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tif (pos < the_index.cache_nr) {\n+\t\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\t\tif (ce_stage(ce) &&\n \t\t\t    ce_namelen(ce) == namelen &&\n \t\t\t    !memcmp(ce->name, path, namelen))\n@@ -656,8 +656,8 @@ static int unresolve_one(const char *path)\n \t\t * want to do anything in the former case.\n \t\t */\n \t\tpos = -pos-1;\n-\t\tif (pos < active_nr) {\n-\t\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tif (pos < the_index.cache_nr) {\n+\t\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\t\tif (ce_namelen(ce) == namelen &&\n \t\t\t    !memcmp(ce->name, path, namelen)) {\n \t\t\t\tfprintf(stderr,\n@@ -752,8 +752,8 @@ static int do_reupdate(const char **paths,\n \t\t */\n \t\thas_head = 0;\n  redo:\n-\tfor (pos = 0; pos < active_nr; pos++) {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tstruct cache_entry *old = NULL;\n \t\tint save_nr;\n \t\tchar *path;\n@@ -782,12 +782,12 @@ static int do_reupdate(const char **paths,\n \t\t * path anymore, in which case, under 'allow_remove',\n \t\t * or worse yet 'allow_replace', active_nr may decrease.\n \t\t */\n-\t\tsave_nr = active_nr;\n+\t\tsave_nr = the_index.cache_nr;\n \t\tpath = xstrdup(ce->name);\n \t\tupdate_one(path);\n \t\tfree(path);\n \t\tdiscard_cache_entry(old);\n-\t\tif (save_nr != active_nr)\n+\t\tif (save_nr != the_index.cache_nr)\n \t\t\tgoto redo;\n \t}\n \tclear_pathspec(&pathspec);\n@@ -813,7 +813,7 @@ static int refresh(struct refresh_params *o, unsigned int flag)\n \t\t * refresh_cache() as these are no actual errors.\n \t\t * cmd_status() does the same.\n \t\t */\n-\t\tactive_cache_changed |= SOMETHING_CHANGED;\n+\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n \t}\n \treturn 0;\n }\n@@ -951,7 +951,7 @@ static enum parse_opt_result unresolve_callback(\n \t*has_errors = do_unresolve(ctx->argc, ctx->argv,\n \t\t\t\tprefix, prefix ? strlen(prefix) : 0);\n \tif (*has_errors)\n-\t\tactive_cache_changed = 0;\n+\t\tthe_index.cache_changed = 0;\n \n \tctx->argv += ctx->argc - 1;\n \tctx->argc = 1;\n@@ -972,7 +972,7 @@ static enum parse_opt_result reupdate_callback(\n \tsetup_work_tree();\n \t*has_errors = do_reupdate(ctx->argv + 1, prefix);\n \tif (*has_errors)\n-\t\tactive_cache_changed = 0;\n+\t\tthe_index.cache_changed = 0;\n \n \tctx->argv += ctx->argc - 1;\n \tctx->argc = 1;\n@@ -1178,7 +1178,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\t    INDEX_FORMAT_LB, INDEX_FORMAT_UB);\n \n \t\tif (the_index.version != preferred_index_format)\n-\t\t\tactive_cache_changed |= SOMETHING_CHANGED;\n+\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n \t\tthe_index.version = preferred_index_format;\n \t}\n \n@@ -1290,7 +1290,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\treport(_(\"fsmonitor disabled\"));\n \t}\n \n-\tif (active_cache_changed || force_write) {\n+\tif (the_index.cache_changed || force_write) {\n \t\tif (newfd < 0) {\n \t\t\tif (refresh_args.flags & REFRESH_QUIET)\n \t\t\t\texit(128);\ndiff --git a/cache.h b/cache.h\nindex 79b8d479710..8b54b627459 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -436,9 +436,7 @@ void prefetch_cache_entries(const struct index_state *istate,\n #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n extern struct index_state the_index;\n \n-#define active_cache (the_index.cache)\n #define active_nr (the_index.cache_nr)\n-#define active_cache_changed (the_index.cache_changed)\n #define active_cache_tree (the_index.cache_tree)\n \n #define read_cache() repo_read_index(the_repository)\ndiff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci\nindex 89c18986160..2e9d8296076 100644\n--- a/contrib/coccinelle/index-compatibility.cocci\n+++ b/contrib/coccinelle/index-compatibility.cocci\n@@ -1,3 +1,30 @@\n+// the_index.* variables\n+@@\n+@@\n+(\n+- active_cache\n++ the_index.cache\n+|\n+- active_cache_changed\n++ the_index.cache_changed\n+)\n+\n+@@\n+identifier f != prepare_to_commit;\n+@@\n+  f(...) {<...\n+- active_nr\n++ the_index.cache_nr\n+  ...>}\n+\n+@@\n+identifier f != cmd_read_tree;\n+@@\n+  f(...) {<...\n+- active_cache_tree\n++ the_index.cache_tree\n+  ...>}\n+\n // \"the_repository\" simple cases\n @@\n @@\ndiff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci\nindex cf1ea57d700..8207aee62c3 100644\n--- a/contrib/coccinelle/index-compatibility.pending.cocci\n+++ b/contrib/coccinelle/index-compatibility.pending.cocci\n@@ -1,20 +1,3 @@\n-// the_index.* variables\n-@@\n-@@\n-(\n-- active_cache\n-+ the_index.cache\n-|\n-- active_nr\n-+ the_index.cache_nr\n-|\n-- active_cache_changed\n-+ the_index.cache_changed\n-|\n-- active_cache_tree\n-+ the_index.cache_tree\n-)\n-\n // \"the_repository\" simple cases\n @@\n @@\ndiff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c\nindex 0d6d7f1ecbf..8d88111b357 100644\n--- a/t/helper/test-dump-cache-tree.c\n+++ b/t/helper/test-dump-cache-tree.c\n@@ -67,7 +67,7 @@ int cmd__dump_cache_tree(int ac, const char **av)\n \tistate = the_index;\n \tistate.cache_tree = another;\n \tcache_tree_update(&istate, WRITE_TREE_DRY_RUN);\n-\tret = dump_cache_tree(active_cache_tree, another, \"\");\n+\tret = dump_cache_tree(the_index.cache_tree, another, \"\");\n \tcache_tree_free(&another);\n \n \treturn ret;\ndiff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c\nindex 026c802479d..20e2e31f9e2 100644\n--- a/t/helper/test-scrap-cache-tree.c\n+++ b/t/helper/test-scrap-cache-tree.c\n@@ -12,8 +12,8 @@ int cmd__scrap_cache_tree(int ac, const char **av)\n \thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n \tif (read_cache() < 0)\n \t\tdie(\"unable to read index file\");\n-\tcache_tree_free(&active_cache_tree);\n-\tactive_cache_tree = NULL;\n+\tcache_tree_free(&the_index.cache_tree);\n+\tthe_index.cache_tree = NULL;\n \tif (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))\n \t\tdie(\"unable to write index file\");\n \treturn 0;\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467503","messageId":"patch-08.12-f3e265e6edb-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 08/12] cocci: apply \"pending\" index-compatibility to \"t/helper/*.c\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:31:02Z","receivedAt":"2022-11-18T11:31:39Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Apply the \"index-compatibility.pending.cocci\" rule to the \"t/helper/*\"\ndirectory, a subsequent commit will extend cache.h to further narrow\ndown the use of \"USE_THE_INDEX_COMPATIBILITY_MACROS\" in this area.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/helper/test-dump-cache-tree.c      |  2 +-\n t/helper/test-dump-untracked-cache.c |  2 +-\n t/helper/test-fast-rebase.c          |  2 +-\n t/helper/test-lazy-init-name-hash.c  | 20 ++++++++++----------\n t/helper/test-read-cache.c           |  4 ++--\n t/helper/test-scrap-cache-tree.c     |  4 ++--\n t/helper/test-write-cache.c          |  5 +++--\n 7 files changed, 20 insertions(+), 19 deletions(-)\n\ndiff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c\nindex 8d88111b357..4bf8bc3df6e 100644\n--- a/t/helper/test-dump-cache-tree.c\n+++ b/t/helper/test-dump-cache-tree.c\n@@ -62,7 +62,7 @@ int cmd__dump_cache_tree(int ac, const char **av)\n \tint ret;\n \n \tsetup_git_directory();\n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(\"unable to read index file\");\n \tistate = the_index;\n \tistate.cache_tree = another;\ndiff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c\nindex 99010614f6d..ffe34736e53 100644\n--- a/t/helper/test-dump-untracked-cache.c\n+++ b/t/helper/test-dump-untracked-cache.c\n@@ -51,7 +51,7 @@ int cmd__dump_untracked_cache(int ac, const char **av)\n \txsetenv(\"GIT_CONFIG_VALUE_0\", \"keep\", 1);\n \n \tsetup_git_directory();\n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(\"unable to read index file\");\n \tuc = the_index.untracked;\n \tif (!uc) {\ndiff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c\nindex 45665ec19a5..9def2ba6889 100644\n--- a/t/helper/test-fast-rebase.c\n+++ b/t/helper/test-fast-rebase.c\n@@ -123,7 +123,7 @@ int cmd__fast_rebase(int argc, const char **argv)\n \t\tdie(_(\"Cannot read HEAD\"));\n \tassert(oideq(&onto->object.oid, &head));\n \n-\thold_locked_index(&lock, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);\n \tif (repo_read_index(the_repository) < 0)\n \t\tBUG(\"Could not read index\");\n \ndiff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c\nindex cd1b4c9736e..7e8723a1900 100644\n--- a/t/helper/test-lazy-init-name-hash.c\n+++ b/t/helper/test-lazy-init-name-hash.c\n@@ -32,7 +32,7 @@ static void dump_run(void)\n \tstruct dir_entry *dir;\n \tstruct cache_entry *ce;\n \n-\tread_cache();\n+\trepo_read_index(the_repository);\n \tif (single) {\n \t\ttest_lazy_init_name_hash(&the_index, 0);\n \t} else {\n@@ -49,7 +49,7 @@ static void dump_run(void)\n \t\t\t\tent /* member name */)\n \t\tprintf(\"name %08x %s\\n\", ce->ent.hash, ce->name);\n \n-\tdiscard_cache();\n+\tdiscard_index(&the_index);\n }\n \n /*\n@@ -66,7 +66,7 @@ static uint64_t time_runs(int try_threaded)\n \n \tfor (i = 0; i < count; i++) {\n \t\tt0 = getnanotime();\n-\t\tread_cache();\n+\t\trepo_read_index(the_repository);\n \t\tt1 = getnanotime();\n \t\tnr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded);\n \t\tt2 = getnanotime();\n@@ -89,7 +89,7 @@ static uint64_t time_runs(int try_threaded)\n \t\t\t\t   the_index.cache_nr);\n \t\tfflush(stdout);\n \n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t}\n \n \tavg = sum / count;\n@@ -113,9 +113,9 @@ static void analyze_run(void)\n \tint i;\n \tint nr;\n \n-\tread_cache();\n+\trepo_read_index(the_repository);\n \tcache_nr_limit = the_index.cache_nr;\n-\tdiscard_cache();\n+\tdiscard_index(&the_index);\n \n \tnr = analyze;\n \twhile (1) {\n@@ -128,23 +128,23 @@ static void analyze_run(void)\n \t\t\tnr = cache_nr_limit;\n \n \t\tfor (i = 0; i < count; i++) {\n-\t\t\tread_cache();\n+\t\t\trepo_read_index(the_repository);\n \t\t\tthe_index.cache_nr = nr; /* cheap truncate of index */\n \t\t\tt1s = getnanotime();\n \t\t\ttest_lazy_init_name_hash(&the_index, 0);\n \t\t\tt2s = getnanotime();\n \t\t\tsum_single += (t2s - t1s);\n \t\t\tthe_index.cache_nr = cache_nr_limit;\n-\t\t\tdiscard_cache();\n+\t\t\tdiscard_index(&the_index);\n \n-\t\t\tread_cache();\n+\t\t\trepo_read_index(the_repository);\n \t\t\tthe_index.cache_nr = nr; /* cheap truncate of index */\n \t\t\tt1m = getnanotime();\n \t\t\tnr_threads_used = test_lazy_init_name_hash(&the_index, 1);\n \t\t\tt2m = getnanotime();\n \t\t\tsum_multi += (t2m - t1m);\n \t\t\tthe_index.cache_nr = cache_nr_limit;\n-\t\t\tdiscard_cache();\n+\t\t\tdiscard_index(&the_index);\n \n \t\t\tif (!nr_threads_used)\n \t\t\t\tprintf(\"    [size %8d] [single %f]   non-threaded code path used\\n\",\ndiff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c\nindex b736ef16421..a089be9104c 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -20,7 +20,7 @@ int cmd__read_cache(int argc, const char **argv)\n \tgit_config(git_default_config, NULL);\n \n \tfor (i = 0; i < cnt; i++) {\n-\t\tread_cache();\n+\t\trepo_read_index(the_repository);\n \t\tif (name) {\n \t\t\tint pos;\n \n@@ -33,7 +33,7 @@ int cmd__read_cache(int argc, const char **argv)\n \t\t\t       ce_uptodate(the_index.cache[pos]) ? \"\" : \" not\");\n \t\t\twrite_file(name, \"%d\\n\", i);\n \t\t}\n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t}\n \treturn 0;\n }\ndiff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c\nindex 20e2e31f9e2..9206dee1fd2 100644\n--- a/t/helper/test-scrap-cache-tree.c\n+++ b/t/helper/test-scrap-cache-tree.c\n@@ -9,8 +9,8 @@ int cmd__scrap_cache_tree(int ac, const char **av)\n \tstruct lock_file index_lock = LOCK_INIT;\n \n \tsetup_git_directory();\n-\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n-\tif (read_cache() < 0)\n+\trepo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(\"unable to read index file\");\n \tcache_tree_free(&the_index.cache_tree);\n \tthe_index.cache_tree = NULL;\ndiff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c\nindex 8837717d36a..66287d6d47d 100644\n--- a/t/helper/test-write-cache.c\n+++ b/t/helper/test-write-cache.c\n@@ -9,9 +9,10 @@ int cmd__write_cache(int argc, const char **argv)\n \tif (argc == 2)\n \t\tcnt = strtol(argv[1], NULL, 0);\n \tsetup_git_directory();\n-\tread_cache();\n+\trepo_read_index(the_repository);\n \tfor (i = 0; i < cnt; i++) {\n-\t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n+\t\trepo_hold_locked_index(the_repository, &index_lock,\n+\t\t\t\t       LOCK_DIE_ON_ERROR);\n \t\tif (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))\n \t\t\tdie(\"unable to write index file\");\n \t}\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467504","messageId":"patch-09.12-5b69cfa17ad-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 09/12] {builtin/*,repository}.c: add & use \"USE_THE_INDEX_VARIABLE\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:31:03Z","receivedAt":"2022-11-18T11:31:42Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Split up the \"USE_THE_INDEX_COMPATIBILITY_MACROS\" into that setting\nand a more narrow \"USE_THE_INDEX_VARIABLE\". In the case of these\nbuilt-ins we only need \"the_index\" variable, but not the compatibility\nwrapper for functions we're not using.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/cat-file.c   | 2 +-\n builtin/difftool.c   | 2 +-\n builtin/merge-tree.c | 2 +-\n builtin/pull.c       | 2 +-\n cache.h              | 6 +++++-\n repository.c         | 2 +-\n 6 files changed, 10 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex fa7bd891692..b3be58b1fb0 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex d7f08c8a7fa..d9b76226f6a 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -11,7 +11,7 @@\n  *\n  * Copyright (C) 2016 Johannes Schindelin\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex fe853aa8f91..e3767087bbf 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"tree-walk.h\"\n #include \"xdiff-interface.h\"\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 4a2a6db2dce..1ab4de0005d 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -5,7 +5,7 @@\n  *\n  * Fetch one or more remote refs and merge it/them into the current HEAD.\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/cache.h b/cache.h\nindex 8b54b627459..72c3d4e2ef5 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -433,9 +433,11 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *);\n void prefetch_cache_entries(const struct index_state *istate,\n \t\t\t    must_prefetch_predicate must_prefetch);\n \n-#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n+#if defined(USE_THE_INDEX_COMPATIBILITY_MACROS) || defined(USE_THE_INDEX_VARIABLE)\n extern struct index_state the_index;\n \n+#ifndef USE_THE_INDEX_VARIABLE\n+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n #define active_nr (the_index.cache_nr)\n #define active_cache_tree (the_index.cache_tree)\n \n@@ -448,6 +450,8 @@ extern struct index_state the_index;\n #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)\n #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n+#endif\n+#endif\n \n #define TYPE_BITS 3\n \ndiff --git a/repository.c b/repository.c\nindex 5d166b692c8..3427085fd6d 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -2,7 +2,7 @@\n  * not really _using_ the compat macros, just make sure the_index\n  * declaration matches the definition in this file.\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"repository.h\"\n #include \"object-store.h\"\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467505","messageId":"patch-10.12-9eda7916e75-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 10/12] cache.h & test-tool.h: add & use \"USE_THE_INDEX_VARIABLE\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:31:04Z","receivedAt":"2022-11-18T11:31:45Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"In a preceding commit we fully applied the\n\"index-compatibility.pending.cocci\" rule to \"t/helper/*\". Let's now\nstop defining \"USE_THE_INDEX_COMPATIBILITY_MACROS\" in test-tool.h\nitself, and instead instead move the define to the individual test\nhelpers that need it. This mirrors how we do the same thing in the\n\"builtin/\" directory.\n\nWe could start using \"USE_THE_INDEX_COMPATIBILITY_MACROS\", but let's\ninstead introduce a narrow version of it named\n\"USE_THE_INDEX_VARIABLE\". As the name suggests this doesn't give us\nany of the compatibility macros, but only \"the_index\" variable.\n\nEventually we'll move other outstanding users of\n\"USE_THE_INDEX_COMPATIBILITY_MACROS\" over to using this more narrow\nand descriptive define.\n\nFor context: The USE_THE_INDEX_COMPATIBILITY_MACROS macro was added to\ntest-tool.h in f8adbec9fea (cache.h: flip\nNO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24).\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/helper/test-dump-cache-tree.c      | 1 +\n t/helper/test-dump-split-index.c     | 1 +\n t/helper/test-dump-untracked-cache.c | 2 +-\n t/helper/test-fast-rebase.c          | 2 +-\n t/helper/test-lazy-init-name-hash.c  | 1 +\n t/helper/test-read-cache.c           | 1 +\n t/helper/test-scrap-cache-tree.c     | 1 +\n t/helper/test-write-cache.c          | 1 +\n 8 files changed, 8 insertions(+), 2 deletions(-)\n\ndiff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c\nindex 4bf8bc3df6e..454f17b1a0c 100644\n--- a/t/helper/test-dump-cache-tree.c\n+++ b/t/helper/test-dump-cache-tree.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"tree.h\"\ndiff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c\nindex a209880eb37..0ea97b84072 100644\n--- a/t/helper/test-dump-split-index.c\n+++ b/t/helper/test-dump-split-index.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"split-index.h\"\ndiff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c\nindex ffe34736e53..6d53683f13b 100644\n--- a/t/helper/test-dump-untracked-cache.c\n+++ b/t/helper/test-dump-untracked-cache.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"dir.h\"\ndiff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c\nindex 9def2ba6889..efc82dd80c5 100644\n--- a/t/helper/test-fast-rebase.c\n+++ b/t/helper/test-fast-rebase.c\n@@ -10,7 +10,7 @@\n  * refactoring is the better route).\n  */\n \n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n \n #include \"cache-tree.h\"\ndiff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c\nindex 7e8723a1900..ab86c14c8ba 100644\n--- a/t/helper/test-lazy-init-name-hash.c\n+++ b/t/helper/test-lazy-init-name-hash.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"parse-options.h\"\ndiff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c\nindex a089be9104c..23e9e27109f 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"config.h\"\ndiff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c\nindex 9206dee1fd2..a26107ed70a 100644\n--- a/t/helper/test-scrap-cache-tree.c\n+++ b/t/helper/test-scrap-cache-tree.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"lockfile.h\"\ndiff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c\nindex 66287d6d47d..7d45cd61e82 100644\n--- a/t/helper/test-write-cache.c\n+++ b/t/helper/test-write-cache.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"lockfile.h\"\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467506","messageId":"patch-12.12-b69cf6d7600-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 12/12] builtin/*: remove or amend \"USE_THE_INDEX_COMPATIBILITY_MACROS\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:31:06Z","receivedAt":"2022-11-18T11:32:12Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Follow-up the preceding commit and change\n\"USE_THE_INDEX_COMPATIBILITY_MACROS\" to the more narrow\n\"USE_THE_INDEX_VARIABLE\" in cases where we still use \"the_index\".\n\nThen remove \"USE_THE_INDEX_VARIABLE\" entirely in the few cases where\nwe don't require any compatibility macros or variables anymore.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/add.c            | 2 +-\n builtin/check-attr.c     | 2 +-\n builtin/check-ignore.c   | 2 +-\n builtin/checkout-index.c | 2 +-\n builtin/clean.c          | 2 +-\n builtin/clone.c          | 2 +-\n builtin/describe.c       | 2 +-\n builtin/diff-files.c     | 1 -\n builtin/diff-index.c     | 1 -\n builtin/diff-tree.c      | 2 +-\n builtin/fsck.c           | 2 +-\n builtin/merge-index.c    | 2 +-\n builtin/merge-ours.c     | 1 -\n builtin/rebase.c         | 2 +-\n builtin/reset.c          | 2 +-\n builtin/rev-parse.c      | 2 +-\n 16 files changed, 13 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 566c27e5311..76277df326b 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) 2006 Linus Torvalds\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/check-attr.c b/builtin/check-attr.c\nindex 2b9271f816c..0fef10eb6bc 100644\n--- a/builtin/check-attr.c\n+++ b/builtin/check-attr.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex 6ebd0169fc8..ab776061c7c 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex 9087005b4fb..cf6fba97ba7 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -4,7 +4,7 @@\n  * Copyright (C) 2005 Linus Torvalds\n  *\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"dir.h\"\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex 7bdeb01d30e..b2701a28158 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -6,7 +6,7 @@\n  * Based on git-clean.sh by Pavel Roskin\n  */\n \n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 8ab0453a292..f518bb2dc1f 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -8,7 +8,7 @@\n  * Clone a repository into a different directory that does not yet exist.\n  */\n \n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 4f4a58eef2b..eea1e330c00 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/diff-files.c b/builtin/diff-files.c\nindex 1f3deb13c28..b1e1cef7a76 100644\n--- a/builtin/diff-files.c\n+++ b/builtin/diff-files.c\n@@ -3,7 +3,6 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"diff.h\"\ndiff --git a/builtin/diff-index.c b/builtin/diff-index.c\nindex a178e774a5a..91ad56af177 100644\n--- a/builtin/diff-index.c\n+++ b/builtin/diff-index.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"diff.h\"\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex a724087261d..25b853b85ca 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"diff.h\"\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex d6f9a31e216..d207bd909b4 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"repository.h\"\ndiff --git a/builtin/merge-index.c b/builtin/merge-index.c\nindex b1d98294cdd..452f833ac46 100644\n--- a/builtin/merge-index.c\n+++ b/builtin/merge-index.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"run-command.h\"\n \ndiff --git a/builtin/merge-ours.c b/builtin/merge-ours.c\nindex 5d95acf52a6..284eb486098 100644\n--- a/builtin/merge-ours.c\n+++ b/builtin/merge-ours.c\n@@ -7,7 +7,6 @@\n  *\n  * Pretend we resolved the heads, but declare our tree trumps everybody else.\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"git-compat-util.h\"\n #include \"builtin.h\"\n #include \"diff.h\"\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 345a55755a3..1384008fe09 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -4,7 +4,7 @@\n  * Copyright (c) 2018 Pratik Karki\n  */\n \n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"run-command.h\"\n #include \"exec-cmd.h\"\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 5ab03e9616a..52a1a9bd513 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -7,7 +7,7 @@\n  *\n  * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex bffdd27bd7e..d4c81352a65 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"commit.h\"\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467507","messageId":"patch-11.12-3cb15ff40f6-20221118T112205Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH 11/12] cocci: apply \"pending\" index-compatibility to some \"builtin/*.c\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T11:31:05Z","receivedAt":"2022-11-18T11:32:15Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Apply \"index-compatibility.pending.cocci\" rule to those \"builtin/*\",\nand commit the ones that have 3 uses or less of the relevant\nmacros.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/add.c            | 6 +++---\n builtin/check-attr.c     | 2 +-\n builtin/check-ignore.c   | 2 +-\n builtin/checkout-index.c | 7 ++++---\n builtin/clean.c          | 2 +-\n builtin/clone.c          | 2 +-\n builtin/describe.c       | 5 +++--\n builtin/diff-files.c     | 2 +-\n builtin/diff-index.c     | 4 ++--\n builtin/diff-tree.c      | 2 +-\n builtin/fsck.c           | 2 +-\n builtin/merge-index.c    | 4 ++--\n builtin/merge-ours.c     | 2 +-\n builtin/rebase.c         | 4 ++--\n builtin/reset.c          | 7 ++++---\n builtin/rev-parse.c      | 2 +-\n 16 files changed, 29 insertions(+), 26 deletions(-)\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 23f9f0e08bb..566c27e5311 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -312,7 +312,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)\n \n \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n \n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"Could not read the index\"));\n \n \trepo_init_revisions(the_repository, &rev, prefix);\n@@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n \t/*\n \t * Check the \"pathspec '%s' did not match any files\" block\n@@ -587,7 +587,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t\t (!(addremove || take_worktree_changes)\n \t\t  ? ADD_CACHE_IGNORE_REMOVAL : 0));\n \n-\tif (read_cache_preload(&pathspec) < 0)\n+\tif (repo_read_index_preload(the_repository, &pathspec, 0) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tdie_in_unpopulated_submodule(&the_index, prefix);\ndiff --git a/builtin/check-attr.c b/builtin/check-attr.c\nindex dd833977864..2b9271f816c 100644\n--- a/builtin/check-attr.c\n+++ b/builtin/check-attr.c\n@@ -115,7 +115,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)\n \targc = parse_options(argc, argv, prefix, check_attr_options,\n \t\t\t     check_attr_usage, PARSE_OPT_KEEP_DASHDASH);\n \n-\tif (read_cache() < 0) {\n+\tif (repo_read_index(the_repository) < 0) {\n \t\tdie(\"invalid cache\");\n \t}\n \ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex 21912569650..6ebd0169fc8 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -179,7 +179,7 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)\n \t\tdie(_(\"--non-matching is only valid with --verbose\"));\n \n \t/* read_cache() is only necessary so we can watch out for submodules. */\n-\tif (!no_index && read_cache() < 0)\n+\tif (!no_index && repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tsetup_standard_excludes(&dir);\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex c2aee450c40..9087005b4fb 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -65,7 +65,7 @@ static void write_tempfile_record(const char *name, const char *prefix)\n static int checkout_file(const char *name, const char *prefix)\n {\n \tint namelen = strlen(name);\n-\tint pos = cache_name_pos(name, namelen);\n+\tint pos = index_name_pos(&the_index, name, namelen);\n \tint has_same_name = 0;\n \tint is_file = 0;\n \tint is_skipped = 1;\n@@ -249,7 +249,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\tif (read_cache() < 0) {\n+\tif (repo_read_index(the_repository) < 0) {\n \t\tdie(\"invalid cache\");\n \t}\n \n@@ -270,7 +270,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \tif (index_opt && !state.base_dir_len && !to_tempfile) {\n \t\tstate.refresh_cache = 1;\n \t\tstate.istate = &the_index;\n-\t\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\t\trepo_hold_locked_index(the_repository, &lock_file,\n+\t\t\t\t       LOCK_DIE_ON_ERROR);\n \t}\n \n \tget_parallel_checkout_configs(&pc_workers, &pc_threshold);\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex 7084e685f6f..7bdeb01d30e 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -1012,7 +1012,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tpl = add_pattern_list(&dir, EXC_CMDL, \"--exclude option\");\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 0e4348686b6..8ab0453a292 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -703,7 +703,7 @@ static int checkout(int submodule_progress, int filter_submodules)\n \t/* We need to be in the new work tree for the checkout */\n \tsetup_work_tree();\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n \tmemset(&opts, 0, sizeof opts);\n \topts.update = 1;\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 23e3f05fb10..4f4a58eef2b 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -653,10 +653,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tint fd, result;\n \n \t\t\tsetup_work_tree();\n-\t\t\tread_cache();\n+\t\t\trepo_read_index(the_repository);\n \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\n-\t\t\tfd = hold_locked_index(&index_lock, 0);\n+\t\t\tfd = repo_hold_locked_index(the_repository,\n+\t\t\t\t\t\t    &index_lock, 0);\n \t\t\tif (0 <= fd)\n \t\t\t\trepo_update_index_if_able(the_repository, &index_lock);\n \ndiff --git a/builtin/diff-files.c b/builtin/diff-files.c\nindex 096ea2fedbc..1f3deb13c28 100644\n--- a/builtin/diff-files.c\n+++ b/builtin/diff-files.c\n@@ -76,7 +76,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)\n \t    (rev.diffopt.output_format & DIFF_FORMAT_PATCH))\n \t\tdiff_merges_set_dense_combined_if_unset(&rev);\n \n-\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n+\tif (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {\n \t\tperror(\"read_cache_preload\");\n \t\tresult = -1;\n \t\tgoto cleanup;\ndiff --git a/builtin/diff-index.c b/builtin/diff-index.c\nindex aea139b9d8f..a178e774a5a 100644\n--- a/builtin/diff-index.c\n+++ b/builtin/diff-index.c\n@@ -62,11 +62,11 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)\n \t\tusage(diff_cache_usage);\n \tif (!(option & DIFF_INDEX_CACHED)) {\n \t\tsetup_work_tree();\n-\t\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n+\t\tif (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {\n \t\t\tperror(\"read_cache_preload\");\n \t\t\treturn -1;\n \t\t}\n-\t} else if (read_cache() < 0) {\n+\t} else if (repo_read_index(the_repository) < 0) {\n \t\tperror(\"read_cache\");\n \t\treturn -1;\n \t}\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex 85e8c81e594..a724087261d 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -120,7 +120,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)\n \n \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n \trepo_init_revisions(the_repository, opt, prefix);\n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \topt->abbrev = 0;\n \topt->diff = 1;\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex cd47675e371..d6f9a31e216 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -958,7 +958,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \tif (keep_cache_objects) {\n \t\tverify_index_checksum = 1;\n \t\tverify_ce_order = 1;\n-\t\tread_cache();\n+\t\trepo_read_index(the_repository);\n \t\t/* TODO: audit for interaction with sparse-index. */\n \t\tensure_full_index(&the_index);\n \t\tfor (i = 0; i < the_index.cache_nr; i++) {\ndiff --git a/builtin/merge-index.c b/builtin/merge-index.c\nindex a334c513c9d..b1d98294cdd 100644\n--- a/builtin/merge-index.c\n+++ b/builtin/merge-index.c\n@@ -47,7 +47,7 @@ static int merge_entry(int pos, const char *path)\n \n static void merge_one_path(const char *path)\n {\n-\tint pos = cache_name_pos(path, strlen(path));\n+\tint pos = index_name_pos(&the_index, path, strlen(path));\n \n \t/*\n \t * If it already exists in the cache as stage0, it's\n@@ -82,7 +82,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix)\n \tif (argc < 3)\n \t\tusage(\"git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])\");\n \n-\tread_cache();\n+\trepo_read_index(the_repository);\n \n \t/* TODO: audit for interaction with sparse-index. */\n \tensure_full_index(&the_index);\ndiff --git a/builtin/merge-ours.c b/builtin/merge-ours.c\nindex 3583cff71c7..5d95acf52a6 100644\n--- a/builtin/merge-ours.c\n+++ b/builtin/merge-ours.c\n@@ -25,7 +25,7 @@ int cmd_merge_ours(int argc, const char **argv, const char *prefix)\n \t * commit.  The index must match HEAD, or this merge cannot go\n \t * through.\n \t */\n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie_errno(\"read_cache failed\");\n \tif (index_differs_from(the_repository, \"HEAD\", NULL, 0))\n \t\treturn 2;\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 5d855fd8f51..345a55755a3 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -292,7 +292,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)\n \tif (ret)\n \t\terror(_(\"could not generate todo list\"));\n \telse {\n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t\tif (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf,\n \t\t\t\t\t\t&todo_list))\n \t\t\tBUG(\"unusable todo list\");\n@@ -1268,7 +1268,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\tif (get_oid(\"HEAD\", &head))\n \t\t\tdie(_(\"Cannot read HEAD\"));\n \n-\t\tfd = hold_locked_index(&lock_file, 0);\n+\t\tfd = repo_hold_locked_index(the_repository, &lock_file, 0);\n \t\tif (repo_read_index(the_repository) < 0)\n \t\t\tdie(_(\"could not read index\"));\n \t\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 25ff76c17a3..5ab03e9616a 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -158,7 +158,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,\n \t\t * if this entry is outside the sparse cone - this is necessary\n \t\t * to properly construct the reset sparse directory.\n \t\t */\n-\t\tpos = cache_name_pos(one->path, strlen(one->path));\n+\t\tpos = index_name_pos(&the_index, one->path, strlen(one->path));\n \t\tif ((pos >= 0 && ce_skip_worktree(the_index.cache[pos])) ||\n \t\t    (pos < 0 && !path_in_sparse_checkout(one->path, &the_index)))\n \t\t\tce->ce_flags |= CE_SKIP_WORKTREE;\n@@ -421,7 +421,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \t/* Soft reset does not touch the index file nor the working tree\n@@ -432,7 +432,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \n \tif (reset_type != SOFT) {\n \t\tstruct lock_file lock = LOCK_INIT;\n-\t\thold_locked_index(&lock, LOCK_DIE_ON_ERROR);\n+\t\trepo_hold_locked_index(the_repository, &lock,\n+\t\t\t\t       LOCK_DIE_ON_ERROR);\n \t\tif (reset_type == MIXED) {\n \t\t\tint flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;\n \t\t\tif (read_from_tree(&pathspec, &oid, intent_to_add))\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 8f61050bde8..bffdd27bd7e 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -997,7 +997,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--shared-index-path\")) {\n-\t\t\t\tif (read_cache() < 0)\n+\t\t\t\tif (repo_read_index(the_repository) < 0)\n \t\t\t\t\tdie(_(\"Could not read the index\"));\n \t\t\t\tif (the_index.split_index) {\n \t\t\t\t\tconst struct object_id *oid = &the_index.split_index->base_oid;\n-- \n2.38.0.1511.gcdcff1f1dc2\n\n"},{"id":"467514","messageId":"51e91e8f-f11c-be8c-a23d-566eb3fbb387@dunelm.org.uk","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"Re: [PATCH 00/12] tree-wide: chip away at USE_THE_INDEX_COMPATIBILITY_MACROS","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-11-18T12:13:37Z","receivedAt":"2022-11-18T12:13:45Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Ævar\n\nOn 18/11/2022 11:30, Ævar Arnfjörð Bjarmason wrote:\n> As 3/12 here notes we've been undergoing a sloooow migration away from\n> functions that provide \"the_index\" for you since 2007, with the last\n> major move away from some of them being in 2019.\n\nThe commit cited in 3/12 actually introduced most of these macros. What \nit did was remove the dependency on `the_index` from cache.c. Maybe I'm \nmissing some context but I struggling to see the benefit in removing the \nmacros with out removing the dependency on `the_index`. Doing that would \nrequire much more manual work as it cannot be automated with coccinelle \nbut it would provide a tangible benefit which I don't see here.\n\nBest Wishes\n\nPhillip\n"},{"id":"467515","messageId":"221118.86v8ncfo1v.gmgdl@evledraar.gmail.com","threadId":"58812","inReplyTo":"51e91e8f-f11c-be8c-a23d-566eb3fbb387@dunelm.org.uk","subject":"Re: [PATCH 00/12] tree-wide: chip away at USE_THE_INDEX_COMPATIBILITY_MACROS","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T12:21:27Z","receivedAt":"2022-11-18T12:24:34Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Nov 18 2022, Phillip Wood wrote:\n\n> Hi Ævar\n>\n> On 18/11/2022 11:30, Ævar Arnfjörð Bjarmason wrote:\n>> As 3/12 here notes we've been undergoing a sloooow migration away from\n>> functions that provide \"the_index\" for you since 2007, with the last\n>> major move away from some of them being in 2019.\n>\n> The commit cited in 3/12 actually introduced most of these\n> macros. What it did was remove the dependency on `the_index` from\n> cache.c. Maybe I'm missing some context but I struggling to see the\n> benefit in removing the macros with out removing the dependency on\n> `the_index`. Doing that would require much more manual work as it\n> cannot be automated with coccinelle but it would provide a tangible\n> benefit which I don't see here.\n\nI didn't cover this myself as I figured the linked-to commits & context\ncovered it: But no, there is no great benefit to doing this, it's just\njanitorial work.\n\nMy proximate motivation for this is having written this to libify some\ncode in a parallel series: [1].\n\nDoes that in itself justify this? No, far from it. But we've had this\nsupposed online migration for years, I tihnk we shouldn't rush to do\nthose sorts of things needlessly (e.g. let's avoid conflicts with other\nin-flight stuff, if it can be helped), but leaving it for another 4-10\nyears would also suck.\n\n1. https://lore.kernel.org/git/patch-v9-09.12-f29343197eb-20221118T110058Z-avarab@gmail.com/\n\n"},{"id":"467528","messageId":"Y3fRv4sQFCJ/qIic@nand.local","threadId":"58812","inReplyTo":"patch-09.12-5b69cfa17ad-20221118T112205Z-avarab@gmail.com","subject":"Re: [PATCH 09/12] {builtin/*,repository}.c: add & use \"USE_THE_INDEX_VARIABLE\"","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-11-18T18:41:03Z","receivedAt":"2022-11-18T18:41:10Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Nov 18, 2022 at 12:31:03PM +0100, Ævar Arnfjörð Bjarmason wrote:\n> Split up the \"USE_THE_INDEX_COMPATIBILITY_MACROS\" into that setting\n> and a more narrow \"USE_THE_INDEX_VARIABLE\". In the case of these\n> built-ins we only need \"the_index\" variable, but not the compatibility\n> wrapper for functions we're not using.\n\nOK. So the old \"#define USE_THE_INDEX_COMPATIBILITY_MACROS\" used to give\nyou the \"the_index\" extern, as well as all of the helper macros.\n\nBut now, USE_THE_INDEX_VARIABLE gives you just \"the_index\", and\nUSE_THE_INDEX_COMPATIBILITY_MACROS gives you that as well as the helper\nmacros, but you only get the latter if USE_THE_INDEX_VARIABLE is unset.\n\nMakes sense.\n\nThanks,\nTaylor\n"},{"id":"467529","messageId":"Y3fR7NMkfVKtfB4J@nand.local","threadId":"58812","inReplyTo":"patch-10.12-9eda7916e75-20221118T112205Z-avarab@gmail.com","subject":"Re: [PATCH 10/12] cache.h & test-tool.h: add & use \"USE_THE_INDEX_VARIABLE\"","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-11-18T18:41:48Z","receivedAt":"2022-11-18T18:41:54Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Nov 18, 2022 at 12:31:04PM +0100, Ævar Arnfjörð Bjarmason wrote:\n> In a preceding commit we fully applied the\n> \"index-compatibility.pending.cocci\" rule to \"t/helper/*\". Let's now\n> stop defining \"USE_THE_INDEX_COMPATIBILITY_MACROS\" in test-tool.h\n> itself, and instead instead move the define to the individual test\n> helpers that need it. This mirrors how we do the same thing in the\n> \"builtin/\" directory.\n>\n> We could start using \"USE_THE_INDEX_COMPATIBILITY_MACROS\", but let's\n> instead introduce a narrow version of it named\n> \"USE_THE_INDEX_VARIABLE\". As the name suggests this doesn't give us\n> any of the compatibility macros, but only \"the_index\" variable.\n>\n> Eventually we'll move other outstanding users of\n> \"USE_THE_INDEX_COMPATIBILITY_MACROS\" over to using this more narrow\n> and descriptive define.\n\nThe above two paragraphs look like they belong in the previous commit,\nno?\n\nOtherwise the rest of the changes here look reasonable.\n\nThanks,\nTaylor\n"},{"id":"467530","messageId":"Y3fSJwm7qoVmvPA8@nand.local","threadId":"58812","inReplyTo":"patch-12.12-b69cf6d7600-20221118T112205Z-avarab@gmail.com","subject":"Re: [PATCH 12/12] builtin/*: remove or amend \"USE_THE_INDEX_COMPATIBILITY_MACROS\"","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-11-18T18:42:47Z","receivedAt":"2022-11-18T18:42:52Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Nov 18, 2022 at 12:31:06PM +0100, Ævar Arnfjörð Bjarmason wrote:\n> Follow-up the preceding commit and change\n> \"USE_THE_INDEX_COMPATIBILITY_MACROS\" to the more narrow\n> \"USE_THE_INDEX_VARIABLE\" in cases where we still use \"the_index\".\n>\n> Then remove \"USE_THE_INDEX_VARIABLE\" entirely in the few cases where\n> we don't require any compatibility macros or variables anymore.\n\nCould this get squashed into the previous commit? IOW, is there any\nreason to keep them separate?\n\nThanks,\nTaylor\n"},{"id":"467534","messageId":"221118.86mt8of3hi.gmgdl@evledraar.gmail.com","threadId":"58812","inReplyTo":"Y3fSJwm7qoVmvPA8@nand.local","subject":"Re: [PATCH 12/12] builtin/*: remove or amend \"USE_THE_INDEX_COMPATIBILITY_MACROS\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-18T19:27:25Z","receivedAt":"2022-11-18T19:48:47Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Nov 18 2022, Taylor Blau wrote:\n\n> On Fri, Nov 18, 2022 at 12:31:06PM +0100, Ævar Arnfjörð Bjarmason wrote:\n>> Follow-up the preceding commit and change\n>> \"USE_THE_INDEX_COMPATIBILITY_MACROS\" to the more narrow\n>> \"USE_THE_INDEX_VARIABLE\" in cases where we still use \"the_index\".\n>>\n>> Then remove \"USE_THE_INDEX_VARIABLE\" entirely in the few cases where\n>> we don't require any compatibility macros or variables anymore.\n>\n> Could this get squashed into the previous commit? IOW, is there any\n> reason to keep them separate?\n\nI figured it would be easier to review if I split out the changes that\nare coccinelle-created v.s. the ones I made manually.\n\nBut I don't have a preference at all, whatever you think is easier.\n\nThis *could* also be a 3 patch series, which I'd prefer, but figured it\nwould get push-back, so I thought I'd spoon-feed the list.\n\nI.e. just:\n\n 1. Fix discard_index() return value\n 2. Add and apply the *.cocci rule to *ALL THE THINGS*\"\n 3. Narrow down the macro for t/helper/*\n\nAt that point we wouldn't need \"USE_THE_INDEX_VARIABLE\", as we'd have\nnothing except \"the_index\", so \"USE_THE_INDEX_COMPATIBILITY_MACROS\"\nwould do exactly what \"USE_THE_INDEX_VARIABLE\" does in this topic.\n\n(We could still rename it, but I think probably the churn isn't worth it\nif it's not a stop-gap to new macro use being re-introduced)\n\nIt would rip the band-aid off, there's conflicts, but the --remerge-diff\nwith \"seen\" is rather easy, or:\n\n\tdiff --git a/builtin/commit.c b/builtin/commit.c\n\tremerge CONFLICT (content): Merge conflict in builtin/commit.c\n\tindex 4fb7604cc24..c7dbdb2a866 100644\n\t--- a/builtin/commit.c\n\t+++ b/builtin/commit.c\n\t@@ -991,16 +991,11 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n\t \t\tstruct object_id oid;\n\t \t\tconst char *parent = \"HEAD\";\n\t \n\t-<<<<<<< c23106a1d9f (hi)\n\t-\t\tif (!the_index.cache_nr && repo_read_index(the_repository) < 0)\n\t-\t\t\tdie(_(\"Cannot read index\"));\n\t-=======\n\t-\t\tif (!active_nr) {\n\t-\t\t\tdiscard_cache();\n\t-\t\t\tif (read_cache() < 0)\n\t+\t\tif (!the_index.cache_nr) {\n\t+\t\t\tdiscard_index(&the_index);\n\t+\t\t\tif (repo_read_index(the_repository) < 0)\n\t \t\t\t\tdie(_(\"Cannot read index\"));\n\t \t\t}\n\t->>>>>>> 75ae5b855fb (Merge branch 'rj/branch-copy-and-rename' into seen)\n\t \n\t \t\tif (amend)\n\t \t\t\tparent = \"HEAD^1\";\n\tdiff --git a/builtin/read-tree.c b/builtin/read-tree.c\n\tremerge CONFLICT (content): Merge conflict in builtin/read-tree.c\n\tindex 5dcf0d09ed1..5d6e638c4b1 100644\n\t--- a/builtin/read-tree.c\n\t+++ b/builtin/read-tree.c\n\t@@ -250,15 +250,11 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n\t \tif (opts.debug_unpack)\n\t \t\topts.fn = debug_merge;\n\t \n\t-<<<<<<< c23106a1d9f (hi)\n\t-\tcache_tree_free(&the_index.cache_tree);\n\t-=======\n\t \t/* If we're going to prime_cache_tree later, skip cache tree update */\n\t \tif (nr_trees == 1 && !opts.prefix)\n\t \t\topts.skip_cache_tree_update = 1;\n\t \n\t-\tcache_tree_free(&active_cache_tree);\n\t->>>>>>> 75ae5b855fb (Merge branch 'rj/branch-copy-and-rename' into seen)\n\t+\tcache_tree_free(&the_index.cache_tree);\n\t \tfor (i = 0; i < nr_trees; i++) {\n\t \t\tstruct tree *tree = trees[i];\n\t \t\tparse_tree(tree);\n\tdiff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c\n\tindex 93051b25f56..5514afdfe7a 100644\n\t--- a/t/helper/test-cache-tree.c\n\t+++ b/t/helper/test-cache-tree.c\n\t@@ -30,7 +30,7 @@ int cmd__cache_tree(int argc, const char **argv)\n\t \n\t \targc = parse_options(argc, argv, NULL, options, test_cache_tree_usage, 0);\n\t \n\t-\tif (read_cache() < 0)\n\t+\tif (repo_read_index(the_repository) < 0)\n\t \t\tdie(_(\"unable to read index file\"));\n\t \n\t \toidcpy(&oid, &the_index.cache_tree->oid);\n\t\n...and can also be applied by a \"take theirs\", re-run the cocci, apply\ncocci patch, so no manual resolution needed. Any future conflicts would\nbe solved with the same procedure.\n\nThe diff would be just under ~2k lines, but pretty trivial in terms of\nnon-cocci changes.\n\nAnyway, just let me know. Right now I'm assuming I'll just re-roll this\n(pending any further feedback for a bit) with squashing & some other\nminor changes...\n"},{"id":"467539","messageId":"Y3gPjQubrF+/v4Vd@nand.local","threadId":"58812","inReplyTo":"221118.86mt8of3hi.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH 12/12] builtin/*: remove or amend \"USE_THE_INDEX_COMPATIBILITY_MACROS\"","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-11-18T23:04:45Z","receivedAt":"2022-11-18T23:19:32Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Nov 18, 2022 at 08:27:25PM +0100, Ævar Arnfjörð Bjarmason wrote:\n>\n> On Fri, Nov 18 2022, Taylor Blau wrote:\n>\n> > On Fri, Nov 18, 2022 at 12:31:06PM +0100, Ævar Arnfjörð Bjarmason wrote:\n> >> Follow-up the preceding commit and change\n> >> \"USE_THE_INDEX_COMPATIBILITY_MACROS\" to the more narrow\n> >> \"USE_THE_INDEX_VARIABLE\" in cases where we still use \"the_index\".\n> >>\n> >> Then remove \"USE_THE_INDEX_VARIABLE\" entirely in the few cases where\n> >> we don't require any compatibility macros or variables anymore.\n> >\n> > Could this get squashed into the previous commit? IOW, is there any\n> > reason to keep them separate?\n>\n> I figured it would be easier to review if I split out the changes that\n> are coccinelle-created v.s. the ones I made manually.\n>\n> But I don't have a preference at all, whatever you think is easier.\n\nI think the 11-patch structure makes most sense to me (basically what\nyou have, with the last couple squashed together).\n\nThanks,\nTaylor\n"},{"id":"467577","messageId":"patch-v2-01.11-3ddae1f5886-20221119T125550Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 01/11] cache.h: remove unused \"the_index\" compat macros","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:28Z","receivedAt":"2022-11-19T13:07:52Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The \"active_alloc\" macro added in 228e94f9357 (Move index-related\nvariables into a structure., 2007-04-01) has not been used since\n4aab5b46f44 (Make read-cache.c \"the_index\" free., 2007-04-01). Let's\nremove it.\n\nThe rest of these are likewise unused, so let's not keep them\naround. E.g. 12cd0bf9b02 (dir: stop using the index compatibility\nmacros, 2017-05-05) is the last use of \"cache_dir_exists\".\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n cache.h | 5 -----\n 1 file changed, 5 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 26ed03bd6de..29bb0ad2b41 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -438,7 +438,6 @@ extern struct index_state the_index;\n \n #define active_cache (the_index.cache)\n #define active_nr (the_index.cache_nr)\n-#define active_alloc (the_index.cache_alloc)\n #define active_cache_changed (the_index.cache_changed)\n #define active_cache_tree (the_index.cache_tree)\n \n@@ -452,7 +451,6 @@ extern struct index_state the_index;\n #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))\n #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))\n #define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))\n-#define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos))\n #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))\n #define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags))\n #define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags))\n@@ -461,13 +459,10 @@ extern struct index_state the_index;\n #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)\n #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))\n #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))\n-#define cache_dir_exists(name, namelen) index_dir_exists(&the_index, (name), (namelen))\n #define cache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))\n #define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))\n #define resolve_undo_clear() resolve_undo_clear_index(&the_index)\n #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)\n-#define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)\n-#define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))\n #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n \n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467578","messageId":"patch-v2-02.11-3dd3af7b7bb-20221119T125550Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 02/11] builtin/{grep,log}.: don't define \"USE_THE_INDEX_COMPATIBILITY_MACROS\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:29Z","receivedAt":"2022-11-19T13:07:55Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Adding \"USE_THE_INDEX_COMPATIBILITY_MACROS\" to these two appears to\nhave been unnecessary from the start, as going back and compiling\nf8adbec9fea (cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch,\n2019-01-24) without that addition works.\n\nLet's not have these ask for the compatibility macros from cache.h\nthat they don't need.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/grep.c | 1 -\n builtin/log.c  | 1 -\n 2 files changed, 2 deletions(-)\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 5fa927d4e22..f7821c5fbba 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -3,7 +3,6 @@\n  *\n  * Copyright (c) 2006 Junio C Hamano\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"repository.h\"\n #include \"config.h\"\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 5eafcf26b49..89447a50838 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -4,7 +4,6 @@\n  * (C) Copyright 2006 Linus Torvalds\n  *\t\t 2006 Junio Hamano\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"refs.h\"\n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467579","messageId":"patch-v2-03.11-5c2776a28f7-20221119T125550Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 03/11] cocci & cache.h: remove rarely used \"the_index\" compat macros","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:30Z","receivedAt":"2022-11-19T13:07:57Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since 4aab5b46f44 (Make read-cache.c \"the_index\" free., 2007-04-01)\nwe've been undergoing a slow migration away from these macros, but\nhaven't made much progress since f8adbec9fea (cache.h: flip\nNO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24).\n\nLet's move forward a bit by changing the users of those macros that\nare rare enough that we can convert them in one go, and then remove\nthe compatibility shim.\n\nThe only manual change to the C code here is to \"cache.h\", the rest is\nall the result of applying the new \"index-compatibility.cocci\".\n\nEven though it's a one-off, let's keep the coccinelle rules for\nnow. We'll extend them in subsequent commits, and this will help\nanything that's in-flight or out-of-tree to migrate.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/add.c                                |  5 ++-\n builtin/am.c                                 |  4 +-\n builtin/checkout.c                           |  4 +-\n builtin/clean.c                              |  2 +-\n builtin/commit.c                             |  2 +-\n builtin/merge.c                              |  2 +-\n builtin/mv.c                                 |  4 +-\n builtin/pull.c                               |  4 +-\n builtin/read-tree.c                          |  4 +-\n builtin/reset.c                              |  4 +-\n builtin/update-index.c                       |  4 +-\n cache.h                                      | 10 -----\n contrib/coccinelle/index-compatibility.cocci | 45 ++++++++++++++++++++\n 13 files changed, 65 insertions(+), 29 deletions(-)\n create mode 100644 contrib/coccinelle/index-compatibility.cocci\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 626c71ec6aa..75be1d021ab 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -55,7 +55,7 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)\n \t\t\tcontinue;\n \n \t\tif (!show_only)\n-\t\t\terr = chmod_cache_entry(ce, flip);\n+\t\t\terr = chmod_index_entry(&the_index, ce, flip);\n \t\telse\n \t\t\terr = S_ISREG(ce->ce_mode) ? 0 : -1;\n \n@@ -172,7 +172,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)\n \t\t\tcontinue; /* do not touch non blobs */\n \t\tif (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))\n \t\t\tcontinue;\n-\t\tretval |= add_file_to_cache(ce->name, flags | ADD_CACHE_RENORMALIZE);\n+\t\tretval |= add_file_to_index(&the_index, ce->name,\n+\t\t\t\t\t    flags | ADD_CACHE_RENORMALIZE);\n \t}\n \n \treturn retval;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 20aea0d2487..f362a1c29fd 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1930,7 +1930,7 @@ static void am_resolve(struct am_state *state, int allow_empty)\n \t\t}\n \t}\n \n-\tif (unmerged_cache()) {\n+\tif (unmerged_index(&the_index)) {\n \t\tprintf_ln(_(\"You still have unmerged paths in your index.\\n\"\n \t\t\t\"You should 'git add' each file with resolved conflicts to mark them as such.\\n\"\n \t\t\t\"You might run `git rm` on a file to accept \\\"deleted by them\\\" for it.\"));\n@@ -2045,7 +2045,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem\n \tif (!remote_tree)\n \t\treturn error(_(\"Could not parse object '%s'.\"), oid_to_hex(remote));\n \n-\tread_cache_unmerged();\n+\trepo_read_index_unmerged(the_repository);\n \n \tif (fast_forward_to(head_tree, head_tree, 1))\n \t\treturn -1;\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 2a132392fbe..aa610b274e3 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -722,7 +722,7 @@ static void init_topts(struct unpack_trees_options *topts, int merge,\n \n \tsetup_unpack_trees_porcelain(topts, \"checkout\");\n \n-\ttopts->initial_checkout = is_cache_unborn();\n+\ttopts->initial_checkout = is_index_unborn(&the_index);\n \ttopts->update = 1;\n \ttopts->merge = 1;\n \ttopts->quiet = merge && old_commit;\n@@ -763,7 +763,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \n \t\trefresh_cache(REFRESH_QUIET);\n \n-\t\tif (unmerged_cache()) {\n+\t\tif (unmerged_index(&the_index)) {\n \t\t\terror(_(\"you need to resolve your current index first\"));\n \t\t\treturn 1;\n \t\t}\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex 40ff2c578de..7084e685f6f 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -1031,7 +1031,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \t\tstruct stat st;\n \t\tconst char *rel;\n \n-\t\tif (!cache_name_is_other(ent->name, ent->len))\n+\t\tif (!index_name_is_other(&the_index, ent->name, ent->len))\n \t\t\tcontinue;\n \n \t\tif (lstat(ent->name, &st))\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex e22bdf23f5f..985503d43a6 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -302,7 +302,7 @@ static void add_remove_files(struct string_list *list)\n \t\t\tcontinue;\n \n \t\tif (!lstat(p->string, &st)) {\n-\t\t\tif (add_to_cache(p->string, &st, 0))\n+\t\t\tif (add_to_index(&the_index, p->string, &st, 0))\n \t\t\t\tdie(_(\"updating files failed\"));\n \t\t} else\n \t\t\tremove_file_from_cache(p->string);\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex b3f75f55c8a..da11dfae19e 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1375,7 +1375,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\tgoto done;\n \t}\n \n-\tif (read_cache_unmerged())\n+\tif (repo_read_index_unmerged(the_repository))\n \t\tdie_resolve_conflict(\"merge\");\n \n \tif (file_exists(git_path_merge_head(the_repository))) {\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 3413ad1c9b1..df6157fd6b5 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -343,7 +343,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\targc += last - first;\n \t\t\tgoto act_on_entry;\n \t\t}\n-\t\tif (!(ce = cache_file_exists(src, length, 0))) {\n+\t\tif (!(ce = index_file_exists(&the_index, src, length, 0))) {\n \t\t\tbad = _(\"not under version control\");\n \t\t\tgoto act_on_entry;\n \t\t}\n@@ -472,7 +472,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tassert(pos >= 0);\n \t\tif (!(mode & SPARSE) && !lstat(src, &st))\n \t\t\tsparse_and_dirty = ce_modified(active_cache[pos], &st, 0);\n-\t\trename_cache_entry_at(pos, dst);\n+\t\trename_index_entry_at(&the_index, pos, dst);\n \n \t\tif (ignore_sparse &&\n \t\t    core_apply_sparse_checkout &&\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex b21edd767aa..4a2a6db2dce 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -1030,7 +1030,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \tif (opt_rebase < 0)\n \t\topt_rebase = config_get_rebase(&rebase_unspecified);\n \n-\tif (read_cache_unmerged())\n+\tif (repo_read_index_unmerged(the_repository))\n \t\tdie_resolve_conflict(\"pull\");\n \n \tif (file_exists(git_path_merge_head(the_repository)))\n@@ -1043,7 +1043,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \t\tif (opt_autostash == -1)\n \t\t\topt_autostash = config_autostash;\n \n-\t\tif (is_null_oid(&orig_head) && !is_cache_unborn())\n+\t\tif (is_null_oid(&orig_head) && !is_index_unborn(&the_index))\n \t\t\tdie(_(\"Updating an unborn branch with changes added to the index.\"));\n \n \t\tif (!opt_autostash)\ndiff --git a/builtin/read-tree.c b/builtin/read-tree.c\nindex 45c6652444b..fd708273101 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -188,7 +188,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \t */\n \n \tif (opts.reset || opts.merge || opts.prefix) {\n-\t\tif (read_cache_unmerged() && (opts.prefix || opts.merge))\n+\t\tif (repo_read_index_unmerged(the_repository) && (opts.prefix || opts.merge))\n \t\t\tdie(_(\"You need to resolve your current index first\"));\n \t\tstage = opts.merge = 1;\n \t}\n@@ -232,7 +232,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \t\t\tbreak;\n \t\tcase 2:\n \t\t\topts.fn = twoway_merge;\n-\t\t\topts.initial_checkout = is_cache_unborn();\n+\t\t\topts.initial_checkout = is_index_unborn(&the_index);\n \t\t\tbreak;\n \t\tcase 3:\n \t\tdefault:\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex ab027774824..e561180e8c4 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -84,7 +84,7 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t\n \t\tBUG(\"invalid reset_type passed to reset_index\");\n \t}\n \n-\tread_cache_unmerged();\n+\trepo_read_index_unmerged(the_repository);\n \n \tif (reset_type == KEEP) {\n \t\tstruct object_id head_oid;\n@@ -220,7 +220,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,\n \n static void die_if_unmerged_cache(int reset_type)\n {\n-\tif (is_merge() || unmerged_cache())\n+\tif (is_merge() || unmerged_index(&the_index))\n \t\tdie(_(\"Cannot do a %s reset in the middle of a merge.\"),\n \t\t    _(reset_type_names[reset_type]));\n \ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex 7b0c924d7d4..e1b2bb78e72 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -445,7 +445,7 @@ static void chmod_path(char flip, const char *path)\n \tif (pos < 0)\n \t\tgoto fail;\n \tce = active_cache[pos];\n-\tif (chmod_cache_entry(ce, flip) < 0)\n+\tif (chmod_index_entry(&the_index, ce, flip) < 0)\n \t\tgoto fail;\n \n \treport(\"chmod %cx '%s'\", flip, path);\n@@ -641,7 +641,7 @@ static int unresolve_one(const char *path)\n \tpos = cache_name_pos(path, namelen);\n \tif (0 <= pos) {\n \t\t/* already merged */\n-\t\tpos = unmerge_cache_entry_at(pos);\n+\t\tpos = unmerge_index_entry_at(&the_index, pos);\n \t\tif (pos < active_nr) {\n \t\t\tconst struct cache_entry *ce = active_cache[pos];\n \t\t\tif (ce_stage(ce) &&\ndiff --git a/cache.h b/cache.h\nindex 29bb0ad2b41..53dc4341717 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -444,25 +444,15 @@ extern struct index_state the_index;\n #define read_cache() repo_read_index(the_repository)\n #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))\n #define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)\n-#define is_cache_unborn() is_index_unborn(&the_index)\n-#define read_cache_unmerged() repo_read_index_unmerged(the_repository)\n #define discard_cache() discard_index(&the_index)\n-#define unmerged_cache() unmerged_index(&the_index)\n #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))\n #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))\n-#define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))\n #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))\n-#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags))\n-#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags))\n-#define chmod_cache_entry(ce, flip) chmod_index_entry(&the_index, (ce), (flip))\n #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)\n #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)\n #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))\n #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))\n-#define cache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))\n-#define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))\n #define resolve_undo_clear() resolve_undo_clear_index(&the_index)\n-#define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)\n #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n \ndiff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci\nnew file mode 100644\nindex 00000000000..04207c409e1\n--- /dev/null\n+++ b/contrib/coccinelle/index-compatibility.cocci\n@@ -0,0 +1,45 @@\n+// \"the_repository\" simple cases\n+@@\n+@@\n+(\n+- read_cache_unmerged\n++ repo_read_index_unmerged\n+)\n+  (\n++ the_repository,\n+  ...)\n+\n+// \"the_index\" simple cases\n+@@\n+@@\n+(\n+- is_cache_unborn\n++ is_index_unborn\n+|\n+- unmerged_cache\n++ unmerged_index\n+|\n+- rename_cache_entry_at\n++ rename_index_entry_at\n+|\n+- chmod_cache_entry\n++ chmod_index_entry\n+|\n+- cache_file_exists\n++ index_file_exists\n+|\n+- cache_name_is_other\n++ index_name_is_other\n+|\n+- unmerge_cache_entry_at\n++ unmerge_index_entry_at\n+|\n+- add_to_cache\n++ add_to_index\n+|\n+- add_file_to_cache\n++ add_file_to_index\n+)\n+  (\n++ &the_index,\n+  ...)\n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467581","messageId":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com","subject":"[PATCH v2 00/11] tree-wide: chip away at USE_THE_INDEX_COMPATIBILITY_MACROS","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:27Z","receivedAt":"2022-11-19T13:07:58Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"A re-roll that should address feedback on v1[1]. Change since v1:\n\n* Since \"vd/skip-cache-tree-update\" has landed on \"master\" the\n  \"test-tool.h\" can stop providing\n  \"USE_THE_INDEX_COMPATIBILITY_MACROS\" to the test tools, which we're\n  unlikely to have a semantic conflict for while this graduates.\n\n  A change in 7/12 is due to rebasing on that topic, ditto applying\n  the transformation in 8/12 to code it added.\n\n* The 11/12 is now quite a bit larger, and now does the\n  transformations that don't conflict with anything in-flight.\n  I.e. (aside from needing to eject v1 of this topic) it'll merge\n  cleanly with \"seen\"\n\n  Hopfully that expanded scope isn't stepping too much outside the\n  bounds here. But once \"vd/skip-cache-tree-update\" had landed just\n  applying it to the rest that didn't conflict didn't seem too\n  bad. It's a relatively large diffstat, but not that much on top of\n  the v1, and it's almost entirely a change coccinelle is making\".\n\n1. https://lore.kernel.org/git/cover-00.12-00000000000-20221118T112205Z-avarab@gmail.com/\n\nBranch & passing CI at:\nhttps://github.com/avar/git/tree/avar/narrow-down-the-index-compatibilty-macros-2\n\nÆvar Arnfjörð Bjarmason (11):\n  cache.h: remove unused \"the_index\" compat macros\n  builtin/{grep,log}.: don't define \"USE_THE_INDEX_COMPATIBILITY_MACROS\"\n  cocci & cache.h: remove rarely used \"the_index\" compat macros\n  read-cache API & users: make discard_index() return void\n  cocci: add a index-compatibility.pending.cocci\n  cocci & cache.h: apply a selection of \"pending\" index-compatibility\n  cocci & cache.h: apply variable section of \"pending\"\n    index-compatibility\n  cocci: apply \"pending\" index-compatibility to \"t/helper/*.c\"\n  {builtin/*,repository}.c: add & use \"USE_THE_INDEX_VARIABLE\"\n  cache.h & test-tool.h: add & use \"USE_THE_INDEX_VARIABLE\"\n  cocci: apply \"pending\" index-compatibility to some \"builtin/*.c\"\n\n add-interactive.c                             |   8 +-\n add-patch.c                                   |   3 +-\n builtin/add.c                                 |  21 +--\n builtin/am.c                                  |  25 ++--\n builtin/cat-file.c                            |   2 +-\n builtin/check-attr.c                          |   4 +-\n builtin/check-ignore.c                        |   4 +-\n builtin/checkout-index.c                      |  19 +--\n builtin/checkout.c                            |  67 ++++-----\n builtin/clean.c                               |   6 +-\n builtin/clone.c                               |   4 +-\n builtin/commit.c                              |  60 ++++----\n builtin/describe.c                            |   7 +-\n builtin/diff-files.c                          |   5 +-\n builtin/diff-index.c                          |   9 +-\n builtin/diff-tree.c                           |   4 +-\n builtin/diff.c                                |  25 ++--\n builtin/difftool.c                            |   2 +-\n builtin/fsck.c                                |  16 +--\n builtin/grep.c                                |   1 -\n builtin/log.c                                 |   1 -\n builtin/merge-index.c                         |  16 +--\n builtin/merge-ours.c                          |   3 +-\n builtin/merge-tree.c                          |   2 +-\n builtin/merge.c                               |  32 +++--\n builtin/mv.c                                  |  41 +++---\n builtin/pull.c                                |   6 +-\n builtin/read-tree.c                           |  12 +-\n builtin/rebase.c                              |   6 +-\n builtin/reset.c                               |  20 +--\n builtin/rev-parse.c                           |   4 +-\n builtin/rm.c                                  |  26 ++--\n builtin/stash.c                               |  43 +++---\n builtin/submodule--helper.c                   |  28 ++--\n builtin/update-index.c                        |  91 ++++++------\n cache.h                                       |  36 +----\n contrib/coccinelle/index-compatibility.cocci  | 135 ++++++++++++++++++\n .../index-compatibility.pending.cocci         |  24 ++++\n read-cache.c                                  |   4 +-\n repository.c                                  |   2 +-\n sequencer.c                                   |  15 +-\n t/helper/test-cache-tree.c                    |   3 +-\n t/helper/test-dump-cache-tree.c               |   5 +-\n t/helper/test-dump-split-index.c              |   1 +\n t/helper/test-dump-untracked-cache.c          |   4 +-\n t/helper/test-fast-rebase.c                   |   4 +-\n t/helper/test-lazy-init-name-hash.c           |  21 +--\n t/helper/test-read-cache.c                    |   5 +-\n t/helper/test-scrap-cache-tree.c              |   9 +-\n t/helper/test-tool.h                          |   1 -\n t/helper/test-write-cache.c                   |   6 +-\n 51 files changed, 532 insertions(+), 366 deletions(-)\n create mode 100644 contrib/coccinelle/index-compatibility.cocci\n create mode 100644 contrib/coccinelle/index-compatibility.pending.cocci\n\nRange-diff against v1:\n 1:  760b4ddf06a =  1:  3ddae1f5886 cache.h: remove unused \"the_index\" compat macros\n 2:  9789509a902 =  2:  3dd3af7b7bb builtin/{grep,log}.: don't define \"USE_THE_INDEX_COMPATIBILITY_MACROS\"\n 3:  faa7757cb32 =  3:  5c2776a28f7 cocci & cache.h: remove rarely used \"the_index\" compat macros\n 4:  362a14a0539 =  4:  b4d6685585a read-cache API & users: make discard_index() return void\n 5:  14bf6e7188c =  5:  ec740a81d9f cocci: add a index-compatibility.pending.cocci\n 6:  dbf14ed23e6 =  6:  6849233bf2b cocci & cache.h: apply a selection of \"pending\" index-compatibility\n 7:  bf507c79d07 !  7:  fff2d0459a0 cocci & cache.h: apply variable section of \"pending\" index-compatibility\n    @@ Commit message\n         In doing so move more of \"index-compatibility.pending.cocci\" to\n         \"index-compatibility.cocci\".\n     \n    -    In the case of \"active_cache_tree\" we'd have a textual conflict with\n    -    \"vd/skip-cache-tree-update\" in \"next\"[1], and in the case of\n    -    \"active_nr\" with \"ab/various-leak-fixes\" in \"seen\". Let's exclude\n    -    those specific cases while moving the rule over from \"pending\".\n    +    In the case of \"active_nr\" we'd have a textual conflict with\n    +    \"ab/various-leak-fixes\" in \"next\"[1]. Let's exclude that specific case\n    +    while moving the rule over from \"pending\".\n     \n    -    1. dc5d40f5bc4 (read-tree: use 'skip_cache_tree_update' option,\n    -       2022-11-10)\n    +    1. 407b94280f8 (commit: discard partial cache before (re-)reading it,\n    +       2022-11-08)\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n    @@ builtin/mv.c: int cmd_mv(int argc, const char **argv, const char *prefix)\n      \t\t\t\t/*\n      \t\t\t\t * if src is clean, it will suffice to remove it\n     \n    + ## builtin/read-tree.c ##\n    +@@ builtin/read-tree.c: int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n    + \tif (nr_trees == 1 && !opts.prefix)\n    + \t\topts.skip_cache_tree_update = 1;\n    + \n    +-\tcache_tree_free(&active_cache_tree);\n    ++\tcache_tree_free(&the_index.cache_tree);\n    + \tfor (i = 0; i < nr_trees; i++) {\n    + \t\tstruct tree *tree = trees[i];\n    + \t\tparse_tree(tree);\n    +\n      ## builtin/reset.c ##\n     @@ builtin/reset.c: static void update_index_from_diff(struct diff_queue_struct *q,\n      \t\t * to properly construct the reset sparse directory.\n    @@ cache.h: void prefetch_cache_entries(const struct index_state *istate,\n     -#define active_cache (the_index.cache)\n      #define active_nr (the_index.cache_nr)\n     -#define active_cache_changed (the_index.cache_changed)\n    - #define active_cache_tree (the_index.cache_tree)\n    +-#define active_cache_tree (the_index.cache_tree)\n      \n      #define read_cache() repo_read_index(the_repository)\n    + #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))\n     \n      ## contrib/coccinelle/index-compatibility.cocci ##\n     @@\n    @@ contrib/coccinelle/index-compatibility.cocci\n     +|\n     +- active_cache_changed\n     ++ the_index.cache_changed\n    ++|\n    ++- active_cache_tree\n    +++ the_index.cache_tree\n     +)\n     +\n     +@@\n    @@ contrib/coccinelle/index-compatibility.cocci\n     +- active_nr\n     ++ the_index.cache_nr\n     +  ...>}\n    -+\n    -+@@\n    -+identifier f != cmd_read_tree;\n    -+@@\n    -+  f(...) {<...\n    -+- active_cache_tree\n    -++ the_index.cache_tree\n    -+  ...>}\n     +\n      // \"the_repository\" simple cases\n      @@\n 8:  f3e265e6edb !  8:  6d57a383623 cocci: apply \"pending\" index-compatibility to \"t/helper/*.c\"\n    @@ Commit message\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n    + ## t/helper/test-cache-tree.c ##\n    +@@ t/helper/test-cache-tree.c: int cmd__cache_tree(int argc, const char **argv)\n    + \n    + \targc = parse_options(argc, argv, NULL, options, test_cache_tree_usage, 0);\n    + \n    +-\tif (read_cache() < 0)\n    ++\tif (repo_read_index(the_repository) < 0)\n    + \t\tdie(_(\"unable to read index file\"));\n    + \n    + \toidcpy(&oid, &the_index.cache_tree->oid);\n    +\n      ## t/helper/test-dump-cache-tree.c ##\n     @@ t/helper/test-dump-cache-tree.c: int cmd__dump_cache_tree(int ac, const char **av)\n      \tint ret;\n 9:  5b69cfa17ad !  9:  429eecc78ec {builtin/*,repository}.c: add & use \"USE_THE_INDEX_VARIABLE\"\n    @@ Commit message\n         built-ins we only need \"the_index\" variable, but not the compatibility\n         wrapper for functions we're not using.\n     \n    +    Let's then have some users of \"USE_THE_INDEX_COMPATIBILITY_MACROS\" use\n    +    this more narrow and descriptive define.\n    +\n    +    For context: The USE_THE_INDEX_COMPATIBILITY_MACROS macro was added to\n    +    test-tool.h in f8adbec9fea (cache.h: flip\n    +    NO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24).\n    +\n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n      ## builtin/cat-file.c ##\n    @@ cache.h: typedef int (*must_prefetch_predicate)(const struct cache_entry *);\n     +#ifndef USE_THE_INDEX_VARIABLE\n     +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n      #define active_nr (the_index.cache_nr)\n    - #define active_cache_tree (the_index.cache_tree)\n      \n    + #define read_cache() repo_read_index(the_repository)\n     @@ cache.h: extern struct index_state the_index;\n      #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)\n      #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n10:  9eda7916e75 ! 10:  5456859b244 cache.h & test-tool.h: add & use \"USE_THE_INDEX_VARIABLE\"\n    @@ Commit message\n         cache.h & test-tool.h: add & use \"USE_THE_INDEX_VARIABLE\"\n     \n         In a preceding commit we fully applied the\n    -    \"index-compatibility.pending.cocci\" rule to \"t/helper/*\". Let's now\n    -    stop defining \"USE_THE_INDEX_COMPATIBILITY_MACROS\" in test-tool.h\n    -    itself, and instead instead move the define to the individual test\n    -    helpers that need it. This mirrors how we do the same thing in the\n    -    \"builtin/\" directory.\n    +    \"index-compatibility.pending.cocci\" rule to \"t/helper/*\".\n     \n    -    We could start using \"USE_THE_INDEX_COMPATIBILITY_MACROS\", but let's\n    -    instead introduce a narrow version of it named\n    -    \"USE_THE_INDEX_VARIABLE\". As the name suggests this doesn't give us\n    -    any of the compatibility macros, but only \"the_index\" variable.\n    -\n    -    Eventually we'll move other outstanding users of\n    -    \"USE_THE_INDEX_COMPATIBILITY_MACROS\" over to using this more narrow\n    -    and descriptive define.\n    -\n    -    For context: The USE_THE_INDEX_COMPATIBILITY_MACROS macro was added to\n    -    test-tool.h in f8adbec9fea (cache.h: flip\n    -    NO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24).\n    +    Let's now stop defining \"USE_THE_INDEX_COMPATIBILITY_MACROS\" in\n    +    test-tool.h itself, and instead instead define\n    +    \"USE_THE_INDEX_VARIABLE\" in the individual test helpers that need\n    +    it. This mirrors how we do the same thing in the \"builtin/\" directory.\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n    + ## t/helper/test-cache-tree.c ##\n    +@@\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"test-tool.h\"\n    + #include \"cache.h\"\n    + #include \"tree.h\"\n    +\n      ## t/helper/test-dump-cache-tree.c ##\n     @@\n     +#define USE_THE_INDEX_VARIABLE\n    @@ t/helper/test-scrap-cache-tree.c\n      #include \"cache.h\"\n      #include \"lockfile.h\"\n     \n    + ## t/helper/test-tool.h ##\n    +@@\n    + #ifndef TEST_TOOL_H\n    + #define TEST_TOOL_H\n    + \n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    + #include \"git-compat-util.h\"\n    + \n    + int cmd__advise_if_enabled(int argc, const char **argv);\n    +\n      ## t/helper/test-write-cache.c ##\n     @@\n     +#define USE_THE_INDEX_VARIABLE\n11:  3cb15ff40f6 ! 11:  b645cec189e cocci: apply \"pending\" index-compatibility to some \"builtin/*.c\"\n    @@ Metadata\n      ## Commit message ##\n         cocci: apply \"pending\" index-compatibility to some \"builtin/*.c\"\n     \n    -    Apply \"index-compatibility.pending.cocci\" rule to those \"builtin/*\",\n    -    and commit the ones that have 3 uses or less of the relevant\n    -    macros.\n    +    Apply \"index-compatibility.pending.cocci\" rule to \"builtin/*\", but\n    +    exclude those where we conflict with in-flight changes.\n    +\n    +    As a result some of them end up using only \"the_index\", so let's have\n    +    them use the more narrow \"USE_THE_INDEX_VARIABLE\" rather than\n    +    \"USE_THE_INDEX_COMPATIBILITY_MACROS\".\n    +\n    +    Manual changes not made by coccinelle, that were squashed in:\n    +\n    +    * Whitespace-wrap argument lists for repo_hold_locked_index(),\n    +      repo_read_index_preload() and repo_refresh_and_write_index(), in cases\n    +      where the line became too long after the transformation.\n    +    * Change \"refresh_cache()\" to \"refresh_index()\" in a comment in\n    +      \"builtin/update-index.c\".\n    +    * For those whose call was followed by perror(\"<macro-name>\"), change\n    +      it to perror(\"<function-name>\"), referring to the new function.\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n      ## builtin/add.c ##\n    +@@\n    +  *\n    +  * Copyright (C) 2006 Linus Torvalds\n    +  */\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"cache.h\"\n    + #include \"config.h\"\n    + #include \"builtin.h\"\n     @@ builtin/add.c: static int edit_patch(int argc, const char **argv, const char *prefix)\n      \n      \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n    @@ builtin/add.c: int cmd_add(int argc, const char **argv, const char *prefix)\n      \n      \tdie_in_unpopulated_submodule(&the_index, prefix);\n     \n    + ## builtin/am.c ##\n    +@@ builtin/am.c: static int run_apply(const struct am_state *state, const char *index_file)\n    + \n    + \tif (index_file) {\n    + \t\t/* Reload index as apply_all_patches() will have modified it. */\n    +-\t\tdiscard_cache();\n    +-\t\tread_cache_from(index_file);\n    ++\t\tdiscard_index(&the_index);\n    ++\t\tread_index_from(&the_index, index_file, get_git_dir());\n    + \t}\n    + \n    + \treturn 0;\n    +@@ builtin/am.c: static int fall_back_threeway(const struct am_state *state, const char *index_pa\n    + \tif (build_fake_ancestor(state, index_path))\n    + \t\treturn error(\"could not build fake ancestor\");\n    + \n    +-\tdiscard_cache();\n    +-\tread_cache_from(index_path);\n    ++\tdiscard_index(&the_index);\n    ++\tread_index_from(&the_index, index_path, get_git_dir());\n    + \n    + \tif (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))\n    + \t\treturn error(_(\"Repository lacks necessary blobs to fall back on 3-way merge.\"));\n    +@@ builtin/am.c: static int fall_back_threeway(const struct am_state *state, const char *index_pa\n    + \n    + \tsay(state, stdout, _(\"Falling back to patching base and 3-way merge...\"));\n    + \n    +-\tdiscard_cache();\n    +-\tread_cache();\n    ++\tdiscard_index(&the_index);\n    ++\trepo_read_index(the_repository);\n    + \n    + \t/*\n    + \t * This is not so wrong. Depending on which base we picked, orig_tree\n    +@@ builtin/am.c: static void am_run(struct am_state *state, int resume)\n    + \n    + \tunlink(am_path(state, \"dirtyindex\"));\n    + \n    +-\tif (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0)\n    ++\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,\n    ++\t\t\t\t\t NULL, NULL, NULL) < 0)\n    + \t\tdie(_(\"unable to write index file\"));\n    + \n    + \tif (repo_index_has_changes(the_repository, NULL, &sb)) {\n    +@@ builtin/am.c: static int fast_forward_to(struct tree *head, struct tree *remote, int reset)\n    + \tif (parse_tree(head) || parse_tree(remote))\n    + \t\treturn -1;\n    + \n    +-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n    ++\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n    + \n    +-\trefresh_cache(REFRESH_QUIET);\n    ++\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n    + \n    + \tmemset(&opts, 0, sizeof(opts));\n    + \topts.head_idx = 1;\n    +@@ builtin/am.c: static int merge_tree(struct tree *tree)\n    + \tif (parse_tree(tree))\n    + \t\treturn -1;\n    + \n    +-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n    ++\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n    + \n    + \tmemset(&opts, 0, sizeof(opts));\n    + \topts.head_idx = 1;\n    +\n      ## builtin/check-attr.c ##\n    +@@\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"cache.h\"\n    + #include \"config.h\"\n     @@ builtin/check-attr.c: int cmd_check_attr(int argc, const char **argv, const char *prefix)\n      \targc = parse_options(argc, argv, prefix, check_attr_options,\n      \t\t\t     check_attr_usage, PARSE_OPT_KEEP_DASHDASH);\n    @@ builtin/check-attr.c: int cmd_check_attr(int argc, const char **argv, const char\n      \n     \n      ## builtin/check-ignore.c ##\n    +@@\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"cache.h\"\n    + #include \"config.h\"\n     @@ builtin/check-ignore.c: int cmd_check_ignore(int argc, const char **argv, const char *prefix)\n      \t\tdie(_(\"--non-matching is only valid with --verbose\"));\n      \n    @@ builtin/check-ignore.c: int cmd_check_ignore(int argc, const char **argv, const\n      \tsetup_standard_excludes(&dir);\n     \n      ## builtin/checkout-index.c ##\n    +@@\n    +  * Copyright (C) 2005 Linus Torvalds\n    +  *\n    +  */\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"config.h\"\n    + #include \"dir.h\"\n     @@ builtin/checkout-index.c: static void write_tempfile_record(const char *name, const char *prefix)\n      static int checkout_file(const char *name, const char *prefix)\n      {\n    @@ builtin/checkout-index.c: int cmd_checkout_index(int argc, const char **argv, co\n      \n      \tget_parallel_checkout_configs(&pc_workers, &pc_threshold);\n     \n    + ## builtin/checkout.c ##\n    +@@\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"advice.h\"\n    + #include \"blob.h\"\n    +@@ builtin/checkout.c: static int update_some(const struct object_id *oid, struct strbuf *base,\n    + \t * entry in place. Whether it is UPTODATE or not, checkout_entry will\n    + \t * do the right thing.\n    + \t */\n    +-\tpos = cache_name_pos(ce->name, ce->ce_namelen);\n    ++\tpos = index_name_pos(&the_index, ce->name, ce->ce_namelen);\n    + \tif (pos >= 0) {\n    + \t\tstruct cache_entry *old = the_index.cache[pos];\n    + \t\tif (ce->ce_mode == old->ce_mode &&\n    +@@ builtin/checkout.c: static int checkout_paths(const struct checkout_opts *opts,\n    + \t}\n    + \n    + \trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n    +-\tif (read_cache_preload(&opts->pathspec) < 0)\n    ++\tif (repo_read_index_preload(the_repository, &opts->pathspec, 0) < 0)\n    + \t\treturn error(_(\"index file corrupt\"));\n    + \n    + \tif (opts->source_tree)\n    +@@ builtin/checkout.c: static int merge_working_tree(const struct checkout_opts *opts,\n    + \tstruct lock_file lock_file = LOCK_INIT;\n    + \tstruct tree *new_tree;\n    + \n    +-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n    +-\tif (read_cache_preload(NULL) < 0)\n    ++\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n    ++\tif (repo_read_index_preload(the_repository, NULL, 0) < 0)\n    + \t\treturn error(_(\"index file corrupt\"));\n    + \n    + \tresolve_undo_clear_index(&the_index);\n    +@@ builtin/checkout.c: static int merge_working_tree(const struct checkout_opts *opts,\n    + \t\tstruct unpack_trees_options topts;\n    + \t\tconst struct object_id *old_commit_oid;\n    + \n    +-\t\trefresh_cache(REFRESH_QUIET);\n    ++\t\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n    + \n    + \t\tif (unmerged_index(&the_index)) {\n    + \t\t\terror(_(\"you need to resolve your current index first\"));\n    +\n      ## builtin/clean.c ##\n    +@@\n    +  * Based on git-clean.sh by Pavel Roskin\n    +  */\n    + \n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"cache.h\"\n    + #include \"config.h\"\n     @@ builtin/clean.c: int cmd_clean(int argc, const char **argv, const char *prefix)\n      \tprepare_repo_settings(the_repository);\n      \tthe_repository->settings.command_requires_full_index = 0;\n    @@ builtin/clean.c: int cmd_clean(int argc, const char **argv, const char *prefix)\n      \tpl = add_pattern_list(&dir, EXC_CMDL, \"--exclude option\");\n     \n      ## builtin/clone.c ##\n    +@@\n    +  * Clone a repository into a different directory that does not yet exist.\n    +  */\n    + \n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"config.h\"\n    + #include \"lockfile.h\"\n     @@ builtin/clone.c: static int checkout(int submodule_progress, int filter_submodules)\n      \t/* We need to be in the new work tree for the checkout */\n      \tsetup_work_tree();\n    @@ builtin/clone.c: static int checkout(int submodule_progress, int filter_submodul\n      \tmemset(&opts, 0, sizeof opts);\n      \topts.update = 1;\n     \n    + ## builtin/commit.c ##\n    +@@ builtin/commit.c: static void create_base_index(const struct commit *current_head)\n    + \tstruct tree_desc t;\n    + \n    + \tif (!current_head) {\n    +-\t\tdiscard_cache();\n    ++\t\tdiscard_index(&the_index);\n    + \t\treturn;\n    + \t}\n    + \n    +@@ builtin/commit.c: static void refresh_cache_or_die(int refresh_flags)\n    + \t * refresh_flags contains REFRESH_QUIET, so the only errors\n    + \t * are for unmerged entries.\n    + \t */\n    +-\tif (refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN))\n    ++\tif (refresh_index(&the_index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))\n    + \t\tdie_resolve_conflict(\"commit\");\n    + }\n    + \n    +@@ builtin/commit.c: static const char *prepare_index(const char **argv, const char *prefix,\n    + \t    (!amend || (fixup_message && strcmp(fixup_prefix, \"amend\"))))))\n    + \t\tdie(_(\"No paths with --include/--only does not make sense.\"));\n    + \n    +-\tif (read_cache_preload(&pathspec) < 0)\n    ++\tif (repo_read_index_preload(the_repository, &pathspec, 0) < 0)\n    + \t\tdie(_(\"index file corrupt\"));\n    + \n    + \tif (interactive) {\n    + \t\tchar *old_index_env = NULL, *old_repo_index_file;\n    +-\t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n    ++\t\trepo_hold_locked_index(the_repository, &index_lock,\n    ++\t\t\t\t       LOCK_DIE_ON_ERROR);\n    + \n    + \t\trefresh_cache_or_die(refresh_flags);\n    + \n    +@@ builtin/commit.c: static const char *prepare_index(const char **argv, const char *prefix,\n    + \t\t\tunsetenv(INDEX_ENVIRONMENT);\n    + \t\tFREE_AND_NULL(old_index_env);\n    + \n    +-\t\tdiscard_cache();\n    +-\t\tread_cache_from(get_lock_file_path(&index_lock));\n    ++\t\tdiscard_index(&the_index);\n    ++\t\tread_index_from(&the_index, get_lock_file_path(&index_lock),\n    ++\t\t\t\tget_git_dir());\n    + \t\tif (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {\n    + \t\t\tif (reopen_lock_file(&index_lock) < 0)\n    + \t\t\t\tdie(_(\"unable to write index file\"));\n    +@@ builtin/commit.c: static const char *prepare_index(const char **argv, const char *prefix,\n    + \t * (B) on failure, rollback the real index.\n    + \t */\n    + \tif (all || (also && pathspec.nr)) {\n    +-\t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n    ++\t\trepo_hold_locked_index(the_repository, &index_lock,\n    ++\t\t\t\t       LOCK_DIE_ON_ERROR);\n    + \t\tadd_files_to_cache(also ? prefix : NULL, &pathspec, 0);\n    + \t\trefresh_cache_or_die(refresh_flags);\n    + \t\tupdate_main_cache_tree(WRITE_TREE_SILENT);\n    +@@ builtin/commit.c: static const char *prepare_index(const char **argv, const char *prefix,\n    + \t * We still need to refresh the index here.\n    + \t */\n    + \tif (!only && !pathspec.nr) {\n    +-\t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n    ++\t\trepo_hold_locked_index(the_repository, &index_lock,\n    ++\t\t\t\t       LOCK_DIE_ON_ERROR);\n    + \t\trefresh_cache_or_die(refresh_flags);\n    + \t\tif (the_index.cache_changed\n    + \t\t    || !cache_tree_fully_valid(the_index.cache_tree))\n    +@@ builtin/commit.c: static const char *prepare_index(const char **argv, const char *prefix,\n    + \tif (list_paths(&partial, !current_head ? NULL : \"HEAD\", &pathspec))\n    + \t\texit(1);\n    + \n    +-\tdiscard_cache();\n    +-\tif (read_cache() < 0)\n    ++\tdiscard_index(&the_index);\n    ++\tif (repo_read_index(the_repository) < 0)\n    + \t\tdie(_(\"cannot read the index\"));\n    + \n    +-\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n    ++\trepo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);\n    + \tadd_remove_files(&partial);\n    +-\trefresh_cache(REFRESH_QUIET);\n    ++\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n    + \tupdate_main_cache_tree(WRITE_TREE_SILENT);\n    + \tif (write_locked_index(&the_index, &index_lock, 0))\n    + \t\tdie(_(\"unable to write new_index file\"));\n    +@@ builtin/commit.c: static const char *prepare_index(const char **argv, const char *prefix,\n    + \n    + \tcreate_base_index(current_head);\n    + \tadd_remove_files(&partial);\n    +-\trefresh_cache(REFRESH_QUIET);\n    ++\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n    + \n    + \tif (write_locked_index(&the_index, &false_lock, 0))\n    + \t\tdie(_(\"unable to write temporary index file\"));\n    + \n    +-\tdiscard_cache();\n    ++\tdiscard_index(&the_index);\n    + \tret = get_lock_file_path(&false_lock);\n    +-\tread_cache_from(ret);\n    ++\tread_index_from(&the_index, ret, get_git_dir());\n    + out:\n    + \tstring_list_clear(&partial, 0);\n    + \tclear_pathspec(&pathspec);\n    +@@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,\n    + \t\t * and could have updated it. We must do this before we invoke\n    + \t\t * the editor and after we invoke run_status above.\n    + \t\t */\n    +-\t\tdiscard_cache();\n    ++\t\tdiscard_index(&the_index);\n    + \t}\n    +-\tread_cache_from(index_file);\n    ++\tread_index_from(&the_index, index_file, get_git_dir());\n    + \n    + \tif (update_main_cache_tree(0)) {\n    + \t\terror(_(\"Error building trees\"));\n    +@@ builtin/commit.c: int cmd_status(int argc, const char **argv, const char *prefix)\n    + \t\t      &s.pathspec, NULL, NULL);\n    + \n    + \tif (use_optional_locks())\n    +-\t\tfd = hold_locked_index(&index_lock, 0);\n    ++\t\tfd = repo_hold_locked_index(the_repository, &index_lock, 0);\n    + \telse\n    + \t\tfd = -1;\n    + \n    +\n      ## builtin/describe.c ##\n    +@@\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"cache.h\"\n    + #include \"config.h\"\n    + #include \"lockfile.h\"\n     @@ builtin/describe.c: int cmd_describe(int argc, const char **argv, const char *prefix)\n      \t\t\tint fd, result;\n      \n    @@ builtin/describe.c: int cmd_describe(int argc, const char **argv, const char *pr\n      \n     \n      ## builtin/diff-files.c ##\n    +@@\n    +  *\n    +  * Copyright (C) Linus Torvalds, 2005\n    +  */\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    + #include \"cache.h\"\n    + #include \"config.h\"\n    + #include \"diff.h\"\n     @@ builtin/diff-files.c: int cmd_diff_files(int argc, const char **argv, const char *prefix)\n      \t    (rev.diffopt.output_format & DIFF_FORMAT_PATCH))\n      \t\tdiff_merges_set_dense_combined_if_unset(&rev);\n      \n     -\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n    +-\t\tperror(\"read_cache_preload\");\n     +\tif (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {\n    - \t\tperror(\"read_cache_preload\");\n    ++\t\tperror(\"repo_read_index_preload\");\n      \t\tresult = -1;\n      \t\tgoto cleanup;\n    + \t}\n     \n      ## builtin/diff-index.c ##\n    +@@\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    + #include \"cache.h\"\n    + #include \"config.h\"\n    + #include \"diff.h\"\n     @@ builtin/diff-index.c: int cmd_diff_index(int argc, const char **argv, const char *prefix)\n      \t\tusage(diff_cache_usage);\n      \tif (!(option & DIFF_INDEX_CACHED)) {\n      \t\tsetup_work_tree();\n     -\t\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n    +-\t\t\tperror(\"read_cache_preload\");\n     +\t\tif (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {\n    - \t\t\tperror(\"read_cache_preload\");\n    ++\t\t\tperror(\"repo_read_index_preload\");\n      \t\t\treturn -1;\n      \t\t}\n     -\t} else if (read_cache() < 0) {\n    +-\t\tperror(\"read_cache\");\n     +\t} else if (repo_read_index(the_repository) < 0) {\n    - \t\tperror(\"read_cache\");\n    ++\t\tperror(\"repo_read_index\");\n      \t\treturn -1;\n      \t}\n    + \tresult = run_diff_index(&rev, option);\n     \n      ## builtin/diff-tree.c ##\n    +@@\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"cache.h\"\n    + #include \"config.h\"\n    + #include \"diff.h\"\n     @@ builtin/diff-tree.c: int cmd_diff_tree(int argc, const char **argv, const char *prefix)\n      \n      \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n    @@ builtin/diff-tree.c: int cmd_diff_tree(int argc, const char **argv, const char *\n      \topt->abbrev = 0;\n      \topt->diff = 1;\n     \n    + ## builtin/diff.c ##\n    +@@\n    +  *\n    +  * Copyright (c) 2006 Junio C Hamano\n    +  */\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"cache.h\"\n    + #include \"config.h\"\n    + #include \"ewah/ewok.h\"\n    +@@ builtin/diff.c: static int builtin_diff_index(struct rev_info *revs,\n    + \t\tusage(builtin_diff_usage);\n    + \tif (!(option & DIFF_INDEX_CACHED)) {\n    + \t\tsetup_work_tree();\n    +-\t\tif (read_cache_preload(&revs->diffopt.pathspec) < 0) {\n    +-\t\t\tperror(\"read_cache_preload\");\n    ++\t\tif (repo_read_index_preload(the_repository,\n    ++\t\t\t\t\t    &revs->diffopt.pathspec, 0) < 0) {\n    ++\t\t\tperror(\"repo_read_index_preload\");\n    + \t\t\treturn -1;\n    + \t\t}\n    +-\t} else if (read_cache() < 0) {\n    +-\t\tperror(\"read_cache\");\n    ++\t} else if (repo_read_index(the_repository) < 0) {\n    ++\t\tperror(\"repo_read_cache\");\n    + \t\treturn -1;\n    + \t}\n    + \treturn run_diff_index(revs, option);\n    +@@ builtin/diff.c: static void refresh_index_quietly(void)\n    + \tstruct lock_file lock_file = LOCK_INIT;\n    + \tint fd;\n    + \n    +-\tfd = hold_locked_index(&lock_file, 0);\n    ++\tfd = repo_hold_locked_index(the_repository, &lock_file, 0);\n    + \tif (fd < 0)\n    + \t\treturn;\n    +-\tdiscard_cache();\n    +-\tread_cache();\n    +-\trefresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);\n    ++\tdiscard_index(&the_index);\n    ++\trepo_read_index(the_repository);\n    ++\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL,\n    ++\t\t      NULL);\n    + \trepo_update_index_if_able(the_repository, &lock_file);\n    + }\n    + \n    +@@ builtin/diff.c: static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv\n    + \t\tdiff_merges_set_dense_combined_if_unset(revs);\n    + \n    + \tsetup_work_tree();\n    +-\tif (read_cache_preload(&revs->diffopt.pathspec) < 0) {\n    +-\t\tperror(\"read_cache_preload\");\n    ++\tif (repo_read_index_preload(the_repository, &revs->diffopt.pathspec,\n    ++\t\t\t\t    0) < 0) {\n    ++\t\tperror(\"repo_read_index_preload\");\n    + \t\treturn -1;\n    + \t}\n    + \treturn run_diff_files(revs, options);\n    +\n      ## builtin/fsck.c ##\n    +@@\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"cache.h\"\n    + #include \"repository.h\"\n     @@ builtin/fsck.c: int cmd_fsck(int argc, const char **argv, const char *prefix)\n      \tif (keep_cache_objects) {\n      \t\tverify_index_checksum = 1;\n    @@ builtin/fsck.c: int cmd_fsck(int argc, const char **argv, const char *prefix)\n      \t\tfor (i = 0; i < the_index.cache_nr; i++) {\n     \n      ## builtin/merge-index.c ##\n    +@@\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"run-command.h\"\n    + \n     @@ builtin/merge-index.c: static int merge_entry(int pos, const char *path)\n      \n      static void merge_one_path(const char *path)\n    @@ builtin/merge-index.c: int cmd_merge_index(int argc, const char **argv, const ch\n      \tensure_full_index(&the_index);\n     \n      ## builtin/merge-ours.c ##\n    +@@\n    +  *\n    +  * Pretend we resolved the heads, but declare our tree trumps everybody else.\n    +  */\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    + #include \"git-compat-util.h\"\n    + #include \"builtin.h\"\n    + #include \"diff.h\"\n     @@ builtin/merge-ours.c: int cmd_merge_ours(int argc, const char **argv, const char *prefix)\n      \t * commit.  The index must match HEAD, or this merge cannot go\n      \t * through.\n    @@ builtin/merge-ours.c: int cmd_merge_ours(int argc, const char **argv, const char\n      \tif (index_differs_from(the_repository, \"HEAD\", NULL, 0))\n      \t\treturn 2;\n     \n    + ## builtin/merge.c ##\n    +@@ builtin/merge.c: static int save_state(struct object_id *stash)\n    + \tint rc = -1;\n    + \n    + \tfd = repo_hold_locked_index(the_repository, &lock_file, 0);\n    +-\trefresh_cache(REFRESH_QUIET);\n    ++\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n    + \tif (0 <= fd)\n    + \t\trepo_update_index_if_able(the_repository, &lock_file);\n    + \trollback_lock_file(&lock_file);\n    +@@ builtin/merge.c: static int try_merge_strategy(const char *strategy, struct commit_list *common,\n    + {\n    + \tconst char *head_arg = \"HEAD\";\n    + \n    +-\tif (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0)\n    ++\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET,\n    ++\t\t\t\t\t SKIP_IF_UNCHANGED, 0, NULL, NULL,\n    ++\t\t\t\t\t NULL) < 0)\n    + \t\treturn error(_(\"Unable to write index.\"));\n    + \n    + \tif (!strcmp(strategy, \"recursive\") || !strcmp(strategy, \"subtree\") ||\n    +@@ builtin/merge.c: static int try_merge_strategy(const char *strategy, struct commit_list *common,\n    + \t\tfor (j = common; j; j = j->next)\n    + \t\t\tcommit_list_insert(j->item, &reversed);\n    + \n    +-\t\thold_locked_index(&lock, LOCK_DIE_ON_ERROR);\n    ++\t\trepo_hold_locked_index(the_repository, &lock,\n    ++\t\t\t\t       LOCK_DIE_ON_ERROR);\n    + \t\tif (!strcmp(strategy, \"ort\"))\n    + \t\t\tclean = merge_ort_recursive(&o, head, remoteheads->item,\n    + \t\t\t\t\t\t    reversed, &result);\n    +@@ builtin/merge.c: static void prepare_to_commit(struct commit_list *remoteheads)\n    + \t\t * the editor and after we invoke run_status above.\n    + \t\t */\n    + \t\tif (invoked_hook)\n    +-\t\t\tdiscard_cache();\n    ++\t\t\tdiscard_index(&the_index);\n    + \t}\n    +-\tread_cache_from(index_file);\n    ++\tread_index_from(&the_index, index_file, get_git_dir());\n    + \tstrbuf_addbuf(&msg, &merge_msg);\n    + \tif (squash)\n    + \t\tBUG(\"the control must not reach here under --squash\");\n    +@@ builtin/merge.c: static int merge_trivial(struct commit *head, struct commit_list *remoteheads)\n    + \tstruct object_id result_tree, result_commit;\n    + \tstruct commit_list *parents, **pptr = &parents;\n    + \n    +-\tif (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0)\n    ++\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET,\n    ++\t\t\t\t\t SKIP_IF_UNCHANGED, 0, NULL, NULL,\n    ++\t\t\t\t\t NULL) < 0)\n    + \t\treturn error(_(\"Unable to write index.\"));\n    + \n    + \twrite_tree_trivial(&result_tree);\n    +@@ builtin/merge.c: int cmd_merge(int argc, const char **argv, const char *prefix)\n    + \t\t * We are not doing octopus, not fast-forward, and have\n    + \t\t * only one common.\n    + \t\t */\n    +-\t\trefresh_cache(REFRESH_QUIET);\n    ++\t\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n    + \t\tif (allow_trivial && fast_forward != FF_ONLY) {\n    + \t\t\t/*\n    + \t\t\t * Must first ensure that index matches HEAD before\n    +\n    + ## builtin/mv.c ##\n    +@@ builtin/mv.c: static int index_range_of_same_dir(const char *src, int length,\n    + \tconst char *src_w_slash = add_slash(src);\n    + \tint first, last, len_w_slash = length + 1;\n    + \n    +-\tfirst = cache_name_pos(src_w_slash, len_w_slash);\n    ++\tfirst = index_name_pos(&the_index, src_w_slash, len_w_slash);\n    + \tif (first >= 0)\n    + \t\tdie(_(\"%.*s is in index\"), len_w_slash, src_w_slash);\n    + \n    +@@ builtin/mv.c: static int empty_dir_has_sparse_contents(const char *name)\n    + \tconst char *with_slash = add_slash(name);\n    + \tint length = strlen(with_slash);\n    + \n    +-\tint pos = cache_name_pos(with_slash, length);\n    ++\tint pos = index_name_pos(&the_index, with_slash, length);\n    + \tconst struct cache_entry *ce;\n    + \n    + \tif (pos < 0) {\n    +@@ builtin/mv.c: int cmd_mv(int argc, const char **argv, const char *prefix)\n    + \tif (--argc < 1)\n    + \t\tusage_with_options(builtin_mv_usage, builtin_mv_options);\n    + \n    +-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n    +-\tif (read_cache() < 0)\n    ++\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n    ++\tif (repo_read_index(the_repository) < 0)\n    + \t\tdie(_(\"index file corrupt\"));\n    + \n    + \tsource = internal_prefix_pathspec(prefix, argv, argc, 0);\n    +@@ builtin/mv.c: int cmd_mv(int argc, const char **argv, const char *prefix)\n    + \t\t\tint pos;\n    + \t\t\tconst struct cache_entry *ce;\n    + \n    +-\t\t\tpos = cache_name_pos(src, length);\n    ++\t\t\tpos = index_name_pos(&the_index, src, length);\n    + \t\t\tif (pos < 0) {\n    + \t\t\t\tconst char *src_w_slash = add_slash(src);\n    + \t\t\t\tif (!path_in_sparse_checkout(src_w_slash, &the_index) &&\n    +@@ builtin/mv.c: int cmd_mv(int argc, const char **argv, const char *prefix)\n    + \t\t\t\tgoto act_on_entry;\n    + \t\t\t}\n    + \t\t\t/* Check if dst exists in index */\n    +-\t\t\tif (cache_name_pos(dst, strlen(dst)) < 0) {\n    ++\t\t\tif (index_name_pos(&the_index, dst, strlen(dst)) < 0) {\n    + \t\t\t\tmodes[i] |= SPARSE;\n    + \t\t\t\tgoto act_on_entry;\n    + \t\t\t}\n    +@@ builtin/mv.c: int cmd_mv(int argc, const char **argv, const char *prefix)\n    + dir_check:\n    + \t\tif (S_ISDIR(st.st_mode)) {\n    + \t\t\tint j, dst_len, n;\n    +-\t\t\tint first = cache_name_pos(src, length), last;\n    ++\t\t\tint first = index_name_pos(&the_index, src, length), last;\n    + \n    + \t\t\tif (first >= 0) {\n    + \t\t\t\tprepare_move_submodule(src, first,\n    +@@ builtin/mv.c: int cmd_mv(int argc, const char **argv, const char *prefix)\n    + \t\tif (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR))\n    + \t\t\tcontinue;\n    + \n    +-\t\tpos = cache_name_pos(src, strlen(src));\n    ++\t\tpos = index_name_pos(&the_index, src, strlen(src));\n    + \t\tassert(pos >= 0);\n    + \t\tif (!(mode & SPARSE) && !lstat(src, &st))\n    + \t\t\tsparse_and_dirty = ie_modified(&the_index,\n    +\n    + ## builtin/read-tree.c ##\n    +@@\n    +  * Copyright (C) Linus Torvalds, 2005\n    +  */\n    + \n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"cache.h\"\n    + #include \"config.h\"\n    + #include \"lockfile.h\"\n    +@@ builtin/read-tree.c: int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n    + \tprepare_repo_settings(the_repository);\n    + \tthe_repository->settings.command_requires_full_index = 0;\n    + \n    +-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n    ++\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n    + \n    + \t/*\n    + \t * NEEDSWORK\n    +\n      ## builtin/rebase.c ##\n    +@@\n    +  * Copyright (c) 2018 Pratik Karki\n    +  */\n    + \n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"run-command.h\"\n    + #include \"exec-cmd.h\"\n     @@ builtin/rebase.c: static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)\n      \tif (ret)\n      \t\terror(_(\"could not generate todo list\"));\n    @@ builtin/rebase.c: int cmd_rebase(int argc, const char **argv, const char *prefix\n      \t\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,\n     \n      ## builtin/reset.c ##\n    +@@\n    +  *\n    +  * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano\n    +  */\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"config.h\"\n    + #include \"lockfile.h\"\n     @@ builtin/reset.c: static void update_index_from_diff(struct diff_queue_struct *q,\n      \t\t * if this entry is outside the sparse cone - this is necessary\n      \t\t * to properly construct the reset sparse directory.\n    @@ builtin/reset.c: int cmd_reset(int argc, const char **argv, const char *prefix)\n      \t\t\tif (read_from_tree(&pathspec, &oid, intent_to_add))\n     \n      ## builtin/rev-parse.c ##\n    +@@\n    +  *\n    +  * Copyright (C) Linus Torvalds, 2005\n    +  */\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"cache.h\"\n    + #include \"config.h\"\n    + #include \"commit.h\"\n     @@ builtin/rev-parse.c: int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n      \t\t\t\tcontinue;\n      \t\t\t}\n    @@ builtin/rev-parse.c: int cmd_rev_parse(int argc, const char **argv, const char *\n      \t\t\t\t\tdie(_(\"Could not read the index\"));\n      \t\t\t\tif (the_index.split_index) {\n      \t\t\t\t\tconst struct object_id *oid = &the_index.split_index->base_oid;\n    +\n    + ## builtin/rm.c ##\n    +@@ builtin/rm.c: static void submodules_absorb_gitdir_if_needed(void)\n    + \t\tint pos;\n    + \t\tconst struct cache_entry *ce;\n    + \n    +-\t\tpos = cache_name_pos(name, strlen(name));\n    ++\t\tpos = index_name_pos(&the_index, name, strlen(name));\n    + \t\tif (pos < 0) {\n    + \t\t\tpos = get_ours_cache_pos(name, pos);\n    + \t\t\tif (pos < 0)\n    +@@ builtin/rm.c: static int check_local_mod(struct object_id *head, int index_only)\n    + \t\tint local_changes = 0;\n    + \t\tint staged_changes = 0;\n    + \n    +-\t\tpos = cache_name_pos(name, strlen(name));\n    ++\t\tpos = index_name_pos(&the_index, name, strlen(name));\n    + \t\tif (pos < 0) {\n    + \t\t\t/*\n    + \t\t\t * Skip unmerged entries except for populated submodules\n    +@@ builtin/rm.c: int cmd_rm(int argc, const char **argv, const char *prefix)\n    + \n    + \tprepare_repo_settings(the_repository);\n    + \tthe_repository->settings.command_requires_full_index = 0;\n    +-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n    ++\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n    + \n    +-\tif (read_cache() < 0)\n    ++\tif (repo_read_index(the_repository) < 0)\n    + \t\tdie(_(\"index file corrupt\"));\n    + \n    + \trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);\n    +\n    + ## builtin/stash.c ##\n    +@@ builtin/stash.c: static int reset_tree(struct object_id *i_tree, int update, int reset)\n    + \tstruct tree *tree;\n    + \tstruct lock_file lock_file = LOCK_INIT;\n    + \n    +-\tread_cache_preload(NULL);\n    +-\tif (refresh_cache(REFRESH_QUIET))\n    ++\trepo_read_index_preload(the_repository, NULL, 0);\n    ++\tif (refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL))\n    + \t\treturn -1;\n    + \n    +-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n    ++\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n    + \n    + \tmemset(&opts, 0, sizeof(opts));\n    + \n    +@@ builtin/stash.c: static int do_apply_stash(const char *prefix, struct stash_info *info,\n    + \tstruct tree *head, *merge, *merge_base;\n    + \tstruct lock_file lock = LOCK_INIT;\n    + \n    +-\tread_cache_preload(NULL);\n    +-\tif (refresh_and_write_cache(REFRESH_QUIET, 0, 0))\n    ++\trepo_read_index_preload(the_repository, NULL, 0);\n    ++\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,\n    ++\t\t\t\t\t NULL, NULL, NULL))\n    + \t\treturn -1;\n    + \n    + \tif (write_cache_as_tree(&c_tree, 0, NULL))\n    +@@ builtin/stash.c: static int do_apply_stash(const char *prefix, struct stash_info *info,\n    + \t\t\t\treturn error(_(\"conflicts in index. \"\n    + \t\t\t\t\t       \"Try without --index.\"));\n    + \n    +-\t\t\tdiscard_cache();\n    +-\t\t\tread_cache();\n    ++\t\t\tdiscard_index(&the_index);\n    ++\t\t\trepo_read_index(the_repository);\n    + \t\t\tif (write_cache_as_tree(&index_tree, 0, NULL))\n    + \t\t\t\treturn error(_(\"could not save index tree\"));\n    + \n    + \t\t\treset_head();\n    +-\t\t\tdiscard_cache();\n    +-\t\t\tread_cache();\n    ++\t\t\tdiscard_index(&the_index);\n    ++\t\t\trepo_read_index(the_repository);\n    + \t\t}\n    + \t}\n    + \n    +@@ builtin/stash.c: static int check_changes_tracked_files(const struct pathspec *ps)\n    + \tif (get_oid(\"HEAD\", &dummy))\n    + \t\treturn -1;\n    + \n    +-\tif (read_cache() < 0)\n    ++\tif (repo_read_index(the_repository) < 0)\n    + \t\treturn -1;\n    + \n    + \tinit_revisions(&rev, NULL);\n    +@@ builtin/stash.c: static int stash_working_tree(struct stash_info *info, const struct pathspec *ps\n    + \trev.diffopt.format_callback = add_diff_to_buf;\n    + \trev.diffopt.format_callback_data = &diff_output;\n    + \n    +-\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n    ++\tif (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {\n    + \t\tret = -1;\n    + \t\tgoto done;\n    + \t}\n    +@@ builtin/stash.c: static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b\n    + \n    + \tprepare_fallback_ident(\"git stash\", \"git@stash\");\n    + \n    +-\tread_cache_preload(NULL);\n    +-\tif (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0) {\n    ++\trepo_read_index_preload(the_repository, NULL, 0);\n    ++\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,\n    ++\t\t\t\t\t NULL, NULL, NULL) < 0) {\n    + \t\tret = -1;\n    + \t\tgoto done;\n    + \t}\n    +@@ builtin/stash.c: static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q\n    + \t\tgoto done;\n    + \t}\n    + \n    +-\tread_cache_preload(NULL);\n    ++\trepo_read_index_preload(the_repository, NULL, 0);\n    + \tif (!include_untracked && ps->nr) {\n    + \t\tint i;\n    + \t\tchar *ps_matched = xcalloc(ps->nr, 1);\n    +@@ builtin/stash.c: static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q\n    + \t\tfree(ps_matched);\n    + \t}\n    + \n    +-\tif (refresh_and_write_cache(REFRESH_QUIET, 0, 0)) {\n    ++\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,\n    ++\t\t\t\t\t NULL, NULL, NULL)) {\n    + \t\tret = -1;\n    + \t\tgoto done;\n    + \t}\n    +@@ builtin/stash.c: static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q\n    + \t\t\t\tgoto done;\n    + \t\t\t}\n    + \t\t}\n    +-\t\tdiscard_cache();\n    ++\t\tdiscard_index(&the_index);\n    + \t\tif (ps->nr) {\n    + \t\t\tstruct child_process cp_add = CHILD_PROCESS_INIT;\n    + \t\t\tstruct child_process cp_diff = CHILD_PROCESS_INIT;\n    +\n    + ## builtin/submodule--helper.c ##\n    +@@\n    +-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    ++#define USE_THE_INDEX_VARIABLE\n    + #include \"builtin.h\"\n    + #include \"repository.h\"\n    + #include \"cache.h\"\n    +@@ builtin/submodule--helper.c: static int module_list_compute(const char **argv,\n    + \tif (pathspec->nr)\n    + \t\tps_matched = xcalloc(pathspec->nr, 1);\n    + \n    +-\tif (read_cache() < 0)\n    ++\tif (repo_read_index(the_repository) < 0)\n    + \t\tdie(_(\"index file corrupt\"));\n    + \n    + \tfor (i = 0; i < the_index.cache_nr; i++) {\n    +@@ builtin/submodule--helper.c: static int compute_summary_module_list(struct object_id *head_oid,\n    + \tif (!info->cached) {\n    + \t\tif (diff_cmd == DIFF_INDEX)\n    + \t\t\tsetup_work_tree();\n    +-\t\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n    +-\t\t\tperror(\"read_cache_preload\");\n    ++\t\tif (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {\n    ++\t\t\tperror(\"repo_read_index_preload\");\n    + \t\t\tret = -1;\n    + \t\t\tgoto cleanup;\n    + \t\t}\n    +-\t} else if (read_cache() < 0) {\n    +-\t\tperror(\"read_cache\");\n    ++\t} else if (repo_read_index(the_repository) < 0) {\n    ++\t\tperror(\"repo_read_cache\");\n    + \t\tret = -1;\n    + \t\tgoto cleanup;\n    + \t}\n    +@@ builtin/submodule--helper.c: static void die_on_index_match(const char *path, int force)\n    + \tconst char *args[] = { path, NULL };\n    + \tparse_pathspec(&ps, 0, PATHSPEC_PREFER_CWD, NULL, args);\n    + \n    +-\tif (read_cache_preload(NULL) < 0)\n    ++\tif (repo_read_index_preload(the_repository, NULL, 0) < 0)\n    + \t\tdie(_(\"index file corrupt\"));\n    + \n    + \tif (ps.nr) {\n    +\n    + ## builtin/update-index.c ##\n    +@@ builtin/update-index.c: static int test_if_untracked_cache_is_supported(void)\n    + static int mark_ce_flags(const char *path, int flag, int mark)\n    + {\n    + \tint namelen = strlen(path);\n    +-\tint pos = cache_name_pos(path, namelen);\n    ++\tint pos = index_name_pos(&the_index, path, namelen);\n    + \tif (0 <= pos) {\n    + \t\tmark_fsmonitor_invalid(&the_index, the_index.cache[pos]);\n    + \t\tif (mark)\n    +@@ builtin/update-index.c: static int add_one_path(const struct cache_entry *old, const char *path, int len\n    + static int process_directory(const char *path, int len, struct stat *st)\n    + {\n    + \tstruct object_id oid;\n    +-\tint pos = cache_name_pos(path, len);\n    ++\tint pos = index_name_pos(&the_index, path, len);\n    + \n    + \t/* Exact match: file or existing gitlink */\n    + \tif (pos >= 0) {\n    +@@ builtin/update-index.c: static void chmod_path(char flip, const char *path)\n    + \tint pos;\n    + \tstruct cache_entry *ce;\n    + \n    +-\tpos = cache_name_pos(path, strlen(path));\n    ++\tpos = index_name_pos(&the_index, path, strlen(path));\n    + \tif (pos < 0)\n    + \t\tgoto fail;\n    + \tce = the_index.cache[pos];\n    +@@ builtin/update-index.c: static int unresolve_one(const char *path)\n    + \tstruct cache_entry *ce_2 = NULL, *ce_3 = NULL;\n    + \n    + \t/* See if there is such entry in the index. */\n    +-\tpos = cache_name_pos(path, namelen);\n    ++\tpos = index_name_pos(&the_index, path, namelen);\n    + \tif (0 <= pos) {\n    + \t\t/* already merged */\n    + \t\tpos = unmerge_index_entry_at(&the_index, pos);\n    +@@ builtin/update-index.c: struct refresh_params {\n    + static int refresh(struct refresh_params *o, unsigned int flag)\n    + {\n    + \tsetup_work_tree();\n    +-\tread_cache();\n    +-\t*o->has_errors |= refresh_cache(o->flags | flag);\n    ++\trepo_read_index(the_repository);\n    ++\t*o->has_errors |= refresh_index(&the_index, o->flags | flag, NULL,\n    ++\t\t\t\t\tNULL, NULL);\n    + \tif (has_racy_timestamp(&the_index)) {\n    + \t\t/*\n    + \t\t * Even if nothing else has changed, updating the file\n    + \t\t * increases the chance that racy timestamps become\n    + \t\t * non-racy, helping future run-time performance.\n    + \t\t * We do that even in case of \"errors\" returned by\n    +-\t\t * refresh_cache() as these are no actual errors.\n    ++\t\t * refresh_index() as these are no actual errors.\n    + \t\t * cmd_status() does the same.\n    + \t\t */\n    + \t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n    +@@ builtin/update-index.c: int cmd_update_index(int argc, const char **argv, const char *prefix)\n    + \tthe_repository->settings.command_requires_full_index = 0;\n    + \n    + \t/* we will diagnose later if it turns out that we need to update it */\n    +-\tnewfd = hold_locked_index(&lock_file, 0);\n    ++\tnewfd = repo_hold_locked_index(the_repository, &lock_file, 0);\n    + \tif (newfd < 0)\n    + \t\tlock_error = errno;\n    + \n    +-\tentries = read_cache();\n    ++\tentries = repo_read_index(the_repository);\n    + \tif (entries < 0)\n    + \t\tdie(\"cache corrupted\");\n    + \n    +\n    + ## cache.h ##\n    +@@ cache.h: extern struct index_state the_index;\n    + #define active_nr (the_index.cache_nr)\n    + \n    + #define read_cache() repo_read_index(the_repository)\n    +-#define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))\n    +-#define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)\n    + #define discard_cache() discard_index(&the_index)\n    + #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))\n    +-#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)\n    +-#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)\n    +-#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n    + #endif\n    + #endif\n    + #endif\n    +\n    + ## contrib/coccinelle/index-compatibility.cocci ##\n    +@@ contrib/coccinelle/index-compatibility.cocci: identifier f != prepare_to_commit;\n    + (\n    + - read_cache_unmerged\n    + + repo_read_index_unmerged\n    ++|\n    ++- hold_locked_index\n    +++ repo_hold_locked_index\n    + )\n    +   (\n    + + the_repository,\n    +   ...)\n    + \n    ++// \"the_repository\" special-cases\n    ++@@\n    ++@@\n    ++(\n    ++- read_cache_preload\n    +++ repo_read_index_preload\n    ++)\n    ++  (\n    +++ the_repository,\n    ++  ...\n    +++ , 0\n    ++  )\n    ++\n    + // \"the_index\" simple cases\n    + @@\n    + @@\n    +@@ contrib/coccinelle/index-compatibility.cocci: identifier f != prepare_to_commit;\n    +   (\n    + + &the_index,\n    +   ...)\n    ++\n    ++@@\n    ++@@\n    ++(\n    ++- refresh_and_write_cache\n    +++ repo_refresh_and_write_index\n    ++)\n    ++  (\n    +++ the_repository,\n    ++  ...\n    +++ , NULL, NULL, NULL\n    ++  )\n    ++\n    ++// \"the_index\" special-cases\n    ++@@\n    ++@@\n    ++(\n    ++- read_cache_from\n    +++ read_index_from\n    ++)\n    ++  (\n    +++ &the_index,\n    ++  ...\n    +++ , get_git_dir()\n    ++  )\n    ++\n    ++@@\n    ++@@\n    ++(\n    ++- refresh_cache\n    +++ refresh_index\n    ++)\n    ++  (\n    +++ &the_index,\n    ++  ...\n    +++ , NULL, NULL, NULL\n    ++  )\n    +\n    + ## contrib/coccinelle/index-compatibility.pending.cocci ##\n    +@@\n    + (\n    + - read_cache\n    + + repo_read_index\n    +-|\n    +-- hold_locked_index\n    +-+ repo_hold_locked_index\n    + )\n    +   (\n    + + the_repository,\n    +@@\n    +   (\n    + + &the_index,\n    +   ...)\n    +-\n    +-// \"the_repository\" special-cases\n    +-@@\n    +-@@\n    +-(\n    +-- read_cache_preload\n    +-+ repo_read_index_preload\n    +-)\n    +-  (\n    +-+ the_repository,\n    +-  ...\n    +-+ , 0\n    +-  )\n    +-\n    +-@@\n    +-@@\n    +-(\n    +-- refresh_and_write_cache\n    +-+ repo_refresh_and_write_index\n    +-)\n    +-  (\n    +-+ the_repository,\n    +-  ...\n    +-+ , NULL, NULL, NULL\n    +-  )\n    +-\n    +-\n    +-// \"the_index\" special-cases\n    +-@@\n    +-@@\n    +-(\n    +-- read_cache_from\n    +-+ read_index_from\n    +-)\n    +-  (\n    +-+ &the_index,\n    +-  ...\n    +-+ , get_git_dir()\n    +-  )\n    +-\n    +-@@\n    +-@@\n    +-(\n    +-- refresh_cache\n    +-+ refresh_index\n    +-)\n    +-  (\n    +-+ &the_index,\n    +-  ...\n    +-+ , NULL, NULL, NULL\n    +-  )\n12:  b69cf6d7600 <  -:  ----------- builtin/*: remove or amend \"USE_THE_INDEX_COMPATIBILITY_MACROS\"\n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467580","messageId":"patch-v2-04.11-b4d6685585a-20221119T125551Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 04/11] read-cache API & users: make discard_index() return void","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:31Z","receivedAt":"2022-11-19T13:08:00Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The discard_index() function has not returned non-zero since\n7a51ed66f65 (Make on-disk index representation separate from in-core\none, 2008-01-14), but we've had various code in-tree still acting as\nthough that might be the case.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n add-interactive.c |  8 ++++----\n add-patch.c       |  3 ++-\n builtin/merge.c   |  3 ++-\n cache.h           |  2 +-\n read-cache.c      |  4 +---\n sequencer.c       | 15 +++++++++------\n 6 files changed, 19 insertions(+), 16 deletions(-)\n\ndiff --git a/add-interactive.c b/add-interactive.c\nindex ecc5ae1b249..ae1839c04a7 100644\n--- a/add-interactive.c\n+++ b/add-interactive.c\n@@ -530,8 +530,8 @@ static int get_modified_files(struct repository *r,\n \tstruct collection_status s = { 0 };\n \tint i;\n \n-\tif (discard_index(r->index) < 0 ||\n-\t    repo_read_index_preload(r, ps, 0) < 0)\n+\tdiscard_index(r->index);\n+\tif (repo_read_index_preload(r, ps, 0) < 0)\n \t\treturn error(_(\"could not read index\"));\n \n \tprefix_item_list_clear(files);\n@@ -1156,8 +1156,8 @@ int run_add_i(struct repository *r, const struct pathspec *ps)\n \t\t    _(\"staged\"), _(\"unstaged\"), _(\"path\"));\n \topts.list_opts.header = header.buf;\n \n-\tif (discard_index(r->index) < 0 ||\n-\t    repo_read_index(r) < 0 ||\n+\tdiscard_index(r->index);\n+\tif (repo_read_index(r) < 0 ||\n \t    repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,\n \t\t\t\t\t NULL, NULL, NULL) < 0)\n \t\twarning(_(\"could not refresh index\"));\ndiff --git a/add-patch.c b/add-patch.c\nindex 33ecd8398a1..a86a92e1646 100644\n--- a/add-patch.c\n+++ b/add-patch.c\n@@ -1750,7 +1750,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode,\n \t\ts.mode = &patch_mode_add;\n \ts.revision = revision;\n \n-\tif (discard_index(r->index) < 0 || repo_read_index(r) < 0 ||\n+\tdiscard_index(r->index);\n+\tif (repo_read_index(r) < 0 ||\n \t    (!s.mode->index_only &&\n \t     repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,\n \t\t\t\t\t  NULL, NULL, NULL) < 0) ||\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex da11dfae19e..89fdac24e40 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -390,7 +390,8 @@ static void restore_state(const struct object_id *head,\n \trun_command(&cmd);\n \n refresh_cache:\n-\tif (discard_cache() < 0 || read_cache() < 0)\n+\tdiscard_cache();\n+\tif (read_cache() < 0)\n \t\tdie(_(\"could not read index\"));\n }\n \ndiff --git a/cache.h b/cache.h\nindex 53dc4341717..489e9e1925b 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -774,7 +774,7 @@ void ensure_full_index(struct index_state *istate);\n  */\n int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);\n \n-int discard_index(struct index_state *);\n+void discard_index(struct index_state *);\n void move_index_extensions(struct index_state *dst, struct index_state *src);\n int unmerged_index(const struct index_state *);\n \ndiff --git a/read-cache.c b/read-cache.c\nindex 32024029274..46f5e497b14 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2531,7 +2531,7 @@ int is_index_unborn(struct index_state *istate)\n \treturn (!istate->cache_nr && !istate->timestamp.sec);\n }\n \n-int discard_index(struct index_state *istate)\n+void discard_index(struct index_state *istate)\n {\n \t/*\n \t * Cache entries in istate->cache[] should have been allocated\n@@ -2562,8 +2562,6 @@ int discard_index(struct index_state *istate)\n \t\tmem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries());\n \t\tFREE_AND_NULL(istate->ce_mem_pool);\n \t}\n-\n-\treturn 0;\n }\n \n /*\ndiff --git a/sequencer.c b/sequencer.c\nindex a46f3ad2e33..746a71cdc92 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -3564,7 +3564,8 @@ static int do_exec(struct repository *r, const char *command_line)\n \tstatus = run_command(&cmd);\n \n \t/* force re-reading of the cache */\n-\tif (discard_index(r->index) < 0 || repo_read_index(r) < 0)\n+\tdiscard_index(r->index);\n+\tif (repo_read_index(r) < 0)\n \t\treturn error(_(\"could not read index\"));\n \n \tdirty = require_clean_work_tree(r, \"rebase\", NULL, 1, 1);\n@@ -4029,9 +4030,11 @@ static int do_merge(struct repository *r,\n \t\tret = run_command(&cmd);\n \n \t\t/* force re-reading of the cache */\n-\t\tif (!ret && (discard_index(r->index) < 0 ||\n-\t\t\t     repo_read_index(r) < 0))\n-\t\t\tret = error(_(\"could not read index\"));\n+\t\tif (!ret) {\n+\t\t\tdiscard_index(r->index);\n+\t\t\tif (repo_read_index(r) < 0)\n+\t\t\t\tret = error(_(\"could not read index\"));\n+\t\t}\n \t\tgoto leave_merge;\n \t}\n \n@@ -4404,8 +4407,8 @@ void create_autostash(struct repository *r, const char *path)\n \t\tprintf(_(\"Created autostash: %s\\n\"), buf.buf);\n \t\tif (reset_head(r, &ropts) < 0)\n \t\t\tdie(_(\"could not reset --hard\"));\n-\t\tif (discard_index(r->index) < 0 ||\n-\t\t\trepo_read_index(r) < 0)\n+\t\tdiscard_index(r->index);\n+\t\tif (repo_read_index(r) < 0)\n \t\t\tdie(_(\"could not read index\"));\n \t}\n \tstrbuf_release(&buf);\n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467582","messageId":"patch-v2-05.11-ec740a81d9f-20221119T125551Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 05/11] cocci: add a index-compatibility.pending.cocci","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:32Z","receivedAt":"2022-11-19T13:08:01Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add a coccinelle rule which covers the rest of the macros guarded by\n\"USE_THE_INDEX_COMPATIBILITY_MACROS\" cache.h. If the result of this\nwere applied it can be reduced down to just:\n\n\t#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n\textern struct index_state the_index;\n\t#endif\n\nBut that patch is just under 2000 lines, so let's first add this as a\n\"pending\", and then incrementally pick changes from it in subsequent\ncommits. In doing that we'll migrate rules from this\n\"index-compatibility.pending.cocci\" to the \"index-compatibility.cocci\"\ncreated in a preceding commit.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .../index-compatibility.pending.cocci         | 110 ++++++++++++++++++\n 1 file changed, 110 insertions(+)\n create mode 100644 contrib/coccinelle/index-compatibility.pending.cocci\n\ndiff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci\nnew file mode 100644\nindex 00000000000..6e96de0f638\n--- /dev/null\n+++ b/contrib/coccinelle/index-compatibility.pending.cocci\n@@ -0,0 +1,110 @@\n+// the_index.* variables\n+@@\n+@@\n+(\n+- active_cache\n++ the_index.cache\n+|\n+- active_nr\n++ the_index.cache_nr\n+|\n+- active_cache_changed\n++ the_index.cache_changed\n+|\n+- active_cache_tree\n++ the_index.cache_tree\n+)\n+\n+// \"the_repository\" simple cases\n+@@\n+@@\n+(\n+- read_cache\n++ repo_read_index\n+|\n+- hold_locked_index\n++ repo_hold_locked_index\n+)\n+  (\n++ the_repository,\n+  ...)\n+\n+// \"the_index\" simple cases\n+@@\n+@@\n+(\n+- discard_cache\n++ discard_index\n+|\n+- cache_name_pos\n++ index_name_pos\n+|\n+- add_cache_entry\n++ add_index_entry\n+|\n+- remove_file_from_cache\n++ remove_file_from_index\n+|\n+- ce_match_stat\n++ ie_match_stat\n+|\n+- ce_modified\n++ ie_modified\n+|\n+- resolve_undo_clear\n++ resolve_undo_clear_index\n+)\n+  (\n++ &the_index,\n+  ...)\n+\n+// \"the_repository\" special-cases\n+@@\n+@@\n+(\n+- read_cache_preload\n++ repo_read_index_preload\n+)\n+  (\n++ the_repository,\n+  ...\n++ , 0\n+  )\n+\n+@@\n+@@\n+(\n+- refresh_and_write_cache\n++ repo_refresh_and_write_index\n+)\n+  (\n++ the_repository,\n+  ...\n++ , NULL, NULL, NULL\n+  )\n+\n+\n+// \"the_index\" special-cases\n+@@\n+@@\n+(\n+- read_cache_from\n++ read_index_from\n+)\n+  (\n++ &the_index,\n+  ...\n++ , get_git_dir()\n+  )\n+\n+@@\n+@@\n+(\n+- refresh_cache\n++ refresh_index\n+)\n+  (\n++ &the_index,\n+  ...\n++ , NULL, NULL, NULL\n+  )\n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467583","messageId":"patch-v2-06.11-6849233bf2b-20221119T125551Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 06/11] cocci & cache.h: apply a selection of \"pending\" index-compatibility","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:33Z","receivedAt":"2022-11-19T13:08:03Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Apply a selection of rules in \"index-compatibility.pending.cocci\"\ntree-wide, and in doing so migrate them to\n\"index-compatibility.cocci\".\n\nAs in preceding commits the only manual changes here are the macro\nremovals in \"cache.h\", and the update to the '*.cocci\" rules. The rest\nof the C code changes are the result of applying those updated rules.\n\nMove rules for some rarely used cache compatibility macros from\n\"index-compatibility.pending.cocci\" to \"index-compatibility.cocci\" and\napply them.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/checkout.c                            |  5 +++--\n builtin/commit.c                              |  2 +-\n builtin/merge.c                               |  2 +-\n builtin/mv.c                                  |  4 +++-\n builtin/read-tree.c                           |  2 +-\n builtin/reset.c                               |  5 +++--\n builtin/rm.c                                  |  4 ++--\n builtin/update-index.c                        | 22 +++++++++----------\n cache.h                                       |  5 -----\n contrib/coccinelle/index-compatibility.cocci  | 15 +++++++++++++\n .../index-compatibility.pending.cocci         | 15 -------------\n 11 files changed, 40 insertions(+), 41 deletions(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex aa610b274e3..afbd71764a3 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -160,7 +160,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \t\t}\n \t}\n \n-\tadd_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n+\tadd_index_entry(&the_index, ce,\n+\t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \treturn 0;\n }\n \n@@ -744,7 +745,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \tif (read_cache_preload(NULL) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \tif (opts->new_orphan_branch && opts->orphan_from_empty_tree) {\n \t\tif (new_branch_info->commit)\n \t\t\tBUG(\"'switch --orphan' should never accept a commit as starting point\");\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 985503d43a6..10a827b1f4a 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -305,7 +305,7 @@ static void add_remove_files(struct string_list *list)\n \t\t\tif (add_to_index(&the_index, p->string, &st, 0))\n \t\t\t\tdie(_(\"updating files failed\"));\n \t\t} else\n-\t\t\tremove_file_from_cache(p->string);\n+\t\t\tremove_file_from_index(&the_index, p->string);\n \t}\n }\n \ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 89fdac24e40..2046992d75a 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1397,7 +1397,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\telse\n \t\t\tdie(_(\"You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\"));\n \t}\n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \n \tif (option_edit < 0)\n \t\toption_edit = default_edit_option();\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex df6157fd6b5..6f94c3b9238 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -471,7 +471,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tpos = cache_name_pos(src, strlen(src));\n \t\tassert(pos >= 0);\n \t\tif (!(mode & SPARSE) && !lstat(src, &st))\n-\t\t\tsparse_and_dirty = ce_modified(active_cache[pos], &st, 0);\n+\t\t\tsparse_and_dirty = ie_modified(&the_index,\n+\t\t\t\t\t\t       active_cache[pos], &st,\n+\t\t\t\t\t\t       0);\n \t\trename_index_entry_at(&the_index, pos, dst);\n \n \t\tif (ignore_sparse &&\ndiff --git a/builtin/read-tree.c b/builtin/read-tree.c\nindex fd708273101..9ced755a6db 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -192,7 +192,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \t\t\tdie(_(\"You need to resolve your current index first\"));\n \t\tstage = opts.merge = 1;\n \t}\n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \n \tfor (i = 0; i < argc; i++) {\n \t\tconst char *arg = argv[i];\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex e561180e8c4..59f777a1da4 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -145,7 +145,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,\n \t\tstruct cache_entry *ce;\n \n \t\tif (!is_in_reset_tree && !intent_to_add) {\n-\t\t\tremove_file_from_cache(one->path);\n+\t\t\tremove_file_from_index(&the_index, one->path);\n \t\t\tcontinue;\n \t\t}\n \n@@ -172,7 +172,8 @@ static void update_index_from_diff(struct diff_queue_struct *q,\n \t\t\tce->ce_flags |= CE_INTENT_TO_ADD;\n \t\t\tset_object_name_for_intent_to_add_entry(ce);\n \t\t}\n-\t\tadd_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n+\t\tadd_index_entry(&the_index, ce,\n+\t\t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \t}\n }\n \ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex f0d025a4e23..c717cdc97f5 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -168,7 +168,7 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\t * Is the index different from the file in the work tree?\n \t\t * If it's a submodule, is its work tree modified?\n \t\t */\n-\t\tif (ce_match_stat(ce, &st, 0) ||\n+\t\tif (ie_match_stat(&the_index, ce, &st, 0) ||\n \t\t    (S_ISGITLINK(ce->ce_mode) &&\n \t\t     bad_to_remove_submodule(ce->name,\n \t\t\t\tSUBMODULE_REMOVAL_DIE_ON_ERROR |\n@@ -386,7 +386,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\tif (!quiet)\n \t\t\tprintf(\"rm '%s'\\n\", path);\n \n-\t\tif (remove_file_from_cache(path))\n+\t\tif (remove_file_from_index(&the_index, path))\n \t\t\tdie(_(\"git rm: unable to remove %s\"), path);\n \t}\n \ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex e1b2bb78e72..533ba66df05 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -256,7 +256,7 @@ static int remove_one_path(const char *path)\n {\n \tif (!allow_remove)\n \t\treturn error(\"%s: does not exist and --remove not passed\", path);\n-\tif (remove_file_from_cache(path))\n+\tif (remove_file_from_index(&the_index, path))\n \t\treturn error(\"%s: cannot remove from the index\", path);\n \treturn 0;\n }\n@@ -281,7 +281,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len\n \tstruct cache_entry *ce;\n \n \t/* Was the old index entry already up-to-date? */\n-\tif (old && !ce_stage(old) && !ce_match_stat(old, st, 0))\n+\tif (old && !ce_stage(old) && !ie_match_stat(&the_index, old, st, 0))\n \t\treturn 0;\n \n \tce = make_empty_cache_entry(&the_index, len);\n@@ -298,7 +298,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len\n \t}\n \toption = allow_add ? ADD_CACHE_OK_TO_ADD : 0;\n \toption |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;\n-\tif (add_cache_entry(ce, option)) {\n+\tif (add_index_entry(&the_index, ce, option)) {\n \t\tdiscard_cache_entry(ce);\n \t\treturn error(\"%s: cannot add to the index - missing --add option?\", path);\n \t}\n@@ -390,7 +390,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)\n \t\t * On the other hand, removing it from index should work\n \t\t */\n \t\tif (!ignore_skip_worktree_entries && allow_remove &&\n-\t\t    remove_file_from_cache(path))\n+\t\t    remove_file_from_index(&the_index, path))\n \t\t\treturn error(\"%s: cannot remove from the index\", path);\n \t\treturn 0;\n \t}\n@@ -429,7 +429,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,\n \t\tce->ce_flags |= CE_VALID;\n \toption = allow_add ? ADD_CACHE_OK_TO_ADD : 0;\n \toption |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;\n-\tif (add_cache_entry(ce, option))\n+\tif (add_index_entry(&the_index, ce, option))\n \t\treturn error(\"%s: cannot add to the index - missing --add option?\",\n \t\t\t     path);\n \treport(\"add '%s'\", path);\n@@ -488,7 +488,7 @@ static void update_one(const char *path)\n \t}\n \n \tif (force_remove) {\n-\t\tif (remove_file_from_cache(path))\n+\t\tif (remove_file_from_index(&the_index, path))\n \t\t\tdie(\"git update-index: unable to remove %s\", path);\n \t\treport(\"remove '%s'\", path);\n \t\treturn;\n@@ -571,7 +571,7 @@ static void read_index_info(int nul_term_line)\n \n \t\tif (!mode) {\n \t\t\t/* mode == 0 means there is no such path -- remove */\n-\t\t\tif (remove_file_from_cache(path_name))\n+\t\t\tif (remove_file_from_index(&the_index, path_name))\n \t\t\t\tdie(\"git update-index: unable to remove %s\",\n \t\t\t\t    ptr);\n \t\t}\n@@ -686,13 +686,13 @@ static int unresolve_one(const char *path)\n \t\tgoto free_return;\n \t}\n \n-\tremove_file_from_cache(path);\n-\tif (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) {\n+\tremove_file_from_index(&the_index, path);\n+\tif (add_index_entry(&the_index, ce_2, ADD_CACHE_OK_TO_ADD)) {\n \t\terror(\"%s: cannot add our version to the index.\", path);\n \t\tret = -1;\n \t\tgoto free_return;\n \t}\n-\tif (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD))\n+\tif (!add_index_entry(&the_index, ce_3, ADD_CACHE_OK_TO_ADD))\n \t\treturn 0;\n \terror(\"%s: cannot add their version to the index.\", path);\n \tret = -1;\n@@ -850,7 +850,7 @@ static int resolve_undo_clear_callback(const struct option *opt,\n {\n \tBUG_ON_OPT_NEG(unset);\n \tBUG_ON_OPT_ARG(arg);\n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \treturn 0;\n }\n \ndiff --git a/cache.h b/cache.h\nindex 489e9e1925b..79b8d479710 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -446,13 +446,8 @@ extern struct index_state the_index;\n #define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)\n #define discard_cache() discard_index(&the_index)\n #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))\n-#define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))\n-#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))\n #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)\n #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)\n-#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))\n-#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))\n-#define resolve_undo_clear() resolve_undo_clear_index(&the_index)\n #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n \ndiff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci\nindex 04207c409e1..89c18986160 100644\n--- a/contrib/coccinelle/index-compatibility.cocci\n+++ b/contrib/coccinelle/index-compatibility.cocci\n@@ -39,6 +39,21 @@\n |\n - add_file_to_cache\n + add_file_to_index\n+|\n+- add_cache_entry\n++ add_index_entry\n+|\n+- remove_file_from_cache\n++ remove_file_from_index\n+|\n+- ce_match_stat\n++ ie_match_stat\n+|\n+- ce_modified\n++ ie_modified\n+|\n+- resolve_undo_clear\n++ resolve_undo_clear_index\n )\n   (\n + &the_index,\ndiff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci\nindex 6e96de0f638..cf1ea57d700 100644\n--- a/contrib/coccinelle/index-compatibility.pending.cocci\n+++ b/contrib/coccinelle/index-compatibility.pending.cocci\n@@ -38,21 +38,6 @@\n |\n - cache_name_pos\n + index_name_pos\n-|\n-- add_cache_entry\n-+ add_index_entry\n-|\n-- remove_file_from_cache\n-+ remove_file_from_index\n-|\n-- ce_match_stat\n-+ ie_match_stat\n-|\n-- ce_modified\n-+ ie_modified\n-|\n-- resolve_undo_clear\n-+ resolve_undo_clear_index\n )\n   (\n + &the_index,\n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467584","messageId":"patch-v2-08.11-6d57a383623-20221119T125551Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 08/11] cocci: apply \"pending\" index-compatibility to \"t/helper/*.c\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:35Z","receivedAt":"2022-11-19T13:08:06Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Apply the \"index-compatibility.pending.cocci\" rule to the \"t/helper/*\"\ndirectory, a subsequent commit will extend cache.h to further narrow\ndown the use of \"USE_THE_INDEX_COMPATIBILITY_MACROS\" in this area.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/helper/test-cache-tree.c           |  2 +-\n t/helper/test-dump-cache-tree.c      |  2 +-\n t/helper/test-dump-untracked-cache.c |  2 +-\n t/helper/test-fast-rebase.c          |  2 +-\n t/helper/test-lazy-init-name-hash.c  | 20 ++++++++++----------\n t/helper/test-read-cache.c           |  4 ++--\n t/helper/test-scrap-cache-tree.c     |  4 ++--\n t/helper/test-write-cache.c          |  5 +++--\n 8 files changed, 21 insertions(+), 20 deletions(-)\n\ndiff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c\nindex 93051b25f56..5514afdfe7a 100644\n--- a/t/helper/test-cache-tree.c\n+++ b/t/helper/test-cache-tree.c\n@@ -30,7 +30,7 @@ int cmd__cache_tree(int argc, const char **argv)\n \n \targc = parse_options(argc, argv, NULL, options, test_cache_tree_usage, 0);\n \n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"unable to read index file\"));\n \n \toidcpy(&oid, &the_index.cache_tree->oid);\ndiff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c\nindex 8d88111b357..4bf8bc3df6e 100644\n--- a/t/helper/test-dump-cache-tree.c\n+++ b/t/helper/test-dump-cache-tree.c\n@@ -62,7 +62,7 @@ int cmd__dump_cache_tree(int ac, const char **av)\n \tint ret;\n \n \tsetup_git_directory();\n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(\"unable to read index file\");\n \tistate = the_index;\n \tistate.cache_tree = another;\ndiff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c\nindex 99010614f6d..ffe34736e53 100644\n--- a/t/helper/test-dump-untracked-cache.c\n+++ b/t/helper/test-dump-untracked-cache.c\n@@ -51,7 +51,7 @@ int cmd__dump_untracked_cache(int ac, const char **av)\n \txsetenv(\"GIT_CONFIG_VALUE_0\", \"keep\", 1);\n \n \tsetup_git_directory();\n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(\"unable to read index file\");\n \tuc = the_index.untracked;\n \tif (!uc) {\ndiff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c\nindex 45665ec19a5..9def2ba6889 100644\n--- a/t/helper/test-fast-rebase.c\n+++ b/t/helper/test-fast-rebase.c\n@@ -123,7 +123,7 @@ int cmd__fast_rebase(int argc, const char **argv)\n \t\tdie(_(\"Cannot read HEAD\"));\n \tassert(oideq(&onto->object.oid, &head));\n \n-\thold_locked_index(&lock, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);\n \tif (repo_read_index(the_repository) < 0)\n \t\tBUG(\"Could not read index\");\n \ndiff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c\nindex cd1b4c9736e..7e8723a1900 100644\n--- a/t/helper/test-lazy-init-name-hash.c\n+++ b/t/helper/test-lazy-init-name-hash.c\n@@ -32,7 +32,7 @@ static void dump_run(void)\n \tstruct dir_entry *dir;\n \tstruct cache_entry *ce;\n \n-\tread_cache();\n+\trepo_read_index(the_repository);\n \tif (single) {\n \t\ttest_lazy_init_name_hash(&the_index, 0);\n \t} else {\n@@ -49,7 +49,7 @@ static void dump_run(void)\n \t\t\t\tent /* member name */)\n \t\tprintf(\"name %08x %s\\n\", ce->ent.hash, ce->name);\n \n-\tdiscard_cache();\n+\tdiscard_index(&the_index);\n }\n \n /*\n@@ -66,7 +66,7 @@ static uint64_t time_runs(int try_threaded)\n \n \tfor (i = 0; i < count; i++) {\n \t\tt0 = getnanotime();\n-\t\tread_cache();\n+\t\trepo_read_index(the_repository);\n \t\tt1 = getnanotime();\n \t\tnr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded);\n \t\tt2 = getnanotime();\n@@ -89,7 +89,7 @@ static uint64_t time_runs(int try_threaded)\n \t\t\t\t   the_index.cache_nr);\n \t\tfflush(stdout);\n \n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t}\n \n \tavg = sum / count;\n@@ -113,9 +113,9 @@ static void analyze_run(void)\n \tint i;\n \tint nr;\n \n-\tread_cache();\n+\trepo_read_index(the_repository);\n \tcache_nr_limit = the_index.cache_nr;\n-\tdiscard_cache();\n+\tdiscard_index(&the_index);\n \n \tnr = analyze;\n \twhile (1) {\n@@ -128,23 +128,23 @@ static void analyze_run(void)\n \t\t\tnr = cache_nr_limit;\n \n \t\tfor (i = 0; i < count; i++) {\n-\t\t\tread_cache();\n+\t\t\trepo_read_index(the_repository);\n \t\t\tthe_index.cache_nr = nr; /* cheap truncate of index */\n \t\t\tt1s = getnanotime();\n \t\t\ttest_lazy_init_name_hash(&the_index, 0);\n \t\t\tt2s = getnanotime();\n \t\t\tsum_single += (t2s - t1s);\n \t\t\tthe_index.cache_nr = cache_nr_limit;\n-\t\t\tdiscard_cache();\n+\t\t\tdiscard_index(&the_index);\n \n-\t\t\tread_cache();\n+\t\t\trepo_read_index(the_repository);\n \t\t\tthe_index.cache_nr = nr; /* cheap truncate of index */\n \t\t\tt1m = getnanotime();\n \t\t\tnr_threads_used = test_lazy_init_name_hash(&the_index, 1);\n \t\t\tt2m = getnanotime();\n \t\t\tsum_multi += (t2m - t1m);\n \t\t\tthe_index.cache_nr = cache_nr_limit;\n-\t\t\tdiscard_cache();\n+\t\t\tdiscard_index(&the_index);\n \n \t\t\tif (!nr_threads_used)\n \t\t\t\tprintf(\"    [size %8d] [single %f]   non-threaded code path used\\n\",\ndiff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c\nindex b736ef16421..a089be9104c 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -20,7 +20,7 @@ int cmd__read_cache(int argc, const char **argv)\n \tgit_config(git_default_config, NULL);\n \n \tfor (i = 0; i < cnt; i++) {\n-\t\tread_cache();\n+\t\trepo_read_index(the_repository);\n \t\tif (name) {\n \t\t\tint pos;\n \n@@ -33,7 +33,7 @@ int cmd__read_cache(int argc, const char **argv)\n \t\t\t       ce_uptodate(the_index.cache[pos]) ? \"\" : \" not\");\n \t\t\twrite_file(name, \"%d\\n\", i);\n \t\t}\n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t}\n \treturn 0;\n }\ndiff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c\nindex 20e2e31f9e2..9206dee1fd2 100644\n--- a/t/helper/test-scrap-cache-tree.c\n+++ b/t/helper/test-scrap-cache-tree.c\n@@ -9,8 +9,8 @@ int cmd__scrap_cache_tree(int ac, const char **av)\n \tstruct lock_file index_lock = LOCK_INIT;\n \n \tsetup_git_directory();\n-\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n-\tif (read_cache() < 0)\n+\trepo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(\"unable to read index file\");\n \tcache_tree_free(&the_index.cache_tree);\n \tthe_index.cache_tree = NULL;\ndiff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c\nindex 8837717d36a..66287d6d47d 100644\n--- a/t/helper/test-write-cache.c\n+++ b/t/helper/test-write-cache.c\n@@ -9,9 +9,10 @@ int cmd__write_cache(int argc, const char **argv)\n \tif (argc == 2)\n \t\tcnt = strtol(argv[1], NULL, 0);\n \tsetup_git_directory();\n-\tread_cache();\n+\trepo_read_index(the_repository);\n \tfor (i = 0; i < cnt; i++) {\n-\t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n+\t\trepo_hold_locked_index(the_repository, &index_lock,\n+\t\t\t\t       LOCK_DIE_ON_ERROR);\n \t\tif (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))\n \t\t\tdie(\"unable to write index file\");\n \t}\n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467585","messageId":"patch-v2-07.11-fff2d0459a0-20221119T125551Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 07/11] cocci & cache.h: apply variable section of \"pending\" index-compatibility","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:34Z","receivedAt":"2022-11-19T13:08:21Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Mostly apply the part of \"index-compatibility.pending.cocci\" that\nrenames the global variables like \"active_nr\", which are a shorthand\nto referencing (in that case) a struct member as \"the_index.cache_nr\".\n\nIn doing so move more of \"index-compatibility.pending.cocci\" to\n\"index-compatibility.cocci\".\n\nIn the case of \"active_nr\" we'd have a textual conflict with\n\"ab/various-leak-fixes\" in \"next\"[1]. Let's exclude that specific case\nwhile moving the rule over from \"pending\".\n\n1. 407b94280f8 (commit: discard partial cache before (re-)reading it,\n   2022-11-08)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/add.c                                 |  8 ++--\n builtin/checkout-index.c                      | 10 ++--\n builtin/checkout.c                            | 46 +++++++++----------\n builtin/commit.c                              | 16 +++----\n builtin/fsck.c                                | 12 ++---\n builtin/merge-index.c                         | 10 ++--\n builtin/merge.c                               |  6 +--\n builtin/mv.c                                  | 19 ++++----\n builtin/read-tree.c                           |  2 +-\n builtin/reset.c                               |  2 +-\n builtin/rm.c                                  | 14 +++---\n builtin/stash.c                               |  8 ++--\n builtin/submodule--helper.c                   | 14 +++---\n builtin/update-index.c                        | 46 +++++++++----------\n cache.h                                       |  3 --\n contrib/coccinelle/index-compatibility.cocci  | 22 +++++++++\n .../index-compatibility.pending.cocci         | 17 -------\n t/helper/test-dump-cache-tree.c               |  2 +-\n t/helper/test-scrap-cache-tree.c              |  4 +-\n 19 files changed, 132 insertions(+), 129 deletions(-)\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 75be1d021ab..23f9f0e08bb 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -42,8 +42,8 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)\n {\n \tint i, ret = 0;\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \t\tint err;\n \n \t\tif (!include_sparse &&\n@@ -159,8 +159,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)\n {\n \tint i, retval = 0;\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \n \t\tif (!include_sparse &&\n \t\t    (ce_skip_worktree(ce) ||\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex 97e06e8c52c..c2aee450c40 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -75,8 +75,8 @@ static int checkout_file(const char *name, const char *prefix)\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n \n-\twhile (pos < active_nr) {\n-\t\tstruct cache_entry *ce = active_cache[pos];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tstruct cache_entry *ce = the_index.cache[pos];\n \t\tif (ce_namelen(ce) != namelen ||\n \t\t    memcmp(ce->name, name, namelen))\n \t\t\tbreak;\n@@ -136,8 +136,8 @@ static int checkout_all(const char *prefix, int prefix_length)\n \tint i, errs = 0;\n \tstruct cache_entry *last_ce = NULL;\n \n-\tfor (i = 0; i < active_nr ; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr ; i++) {\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \n \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n \t\t\tif (!ce_skip_worktree(ce))\n@@ -151,7 +151,7 @@ static int checkout_all(const char *prefix, int prefix_length)\n \t\t\t */\n \t\t\tif (ignore_skip_worktree) {\n \t\t\t\tensure_full_index(&the_index);\n-\t\t\t\tce = active_cache[i];\n+\t\t\t\tce = the_index.cache[i];\n \t\t\t}\n \t\t}\n \ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex afbd71764a3..3fd303f5604 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -150,7 +150,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \t */\n \tpos = cache_name_pos(ce->name, ce->ce_namelen);\n \tif (pos >= 0) {\n-\t\tstruct cache_entry *old = active_cache[pos];\n+\t\tstruct cache_entry *old = the_index.cache[pos];\n \t\tif (ce->ce_mode == old->ce_mode &&\n \t\t    !ce_intent_to_add(old) &&\n \t\t    oideq(&ce->oid, &old->oid)) {\n@@ -179,8 +179,8 @@ static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)\n \n static int skip_same_name(const struct cache_entry *ce, int pos)\n {\n-\twhile (++pos < active_nr &&\n-\t       !strcmp(active_cache[pos]->name, ce->name))\n+\twhile (++pos < the_index.cache_nr &&\n+\t       !strcmp(the_index.cache[pos]->name, ce->name))\n \t\t; /* skip */\n \treturn pos;\n }\n@@ -188,9 +188,9 @@ static int skip_same_name(const struct cache_entry *ce, int pos)\n static int check_stage(int stage, const struct cache_entry *ce, int pos,\n \t\t       int overlay_mode)\n {\n-\twhile (pos < active_nr &&\n-\t       !strcmp(active_cache[pos]->name, ce->name)) {\n-\t\tif (ce_stage(active_cache[pos]) == stage)\n+\twhile (pos < the_index.cache_nr &&\n+\t       !strcmp(the_index.cache[pos]->name, ce->name)) {\n+\t\tif (ce_stage(the_index.cache[pos]) == stage)\n \t\t\treturn 0;\n \t\tpos++;\n \t}\n@@ -207,8 +207,8 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)\n \tunsigned seen = 0;\n \tconst char *name = ce->name;\n \n-\twhile (pos < active_nr) {\n-\t\tce = active_cache[pos];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tce = the_index.cache[pos];\n \t\tif (strcmp(name, ce->name))\n \t\t\tbreak;\n \t\tseen |= (1 << ce_stage(ce));\n@@ -224,10 +224,10 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,\n \t\t\t  const struct checkout *state, int *nr_checkouts,\n \t\t\t  int overlay_mode)\n {\n-\twhile (pos < active_nr &&\n-\t       !strcmp(active_cache[pos]->name, ce->name)) {\n-\t\tif (ce_stage(active_cache[pos]) == stage)\n-\t\t\treturn checkout_entry(active_cache[pos], state,\n+\twhile (pos < the_index.cache_nr &&\n+\t       !strcmp(the_index.cache[pos]->name, ce->name)) {\n+\t\tif (ce_stage(the_index.cache[pos]) == stage)\n+\t\t\treturn checkout_entry(the_index.cache[pos], state,\n \t\t\t\t\t      NULL, nr_checkouts);\n \t\tpos++;\n \t}\n@@ -244,7 +244,7 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,\n static int checkout_merged(int pos, const struct checkout *state,\n \t\t\t   int *nr_checkouts, struct mem_pool *ce_mem_pool)\n {\n-\tstruct cache_entry *ce = active_cache[pos];\n+\tstruct cache_entry *ce = the_index.cache[pos];\n \tconst char *path = ce->name;\n \tmmfile_t ancestor, ours, theirs;\n \tenum ll_merge_result merge_status;\n@@ -257,7 +257,7 @@ static int checkout_merged(int pos, const struct checkout *state,\n \tint renormalize = 0;\n \n \tmemset(threeway, 0, sizeof(threeway));\n-\twhile (pos < active_nr) {\n+\twhile (pos < the_index.cache_nr) {\n \t\tint stage;\n \t\tstage = ce_stage(ce);\n \t\tif (!stage || strcmp(path, ce->name))\n@@ -266,7 +266,7 @@ static int checkout_merged(int pos, const struct checkout *state,\n \t\tif (stage == 2)\n \t\t\tmode = create_ce_mode(ce->ce_mode);\n \t\tpos++;\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \t}\n \tif (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))\n \t\treturn error(_(\"path '%s' does not have necessary versions\"), path);\n@@ -392,8 +392,8 @@ static int checkout_worktree(const struct checkout_opts *opts,\n \tif (pc_workers > 1)\n \t\tinit_parallel_checkout();\n \n-\tfor (pos = 0; pos < active_nr; pos++) {\n-\t\tstruct cache_entry *ce = active_cache[pos];\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n+\t\tstruct cache_entry *ce = the_index.cache[pos];\n \t\tif (ce->ce_flags & CE_MATCHED) {\n \t\t\tif (!ce_stage(ce)) {\n \t\t\t\terrs |= checkout_entry(ce, &state,\n@@ -541,13 +541,13 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t * Make sure all pathspecs participated in locating the paths\n \t * to be checked out.\n \t */\n-\tfor (pos = 0; pos < active_nr; pos++)\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++)\n \t\tif (opts->overlay_mode)\n-\t\t\tmark_ce_for_checkout_overlay(active_cache[pos],\n+\t\t\tmark_ce_for_checkout_overlay(the_index.cache[pos],\n \t\t\t\t\t\t     ps_matched,\n \t\t\t\t\t\t     opts);\n \t\telse\n-\t\t\tmark_ce_for_checkout_no_overlay(active_cache[pos],\n+\t\t\tmark_ce_for_checkout_no_overlay(the_index.cache[pos],\n \t\t\t\t\t\t\tps_matched,\n \t\t\t\t\t\t\topts);\n \n@@ -562,8 +562,8 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t\tunmerge_marked_index(&the_index);\n \n \t/* Any unmerged paths? */\n-\tfor (pos = 0; pos < active_nr; pos++) {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tif (ce->ce_flags & CE_MATCHED) {\n \t\t\tif (!ce_stage(ce))\n \t\t\t\tcontinue;\n@@ -868,7 +868,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \t\t}\n \t}\n \n-\tif (!cache_tree_fully_valid(active_cache_tree))\n+\tif (!cache_tree_fully_valid(the_index.cache_tree))\n \t\tcache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n \n \tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 10a827b1f4a..abbed750276 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -272,8 +272,8 @@ static int list_paths(struct string_list *list, const char *with_tree,\n \n \t/* TODO: audit for interaction with sparse-index. */\n \tensure_full_index(&the_index);\n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \t\tstruct string_list_item *item;\n \n \t\tif (ce->ce_flags & CE_UPDATE)\n@@ -461,8 +461,8 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \tif (!only && !pathspec.nr) {\n \t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n \t\trefresh_cache_or_die(refresh_flags);\n-\t\tif (active_cache_changed\n-\t\t    || !cache_tree_fully_valid(active_cache_tree))\n+\t\tif (the_index.cache_changed\n+\t\t    || !cache_tree_fully_valid(the_index.cache_tree))\n \t\t\tupdate_main_cache_tree(WRITE_TREE_SILENT);\n \t\tif (write_locked_index(&the_index, &index_lock,\n \t\t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n@@ -998,10 +998,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \n \t\t\t/* TODO: audit for interaction with sparse-index. */\n \t\t\tensure_full_index(&the_index);\n-\t\t\tfor (i = 0; i < active_nr; i++)\n-\t\t\t\tif (ce_intent_to_add(active_cache[i]))\n+\t\t\tfor (i = 0; i < the_index.cache_nr; i++)\n+\t\t\t\tif (ce_intent_to_add(the_index.cache[i]))\n \t\t\t\t\tita_nr++;\n-\t\t\tcommittable = active_nr - ita_nr > 0;\n+\t\t\tcommittable = the_index.cache_nr - ita_nr > 0;\n \t\t} else {\n \t\t\t/*\n \t\t\t * Unless the user did explicitly request a submodule\n@@ -1823,7 +1823,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tappend_merge_tag_headers(parents, &tail);\n \t}\n \n-\tif (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,\n+\tif (commit_tree_extended(sb.buf, sb.len, &the_index.cache_tree->oid,\n \t\t\t\t parents, &oid, author_ident.buf, NULL,\n \t\t\t\t sign_commit, extra)) {\n \t\trollback_index_files();\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 7436e1a68ef..cd47675e371 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -961,26 +961,26 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\tread_cache();\n \t\t/* TODO: audit for interaction with sparse-index. */\n \t\tensure_full_index(&the_index);\n-\t\tfor (i = 0; i < active_nr; i++) {\n+\t\tfor (i = 0; i < the_index.cache_nr; i++) {\n \t\t\tunsigned int mode;\n \t\t\tstruct blob *blob;\n \t\t\tstruct object *obj;\n \n-\t\t\tmode = active_cache[i]->ce_mode;\n+\t\t\tmode = the_index.cache[i]->ce_mode;\n \t\t\tif (S_ISGITLINK(mode))\n \t\t\t\tcontinue;\n \t\t\tblob = lookup_blob(the_repository,\n-\t\t\t\t\t   &active_cache[i]->oid);\n+\t\t\t\t\t   &the_index.cache[i]->oid);\n \t\t\tif (!blob)\n \t\t\t\tcontinue;\n \t\t\tobj = &blob->object;\n \t\t\tobj->flags |= USED;\n \t\t\tfsck_put_object_name(&fsck_walk_options, &obj->oid,\n-\t\t\t\t\t     \":%s\", active_cache[i]->name);\n+\t\t\t\t\t     \":%s\", the_index.cache[i]->name);\n \t\t\tmark_object_reachable(obj);\n \t\t}\n-\t\tif (active_cache_tree)\n-\t\t\tfsck_cache_tree(active_cache_tree);\n+\t\tif (the_index.cache_tree)\n+\t\t\tfsck_cache_tree(the_index.cache_tree);\n \t\tfsck_resolve_undo(&the_index);\n \t}\n \ndiff --git a/builtin/merge-index.c b/builtin/merge-index.c\nindex 012f52bd007..a334c513c9d 100644\n--- a/builtin/merge-index.c\n+++ b/builtin/merge-index.c\n@@ -14,11 +14,11 @@ static int merge_entry(int pos, const char *path)\n \tchar ownbuf[4][60];\n \tstruct child_process cmd = CHILD_PROCESS_INIT;\n \n-\tif (pos >= active_nr)\n+\tif (pos >= the_index.cache_nr)\n \t\tdie(\"git merge-index: %s not in the cache\", path);\n \tfound = 0;\n \tdo {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tint stage = ce_stage(ce);\n \n \t\tif (strcmp(ce->name, path))\n@@ -28,7 +28,7 @@ static int merge_entry(int pos, const char *path)\n \t\txsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), \"%o\", ce->ce_mode);\n \t\targuments[stage] = hexbuf[stage];\n \t\targuments[stage + 4] = ownbuf[stage];\n-\t} while (++pos < active_nr);\n+\t} while (++pos < the_index.cache_nr);\n \tif (!found)\n \t\tdie(\"git merge-index: %s not in the cache\", path);\n \n@@ -62,8 +62,8 @@ static void merge_all(void)\n \tint i;\n \t/* TODO: audit for interaction with sparse-index. */\n \tensure_full_index(&the_index);\n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \t\ti += merge_entry(i, ce->name)-1;\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 2046992d75a..27218ee93c9 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -694,7 +694,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,\n \tif (!trees[nr_trees++])\n \t\treturn -1;\n \topts.fn = threeway_merge;\n-\tcache_tree_free(&active_cache_tree);\n+\tcache_tree_free(&the_index.cache_tree);\n \tfor (i = 0; i < nr_trees; i++) {\n \t\tparse_tree(trees[i]);\n \t\tinit_tree_desc(t+i, trees[i]->buffer, trees[i]->size);\n@@ -784,8 +784,8 @@ static int count_unmerged_entries(void)\n {\n \tint i, ret = 0;\n \n-\tfor (i = 0; i < active_nr; i++)\n-\t\tif (ce_stage(active_cache[i]))\n+\tfor (i = 0; i < the_index.cache_nr; i++)\n+\t\tif (ce_stage(the_index.cache[i]))\n \t\t\tret++;\n \n \treturn ret;\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 6f94c3b9238..883cf3ff12b 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -87,7 +87,7 @@ static void prepare_move_submodule(const char *src, int first,\n \t\t\t\t   const char **submodule_gitfile)\n {\n \tstruct strbuf submodule_dotgit = STRBUF_INIT;\n-\tif (!S_ISGITLINK(active_cache[first]->ce_mode))\n+\tif (!S_ISGITLINK(the_index.cache[first]->ce_mode))\n \t\tdie(_(\"Directory %s is in index and no submodule?\"), src);\n \tif (!is_staging_gitmodules_ok(&the_index))\n \t\tdie(_(\"Please stage your changes to .gitmodules or stash them to proceed\"));\n@@ -111,8 +111,8 @@ static int index_range_of_same_dir(const char *src, int length,\n \t\tdie(_(\"%.*s is in index\"), len_w_slash, src_w_slash);\n \n \tfirst = -1 - first;\n-\tfor (last = first; last < active_nr; last++) {\n-\t\tconst char *path = active_cache[last]->name;\n+\tfor (last = first; last < the_index.cache_nr; last++) {\n+\t\tconst char *path = the_index.cache[last]->name;\n \t\tif (strncmp(path, src_w_slash, len_w_slash))\n \t\t\tbreak;\n \t}\n@@ -143,7 +143,7 @@ static int empty_dir_has_sparse_contents(const char *name)\n \t\tpos = -pos - 1;\n \t\tif (pos >= the_index.cache_nr)\n \t\t\tgoto free_return;\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \t\tif (strncmp(with_slash, ce->name, length))\n \t\t\tgoto free_return;\n \t\tif (ce_skip_worktree(ce))\n@@ -268,7 +268,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tbad = _(\"bad source\");\n \t\t\t\tgoto act_on_entry;\n \t\t\t}\n-\t\t\tce = active_cache[pos];\n+\t\t\tce = the_index.cache[pos];\n \t\t\tif (!ce_skip_worktree(ce)) {\n \t\t\t\tbad = _(\"bad source\");\n \t\t\t\tgoto act_on_entry;\n@@ -331,7 +331,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tdst_len = strlen(dst);\n \n \t\t\tfor (j = 0; j < last - first; j++) {\n-\t\t\t\tconst struct cache_entry *ce = active_cache[first + j];\n+\t\t\t\tconst struct cache_entry *ce = the_index.cache[first + j];\n \t\t\t\tconst char *path = ce->name;\n \t\t\t\tsource[argc + j] = path;\n \t\t\t\tdestination[argc + j] =\n@@ -472,7 +472,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tassert(pos >= 0);\n \t\tif (!(mode & SPARSE) && !lstat(src, &st))\n \t\t\tsparse_and_dirty = ie_modified(&the_index,\n-\t\t\t\t\t\t       active_cache[pos], &st,\n+\t\t\t\t\t\t       the_index.cache[pos],\n+\t\t\t\t\t\t       &st,\n \t\t\t\t\t\t       0);\n \t\trename_index_entry_at(&the_index, pos, dst);\n \n@@ -489,7 +490,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t    path_in_sparse_checkout(dst, &the_index)) {\n \t\t\t\t/* from out-of-cone to in-cone */\n \t\t\t\tint dst_pos = cache_name_pos(dst, strlen(dst));\n-\t\t\t\tstruct cache_entry *dst_ce = active_cache[dst_pos];\n+\t\t\t\tstruct cache_entry *dst_ce = the_index.cache[dst_pos];\n \n \t\t\t\tdst_ce->ce_flags &= ~CE_SKIP_WORKTREE;\n \n@@ -500,7 +501,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t\t   !path_in_sparse_checkout(dst, &the_index)) {\n \t\t\t\t/* from in-cone to out-of-cone */\n \t\t\t\tint dst_pos = cache_name_pos(dst, strlen(dst));\n-\t\t\t\tstruct cache_entry *dst_ce = active_cache[dst_pos];\n+\t\t\t\tstruct cache_entry *dst_ce = the_index.cache[dst_pos];\n \n \t\t\t\t/*\n \t\t\t\t * if src is clean, it will suffice to remove it\ndiff --git a/builtin/read-tree.c b/builtin/read-tree.c\nindex 9ced755a6db..c50b563e2be 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -253,7 +253,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \tif (nr_trees == 1 && !opts.prefix)\n \t\topts.skip_cache_tree_update = 1;\n \n-\tcache_tree_free(&active_cache_tree);\n+\tcache_tree_free(&the_index.cache_tree);\n \tfor (i = 0; i < nr_trees; i++) {\n \t\tstruct tree *tree = trees[i];\n \t\tparse_tree(tree);\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 59f777a1da4..75e061f5dcf 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -161,7 +161,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,\n \t\t * to properly construct the reset sparse directory.\n \t\t */\n \t\tpos = cache_name_pos(one->path, strlen(one->path));\n-\t\tif ((pos >= 0 && ce_skip_worktree(active_cache[pos])) ||\n+\t\tif ((pos >= 0 && ce_skip_worktree(the_index.cache[pos])) ||\n \t\t    (pos < 0 && !path_in_sparse_checkout(one->path, &the_index)))\n \t\t\tce->ce_flags |= CE_SKIP_WORKTREE;\n \ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex c717cdc97f5..2b23eb25438 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -35,8 +35,8 @@ static int get_ours_cache_pos(const char *path, int pos)\n {\n \tint i = -pos - 1;\n \n-\twhile ((i < active_nr) && !strcmp(active_cache[i]->name, path)) {\n-\t\tif (ce_stage(active_cache[i]) == 2)\n+\twhile ((i < the_index.cache_nr) && !strcmp(the_index.cache[i]->name, path)) {\n+\t\tif (ce_stage(the_index.cache[i]) == 2)\n \t\t\treturn i;\n \t\ti++;\n \t}\n@@ -78,7 +78,7 @@ static void submodules_absorb_gitdir_if_needed(void)\n \t\t\tif (pos < 0)\n \t\t\t\tcontinue;\n \t\t}\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \n \t\tif (!S_ISGITLINK(ce->ce_mode) ||\n \t\t    !file_exists(ce->name) ||\n@@ -127,11 +127,11 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\t\tif (pos < 0)\n \t\t\t\tcontinue;\n \n-\t\t\tif (!S_ISGITLINK(active_cache[pos]->ce_mode) ||\n+\t\t\tif (!S_ISGITLINK(the_index.cache[pos]->ce_mode) ||\n \t\t\t    is_empty_dir(name))\n \t\t\t\tcontinue;\n \t\t}\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \n \t\tif (lstat(ce->name, &st) < 0) {\n \t\t\tif (!is_missing_file_error(errno))\n@@ -303,8 +303,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \tif (pathspec_needs_expanded_index(&the_index, &pathspec))\n \t\tensure_full_index(&the_index);\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \n \t\tif (!include_sparse &&\n \t\t    (ce_skip_worktree(ce) ||\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex bb5485b4095..c251419af7c 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -454,10 +454,10 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)\n \t\t * path, but left it out of the working tree, then clear the\n \t\t * SKIP_WORKTREE bit and write it to the working tree.\n \t\t */\n-\t\tif (pos >= 0 && ce_skip_worktree(active_cache[pos])) {\n+\t\tif (pos >= 0 && ce_skip_worktree(the_index.cache[pos])) {\n \t\t\tstruct stat st;\n \n-\t\t\tce = active_cache[pos];\n+\t\t\tce = the_index.cache[pos];\n \t\t\tif (!lstat(ce->name, &st)) {\n \t\t\t\t/* Conflicting path present; relocate it */\n \t\t\t\tstruct strbuf new_path = STRBUF_INIT;\n@@ -1520,8 +1520,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q\n \n \t\t/* TODO: audit for interaction with sparse-index. */\n \t\tensure_full_index(&the_index);\n-\t\tfor (i = 0; i < active_nr; i++)\n-\t\t\tce_path_match(&the_index, active_cache[i], ps,\n+\t\tfor (i = 0; i < the_index.cache_nr; i++)\n+\t\t\tce_path_match(&the_index, the_index.cache[i], ps,\n \t\t\t\t      ps_matched);\n \n \t\tif (report_path_error(ps_matched, ps)) {\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex a7683d35299..808865a5e31 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -199,8 +199,8 @@ static int module_list_compute(const char **argv,\n \tif (read_cache() < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \n \t\tif (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),\n \t\t\t\t    0, ps_matched, 1) ||\n@@ -209,8 +209,8 @@ static int module_list_compute(const char **argv,\n \n \t\tALLOC_GROW(list->entries, list->nr + 1, list->alloc);\n \t\tlist->entries[list->nr++] = ce;\n-\t\twhile (i + 1 < active_nr &&\n-\t\t       !strcmp(ce->name, active_cache[i + 1]->name))\n+\t\twhile (i + 1 < the_index.cache_nr &&\n+\t\t       !strcmp(ce->name, the_index.cache[i + 1]->name))\n \t\t\t/*\n \t\t\t * Skip entries with the same name in different stages\n \t\t\t * to make sure an entry is returned only once.\n@@ -3255,15 +3255,15 @@ static void die_on_index_match(const char *path, int force)\n \t\t * need to check ps_matched[0] to know if a cache\n \t\t * entry matched.\n \t\t */\n-\t\tfor (i = 0; i < active_nr; i++) {\n-\t\t\tce_path_match(&the_index, active_cache[i], &ps,\n+\t\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\t\tce_path_match(&the_index, the_index.cache[i], &ps,\n \t\t\t\t      ps_matched);\n \n \t\t\tif (ps_matched[0]) {\n \t\t\t\tif (!force)\n \t\t\t\t\tdie(_(\"'%s' already exists in the index\"),\n \t\t\t\t\t    path);\n-\t\t\t\tif (!S_ISGITLINK(active_cache[i]->ce_mode))\n+\t\t\t\tif (!S_ISGITLINK(the_index.cache[i]->ce_mode))\n \t\t\t\t\tdie(_(\"'%s' already exists in the index \"\n \t\t\t\t\t      \"and is not a submodule\"), path);\n \t\t\t\tbreak;\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex 533ba66df05..fec3da05abb 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -239,14 +239,14 @@ static int mark_ce_flags(const char *path, int flag, int mark)\n \tint namelen = strlen(path);\n \tint pos = cache_name_pos(path, namelen);\n \tif (0 <= pos) {\n-\t\tmark_fsmonitor_invalid(&the_index, active_cache[pos]);\n+\t\tmark_fsmonitor_invalid(&the_index, the_index.cache[pos]);\n \t\tif (mark)\n-\t\t\tactive_cache[pos]->ce_flags |= flag;\n+\t\t\tthe_index.cache[pos]->ce_flags |= flag;\n \t\telse\n-\t\t\tactive_cache[pos]->ce_flags &= ~flag;\n-\t\tactive_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;\n+\t\t\tthe_index.cache[pos]->ce_flags &= ~flag;\n+\t\tthe_index.cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;\n \t\tcache_tree_invalidate_path(&the_index, path);\n-\t\tactive_cache_changed |= CE_ENTRY_CHANGED;\n+\t\tthe_index.cache_changed |= CE_ENTRY_CHANGED;\n \t\treturn 0;\n \t}\n \treturn -1;\n@@ -335,7 +335,7 @@ static int process_directory(const char *path, int len, struct stat *st)\n \n \t/* Exact match: file or existing gitlink */\n \tif (pos >= 0) {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tif (S_ISGITLINK(ce->ce_mode)) {\n \n \t\t\t/* Do nothing to the index if there is no HEAD! */\n@@ -350,8 +350,8 @@ static int process_directory(const char *path, int len, struct stat *st)\n \n \t/* Inexact match: is there perhaps a subdirectory match? */\n \tpos = -pos-1;\n-\twhile (pos < active_nr) {\n-\t\tconst struct cache_entry *ce = active_cache[pos++];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tconst struct cache_entry *ce = the_index.cache[pos++];\n \n \t\tif (strncmp(ce->name, path, len))\n \t\t\tbreak;\n@@ -382,7 +382,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)\n \t\treturn error(\"'%s' is beyond a symbolic link\", path);\n \n \tpos = cache_name_pos(path, len);\n-\tce = pos < 0 ? NULL : active_cache[pos];\n+\tce = pos < 0 ? NULL : the_index.cache[pos];\n \tif (ce && ce_skip_worktree(ce)) {\n \t\t/*\n \t\t * working directory version is assumed \"good\"\n@@ -444,7 +444,7 @@ static void chmod_path(char flip, const char *path)\n \tpos = cache_name_pos(path, strlen(path));\n \tif (pos < 0)\n \t\tgoto fail;\n-\tce = active_cache[pos];\n+\tce = the_index.cache[pos];\n \tif (chmod_index_entry(&the_index, ce, flip) < 0)\n \t\tgoto fail;\n \n@@ -642,8 +642,8 @@ static int unresolve_one(const char *path)\n \tif (0 <= pos) {\n \t\t/* already merged */\n \t\tpos = unmerge_index_entry_at(&the_index, pos);\n-\t\tif (pos < active_nr) {\n-\t\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tif (pos < the_index.cache_nr) {\n+\t\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\t\tif (ce_stage(ce) &&\n \t\t\t    ce_namelen(ce) == namelen &&\n \t\t\t    !memcmp(ce->name, path, namelen))\n@@ -656,8 +656,8 @@ static int unresolve_one(const char *path)\n \t\t * want to do anything in the former case.\n \t\t */\n \t\tpos = -pos-1;\n-\t\tif (pos < active_nr) {\n-\t\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tif (pos < the_index.cache_nr) {\n+\t\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\t\tif (ce_namelen(ce) == namelen &&\n \t\t\t    !memcmp(ce->name, path, namelen)) {\n \t\t\t\tfprintf(stderr,\n@@ -752,8 +752,8 @@ static int do_reupdate(const char **paths,\n \t\t */\n \t\thas_head = 0;\n  redo:\n-\tfor (pos = 0; pos < active_nr; pos++) {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tstruct cache_entry *old = NULL;\n \t\tint save_nr;\n \t\tchar *path;\n@@ -782,12 +782,12 @@ static int do_reupdate(const char **paths,\n \t\t * path anymore, in which case, under 'allow_remove',\n \t\t * or worse yet 'allow_replace', active_nr may decrease.\n \t\t */\n-\t\tsave_nr = active_nr;\n+\t\tsave_nr = the_index.cache_nr;\n \t\tpath = xstrdup(ce->name);\n \t\tupdate_one(path);\n \t\tfree(path);\n \t\tdiscard_cache_entry(old);\n-\t\tif (save_nr != active_nr)\n+\t\tif (save_nr != the_index.cache_nr)\n \t\t\tgoto redo;\n \t}\n \tclear_pathspec(&pathspec);\n@@ -813,7 +813,7 @@ static int refresh(struct refresh_params *o, unsigned int flag)\n \t\t * refresh_cache() as these are no actual errors.\n \t\t * cmd_status() does the same.\n \t\t */\n-\t\tactive_cache_changed |= SOMETHING_CHANGED;\n+\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n \t}\n \treturn 0;\n }\n@@ -951,7 +951,7 @@ static enum parse_opt_result unresolve_callback(\n \t*has_errors = do_unresolve(ctx->argc, ctx->argv,\n \t\t\t\tprefix, prefix ? strlen(prefix) : 0);\n \tif (*has_errors)\n-\t\tactive_cache_changed = 0;\n+\t\tthe_index.cache_changed = 0;\n \n \tctx->argv += ctx->argc - 1;\n \tctx->argc = 1;\n@@ -972,7 +972,7 @@ static enum parse_opt_result reupdate_callback(\n \tsetup_work_tree();\n \t*has_errors = do_reupdate(ctx->argv + 1, prefix);\n \tif (*has_errors)\n-\t\tactive_cache_changed = 0;\n+\t\tthe_index.cache_changed = 0;\n \n \tctx->argv += ctx->argc - 1;\n \tctx->argc = 1;\n@@ -1178,7 +1178,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\t    INDEX_FORMAT_LB, INDEX_FORMAT_UB);\n \n \t\tif (the_index.version != preferred_index_format)\n-\t\t\tactive_cache_changed |= SOMETHING_CHANGED;\n+\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n \t\tthe_index.version = preferred_index_format;\n \t}\n \n@@ -1290,7 +1290,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\treport(_(\"fsmonitor disabled\"));\n \t}\n \n-\tif (active_cache_changed || force_write) {\n+\tif (the_index.cache_changed || force_write) {\n \t\tif (newfd < 0) {\n \t\t\tif (refresh_args.flags & REFRESH_QUIET)\n \t\t\t\texit(128);\ndiff --git a/cache.h b/cache.h\nindex 79b8d479710..805e25f9a67 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -436,10 +436,7 @@ void prefetch_cache_entries(const struct index_state *istate,\n #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n extern struct index_state the_index;\n \n-#define active_cache (the_index.cache)\n #define active_nr (the_index.cache_nr)\n-#define active_cache_changed (the_index.cache_changed)\n-#define active_cache_tree (the_index.cache_tree)\n \n #define read_cache() repo_read_index(the_repository)\n #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))\ndiff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci\nindex 89c18986160..8b1ed65e7b0 100644\n--- a/contrib/coccinelle/index-compatibility.cocci\n+++ b/contrib/coccinelle/index-compatibility.cocci\n@@ -1,3 +1,25 @@\n+// the_index.* variables\n+@@\n+@@\n+(\n+- active_cache\n++ the_index.cache\n+|\n+- active_cache_changed\n++ the_index.cache_changed\n+|\n+- active_cache_tree\n++ the_index.cache_tree\n+)\n+\n+@@\n+identifier f != prepare_to_commit;\n+@@\n+  f(...) {<...\n+- active_nr\n++ the_index.cache_nr\n+  ...>}\n+\n // \"the_repository\" simple cases\n @@\n @@\ndiff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci\nindex cf1ea57d700..8207aee62c3 100644\n--- a/contrib/coccinelle/index-compatibility.pending.cocci\n+++ b/contrib/coccinelle/index-compatibility.pending.cocci\n@@ -1,20 +1,3 @@\n-// the_index.* variables\n-@@\n-@@\n-(\n-- active_cache\n-+ the_index.cache\n-|\n-- active_nr\n-+ the_index.cache_nr\n-|\n-- active_cache_changed\n-+ the_index.cache_changed\n-|\n-- active_cache_tree\n-+ the_index.cache_tree\n-)\n-\n // \"the_repository\" simple cases\n @@\n @@\ndiff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c\nindex 0d6d7f1ecbf..8d88111b357 100644\n--- a/t/helper/test-dump-cache-tree.c\n+++ b/t/helper/test-dump-cache-tree.c\n@@ -67,7 +67,7 @@ int cmd__dump_cache_tree(int ac, const char **av)\n \tistate = the_index;\n \tistate.cache_tree = another;\n \tcache_tree_update(&istate, WRITE_TREE_DRY_RUN);\n-\tret = dump_cache_tree(active_cache_tree, another, \"\");\n+\tret = dump_cache_tree(the_index.cache_tree, another, \"\");\n \tcache_tree_free(&another);\n \n \treturn ret;\ndiff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c\nindex 026c802479d..20e2e31f9e2 100644\n--- a/t/helper/test-scrap-cache-tree.c\n+++ b/t/helper/test-scrap-cache-tree.c\n@@ -12,8 +12,8 @@ int cmd__scrap_cache_tree(int ac, const char **av)\n \thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n \tif (read_cache() < 0)\n \t\tdie(\"unable to read index file\");\n-\tcache_tree_free(&active_cache_tree);\n-\tactive_cache_tree = NULL;\n+\tcache_tree_free(&the_index.cache_tree);\n+\tthe_index.cache_tree = NULL;\n \tif (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))\n \t\tdie(\"unable to write index file\");\n \treturn 0;\n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467586","messageId":"patch-v2-09.11-429eecc78ec-20221119T125551Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 09/11] {builtin/*,repository}.c: add & use \"USE_THE_INDEX_VARIABLE\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:36Z","receivedAt":"2022-11-19T13:08:25Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Split up the \"USE_THE_INDEX_COMPATIBILITY_MACROS\" into that setting\nand a more narrow \"USE_THE_INDEX_VARIABLE\". In the case of these\nbuilt-ins we only need \"the_index\" variable, but not the compatibility\nwrapper for functions we're not using.\n\nLet's then have some users of \"USE_THE_INDEX_COMPATIBILITY_MACROS\" use\nthis more narrow and descriptive define.\n\nFor context: The USE_THE_INDEX_COMPATIBILITY_MACROS macro was added to\ntest-tool.h in f8adbec9fea (cache.h: flip\nNO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24).\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/cat-file.c   | 2 +-\n builtin/difftool.c   | 2 +-\n builtin/merge-tree.c | 2 +-\n builtin/pull.c       | 2 +-\n cache.h              | 6 +++++-\n repository.c         | 2 +-\n 6 files changed, 10 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex fa7bd891692..b3be58b1fb0 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex d7f08c8a7fa..d9b76226f6a 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -11,7 +11,7 @@\n  *\n  * Copyright (C) 2016 Johannes Schindelin\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex fe853aa8f91..e3767087bbf 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"tree-walk.h\"\n #include \"xdiff-interface.h\"\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 4a2a6db2dce..1ab4de0005d 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -5,7 +5,7 @@\n  *\n  * Fetch one or more remote refs and merge it/them into the current HEAD.\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/cache.h b/cache.h\nindex 805e25f9a67..707806d2125 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -433,9 +433,11 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *);\n void prefetch_cache_entries(const struct index_state *istate,\n \t\t\t    must_prefetch_predicate must_prefetch);\n \n-#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n+#if defined(USE_THE_INDEX_COMPATIBILITY_MACROS) || defined(USE_THE_INDEX_VARIABLE)\n extern struct index_state the_index;\n \n+#ifndef USE_THE_INDEX_VARIABLE\n+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n #define active_nr (the_index.cache_nr)\n \n #define read_cache() repo_read_index(the_repository)\n@@ -447,6 +449,8 @@ extern struct index_state the_index;\n #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)\n #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n+#endif\n+#endif\n \n #define TYPE_BITS 3\n \ndiff --git a/repository.c b/repository.c\nindex 5d166b692c8..3427085fd6d 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -2,7 +2,7 @@\n  * not really _using_ the compat macros, just make sure the_index\n  * declaration matches the definition in this file.\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"repository.h\"\n #include \"object-store.h\"\n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467587","messageId":"patch-v2-10.11-5456859b244-20221119T125551Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 10/11] cache.h & test-tool.h: add & use \"USE_THE_INDEX_VARIABLE\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:37Z","receivedAt":"2022-11-19T13:08:28Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"In a preceding commit we fully applied the\n\"index-compatibility.pending.cocci\" rule to \"t/helper/*\".\n\nLet's now stop defining \"USE_THE_INDEX_COMPATIBILITY_MACROS\" in\ntest-tool.h itself, and instead instead define\n\"USE_THE_INDEX_VARIABLE\" in the individual test helpers that need\nit. This mirrors how we do the same thing in the \"builtin/\" directory.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/helper/test-cache-tree.c           | 1 +\n t/helper/test-dump-cache-tree.c      | 1 +\n t/helper/test-dump-split-index.c     | 1 +\n t/helper/test-dump-untracked-cache.c | 2 +-\n t/helper/test-fast-rebase.c          | 2 +-\n t/helper/test-lazy-init-name-hash.c  | 1 +\n t/helper/test-read-cache.c           | 1 +\n t/helper/test-scrap-cache-tree.c     | 1 +\n t/helper/test-tool.h                 | 1 -\n t/helper/test-write-cache.c          | 1 +\n 10 files changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c\nindex 5514afdfe7a..9159a173015 100644\n--- a/t/helper/test-cache-tree.c\n+++ b/t/helper/test-cache-tree.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"tree.h\"\ndiff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c\nindex 4bf8bc3df6e..454f17b1a0c 100644\n--- a/t/helper/test-dump-cache-tree.c\n+++ b/t/helper/test-dump-cache-tree.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"tree.h\"\ndiff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c\nindex a209880eb37..0ea97b84072 100644\n--- a/t/helper/test-dump-split-index.c\n+++ b/t/helper/test-dump-split-index.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"split-index.h\"\ndiff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c\nindex ffe34736e53..6d53683f13b 100644\n--- a/t/helper/test-dump-untracked-cache.c\n+++ b/t/helper/test-dump-untracked-cache.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"dir.h\"\ndiff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c\nindex 9def2ba6889..efc82dd80c5 100644\n--- a/t/helper/test-fast-rebase.c\n+++ b/t/helper/test-fast-rebase.c\n@@ -10,7 +10,7 @@\n  * refactoring is the better route).\n  */\n \n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n \n #include \"cache-tree.h\"\ndiff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c\nindex 7e8723a1900..ab86c14c8ba 100644\n--- a/t/helper/test-lazy-init-name-hash.c\n+++ b/t/helper/test-lazy-init-name-hash.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"parse-options.h\"\ndiff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c\nindex a089be9104c..23e9e27109f 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"config.h\"\ndiff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c\nindex 9206dee1fd2..a26107ed70a 100644\n--- a/t/helper/test-scrap-cache-tree.c\n+++ b/t/helper/test-scrap-cache-tree.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"lockfile.h\"\ndiff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\nindex da7cd6351a6..2e20a16eb82 100644\n--- a/t/helper/test-tool.h\n+++ b/t/helper/test-tool.h\n@@ -1,7 +1,6 @@\n #ifndef TEST_TOOL_H\n #define TEST_TOOL_H\n \n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"git-compat-util.h\"\n \n int cmd__advise_if_enabled(int argc, const char **argv);\ndiff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c\nindex 66287d6d47d..7d45cd61e82 100644\n--- a/t/helper/test-write-cache.c\n+++ b/t/helper/test-write-cache.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"cache.h\"\n #include \"lockfile.h\"\n-- \n2.38.0.1509.g9445af83948\n\n"},{"id":"467588","messageId":"patch-v2-11.11-b645cec189e-20221119T125551Z-avarab@gmail.com","threadId":"58812","inReplyTo":"cover-v2-00.11-00000000000-20221119T125550Z-avarab@gmail.com","subject":"[PATCH v2 11/11] cocci: apply \"pending\" index-compatibility to some \"builtin/*.c\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-19T13:07:38Z","receivedAt":"2022-11-19T13:08:34Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Apply \"index-compatibility.pending.cocci\" rule to \"builtin/*\", but\nexclude those where we conflict with in-flight changes.\n\nAs a result some of them end up using only \"the_index\", so let's have\nthem use the more narrow \"USE_THE_INDEX_VARIABLE\" rather than\n\"USE_THE_INDEX_COMPATIBILITY_MACROS\".\n\nManual changes not made by coccinelle, that were squashed in:\n\n* Whitespace-wrap argument lists for repo_hold_locked_index(),\n  repo_read_index_preload() and repo_refresh_and_write_index(), in cases\n  where the line became too long after the transformation.\n* Change \"refresh_cache()\" to \"refresh_index()\" in a comment in\n  \"builtin/update-index.c\".\n* For those whose call was followed by perror(\"<macro-name>\"), change\n  it to perror(\"<function-name>\"), referring to the new function.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/add.c                                 |  8 +--\n builtin/am.c                                  | 21 ++++----\n builtin/check-attr.c                          |  4 +-\n builtin/check-ignore.c                        |  4 +-\n builtin/checkout-index.c                      |  9 ++--\n builtin/checkout.c                            | 12 ++---\n builtin/clean.c                               |  4 +-\n builtin/clone.c                               |  4 +-\n builtin/commit.c                              | 40 +++++++-------\n builtin/describe.c                            |  7 +--\n builtin/diff-files.c                          |  5 +-\n builtin/diff-index.c                          |  9 ++--\n builtin/diff-tree.c                           |  4 +-\n builtin/diff.c                                | 25 +++++----\n builtin/fsck.c                                |  4 +-\n builtin/merge-index.c                         |  6 +--\n builtin/merge-ours.c                          |  3 +-\n builtin/merge.c                               | 19 ++++---\n builtin/mv.c                                  | 16 +++---\n builtin/read-tree.c                           |  4 +-\n builtin/rebase.c                              |  6 +--\n builtin/reset.c                               |  9 ++--\n builtin/rev-parse.c                           |  4 +-\n builtin/rm.c                                  |  8 +--\n builtin/stash.c                               | 35 ++++++------\n builtin/submodule--helper.c                   | 14 ++---\n builtin/update-index.c                        | 19 +++----\n cache.h                                       |  5 --\n contrib/coccinelle/index-compatibility.cocci  | 53 ++++++++++++++++++\n .../index-compatibility.pending.cocci         | 54 -------------------\n 30 files changed, 213 insertions(+), 202 deletions(-)\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 23f9f0e08bb..76277df326b 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) 2006 Linus Torvalds\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n@@ -312,7 +312,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)\n \n \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n \n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"Could not read the index\"));\n \n \trepo_init_revisions(the_repository, &rev, prefix);\n@@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n \t/*\n \t * Check the \"pathspec '%s' did not match any files\" block\n@@ -587,7 +587,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t\t (!(addremove || take_worktree_changes)\n \t\t  ? ADD_CACHE_IGNORE_REMOVAL : 0));\n \n-\tif (read_cache_preload(&pathspec) < 0)\n+\tif (repo_read_index_preload(the_repository, &pathspec, 0) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tdie_in_unpopulated_submodule(&the_index, prefix);\ndiff --git a/builtin/am.c b/builtin/am.c\nindex f362a1c29fd..30c9b3a9cd7 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1519,8 +1519,8 @@ static int run_apply(const struct am_state *state, const char *index_file)\n \n \tif (index_file) {\n \t\t/* Reload index as apply_all_patches() will have modified it. */\n-\t\tdiscard_cache();\n-\t\tread_cache_from(index_file);\n+\t\tdiscard_index(&the_index);\n+\t\tread_index_from(&the_index, index_file, get_git_dir());\n \t}\n \n \treturn 0;\n@@ -1562,8 +1562,8 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \tif (build_fake_ancestor(state, index_path))\n \t\treturn error(\"could not build fake ancestor\");\n \n-\tdiscard_cache();\n-\tread_cache_from(index_path);\n+\tdiscard_index(&the_index);\n+\tread_index_from(&the_index, index_path, get_git_dir());\n \n \tif (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))\n \t\treturn error(_(\"Repository lacks necessary blobs to fall back on 3-way merge.\"));\n@@ -1596,8 +1596,8 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \n \tsay(state, stdout, _(\"Falling back to patching base and 3-way merge...\"));\n \n-\tdiscard_cache();\n-\tread_cache();\n+\tdiscard_index(&the_index);\n+\trepo_read_index(the_repository);\n \n \t/*\n \t * This is not so wrong. Depending on which base we picked, orig_tree\n@@ -1781,7 +1781,8 @@ static void am_run(struct am_state *state, int resume)\n \n \tunlink(am_path(state, \"dirtyindex\"));\n \n-\tif (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0)\n+\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,\n+\t\t\t\t\t NULL, NULL, NULL) < 0)\n \t\tdie(_(\"unable to write index file\"));\n \n \tif (repo_index_has_changes(the_repository, NULL, &sb)) {\n@@ -1967,9 +1968,9 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)\n \tif (parse_tree(head) || parse_tree(remote))\n \t\treturn -1;\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 1;\n@@ -2007,7 +2008,7 @@ static int merge_tree(struct tree *tree)\n \tif (parse_tree(tree))\n \t\treturn -1;\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 1;\ndiff --git a/builtin/check-attr.c b/builtin/check-attr.c\nindex dd833977864..0fef10eb6bc 100644\n--- a/builtin/check-attr.c\n+++ b/builtin/check-attr.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\n@@ -115,7 +115,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)\n \targc = parse_options(argc, argv, prefix, check_attr_options,\n \t\t\t     check_attr_usage, PARSE_OPT_KEEP_DASHDASH);\n \n-\tif (read_cache() < 0) {\n+\tif (repo_read_index(the_repository) < 0) {\n \t\tdie(\"invalid cache\");\n \t}\n \ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex 21912569650..ab776061c7c 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\n@@ -179,7 +179,7 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)\n \t\tdie(_(\"--non-matching is only valid with --verbose\"));\n \n \t/* read_cache() is only necessary so we can watch out for submodules. */\n-\tif (!no_index && read_cache() < 0)\n+\tif (!no_index && repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tsetup_standard_excludes(&dir);\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex c2aee450c40..cf6fba97ba7 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -4,7 +4,7 @@\n  * Copyright (C) 2005 Linus Torvalds\n  *\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"dir.h\"\n@@ -65,7 +65,7 @@ static void write_tempfile_record(const char *name, const char *prefix)\n static int checkout_file(const char *name, const char *prefix)\n {\n \tint namelen = strlen(name);\n-\tint pos = cache_name_pos(name, namelen);\n+\tint pos = index_name_pos(&the_index, name, namelen);\n \tint has_same_name = 0;\n \tint is_file = 0;\n \tint is_skipped = 1;\n@@ -249,7 +249,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\tif (read_cache() < 0) {\n+\tif (repo_read_index(the_repository) < 0) {\n \t\tdie(\"invalid cache\");\n \t}\n \n@@ -270,7 +270,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \tif (index_opt && !state.base_dir_len && !to_tempfile) {\n \t\tstate.refresh_cache = 1;\n \t\tstate.istate = &the_index;\n-\t\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\t\trepo_hold_locked_index(the_repository, &lock_file,\n+\t\t\t\t       LOCK_DIE_ON_ERROR);\n \t}\n \n \tget_parallel_checkout_configs(&pc_workers, &pc_threshold);\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 3fd303f5604..3fa29a08eea 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"blob.h\"\n@@ -148,7 +148,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \t * entry in place. Whether it is UPTODATE or not, checkout_entry will\n \t * do the right thing.\n \t */\n-\tpos = cache_name_pos(ce->name, ce->ce_namelen);\n+\tpos = index_name_pos(&the_index, ce->name, ce->ce_namelen);\n \tif (pos >= 0) {\n \t\tstruct cache_entry *old = the_index.cache[pos];\n \t\tif (ce->ce_mode == old->ce_mode &&\n@@ -529,7 +529,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t}\n \n \trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n-\tif (read_cache_preload(&opts->pathspec) < 0)\n+\tif (repo_read_index_preload(the_repository, &opts->pathspec, 0) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n \tif (opts->source_tree)\n@@ -741,8 +741,8 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \tstruct lock_file lock_file = LOCK_INIT;\n \tstruct tree *new_tree;\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n-\tif (read_cache_preload(NULL) < 0)\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n+\tif (repo_read_index_preload(the_repository, NULL, 0) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n \tresolve_undo_clear_index(&the_index);\n@@ -762,7 +762,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \t\tstruct unpack_trees_options topts;\n \t\tconst struct object_id *old_commit_oid;\n \n-\t\trefresh_cache(REFRESH_QUIET);\n+\t\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \n \t\tif (unmerged_index(&the_index)) {\n \t\t\terror(_(\"you need to resolve your current index first\"));\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex 7084e685f6f..b2701a28158 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -6,7 +6,7 @@\n  * Based on git-clean.sh by Pavel Roskin\n  */\n \n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\n@@ -1012,7 +1012,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tpl = add_pattern_list(&dir, EXC_CMDL, \"--exclude option\");\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 0e4348686b6..f518bb2dc1f 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -8,7 +8,7 @@\n  * Clone a repository into a different directory that does not yet exist.\n  */\n \n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n@@ -703,7 +703,7 @@ static int checkout(int submodule_progress, int filter_submodules)\n \t/* We need to be in the new work tree for the checkout */\n \tsetup_work_tree();\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n \tmemset(&opts, 0, sizeof opts);\n \topts.update = 1;\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex abbed750276..06b1330346f 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -316,7 +316,7 @@ static void create_base_index(const struct commit *current_head)\n \tstruct tree_desc t;\n \n \tif (!current_head) {\n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t\treturn;\n \t}\n \n@@ -343,7 +343,7 @@ static void refresh_cache_or_die(int refresh_flags)\n \t * refresh_flags contains REFRESH_QUIET, so the only errors\n \t * are for unmerged entries.\n \t */\n-\tif (refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN))\n+\tif (refresh_index(&the_index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))\n \t\tdie_resolve_conflict(\"commit\");\n }\n \n@@ -382,12 +382,13 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \t    (!amend || (fixup_message && strcmp(fixup_prefix, \"amend\"))))))\n \t\tdie(_(\"No paths with --include/--only does not make sense.\"));\n \n-\tif (read_cache_preload(&pathspec) < 0)\n+\tif (repo_read_index_preload(the_repository, &pathspec, 0) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tif (interactive) {\n \t\tchar *old_index_env = NULL, *old_repo_index_file;\n-\t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n+\t\trepo_hold_locked_index(the_repository, &index_lock,\n+\t\t\t\t       LOCK_DIE_ON_ERROR);\n \n \t\trefresh_cache_or_die(refresh_flags);\n \n@@ -410,8 +411,9 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \t\t\tunsetenv(INDEX_ENVIRONMENT);\n \t\tFREE_AND_NULL(old_index_env);\n \n-\t\tdiscard_cache();\n-\t\tread_cache_from(get_lock_file_path(&index_lock));\n+\t\tdiscard_index(&the_index);\n+\t\tread_index_from(&the_index, get_lock_file_path(&index_lock),\n+\t\t\t\tget_git_dir());\n \t\tif (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {\n \t\t\tif (reopen_lock_file(&index_lock) < 0)\n \t\t\t\tdie(_(\"unable to write index file\"));\n@@ -438,7 +440,8 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \t * (B) on failure, rollback the real index.\n \t */\n \tif (all || (also && pathspec.nr)) {\n-\t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n+\t\trepo_hold_locked_index(the_repository, &index_lock,\n+\t\t\t\t       LOCK_DIE_ON_ERROR);\n \t\tadd_files_to_cache(also ? prefix : NULL, &pathspec, 0);\n \t\trefresh_cache_or_die(refresh_flags);\n \t\tupdate_main_cache_tree(WRITE_TREE_SILENT);\n@@ -459,7 +462,8 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \t * We still need to refresh the index here.\n \t */\n \tif (!only && !pathspec.nr) {\n-\t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n+\t\trepo_hold_locked_index(the_repository, &index_lock,\n+\t\t\t\t       LOCK_DIE_ON_ERROR);\n \t\trefresh_cache_or_die(refresh_flags);\n \t\tif (the_index.cache_changed\n \t\t    || !cache_tree_fully_valid(the_index.cache_tree))\n@@ -505,13 +509,13 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \tif (list_paths(&partial, !current_head ? NULL : \"HEAD\", &pathspec))\n \t\texit(1);\n \n-\tdiscard_cache();\n-\tif (read_cache() < 0)\n+\tdiscard_index(&the_index);\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"cannot read the index\"));\n \n-\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);\n \tadd_remove_files(&partial);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \tupdate_main_cache_tree(WRITE_TREE_SILENT);\n \tif (write_locked_index(&the_index, &index_lock, 0))\n \t\tdie(_(\"unable to write new_index file\"));\n@@ -523,14 +527,14 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \n \tcreate_base_index(current_head);\n \tadd_remove_files(&partial);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \n \tif (write_locked_index(&the_index, &false_lock, 0))\n \t\tdie(_(\"unable to write temporary index file\"));\n \n-\tdiscard_cache();\n+\tdiscard_index(&the_index);\n \tret = get_lock_file_path(&false_lock);\n-\tread_cache_from(ret);\n+\tread_index_from(&the_index, ret, get_git_dir());\n out:\n \tstring_list_clear(&partial, 0);\n \tclear_pathspec(&pathspec);\n@@ -1068,9 +1072,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\t * and could have updated it. We must do this before we invoke\n \t\t * the editor and after we invoke run_status above.\n \t\t */\n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t}\n-\tread_cache_from(index_file);\n+\tread_index_from(&the_index, index_file, get_git_dir());\n \n \tif (update_main_cache_tree(0)) {\n \t\terror(_(\"Error building trees\"));\n@@ -1556,7 +1560,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \t\t      &s.pathspec, NULL, NULL);\n \n \tif (use_optional_locks())\n-\t\tfd = hold_locked_index(&index_lock, 0);\n+\t\tfd = repo_hold_locked_index(the_repository, &index_lock, 0);\n \telse\n \t\tfd = -1;\n \ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 23e3f05fb10..eea1e330c00 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n@@ -653,10 +653,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tint fd, result;\n \n \t\t\tsetup_work_tree();\n-\t\t\tread_cache();\n+\t\t\trepo_read_index(the_repository);\n \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\n-\t\t\tfd = hold_locked_index(&index_lock, 0);\n+\t\t\tfd = repo_hold_locked_index(the_repository,\n+\t\t\t\t\t\t    &index_lock, 0);\n \t\t\tif (0 <= fd)\n \t\t\t\trepo_update_index_if_able(the_repository, &index_lock);\n \ndiff --git a/builtin/diff-files.c b/builtin/diff-files.c\nindex 096ea2fedbc..dc991f753bb 100644\n--- a/builtin/diff-files.c\n+++ b/builtin/diff-files.c\n@@ -3,7 +3,6 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"diff.h\"\n@@ -76,8 +75,8 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)\n \t    (rev.diffopt.output_format & DIFF_FORMAT_PATCH))\n \t\tdiff_merges_set_dense_combined_if_unset(&rev);\n \n-\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n-\t\tperror(\"read_cache_preload\");\n+\tif (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {\n+\t\tperror(\"repo_read_index_preload\");\n \t\tresult = -1;\n \t\tgoto cleanup;\n \t}\ndiff --git a/builtin/diff-index.c b/builtin/diff-index.c\nindex aea139b9d8f..35dc9b23eef 100644\n--- a/builtin/diff-index.c\n+++ b/builtin/diff-index.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"diff.h\"\n@@ -62,12 +61,12 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)\n \t\tusage(diff_cache_usage);\n \tif (!(option & DIFF_INDEX_CACHED)) {\n \t\tsetup_work_tree();\n-\t\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n-\t\t\tperror(\"read_cache_preload\");\n+\t\tif (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {\n+\t\t\tperror(\"repo_read_index_preload\");\n \t\t\treturn -1;\n \t\t}\n-\t} else if (read_cache() < 0) {\n-\t\tperror(\"read_cache\");\n+\t} else if (repo_read_index(the_repository) < 0) {\n+\t\tperror(\"repo_read_index\");\n \t\treturn -1;\n \t}\n \tresult = run_diff_index(&rev, option);\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex 85e8c81e594..25b853b85ca 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"diff.h\"\n@@ -120,7 +120,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)\n \n \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n \trepo_init_revisions(the_repository, opt, prefix);\n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \topt->abbrev = 0;\n \topt->diff = 1;\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 854d2c5a5c4..163f2c6a874 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (c) 2006 Junio C Hamano\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"ewah/ewok.h\"\n@@ -157,12 +157,13 @@ static int builtin_diff_index(struct rev_info *revs,\n \t\tusage(builtin_diff_usage);\n \tif (!(option & DIFF_INDEX_CACHED)) {\n \t\tsetup_work_tree();\n-\t\tif (read_cache_preload(&revs->diffopt.pathspec) < 0) {\n-\t\t\tperror(\"read_cache_preload\");\n+\t\tif (repo_read_index_preload(the_repository,\n+\t\t\t\t\t    &revs->diffopt.pathspec, 0) < 0) {\n+\t\t\tperror(\"repo_read_index_preload\");\n \t\t\treturn -1;\n \t\t}\n-\t} else if (read_cache() < 0) {\n-\t\tperror(\"read_cache\");\n+\t} else if (repo_read_index(the_repository) < 0) {\n+\t\tperror(\"repo_read_cache\");\n \t\treturn -1;\n \t}\n \treturn run_diff_index(revs, option);\n@@ -239,12 +240,13 @@ static void refresh_index_quietly(void)\n \tstruct lock_file lock_file = LOCK_INIT;\n \tint fd;\n \n-\tfd = hold_locked_index(&lock_file, 0);\n+\tfd = repo_hold_locked_index(the_repository, &lock_file, 0);\n \tif (fd < 0)\n \t\treturn;\n-\tdiscard_cache();\n-\tread_cache();\n-\trefresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);\n+\tdiscard_index(&the_index);\n+\trepo_read_index(the_repository);\n+\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL,\n+\t\t      NULL);\n \trepo_update_index_if_able(the_repository, &lock_file);\n }\n \n@@ -279,8 +281,9 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv\n \t\tdiff_merges_set_dense_combined_if_unset(revs);\n \n \tsetup_work_tree();\n-\tif (read_cache_preload(&revs->diffopt.pathspec) < 0) {\n-\t\tperror(\"read_cache_preload\");\n+\tif (repo_read_index_preload(the_repository, &revs->diffopt.pathspec,\n+\t\t\t\t    0) < 0) {\n+\t\tperror(\"repo_read_index_preload\");\n \t\treturn -1;\n \t}\n \treturn run_diff_files(revs, options);\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex cd47675e371..d207bd909b4 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"repository.h\"\n@@ -958,7 +958,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \tif (keep_cache_objects) {\n \t\tverify_index_checksum = 1;\n \t\tverify_ce_order = 1;\n-\t\tread_cache();\n+\t\trepo_read_index(the_repository);\n \t\t/* TODO: audit for interaction with sparse-index. */\n \t\tensure_full_index(&the_index);\n \t\tfor (i = 0; i < the_index.cache_nr; i++) {\ndiff --git a/builtin/merge-index.c b/builtin/merge-index.c\nindex a334c513c9d..452f833ac46 100644\n--- a/builtin/merge-index.c\n+++ b/builtin/merge-index.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"run-command.h\"\n \n@@ -47,7 +47,7 @@ static int merge_entry(int pos, const char *path)\n \n static void merge_one_path(const char *path)\n {\n-\tint pos = cache_name_pos(path, strlen(path));\n+\tint pos = index_name_pos(&the_index, path, strlen(path));\n \n \t/*\n \t * If it already exists in the cache as stage0, it's\n@@ -82,7 +82,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix)\n \tif (argc < 3)\n \t\tusage(\"git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])\");\n \n-\tread_cache();\n+\trepo_read_index(the_repository);\n \n \t/* TODO: audit for interaction with sparse-index. */\n \tensure_full_index(&the_index);\ndiff --git a/builtin/merge-ours.c b/builtin/merge-ours.c\nindex 3583cff71c7..284eb486098 100644\n--- a/builtin/merge-ours.c\n+++ b/builtin/merge-ours.c\n@@ -7,7 +7,6 @@\n  *\n  * Pretend we resolved the heads, but declare our tree trumps everybody else.\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"git-compat-util.h\"\n #include \"builtin.h\"\n #include \"diff.h\"\n@@ -25,7 +24,7 @@ int cmd_merge_ours(int argc, const char **argv, const char *prefix)\n \t * commit.  The index must match HEAD, or this merge cannot go\n \t * through.\n \t */\n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie_errno(\"read_cache failed\");\n \tif (index_differs_from(the_repository, \"HEAD\", NULL, 0))\n \t\treturn 2;\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 27218ee93c9..dd474371a25 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -318,7 +318,7 @@ static int save_state(struct object_id *stash)\n \tint rc = -1;\n \n \tfd = repo_hold_locked_index(the_repository, &lock_file, 0);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \tif (0 <= fd)\n \t\trepo_update_index_if_able(the_repository, &lock_file);\n \trollback_lock_file(&lock_file);\n@@ -716,7 +716,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,\n {\n \tconst char *head_arg = \"HEAD\";\n \n-\tif (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0)\n+\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET,\n+\t\t\t\t\t SKIP_IF_UNCHANGED, 0, NULL, NULL,\n+\t\t\t\t\t NULL) < 0)\n \t\treturn error(_(\"Unable to write index.\"));\n \n \tif (!strcmp(strategy, \"recursive\") || !strcmp(strategy, \"subtree\") ||\n@@ -750,7 +752,8 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,\n \t\tfor (j = common; j; j = j->next)\n \t\t\tcommit_list_insert(j->item, &reversed);\n \n-\t\thold_locked_index(&lock, LOCK_DIE_ON_ERROR);\n+\t\trepo_hold_locked_index(the_repository, &lock,\n+\t\t\t\t       LOCK_DIE_ON_ERROR);\n \t\tif (!strcmp(strategy, \"ort\"))\n \t\t\tclean = merge_ort_recursive(&o, head, remoteheads->item,\n \t\t\t\t\t\t    reversed, &result);\n@@ -859,9 +862,9 @@ static void prepare_to_commit(struct commit_list *remoteheads)\n \t\t * the editor and after we invoke run_status above.\n \t\t */\n \t\tif (invoked_hook)\n-\t\t\tdiscard_cache();\n+\t\t\tdiscard_index(&the_index);\n \t}\n-\tread_cache_from(index_file);\n+\tread_index_from(&the_index, index_file, get_git_dir());\n \tstrbuf_addbuf(&msg, &merge_msg);\n \tif (squash)\n \t\tBUG(\"the control must not reach here under --squash\");\n@@ -910,7 +913,9 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)\n \tstruct object_id result_tree, result_commit;\n \tstruct commit_list *parents, **pptr = &parents;\n \n-\tif (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0)\n+\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET,\n+\t\t\t\t\t SKIP_IF_UNCHANGED, 0, NULL, NULL,\n+\t\t\t\t\t NULL) < 0)\n \t\treturn error(_(\"Unable to write index.\"));\n \n \twrite_tree_trivial(&result_tree);\n@@ -1602,7 +1607,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t * We are not doing octopus, not fast-forward, and have\n \t\t * only one common.\n \t\t */\n-\t\trefresh_cache(REFRESH_QUIET);\n+\t\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \t\tif (allow_trivial && fast_forward != FF_ONLY) {\n \t\t\t/*\n \t\t\t * Must first ensure that index matches HEAD before\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 883cf3ff12b..19790ce38fa 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -106,7 +106,7 @@ static int index_range_of_same_dir(const char *src, int length,\n \tconst char *src_w_slash = add_slash(src);\n \tint first, last, len_w_slash = length + 1;\n \n-\tfirst = cache_name_pos(src_w_slash, len_w_slash);\n+\tfirst = index_name_pos(&the_index, src_w_slash, len_w_slash);\n \tif (first >= 0)\n \t\tdie(_(\"%.*s is in index\"), len_w_slash, src_w_slash);\n \n@@ -136,7 +136,7 @@ static int empty_dir_has_sparse_contents(const char *name)\n \tconst char *with_slash = add_slash(name);\n \tint length = strlen(with_slash);\n \n-\tint pos = cache_name_pos(with_slash, length);\n+\tint pos = index_name_pos(&the_index, with_slash, length);\n \tconst struct cache_entry *ce;\n \n \tif (pos < 0) {\n@@ -189,8 +189,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \tif (--argc < 1)\n \t\tusage_with_options(builtin_mv_usage, builtin_mv_options);\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n-\tif (read_cache() < 0)\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tsource = internal_prefix_pathspec(prefix, argv, argc, 0);\n@@ -255,7 +255,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tint pos;\n \t\t\tconst struct cache_entry *ce;\n \n-\t\t\tpos = cache_name_pos(src, length);\n+\t\t\tpos = index_name_pos(&the_index, src, length);\n \t\t\tif (pos < 0) {\n \t\t\t\tconst char *src_w_slash = add_slash(src);\n \t\t\t\tif (!path_in_sparse_checkout(src_w_slash, &the_index) &&\n@@ -278,7 +278,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t\tgoto act_on_entry;\n \t\t\t}\n \t\t\t/* Check if dst exists in index */\n-\t\t\tif (cache_name_pos(dst, strlen(dst)) < 0) {\n+\t\t\tif (index_name_pos(&the_index, dst, strlen(dst)) < 0) {\n \t\t\t\tmodes[i] |= SPARSE;\n \t\t\t\tgoto act_on_entry;\n \t\t\t}\n@@ -303,7 +303,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n dir_check:\n \t\tif (S_ISDIR(st.st_mode)) {\n \t\t\tint j, dst_len, n;\n-\t\t\tint first = cache_name_pos(src, length), last;\n+\t\t\tint first = index_name_pos(&the_index, src, length), last;\n \n \t\t\tif (first >= 0) {\n \t\t\t\tprepare_move_submodule(src, first,\n@@ -468,7 +468,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tif (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR))\n \t\t\tcontinue;\n \n-\t\tpos = cache_name_pos(src, strlen(src));\n+\t\tpos = index_name_pos(&the_index, src, strlen(src));\n \t\tassert(pos >= 0);\n \t\tif (!(mode & SPARSE) && !lstat(src, &st))\n \t\t\tsparse_and_dirty = ie_modified(&the_index,\ndiff --git a/builtin/read-tree.c b/builtin/read-tree.c\nindex c50b563e2be..f702f9d47bb 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -4,7 +4,7 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n \n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n@@ -176,7 +176,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n \t/*\n \t * NEEDSWORK\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 5d855fd8f51..1384008fe09 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -4,7 +4,7 @@\n  * Copyright (c) 2018 Pratik Karki\n  */\n \n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"run-command.h\"\n #include \"exec-cmd.h\"\n@@ -292,7 +292,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)\n \tif (ret)\n \t\terror(_(\"could not generate todo list\"));\n \telse {\n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t\tif (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf,\n \t\t\t\t\t\t&todo_list))\n \t\t\tBUG(\"unusable todo list\");\n@@ -1268,7 +1268,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\tif (get_oid(\"HEAD\", &head))\n \t\t\tdie(_(\"Cannot read HEAD\"));\n \n-\t\tfd = hold_locked_index(&lock_file, 0);\n+\t\tfd = repo_hold_locked_index(the_repository, &lock_file, 0);\n \t\tif (repo_read_index(the_repository) < 0)\n \t\t\tdie(_(\"could not read index\"));\n \t\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 75e061f5dcf..1fa86edb4c9 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -7,7 +7,7 @@\n  *\n  * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\n@@ -160,7 +160,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,\n \t\t * if this entry is outside the sparse cone - this is necessary\n \t\t * to properly construct the reset sparse directory.\n \t\t */\n-\t\tpos = cache_name_pos(one->path, strlen(one->path));\n+\t\tpos = index_name_pos(&the_index, one->path, strlen(one->path));\n \t\tif ((pos >= 0 && ce_skip_worktree(the_index.cache[pos])) ||\n \t\t    (pos < 0 && !path_in_sparse_checkout(one->path, &the_index)))\n \t\t\tce->ce_flags |= CE_SKIP_WORKTREE;\n@@ -423,7 +423,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n \n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \t/* Soft reset does not touch the index file nor the working tree\n@@ -434,7 +434,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \n \tif (reset_type != SOFT) {\n \t\tstruct lock_file lock = LOCK_INIT;\n-\t\thold_locked_index(&lock, LOCK_DIE_ON_ERROR);\n+\t\trepo_hold_locked_index(the_repository, &lock,\n+\t\t\t\t       LOCK_DIE_ON_ERROR);\n \t\tif (reset_type == MIXED) {\n \t\t\tint flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;\n \t\t\tif (read_from_tree(&pathspec, &oid, intent_to_add))\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 8f61050bde8..d4c81352a65 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"config.h\"\n #include \"commit.h\"\n@@ -997,7 +997,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--shared-index-path\")) {\n-\t\t\t\tif (read_cache() < 0)\n+\t\t\t\tif (repo_read_index(the_repository) < 0)\n \t\t\t\t\tdie(_(\"Could not read the index\"));\n \t\t\t\tif (the_index.split_index) {\n \t\t\t\t\tconst struct object_id *oid = &the_index.split_index->base_oid;\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 2b23eb25438..40b7990de11 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -72,7 +72,7 @@ static void submodules_absorb_gitdir_if_needed(void)\n \t\tint pos;\n \t\tconst struct cache_entry *ce;\n \n-\t\tpos = cache_name_pos(name, strlen(name));\n+\t\tpos = index_name_pos(&the_index, name, strlen(name));\n \t\tif (pos < 0) {\n \t\t\tpos = get_ours_cache_pos(name, pos);\n \t\t\tif (pos < 0)\n@@ -117,7 +117,7 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\tint local_changes = 0;\n \t\tint staged_changes = 0;\n \n-\t\tpos = cache_name_pos(name, strlen(name));\n+\t\tpos = index_name_pos(&the_index, name, strlen(name));\n \t\tif (pos < 0) {\n \t\t\t/*\n \t\t\t * Skip unmerged entries except for populated submodules\n@@ -291,9 +291,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \n \tprepare_repo_settings(the_repository);\n \tthe_repository->settings.command_requires_full_index = 0;\n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex c251419af7c..62e36718d38 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -261,11 +261,11 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)\n \tstruct tree *tree;\n \tstruct lock_file lock_file = LOCK_INIT;\n \n-\tread_cache_preload(NULL);\n-\tif (refresh_cache(REFRESH_QUIET))\n+\trepo_read_index_preload(the_repository, NULL, 0);\n+\tif (refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL))\n \t\treturn -1;\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n \tmemset(&opts, 0, sizeof(opts));\n \n@@ -523,8 +523,9 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,\n \tstruct tree *head, *merge, *merge_base;\n \tstruct lock_file lock = LOCK_INIT;\n \n-\tread_cache_preload(NULL);\n-\tif (refresh_and_write_cache(REFRESH_QUIET, 0, 0))\n+\trepo_read_index_preload(the_repository, NULL, 0);\n+\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,\n+\t\t\t\t\t NULL, NULL, NULL))\n \t\treturn -1;\n \n \tif (write_cache_as_tree(&c_tree, 0, NULL))\n@@ -549,14 +550,14 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,\n \t\t\t\treturn error(_(\"conflicts in index. \"\n \t\t\t\t\t       \"Try without --index.\"));\n \n-\t\t\tdiscard_cache();\n-\t\t\tread_cache();\n+\t\t\tdiscard_index(&the_index);\n+\t\t\trepo_read_index(the_repository);\n \t\t\tif (write_cache_as_tree(&index_tree, 0, NULL))\n \t\t\t\treturn error(_(\"could not save index tree\"));\n \n \t\t\treset_head();\n-\t\t\tdiscard_cache();\n-\t\t\tread_cache();\n+\t\t\tdiscard_index(&the_index);\n+\t\t\trepo_read_index(the_repository);\n \t\t}\n \t}\n \n@@ -1082,7 +1083,7 @@ static int check_changes_tracked_files(const struct pathspec *ps)\n \tif (get_oid(\"HEAD\", &dummy))\n \t\treturn -1;\n \n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\treturn -1;\n \n \tinit_revisions(&rev, NULL);\n@@ -1286,7 +1287,7 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps\n \trev.diffopt.format_callback = add_diff_to_buf;\n \trev.diffopt.format_callback_data = &diff_output;\n \n-\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n+\tif (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {\n \t\tret = -1;\n \t\tgoto done;\n \t}\n@@ -1344,8 +1345,9 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b\n \n \tprepare_fallback_ident(\"git stash\", \"git@stash\");\n \n-\tread_cache_preload(NULL);\n-\tif (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0) {\n+\trepo_read_index_preload(the_repository, NULL, 0);\n+\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,\n+\t\t\t\t\t NULL, NULL, NULL) < 0) {\n \t\tret = -1;\n \t\tgoto done;\n \t}\n@@ -1513,7 +1515,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q\n \t\tgoto done;\n \t}\n \n-\tread_cache_preload(NULL);\n+\trepo_read_index_preload(the_repository, NULL, 0);\n \tif (!include_untracked && ps->nr) {\n \t\tint i;\n \t\tchar *ps_matched = xcalloc(ps->nr, 1);\n@@ -1533,7 +1535,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q\n \t\tfree(ps_matched);\n \t}\n \n-\tif (refresh_and_write_cache(REFRESH_QUIET, 0, 0)) {\n+\tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,\n+\t\t\t\t\t NULL, NULL, NULL)) {\n \t\tret = -1;\n \t\tgoto done;\n \t}\n@@ -1590,7 +1593,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q\n \t\t\t\tgoto done;\n \t\t\t}\n \t\t}\n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t\tif (ps->nr) {\n \t\t\tstruct child_process cp_add = CHILD_PROCESS_INIT;\n \t\t\tstruct child_process cp_diff = CHILD_PROCESS_INIT;\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 808865a5e31..ebe86e68176 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1,4 +1,4 @@\n-#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"repository.h\"\n #include \"cache.h\"\n@@ -196,7 +196,7 @@ static int module_list_compute(const char **argv,\n \tif (pathspec->nr)\n \t\tps_matched = xcalloc(pathspec->nr, 1);\n \n-\tif (read_cache() < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tfor (i = 0; i < the_index.cache_nr; i++) {\n@@ -1109,13 +1109,13 @@ static int compute_summary_module_list(struct object_id *head_oid,\n \tif (!info->cached) {\n \t\tif (diff_cmd == DIFF_INDEX)\n \t\t\tsetup_work_tree();\n-\t\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n-\t\t\tperror(\"read_cache_preload\");\n+\t\tif (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {\n+\t\t\tperror(\"repo_read_index_preload\");\n \t\t\tret = -1;\n \t\t\tgoto cleanup;\n \t\t}\n-\t} else if (read_cache() < 0) {\n-\t\tperror(\"read_cache\");\n+\t} else if (repo_read_index(the_repository) < 0) {\n+\t\tperror(\"repo_read_cache\");\n \t\tret = -1;\n \t\tgoto cleanup;\n \t}\n@@ -3240,7 +3240,7 @@ static void die_on_index_match(const char *path, int force)\n \tconst char *args[] = { path, NULL };\n \tparse_pathspec(&ps, 0, PATHSPEC_PREFER_CWD, NULL, args);\n \n-\tif (read_cache_preload(NULL) < 0)\n+\tif (repo_read_index_preload(the_repository, NULL, 0) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tif (ps.nr) {\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex fec3da05abb..82d5902cc8b 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -237,7 +237,7 @@ static int test_if_untracked_cache_is_supported(void)\n static int mark_ce_flags(const char *path, int flag, int mark)\n {\n \tint namelen = strlen(path);\n-\tint pos = cache_name_pos(path, namelen);\n+\tint pos = index_name_pos(&the_index, path, namelen);\n \tif (0 <= pos) {\n \t\tmark_fsmonitor_invalid(&the_index, the_index.cache[pos]);\n \t\tif (mark)\n@@ -331,7 +331,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len\n static int process_directory(const char *path, int len, struct stat *st)\n {\n \tstruct object_id oid;\n-\tint pos = cache_name_pos(path, len);\n+\tint pos = index_name_pos(&the_index, path, len);\n \n \t/* Exact match: file or existing gitlink */\n \tif (pos >= 0) {\n@@ -441,7 +441,7 @@ static void chmod_path(char flip, const char *path)\n \tint pos;\n \tstruct cache_entry *ce;\n \n-\tpos = cache_name_pos(path, strlen(path));\n+\tpos = index_name_pos(&the_index, path, strlen(path));\n \tif (pos < 0)\n \t\tgoto fail;\n \tce = the_index.cache[pos];\n@@ -638,7 +638,7 @@ static int unresolve_one(const char *path)\n \tstruct cache_entry *ce_2 = NULL, *ce_3 = NULL;\n \n \t/* See if there is such entry in the index. */\n-\tpos = cache_name_pos(path, namelen);\n+\tpos = index_name_pos(&the_index, path, namelen);\n \tif (0 <= pos) {\n \t\t/* already merged */\n \t\tpos = unmerge_index_entry_at(&the_index, pos);\n@@ -802,15 +802,16 @@ struct refresh_params {\n static int refresh(struct refresh_params *o, unsigned int flag)\n {\n \tsetup_work_tree();\n-\tread_cache();\n-\t*o->has_errors |= refresh_cache(o->flags | flag);\n+\trepo_read_index(the_repository);\n+\t*o->has_errors |= refresh_index(&the_index, o->flags | flag, NULL,\n+\t\t\t\t\tNULL, NULL);\n \tif (has_racy_timestamp(&the_index)) {\n \t\t/*\n \t\t * Even if nothing else has changed, updating the file\n \t\t * increases the chance that racy timestamps become\n \t\t * non-racy, helping future run-time performance.\n \t\t * We do that even in case of \"errors\" returned by\n-\t\t * refresh_cache() as these are no actual errors.\n+\t\t * refresh_index() as these are no actual errors.\n \t\t * cmd_status() does the same.\n \t\t */\n \t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n@@ -1109,11 +1110,11 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \tthe_repository->settings.command_requires_full_index = 0;\n \n \t/* we will diagnose later if it turns out that we need to update it */\n-\tnewfd = hold_locked_index(&lock_file, 0);\n+\tnewfd = repo_hold_locked_index(the_repository, &lock_file, 0);\n \tif (newfd < 0)\n \t\tlock_error = errno;\n \n-\tentries = read_cache();\n+\tentries = repo_read_index(the_repository);\n \tif (entries < 0)\n \t\tdie(\"cache corrupted\");\n \ndiff --git a/cache.h b/cache.h\nindex 707806d2125..07d40b0964b 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -441,13 +441,8 @@ extern struct index_state the_index;\n #define active_nr (the_index.cache_nr)\n \n #define read_cache() repo_read_index(the_repository)\n-#define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))\n-#define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)\n #define discard_cache() discard_index(&the_index)\n #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))\n-#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)\n-#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)\n-#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n #endif\n #endif\ndiff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci\nindex 8b1ed65e7b0..4c1b890c3ef 100644\n--- a/contrib/coccinelle/index-compatibility.cocci\n+++ b/contrib/coccinelle/index-compatibility.cocci\n@@ -26,11 +26,27 @@ identifier f != prepare_to_commit;\n (\n - read_cache_unmerged\n + repo_read_index_unmerged\n+|\n+- hold_locked_index\n++ repo_hold_locked_index\n )\n   (\n + the_repository,\n   ...)\n \n+// \"the_repository\" special-cases\n+@@\n+@@\n+(\n+- read_cache_preload\n++ repo_read_index_preload\n+)\n+  (\n++ the_repository,\n+  ...\n++ , 0\n+  )\n+\n // \"the_index\" simple cases\n @@\n @@\n@@ -80,3 +96,40 @@ identifier f != prepare_to_commit;\n   (\n + &the_index,\n   ...)\n+\n+@@\n+@@\n+(\n+- refresh_and_write_cache\n++ repo_refresh_and_write_index\n+)\n+  (\n++ the_repository,\n+  ...\n++ , NULL, NULL, NULL\n+  )\n+\n+// \"the_index\" special-cases\n+@@\n+@@\n+(\n+- read_cache_from\n++ read_index_from\n+)\n+  (\n++ &the_index,\n+  ...\n++ , get_git_dir()\n+  )\n+\n+@@\n+@@\n+(\n+- refresh_cache\n++ refresh_index\n+)\n+  (\n++ &the_index,\n+  ...\n++ , NULL, NULL, NULL\n+  )\ndiff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci\nindex 8207aee62c3..01f875d0060 100644\n--- a/contrib/coccinelle/index-compatibility.pending.cocci\n+++ b/contrib/coccinelle/index-compatibility.pending.cocci\n@@ -4,9 +4,6 @@\n (\n - read_cache\n + repo_read_index\n-|\n-- hold_locked_index\n-+ repo_hold_locked_index\n )\n   (\n + the_repository,\n@@ -25,54 +22,3 @@\n   (\n + &the_index,\n   ...)\n-\n-// \"the_repository\" special-cases\n-@@\n-@@\n-(\n-- read_cache_preload\n-+ repo_read_index_preload\n-)\n-  (\n-+ the_repository,\n-  ...\n-+ , 0\n-  )\n-\n-@@\n-@@\n-(\n-- refresh_and_write_cache\n-+ repo_refresh_and_write_index\n-)\n-  (\n-+ the_repository,\n-  ...\n-+ , NULL, NULL, NULL\n-  )\n-\n-\n-// \"the_index\" special-cases\n-@@\n-@@\n-(\n-- read_cache_from\n-+ read_index_from\n-)\n-  (\n-+ &the_index,\n-  ...\n-+ , get_git_dir()\n-  )\n-\n-@@\n-@@\n-(\n-- refresh_cache\n-+ refresh_index\n-)\n-  (\n-+ &the_index,\n-  ...\n-+ , NULL, NULL, NULL\n-  )\n-- \n2.38.0.1509.g9445af83948\n\n"}]}