{"thread":{"id":"61321","subject":"[PATCH 0/5] global: drop external `the_index` variable","startedAt":"2024-04-15T11:42:36Z","lastAt":"2024-04-19T04:25:54Z","messageCount":26,"participants":["Patrick Steinhardt","Phillip Wood","Junio C Hamano","Karthik Nayak"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"492936","messageId":"cover.1713180749.git.ps@pks.im","threadId":"61321","inReplyTo":null,"subject":"[PATCH 0/5] global: drop external `the_index` variable","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-15T11:42:30Z","receivedAt":"2024-04-15T11:42:36Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nthis patch series converts remaining users of `the_index` to stop using\nit, instead using `the_repository->index`. This gets rid of one more\nglobal variable and brings a project over the finish line that has\nstarted back in 2007.\n\nI realize that this patch series is quite large, and that reviewers will\neventually start to just gloss over things because the conversions are\nkind of boring, too. Also, due to the size it's quite likely to conflict\nwith in-flight topics. So if you think that this is too large, please\nlet me know and I will happily split this up into multiple series.\n\nThe motivation of these patches comes from the introduction of the ref\nformat extension. I found it really hard to reason about the state of\n`the_repository` and would like to continue its deprecation in favor of\nexplicitly passing down a `struct repository *`. Getting rid of\n`the_index` is a first easy step into that direction to make things more\nself-contained.\n\nPatrick\n\nPatrick Steinhardt (5):\n  t/helper: stop using `the_index`\n  builtin: stop using `the_index`\n  repository: initialize index in `repo_init()`\n  builtin/clone: stop using `the_index`\n  repository: drop global `the_index` variable\n\n builtin/add.c                        |  48 +++++------\n builtin/am.c                         |  36 ++++----\n builtin/cat-file.c                   |   3 +-\n builtin/check-attr.c                 |   5 +-\n builtin/check-ignore.c               |   7 +-\n builtin/checkout-index.c             |  22 ++---\n builtin/checkout.c                   |  87 ++++++++++---------\n builtin/clean.c                      |   7 +-\n builtin/clone.c                      |   7 +-\n builtin/commit.c                     |  81 +++++++++---------\n builtin/describe.c                   |   3 +-\n builtin/diff-tree.c                  |   3 +-\n builtin/diff.c                       |   6 +-\n builtin/difftool.c                   |   4 +-\n builtin/merge-index.c                |  17 ++--\n builtin/merge-tree.c                 |   3 +-\n builtin/merge.c                      |  31 ++++---\n builtin/mv.c                         |  68 +++++++--------\n builtin/pull.c                       |   4 +-\n builtin/read-tree.c                  |  15 ++--\n builtin/rebase.c                     |   3 +-\n builtin/replay.c                     |   1 -\n builtin/reset.c                      |  32 +++----\n builtin/rev-parse.c                  |   6 +-\n builtin/rm.c                         |  40 ++++-----\n builtin/stash.c                      |  45 +++++-----\n builtin/submodule--helper.c          |  21 +++--\n builtin/update-index.c               | 122 +++++++++++++--------------\n builtin/write-tree.c                 |   6 +-\n repository.c                         |  32 ++++---\n repository.h                         |   3 -\n t/helper/test-cache-tree.c           |  17 ++--\n t/helper/test-dump-cache-tree.c      |   5 +-\n t/helper/test-dump-split-index.c     |  11 ++-\n t/helper/test-dump-untracked-cache.c |   3 +-\n t/helper/test-lazy-init-name-hash.c  |  39 +++++----\n t/helper/test-read-cache.c           |   9 +-\n t/helper/test-scrap-cache-tree.c     |   7 +-\n t/helper/test-write-cache.c          |   3 +-\n 39 files changed, 420 insertions(+), 442 deletions(-)\n\n-- \n2.44.GIT\n\n"},{"id":"492937","messageId":"7b5ec04efc89af6874461d967bf5f61939e054dd.1713180749.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713180749.git.ps@pks.im","subject":"[PATCH 1/5] t/helper: stop using `the_index`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-15T11:42:36Z","receivedAt":"2024-04-15T11:42:40Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Convert test-helper tools to use `the_repository->index` instead of\n`the_index`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n t/helper/test-cache-tree.c           | 17 ++++++------\n t/helper/test-dump-cache-tree.c      |  5 ++--\n t/helper/test-dump-split-index.c     | 11 ++++----\n t/helper/test-dump-untracked-cache.c |  3 +--\n t/helper/test-lazy-init-name-hash.c  | 39 ++++++++++++++--------------\n t/helper/test-read-cache.c           |  9 +++----\n t/helper/test-scrap-cache-tree.c     |  7 +++--\n t/helper/test-write-cache.c          |  3 +--\n 8 files changed, 43 insertions(+), 51 deletions(-)\n\ndiff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c\nindex e7236392c8..dc89ecfd71 100644\n--- a/t/helper/test-cache-tree.c\n+++ b/t/helper/test-cache-tree.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n@@ -38,29 +37,29 @@ int cmd__cache_tree(int argc, const char **argv)\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+\toidcpy(&oid, &the_repository->index->cache_tree->oid);\n \ttree = parse_tree_indirect(&oid);\n \tif (!tree)\n \t\tdie(_(\"not a tree object: %s\"), oid_to_hex(&oid));\n \n \tif (empty) {\n \t\t/* clear the cache tree & allocate a new one */\n-\t\tcache_tree_free(&the_index.cache_tree);\n-\t\tthe_index.cache_tree = cache_tree();\n+\t\tcache_tree_free(&the_repository->index->cache_tree);\n+\t\tthe_repository->index->cache_tree = cache_tree();\n \t} else if (invalidate_qty) {\n \t\t/* invalidate the specified number of unique paths */\n-\t\tfloat f_interval = (float)the_index.cache_nr / invalidate_qty;\n+\t\tfloat f_interval = (float)the_repository->index->cache_nr / invalidate_qty;\n \t\tint interval = f_interval < 1.0 ? 1 : (int)f_interval;\n-\t\tfor (i = 0; i < invalidate_qty && i * interval < the_index.cache_nr; i++)\n-\t\t\tcache_tree_invalidate_path(&the_index, the_index.cache[i * interval]->name);\n+\t\tfor (i = 0; i < invalidate_qty && i * interval < the_repository->index->cache_nr; i++)\n+\t\t\tcache_tree_invalidate_path(the_repository->index, the_repository->index->cache[i * interval]->name);\n \t}\n \n \tif (argc != 1)\n \t\tusage_with_options(test_cache_tree_usage, options);\n \telse if (!strcmp(argv[0], \"prime\"))\n-\t\tprime_cache_tree(the_repository, &the_index, tree);\n+\t\tprime_cache_tree(the_repository, the_repository->index, tree);\n \telse if (!strcmp(argv[0], \"update\"))\n-\t\tcache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n+\t\tcache_tree_update(the_repository->index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n \t/* use \"control\" subcommand to specify no-op */\n \telse if (!!strcmp(argv[0], \"control\"))\n \t\tdie(_(\"Unhandled subcommand '%s'\"), argv[0]);\ndiff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c\nindex c38f546e4f..02b0b46c3f 100644\n--- a/t/helper/test-dump-cache-tree.c\n+++ b/t/helper/test-dump-cache-tree.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"hash.h\"\n #include \"hex.h\"\n@@ -68,10 +67,10 @@ int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED)\n \tsetup_git_directory();\n \tif (repo_read_index(the_repository) < 0)\n \t\tdie(\"unable to read index file\");\n-\tistate = the_index;\n+\tistate = *the_repository->index;\n \tistate.cache_tree = another;\n \tcache_tree_update(&istate, WRITE_TREE_DRY_RUN);\n-\tret = dump_cache_tree(the_index.cache_tree, another, \"\");\n+\tret = dump_cache_tree(the_repository->index->cache_tree, another, \"\");\n \tcache_tree_free(&another);\n \n \treturn ret;\ndiff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c\nindex f29d18ef94..f472691a3c 100644\n--- a/t/helper/test-dump-split-index.c\n+++ b/t/helper/test-dump-split-index.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"hex.h\"\n #include \"read-cache-ll.h\"\n@@ -19,16 +18,16 @@ int cmd__dump_split_index(int ac UNUSED, const char **av)\n \n \tsetup_git_directory();\n \n-\tdo_read_index(&the_index, av[1], 1);\n-\tprintf(\"own %s\\n\", oid_to_hex(&the_index.oid));\n-\tsi = the_index.split_index;\n+\tdo_read_index(the_repository->index, av[1], 1);\n+\tprintf(\"own %s\\n\", oid_to_hex(&the_repository->index->oid));\n+\tsi = the_repository->index->split_index;\n \tif (!si) {\n \t\tprintf(\"not a split index\\n\");\n \t\treturn 0;\n \t}\n \tprintf(\"base %s\\n\", oid_to_hex(&si->base_oid));\n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tstruct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n \t\tprintf(\"%06o %s %d\\t%s\\n\", ce->ce_mode,\n \t\t       oid_to_hex(&ce->oid), ce_stage(ce), ce->name);\n \t}\ndiff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c\nindex b4af9712fe..9ff67c3967 100644\n--- a/t/helper/test-dump-untracked-cache.c\n+++ b/t/helper/test-dump-untracked-cache.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"dir.h\"\n #include \"hex.h\"\n@@ -56,7 +55,7 @@ int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED)\n \tsetup_git_directory();\n \tif (repo_read_index(the_repository) < 0)\n \t\tdie(\"unable to read index file\");\n-\tuc = the_index.untracked;\n+\tuc = the_repository->index->untracked;\n \tif (!uc) {\n \t\tprintf(\"no untracked cache\\n\");\n \t\treturn 0;\ndiff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c\nindex 187a115d57..5f33bb7b8f 100644\n--- a/t/helper/test-lazy-init-name-hash.c\n+++ b/t/helper/test-lazy-init-name-hash.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"environment.h\"\n #include \"name-hash.h\"\n@@ -40,22 +39,22 @@ static void dump_run(void)\n \n \trepo_read_index(the_repository);\n \tif (single) {\n-\t\ttest_lazy_init_name_hash(&the_index, 0);\n+\t\ttest_lazy_init_name_hash(the_repository->index, 0);\n \t} else {\n-\t\tint nr_threads_used = test_lazy_init_name_hash(&the_index, 1);\n+\t\tint nr_threads_used = test_lazy_init_name_hash(the_repository->index, 1);\n \t\tif (!nr_threads_used)\n \t\t\tdie(\"non-threaded code path used\");\n \t}\n \n-\thashmap_for_each_entry(&the_index.dir_hash, &iter_dir, dir,\n+\thashmap_for_each_entry(&the_repository->index->dir_hash, &iter_dir, dir,\n \t\t\t\tent /* member name */)\n \t\tprintf(\"dir %08x %7d %s\\n\", dir->ent.hash, dir->nr, dir->name);\n \n-\thashmap_for_each_entry(&the_index.name_hash, &iter_cache, ce,\n+\thashmap_for_each_entry(&the_repository->index->name_hash, &iter_cache, ce,\n \t\t\t\tent /* member name */)\n \t\tprintf(\"name %08x %s\\n\", ce->ent.hash, ce->name);\n \n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n }\n \n /*\n@@ -74,7 +73,7 @@ static uint64_t time_runs(int try_threaded)\n \t\tt0 = getnanotime();\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\tnr_threads_used = test_lazy_init_name_hash(the_repository->index, try_threaded);\n \t\tt2 = getnanotime();\n \n \t\tsum += (t2 - t1);\n@@ -86,16 +85,16 @@ static uint64_t time_runs(int try_threaded)\n \t\t\tprintf(\"%f %f %d multi %d\\n\",\n \t\t\t\t   ((double)(t1 - t0))/1000000000,\n \t\t\t\t   ((double)(t2 - t1))/1000000000,\n-\t\t\t\t   the_index.cache_nr,\n+\t\t\t\t   the_repository->index->cache_nr,\n \t\t\t\t   nr_threads_used);\n \t\telse\n \t\t\tprintf(\"%f %f %d single\\n\",\n \t\t\t\t   ((double)(t1 - t0))/1000000000,\n \t\t\t\t   ((double)(t2 - t1))/1000000000,\n-\t\t\t\t   the_index.cache_nr);\n+\t\t\t\t   the_repository->index->cache_nr);\n \t\tfflush(stdout);\n \n-\t\tdiscard_index(&the_index);\n+\t\tdiscard_index(the_repository->index);\n \t}\n \n \tavg = sum / count;\n@@ -120,8 +119,8 @@ static void analyze_run(void)\n \tint nr;\n \n \trepo_read_index(the_repository);\n-\tcache_nr_limit = the_index.cache_nr;\n-\tdiscard_index(&the_index);\n+\tcache_nr_limit = the_repository->index->cache_nr;\n+\tdiscard_index(the_repository->index);\n \n \tnr = analyze;\n \twhile (1) {\n@@ -135,22 +134,22 @@ static void analyze_run(void)\n \n \t\tfor (i = 0; i < count; i++) {\n \t\t\trepo_read_index(the_repository);\n-\t\t\tthe_index.cache_nr = nr; /* cheap truncate of index */\n+\t\t\tthe_repository->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\ttest_lazy_init_name_hash(the_repository->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_index(&the_index);\n+\t\t\tthe_repository->index->cache_nr = cache_nr_limit;\n+\t\t\tdiscard_index(the_repository->index);\n \n \t\t\trepo_read_index(the_repository);\n-\t\t\tthe_index.cache_nr = nr; /* cheap truncate of index */\n+\t\t\tthe_repository->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\tnr_threads_used = test_lazy_init_name_hash(the_repository->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_index(&the_index);\n+\t\t\tthe_repository->index->cache_nr = cache_nr_limit;\n+\t\t\tdiscard_index(the_repository->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 1acd362346..458efa88a6 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"config.h\"\n #include \"read-cache-ll.h\"\n@@ -27,16 +26,16 @@ int cmd__read_cache(int argc, const char **argv)\n \t\tif (name) {\n \t\t\tint pos;\n \n-\t\t\trefresh_index(&the_index, REFRESH_QUIET,\n+\t\t\trefresh_index(the_repository->index, REFRESH_QUIET,\n \t\t\t\t      NULL, NULL, NULL);\n-\t\t\tpos = index_name_pos(&the_index, name, strlen(name));\n+\t\t\tpos = index_name_pos(the_repository->index, name, strlen(name));\n \t\t\tif (pos < 0)\n \t\t\t\tdie(\"%s not in index\", name);\n \t\t\tprintf(\"%s is%s up to date\\n\", name,\n-\t\t\t       ce_uptodate(the_index.cache[pos]) ? \"\" : \" not\");\n+\t\t\t       ce_uptodate(the_repository->index->cache[pos]) ? \"\" : \" not\");\n \t\t\twrite_file(name, \"%d\\n\", i);\n \t\t}\n-\t\tdiscard_index(&the_index);\n+\t\tdiscard_index(the_repository->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 0a816a96e2..737cbe475b 100644\n--- a/t/helper/test-scrap-cache-tree.c\n+++ b/t/helper/test-scrap-cache-tree.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"lockfile.h\"\n #include \"read-cache-ll.h\"\n@@ -15,9 +14,9 @@ int cmd__scrap_cache_tree(int ac UNUSED, const char **av UNUSED)\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;\n-\tif (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))\n+\tcache_tree_free(&the_repository->index->cache_tree);\n+\tthe_repository->index->cache_tree = NULL;\n+\tif (write_locked_index(the_repository->index, &index_lock, COMMIT_LOCK))\n \t\tdie(\"unable to write index file\");\n \treturn 0;\n }\ndiff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c\nindex f084034d38..7e3da380a9 100644\n--- a/t/helper/test-write-cache.c\n+++ b/t/helper/test-write-cache.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"lockfile.h\"\n #include \"read-cache-ll.h\"\n@@ -16,7 +15,7 @@ int cmd__write_cache(int argc, const char **argv)\n \tfor (i = 0; i < cnt; i++) {\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\tif (write_locked_index(the_repository->index, &index_lock, COMMIT_LOCK))\n \t\t\tdie(\"unable to write index file\");\n \t}\n \n-- \n2.44.GIT\n\n"},{"id":"492938","messageId":"9d5f2eff8ab2a9d7a994a2031a31d4fa6f4791d2.1713180749.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713180749.git.ps@pks.im","subject":"[PATCH 2/5] builtin: stop using `the_index`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-15T11:42:44Z","receivedAt":"2024-04-15T11:42:48Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Convert builtins to use `the_repository->index` instead of `the_index`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/add.c               |  48 +++++++-------\n builtin/am.c                |  36 +++++------\n builtin/cat-file.c          |   3 +-\n builtin/check-attr.c        |   5 +-\n builtin/check-ignore.c      |   7 +--\n builtin/checkout-index.c    |  22 +++----\n builtin/checkout.c          |  87 +++++++++++++------------\n builtin/clean.c             |   7 +--\n builtin/commit.c            |  81 ++++++++++++------------\n builtin/describe.c          |   3 +-\n builtin/diff-tree.c         |   3 +-\n builtin/diff.c              |   6 +-\n builtin/difftool.c          |   4 +-\n builtin/merge-index.c       |  17 +++--\n builtin/merge-tree.c        |   3 +-\n builtin/merge.c             |  31 +++++----\n builtin/mv.c                |  68 ++++++++++----------\n builtin/pull.c              |   4 +-\n builtin/read-tree.c         |  15 +++--\n builtin/rebase.c            |   3 +-\n builtin/replay.c            |   1 -\n builtin/reset.c             |  32 +++++-----\n builtin/rev-parse.c         |   6 +-\n builtin/rm.c                |  40 ++++++------\n builtin/stash.c             |  45 +++++++------\n builtin/submodule--helper.c |  21 +++----\n builtin/update-index.c      | 122 ++++++++++++++++++------------------\n builtin/write-tree.c        |   6 +-\n 28 files changed, 355 insertions(+), 371 deletions(-)\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex e97699d6b9..dd1e536c03 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -40,20 +40,20 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)\n {\n \tint i, ret = 0;\n \n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tstruct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n \t\tint err;\n \n \t\tif (!include_sparse &&\n \t\t    (ce_skip_worktree(ce) ||\n-\t\t     !path_in_sparse_checkout(ce->name, &the_index)))\n+\t\t     !path_in_sparse_checkout(ce->name, the_repository->index)))\n \t\t\tcontinue;\n \n-\t\tif (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))\n+\t\tif (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))\n \t\t\tcontinue;\n \n \t\tif (!show_only)\n-\t\t\terr = chmod_index_entry(&the_index, ce, flip);\n+\t\t\terr = chmod_index_entry(the_repository->index, ce, flip);\n \t\telse\n \t\t\terr = S_ISREG(ce->ce_mode) ? 0 : -1;\n \n@@ -68,20 +68,20 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)\n {\n \tint i, retval = 0;\n \n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tstruct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n \n \t\tif (!include_sparse &&\n \t\t    (ce_skip_worktree(ce) ||\n-\t\t     !path_in_sparse_checkout(ce->name, &the_index)))\n+\t\t     !path_in_sparse_checkout(ce->name, the_repository->index)))\n \t\t\tcontinue;\n \t\tif (ce_stage(ce))\n \t\t\tcontinue; /* do not touch unmerged paths */\n \t\tif (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))\n \t\t\tcontinue; /* do not touch non blobs */\n-\t\tif (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))\n+\t\tif (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))\n \t\t\tcontinue;\n-\t\tretval |= add_file_to_index(&the_index, ce->name,\n+\t\tretval |= add_file_to_index(the_repository->index, ce->name,\n \t\t\t\t\t    flags | ADD_CACHE_RENORMALIZE);\n \t}\n \n@@ -100,11 +100,11 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,\n \ti = dir->nr;\n \twhile (--i >= 0) {\n \t\tstruct dir_entry *entry = *src++;\n-\t\tif (dir_path_match(&the_index, entry, pathspec, prefix, seen))\n+\t\tif (dir_path_match(the_repository->index, entry, pathspec, prefix, seen))\n \t\t\t*dst++ = entry;\n \t}\n \tdir->nr = dst - dir->entries;\n-\tadd_pathspec_matches_against_index(pathspec, &the_index, seen,\n+\tadd_pathspec_matches_against_index(pathspec, the_repository->index, seen,\n \t\t\t\t\t   PS_IGNORE_SKIP_WORKTREE);\n \treturn seen;\n }\n@@ -119,14 +119,14 @@ static int refresh(int verbose, const struct pathspec *pathspec)\n \t\t    (verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);\n \n \tseen = xcalloc(pathspec->nr, 1);\n-\trefresh_index(&the_index, flags, pathspec, seen,\n+\trefresh_index(the_repository->index, flags, pathspec, seen,\n \t\t      _(\"Unstaged changes after refreshing the index:\"));\n \tfor (i = 0; i < pathspec->nr; i++) {\n \t\tif (!seen[i]) {\n \t\t\tconst char *path = pathspec->items[i].original;\n \n \t\t\tif (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||\n-\t\t\t    !path_in_sparse_checkout(path, &the_index)) {\n+\t\t\t    !path_in_sparse_checkout(path, the_repository->index)) {\n \t\t\t\tstring_list_append(&only_match_skip_worktree,\n \t\t\t\t\t\t   pathspec->items[i].original);\n \t\t\t} else {\n@@ -335,12 +335,12 @@ static int add_files(struct dir_struct *dir, int flags)\n \n \tfor (i = 0; i < dir->nr; i++) {\n \t\tif (!include_sparse &&\n-\t\t    !path_in_sparse_checkout(dir->entries[i]->name, &the_index)) {\n+\t\t    !path_in_sparse_checkout(dir->entries[i]->name, the_repository->index)) {\n \t\t\tstring_list_append(&matched_sparse_paths,\n \t\t\t\t\t   dir->entries[i]->name);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (add_file_to_index(&the_index, dir->entries[i]->name, flags)) {\n+\t\tif (add_file_to_index(the_repository->index, dir->entries[i]->name, flags)) {\n \t\t\tif (!ignore_add_errors)\n \t\t\t\tdie(_(\"adding files failed\"));\n \t\t\texit_status = 1;\n@@ -457,8 +457,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)\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);\n-\tdie_path_inside_submodule(&the_index, &pathspec);\n+\tdie_in_unpopulated_submodule(the_repository->index, prefix);\n+\tdie_path_inside_submodule(the_repository->index, &pathspec);\n \n \tif (add_new_files) {\n \t\tint baselen;\n@@ -470,7 +470,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t\t}\n \n \t\t/* This picks up the paths that are not tracked */\n-\t\tbaselen = fill_directory(&dir, &the_index, &pathspec);\n+\t\tbaselen = fill_directory(&dir, the_repository->index, &pathspec);\n \t\tif (pathspec.nr)\n \t\t\tseen = prune_directory(&dir, &pathspec, baselen);\n \t}\n@@ -487,7 +487,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \n \t\tif (!seen)\n \t\t\tseen = find_pathspecs_matching_against_index(&pathspec,\n-\t\t\t\t\t&the_index, PS_IGNORE_SKIP_WORKTREE);\n+\t\t\t\t\tthe_repository->index, PS_IGNORE_SKIP_WORKTREE);\n \n \t\t/*\n \t\t * file_exists() assumes exact match\n@@ -523,8 +523,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t\t\t    !file_exists(path)) {\n \t\t\t\tif (ignore_missing) {\n \t\t\t\t\tint dtype = DT_UNKNOWN;\n-\t\t\t\t\tif (is_excluded(&dir, &the_index, path, &dtype))\n-\t\t\t\t\t\tdir_add_ignored(&dir, &the_index,\n+\t\t\t\t\tif (is_excluded(&dir, the_repository->index, path, &dtype))\n+\t\t\t\t\t\tdir_add_ignored(&dir, the_repository->index,\n \t\t\t\t\t\t\t\tpath, pathspec.items[i].len);\n \t\t\t\t} else\n \t\t\t\t\tdie(_(\"pathspec '%s' did not match any files\"),\n@@ -560,7 +560,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \tend_odb_transaction();\n \n finish:\n-\tif (write_locked_index(&the_index, &lock_file,\n+\tif (write_locked_index(the_repository->index, &lock_file,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\tdie(_(\"unable to write new index file\"));\n \ndiff --git a/builtin/am.c b/builtin/am.c\nindex 022cae2e8d..4db2bc3c2f 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -3,7 +3,7 @@\n  *\n  * Based on git-am.sh by Junio C Hamano.\n  */\n-#define USE_THE_INDEX_VARIABLE\n+\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n@@ -1536,8 +1536,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_index(&the_index);\n-\t\tread_index_from(&the_index, index_file, get_git_dir());\n+\t\tdiscard_index(the_repository->index);\n+\t\tread_index_from(the_repository->index, index_file, get_git_dir());\n \t}\n \n \treturn 0;\n@@ -1579,10 +1579,10 @@ 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_index(&the_index);\n-\tread_index_from(&the_index, index_path, get_git_dir());\n+\tdiscard_index(the_repository->index);\n+\tread_index_from(the_repository->index, index_path, get_git_dir());\n \n-\tif (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))\n+\tif (write_index_as_tree(&orig_tree, the_repository->index, index_path, 0, NULL))\n \t\treturn error(_(\"Repository lacks necessary blobs to fall back on 3-way merge.\"));\n \n \tsay(state, stdout, _(\"Using index info to reconstruct a base tree...\"));\n@@ -1608,12 +1608,12 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \t\treturn error(_(\"Did you hand edit your patch?\\n\"\n \t\t\t\t\"It does not apply to blobs recorded in its index.\"));\n \n-\tif (write_index_as_tree(&their_tree, &the_index, index_path, 0, NULL))\n+\tif (write_index_as_tree(&their_tree, the_repository->index, index_path, 0, NULL))\n \t\treturn error(\"could not write tree\");\n \n \tsay(state, stdout, _(\"Falling back to patching base and 3-way merge...\"));\n \n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \trepo_read_index(the_repository);\n \n \t/*\n@@ -1660,7 +1660,7 @@ static void do_commit(const struct am_state *state)\n \tif (!state->no_verify && run_hooks(\"pre-applypatch\"))\n \t\texit(1);\n \n-\tif (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL))\n+\tif (write_index_as_tree(&tree, the_repository->index, get_index_file(), 0, NULL))\n \t\tdie(_(\"git write-tree failed to write a tree\"));\n \n \tif (!repo_get_oid_commit(the_repository, \"HEAD\", &parent)) {\n@@ -1948,7 +1948,7 @@ static void am_resolve(struct am_state *state, int allow_empty)\n \t\t}\n \t}\n \n-\tif (unmerged_index(&the_index)) {\n+\tif (unmerged_index(the_repository->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@@ -1987,12 +1987,12 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)\n \n \trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n-\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n+\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \topts.update = 1;\n \topts.merge = 1;\n \topts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;\n@@ -2006,7 +2006,7 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)\n \t\treturn -1;\n \t}\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write new index file\"));\n \n \treturn 0;\n@@ -2029,8 +2029,8 @@ static int merge_tree(struct tree *tree)\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \topts.merge = 1;\n \topts.fn = oneway_merge;\n \tinit_tree_desc(&t[0], &tree->object.oid, tree->buffer, tree->size);\n@@ -2040,7 +2040,7 @@ static int merge_tree(struct tree *tree)\n \t\treturn -1;\n \t}\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write new index file\"));\n \n \treturn 0;\n@@ -2068,7 +2068,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem\n \tif (fast_forward_to(head_tree, head_tree, 1))\n \t\treturn -1;\n \n-\tif (write_index_as_tree(&index, &the_index, get_index_file(), 0, NULL))\n+\tif (write_index_as_tree(&index, the_repository->index, get_index_file(), 0, NULL))\n \t\treturn -1;\n \n \tindex_tree = parse_tree_indirect(&index);\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 0c948f40fb..fe873807ed 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -3,7 +3,6 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"convert.h\"\n@@ -77,7 +76,7 @@ static int filter_object(const char *path, unsigned mode,\n \t\tstruct checkout_metadata meta;\n \n \t\tinit_checkout_metadata(&meta, NULL, NULL, oid);\n-\t\tif (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf, &meta)) {\n+\t\tif (convert_to_working_tree(the_repository->index, path, *buf, *size, &strbuf, &meta)) {\n \t\t\tfree(*buf);\n \t\t\t*size = strbuf.len;\n \t\t\t*buf = strbuf_detach(&strbuf, NULL);\ndiff --git a/builtin/check-attr.c b/builtin/check-attr.c\nindex c1da1d184e..9376810710 100644\n--- a/builtin/check-attr.c\n+++ b/builtin/check-attr.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"attr.h\"\n@@ -71,9 +70,9 @@ static void check_attr(const char *prefix, struct attr_check *check,\n \t\tprefix_path(prefix, prefix ? strlen(prefix) : 0, file);\n \n \tif (collect_all) {\n-\t\tgit_all_attrs(&the_index, full_path, check);\n+\t\tgit_all_attrs(the_repository->index, full_path, check);\n \t} else {\n-\t\tgit_check_attr(&the_index, full_path, check);\n+\t\tgit_check_attr(the_repository->index, full_path, check);\n \t}\n \toutput_attr(check, file);\n \ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex 906cd96753..6c43430ec4 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"dir.h\"\n@@ -95,21 +94,21 @@ static int check_ignore(struct dir_struct *dir,\n \t\t       PATHSPEC_KEEP_ORDER,\n \t\t       prefix, argv);\n \n-\tdie_path_inside_submodule(&the_index, &pathspec);\n+\tdie_path_inside_submodule(the_repository->index, &pathspec);\n \n \t/*\n \t * look for pathspecs matching entries in the index, since these\n \t * should not be ignored, in order to be consistent with\n \t * 'git status', 'git add' etc.\n \t */\n-\tseen = find_pathspecs_matching_against_index(&pathspec, &the_index,\n+\tseen = find_pathspecs_matching_against_index(&pathspec, the_repository->index,\n \t\t\t\t\t\t     PS_HEED_SKIP_WORKTREE);\n \tfor (i = 0; i < pathspec.nr; i++) {\n \t\tfull_path = pathspec.items[i].match;\n \t\tpattern = NULL;\n \t\tif (!seen[i]) {\n \t\t\tint dtype = DT_UNKNOWN;\n-\t\t\tpattern = last_matching_pattern(dir, &the_index,\n+\t\t\tpattern = last_matching_pattern(dir, the_repository->index,\n \t\t\t\t\t\t\tfull_path, &dtype);\n \t\t\tif (!verbose && pattern &&\n \t\t\t    pattern->flags & PATTERN_FLAG_NEGATIVE)\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex 2e086a204d..29e744d11b 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -69,7 +69,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 = index_name_pos(&the_index, name, namelen);\n+\tint pos = index_name_pos(the_repository->index, name, namelen);\n \tint has_same_name = 0;\n \tint is_file = 0;\n \tint is_skipped = 1;\n@@ -79,8 +79,8 @@ static int checkout_file(const char *name, const char *prefix)\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n \n-\twhile (pos < the_index.cache_nr) {\n-\t\tstruct cache_entry *ce = the_index.cache[pos];\n+\twhile (pos <the_repository->index->cache_nr) {\n+\t\tstruct cache_entry *ce =the_repository->index->cache[pos];\n \t\tif (ce_namelen(ce) != namelen ||\n \t\t    memcmp(ce->name, name, namelen))\n \t\t\tbreak;\n@@ -140,8 +140,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 < the_index.cache_nr ; i++) {\n-\t\tstruct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr ; i++) {\n+\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n \n \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n \t\t\tif (!ce_skip_worktree(ce))\n@@ -154,8 +154,8 @@ static int checkout_all(const char *prefix, int prefix_length)\n \t\t\t * first entry inside the expanded sparse directory).\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 = the_index.cache[i];\n+\t\t\t\tensure_full_index(the_repository->index);\n+\t\t\t\tce = the_repository->index->cache[i];\n \t\t\t}\n \t\t}\n \n@@ -260,7 +260,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \n \targc = parse_options(argc, argv, prefix, builtin_checkout_index_options,\n \t\t\tbuiltin_checkout_index_usage, 0);\n-\tstate.istate = &the_index;\n+\tstate.istate = the_repository->index;\n \tstate.force = force;\n \tstate.quiet = quiet;\n \tstate.not_new = not_new;\n@@ -280,7 +280,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \t */\n \tif (index_opt && !state.base_dir_len && !to_tempfile) {\n \t\tstate.refresh_cache = 1;\n-\t\tstate.istate = &the_index;\n+\t\tstate.istate = the_repository->index;\n \t\trepo_hold_locked_index(the_repository, &lock_file,\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n \t}\n@@ -339,7 +339,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \t\treturn 1;\n \n \tif (is_lock_file_locked(&lock_file) &&\n-\t    write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\t    write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(\"Unable to write new index file\");\n \treturn 0;\n }\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 947827de1d..d9dd7ab325 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"branch.h\"\n@@ -146,7 +145,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \t\treturn READ_TREE_RECURSIVE;\n \n \tlen = base->len + strlen(pathname);\n-\tce = make_empty_cache_entry(&the_index, len);\n+\tce = make_empty_cache_entry(the_repository->index, len);\n \toidcpy(&ce->oid, oid);\n \tmemcpy(ce->name, base->buf, base->len);\n \tmemcpy(ce->name + base->len, pathname, len - base->len);\n@@ -159,9 +158,9 @@ 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 = index_name_pos(&the_index, ce->name, ce->ce_namelen);\n+\tpos = index_name_pos(the_repository->index, ce->name, ce->ce_namelen);\n \tif (pos >= 0) {\n-\t\tstruct cache_entry *old = the_index.cache[pos];\n+\t\tstruct cache_entry *old = the_repository->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@@ -171,7 +170,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \t\t}\n \t}\n \n-\tadd_index_entry(&the_index, ce,\n+\tadd_index_entry(the_repository->index, ce,\n \t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \treturn 0;\n }\n@@ -190,8 +189,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 < the_index.cache_nr &&\n-\t       !strcmp(the_index.cache[pos]->name, ce->name))\n+\twhile (++pos < the_repository->index->cache_nr &&\n+\t       !strcmp(the_repository->index->cache[pos]->name, ce->name))\n \t\t; /* skip */\n \treturn pos;\n }\n@@ -199,9 +198,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 < 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+\twhile (pos < the_repository->index->cache_nr &&\n+\t       !strcmp(the_repository->index->cache[pos]->name, ce->name)) {\n+\t\tif (ce_stage(the_repository->index->cache[pos]) == stage)\n \t\t\treturn 0;\n \t\tpos++;\n \t}\n@@ -218,8 +217,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 < the_index.cache_nr) {\n-\t\tce = the_index.cache[pos];\n+\twhile (pos < the_repository->index->cache_nr) {\n+\t\tce = the_repository->index->cache[pos];\n \t\tif (strcmp(name, ce->name))\n \t\t\tbreak;\n \t\tseen |= (1 << ce_stage(ce));\n@@ -235,10 +234,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 < 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+\twhile (pos < the_repository->index->cache_nr &&\n+\t       !strcmp(the_repository->index->cache[pos]->name, ce->name)) {\n+\t\tif (ce_stage(the_repository->index->cache[pos]) == stage)\n+\t\t\treturn checkout_entry(the_repository->index->cache[pos], state,\n \t\t\t\t\t      NULL, nr_checkouts);\n \t\tpos++;\n \t}\n@@ -256,7 +255,7 @@ static int checkout_merged(int pos, const struct checkout *state,\n \t\t\t   int *nr_checkouts, struct mem_pool *ce_mem_pool,\n \t\t\t   int conflict_style)\n {\n-\tstruct cache_entry *ce = the_index.cache[pos];\n+\tstruct cache_entry *ce = the_repository->index->cache[pos];\n \tconst char *path = ce->name;\n \tmmfile_t ancestor, ours, theirs;\n \tenum ll_merge_result merge_status;\n@@ -269,7 +268,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 < the_index.cache_nr) {\n+\twhile (pos < the_repository->index->cache_nr) {\n \t\tint stage;\n \t\tstage = ce_stage(ce);\n \t\tif (!stage || strcmp(path, ce->name))\n@@ -278,7 +277,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 = the_index.cache[pos];\n+\t\tce = the_repository->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@@ -356,7 +355,7 @@ static void mark_ce_for_checkout_overlay(struct cache_entry *ce,\n \t * match_pathspec() for _all_ entries when\n \t * opts->source_tree != NULL.\n \t */\n-\tif (ce_path_match(&the_index, ce, &opts->pathspec, ps_matched))\n+\tif (ce_path_match(the_repository->index, ce, &opts->pathspec, ps_matched))\n \t\tce->ce_flags |= CE_MATCHED;\n }\n \n@@ -367,7 +366,7 @@ static void mark_ce_for_checkout_no_overlay(struct cache_entry *ce,\n \tce->ce_flags &= ~CE_MATCHED;\n \tif (!opts->ignore_skipworktree && ce_skip_worktree(ce))\n \t\treturn;\n-\tif (ce_path_match(&the_index, ce, &opts->pathspec, ps_matched)) {\n+\tif (ce_path_match(the_repository->index, ce, &opts->pathspec, ps_matched)) {\n \t\tce->ce_flags |= CE_MATCHED;\n \t\tif (opts->source_tree && !(ce->ce_flags & CE_UPDATE))\n \t\t\t/*\n@@ -391,7 +390,7 @@ static int checkout_worktree(const struct checkout_opts *opts,\n \n \tstate.force = 1;\n \tstate.refresh_cache = 1;\n-\tstate.istate = &the_index;\n+\tstate.istate = the_repository->index;\n \n \tmem_pool_init(&ce_mem_pool, 0);\n \tget_parallel_checkout_configs(&pc_workers, &pc_threshold);\n@@ -404,8 +403,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 < the_index.cache_nr; pos++) {\n-\t\tstruct cache_entry *ce = the_index.cache[pos];\n+\tfor (pos = 0; pos < the_repository->index->cache_nr; pos++) {\n+\t\tstruct cache_entry *ce = the_repository->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@@ -429,7 +428,7 @@ static int checkout_worktree(const struct checkout_opts *opts,\n \t\terrs |= run_parallel_checkout(&state, pc_workers, pc_threshold,\n \t\t\t\t\t      NULL, NULL);\n \tmem_pool_discard(&ce_mem_pool, should_validate_cache_entries());\n-\tremove_marked_cache_entries(&the_index, 1);\n+\tremove_marked_cache_entries(the_repository->index, 1);\n \tremove_scheduled_dirs();\n \terrs |= finish_delayed_checkout(&state, opts->show_progress);\n \n@@ -571,7 +570,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \tif (opts->source_tree)\n \t\tread_tree_some(opts->source_tree, &opts->pathspec);\n \tif (opts->merge)\n-\t\tunmerge_index(&the_index, &opts->pathspec, CE_MATCHED);\n+\t\tunmerge_index(the_repository->index, &opts->pathspec, CE_MATCHED);\n \n \tps_matched = xcalloc(opts->pathspec.nr, 1);\n \n@@ -579,13 +578,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 < the_index.cache_nr; pos++)\n+\tfor (pos = 0; pos < the_repository->index->cache_nr; pos++)\n \t\tif (opts->overlay_mode)\n-\t\t\tmark_ce_for_checkout_overlay(the_index.cache[pos],\n+\t\t\tmark_ce_for_checkout_overlay(the_repository->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(the_index.cache[pos],\n+\t\t\tmark_ce_for_checkout_no_overlay(the_repository->index->cache[pos],\n \t\t\t\t\t\t\tps_matched,\n \t\t\t\t\t\t\topts);\n \n@@ -596,8 +595,8 @@ static int checkout_paths(const struct checkout_opts *opts,\n \tfree(ps_matched);\n \n \t/* Any unmerged paths? */\n-\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n-\t\tconst struct cache_entry *ce = the_index.cache[pos];\n+\tfor (pos = 0; pos < the_repository->index->cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[pos];\n \t\tif (ce->ce_flags & CE_MATCHED) {\n \t\t\tif (!ce_stage(ce))\n \t\t\t\tcontinue;\n@@ -622,7 +621,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \tif (opts->checkout_worktree)\n \t\terrs |= checkout_worktree(opts, new_branch_info);\n \telse\n-\t\tremove_marked_cache_entries(&the_index, 1);\n+\t\tremove_marked_cache_entries(the_repository->index, 1);\n \n \t/*\n \t * Allow updating the index when checking out from the index.\n@@ -634,7 +633,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t\tcheckout_index = opts->checkout_index;\n \n \tif (checkout_index) {\n-\t\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\t\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\t\tdie(_(\"unable to write new index file\"));\n \t} else {\n \t\t/*\n@@ -703,8 +702,8 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,\n \topts.merge = 1;\n \topts.fn = oneway_merge;\n \topts.verbose_update = o->show_progress;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \tinit_checkout_metadata(&opts.meta, info->refname,\n \t\t\t       info->commit ? &info->commit->object.oid : null_oid(),\n \t\t\t       NULL);\n@@ -756,12 +755,12 @@ static void init_topts(struct unpack_trees_options *topts, int merge,\n {\n \tmemset(topts, 0, sizeof(*topts));\n \ttopts->head_idx = -1;\n-\ttopts->src_index = &the_index;\n-\ttopts->dst_index = &the_index;\n+\ttopts->src_index = the_repository->index;\n+\ttopts->dst_index = the_repository->index;\n \n \tsetup_unpack_trees_porcelain(topts, \"checkout\");\n \n-\ttopts->initial_checkout = is_index_unborn(&the_index);\n+\ttopts->initial_checkout = is_index_unborn(the_repository->index);\n \ttopts->update = 1;\n \ttopts->merge = 1;\n \ttopts->quiet = merge && old_commit;\n@@ -783,7 +782,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\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+\tresolve_undo_clear_index(the_repository->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\");\n@@ -807,9 +806,9 @@ 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_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n+\t\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);\n \n-\t\tif (unmerged_index(&the_index)) {\n+\t\tif (unmerged_index(the_repository->index)) {\n \t\t\terror(_(\"you need to resolve your current index first\"));\n \t\t\treturn 1;\n \t\t}\n@@ -918,10 +917,10 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \t\t}\n \t}\n \n-\tif (!cache_tree_fully_valid(the_index.cache_tree))\n-\t\tcache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n+\tif (!cache_tree_fully_valid(the_repository->index->cache_tree))\n+\t\tcache_tree_update(the_repository->index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write new index file\"));\n \n \tif (!opts->discard_changes && !opts->quiet && new_branch_info->commit)\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex 29efe84153..ded5a91534 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -6,7 +6,6 @@\n  * Based on git-clean.sh by Pavel Roskin\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -714,7 +713,7 @@ static int filter_by_patterns_cmd(void)\n \t\tfor_each_string_list_item(item, &del_list) {\n \t\t\tint dtype = DT_UNKNOWN;\n \n-\t\t\tif (is_excluded(&dir, &the_index, item->string, &dtype)) {\n+\t\t\tif (is_excluded(&dir, the_repository->index, item->string, &dtype)) {\n \t\t\t\t*item->string = '\\0';\n \t\t\t\tchanged++;\n \t\t\t}\n@@ -1021,7 +1020,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \t\t       PATHSPEC_PREFER_CWD,\n \t\t       prefix, argv);\n \n-\tfill_directory(&dir, &the_index, &pathspec);\n+\tfill_directory(&dir, the_repository->index, &pathspec);\n \tcorrect_untracked_entries(&dir);\n \n \tfor (i = 0; i < dir.nr; i++) {\n@@ -1029,7 +1028,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 (!index_name_is_other(&the_index, ent->name, ent->len))\n+\t\tif (!index_name_is_other(the_repository->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 7ba7201cfb..09df930d6a 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -5,7 +5,6 @@\n  * Based on git-commit.sh by Junio C Hamano and Linus Torvalds\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -266,19 +265,19 @@ static int list_paths(struct string_list *list, const char *with_tree,\n \n \tif (with_tree) {\n \t\tchar *max_prefix = common_prefix(pattern);\n-\t\toverlay_tree_on_index(&the_index, with_tree, max_prefix);\n+\t\toverlay_tree_on_index(the_repository->index, with_tree, max_prefix);\n \t\tfree(max_prefix);\n \t}\n \n \t/* TODO: audit for interaction with sparse-index. */\n-\tensure_full_index(&the_index);\n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tconst struct cache_entry *ce = the_index.cache[i];\n+\tensure_full_index(the_repository->index);\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[i];\n \t\tstruct string_list_item *item;\n \n \t\tif (ce->ce_flags & CE_UPDATE)\n \t\t\tcontinue;\n-\t\tif (!ce_path_match(&the_index, ce, pattern, m))\n+\t\tif (!ce_path_match(the_repository->index, ce, pattern, m))\n \t\t\tcontinue;\n \t\titem = string_list_insert(list, ce->name);\n \t\tif (ce_skip_worktree(ce))\n@@ -302,10 +301,10 @@ 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_index(&the_index, p->string, &st, 0))\n+\t\t\tif (add_to_index(the_repository->index, p->string, &st, 0))\n \t\t\t\tdie(_(\"updating files failed\"));\n \t\t} else\n-\t\t\tremove_file_from_index(&the_index, p->string);\n+\t\t\tremove_file_from_index(the_repository->index, p->string);\n \t}\n }\n \n@@ -316,7 +315,7 @@ static void create_base_index(const struct commit *current_head)\n \tstruct tree_desc t;\n \n \tif (!current_head) {\n-\t\tdiscard_index(&the_index);\n+\t\tdiscard_index(the_repository->index);\n \t\treturn;\n \t}\n \n@@ -324,8 +323,8 @@ static void create_base_index(const struct commit *current_head)\n \topts.head_idx = 1;\n \topts.index_only = 1;\n \topts.merge = 1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \n \topts.fn = oneway_merge;\n \ttree = parse_tree_indirect(&current_head->object.oid);\n@@ -344,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_index(&the_index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))\n+\tif (refresh_index(the_repository->index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))\n \t\tdie_resolve_conflict(\"commit\");\n }\n \n@@ -393,7 +392,7 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \n \t\trefresh_cache_or_die(refresh_flags);\n \n-\t\tif (write_locked_index(&the_index, &index_lock, 0))\n+\t\tif (write_locked_index(the_repository->index, &index_lock, 0))\n \t\t\tdie(_(\"unable to create temporary index\"));\n \n \t\told_repo_index_file = the_repository->index_file;\n@@ -412,13 +411,13 @@ 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_index(&the_index);\n-\t\tread_index_from(&the_index, get_lock_file_path(&index_lock),\n+\t\tdiscard_index(the_repository->index);\n+\t\tread_index_from(the_repository->index, get_lock_file_path(&index_lock),\n \t\t\t\tget_git_dir());\n-\t\tif (cache_tree_update(&the_index, WRITE_TREE_SILENT) == 0) {\n+\t\tif (cache_tree_update(the_repository->index, 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-\t\t\tif (write_locked_index(&the_index, &index_lock, 0))\n+\t\t\tif (write_locked_index(the_repository->index, &index_lock, 0))\n \t\t\t\tdie(_(\"unable to update temporary index\"));\n \t\t} else\n \t\t\twarning(_(\"Failed to update main cache tree\"));\n@@ -446,8 +445,8 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \t\tadd_files_to_cache(the_repository, also ? prefix : NULL,\n \t\t\t\t   &pathspec, 0, 0);\n \t\trefresh_cache_or_die(refresh_flags);\n-\t\tcache_tree_update(&the_index, WRITE_TREE_SILENT);\n-\t\tif (write_locked_index(&the_index, &index_lock, 0))\n+\t\tcache_tree_update(the_repository->index, WRITE_TREE_SILENT);\n+\t\tif (write_locked_index(the_repository->index, &index_lock, 0))\n \t\t\tdie(_(\"unable to write new index file\"));\n \t\tcommit_style = COMMIT_NORMAL;\n \t\tret = get_lock_file_path(&index_lock);\n@@ -467,10 +466,10 @@ static const char *prepare_index(const char **argv, const char *prefix,\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-\t\t\tcache_tree_update(&the_index, WRITE_TREE_SILENT);\n-\t\tif (write_locked_index(&the_index, &index_lock,\n+\t\tif (the_repository->index->cache_changed\n+\t\t    || !cache_tree_fully_valid(the_repository->index->cache_tree))\n+\t\t\tcache_tree_update(the_repository->index, WRITE_TREE_SILENT);\n+\t\tif (write_locked_index(the_repository->index, &index_lock,\n \t\t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\t\tdie(_(\"unable to write new index file\"));\n \t\tcommit_style = COMMIT_AS_IS;\n@@ -511,15 +510,15 @@ 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_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"cannot read the index\"));\n \n \trepo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);\n \tadd_remove_files(&partial);\n-\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n-\tcache_tree_update(&the_index, WRITE_TREE_SILENT);\n-\tif (write_locked_index(&the_index, &index_lock, 0))\n+\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);\n+\tcache_tree_update(the_repository->index, WRITE_TREE_SILENT);\n+\tif (write_locked_index(the_repository->index, &index_lock, 0))\n \t\tdie(_(\"unable to write new index file\"));\n \n \thold_lock_file_for_update(&false_lock,\n@@ -529,14 +528,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_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n+\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);\n \n-\tif (write_locked_index(&the_index, &false_lock, 0))\n+\tif (write_locked_index(the_repository->index, &false_lock, 0))\n \t\tdie(_(\"unable to write temporary index file\"));\n \n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \tret = get_lock_file_path(&false_lock);\n-\tread_index_from(&the_index, ret, get_git_dir());\n+\tread_index_from(the_repository->index, ret, get_git_dir());\n out:\n \tstring_list_clear(&partial, 0);\n \tclear_pathspec(&pathspec);\n@@ -994,7 +993,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\tstruct object_id oid;\n \t\tconst char *parent = \"HEAD\";\n \n-\t\tif (!the_index.initialized && repo_read_index(the_repository) < 0)\n+\t\tif (!the_repository->index->initialized && repo_read_index(the_repository) < 0)\n \t\t\tdie(_(\"Cannot read index\"));\n \n \t\tif (amend)\n@@ -1004,11 +1003,11 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\t\tint i, ita_nr = 0;\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 < the_index.cache_nr; i++)\n-\t\t\t\tif (ce_intent_to_add(the_index.cache[i]))\n+\t\t\tensure_full_index(the_repository->index);\n+\t\t\tfor (i = 0; i < the_repository->index->cache_nr; i++)\n+\t\t\t\tif (ce_intent_to_add(the_repository->index->cache[i]))\n \t\t\t\t\tita_nr++;\n-\t\t\tcommittable = the_index.cache_nr - ita_nr > 0;\n+\t\t\tcommittable = the_repository->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@@ -1076,11 +1075,11 @@ 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_index(&the_index);\n+\t\tdiscard_index(the_repository->index);\n \t}\n-\tread_index_from(&the_index, index_file, get_git_dir());\n+\tread_index_from(the_repository->index, index_file, get_git_dir());\n \n-\tif (cache_tree_update(&the_index, 0)) {\n+\tif (cache_tree_update(the_repository->index, 0)) {\n \t\terror(_(\"Error building trees\"));\n \t\treturn 0;\n \t}\n@@ -1581,7 +1580,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \t    status_format != STATUS_FORMAT_PORCELAIN_V2)\n \t\tprogress_flag = REFRESH_PROGRESS;\n \trepo_read_index(the_repository);\n-\trefresh_index(&the_index,\n+\trefresh_index(the_repository->index,\n \t\t      REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,\n \t\t      &s.pathspec, NULL, NULL);\n \n@@ -1851,7 +1850,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, &the_index.cache_tree->oid,\n+\tif (commit_tree_extended(sb.buf, sb.len, &the_repository->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/describe.c b/builtin/describe.c\nindex d6c77a714f..c0e3301e3c 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"environment.h\"\n@@ -674,7 +673,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tprepare_repo_settings(the_repository);\n \t\t\tthe_repository->settings.command_requires_full_index = 0;\n \t\t\trepo_read_index(the_repository);\n-\t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n+\t\t\trefresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\n \t\t\tfd = repo_hold_locked_index(the_repository,\n \t\t\t\t\t\t    &index_lock, 0);\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex a8e68ce8ef..0d3c611aac 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"diff.h\"\n@@ -206,7 +205,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)\n \t\topt->diffopt.rotate_to_strict = 0;\n \t\topt->diffopt.no_free = 1;\n \t\tif (opt->diffopt.detect_rename) {\n-\t\t\tif (!the_index.cache)\n+\t\t\tif (the_repository->index->cache)\n \t\t\t\trepo_read_index(the_repository);\n \t\t\topt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;\n \t\t}\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 6e196e0c7d..efc37483b3 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"ewah/ewok.h\"\n@@ -239,9 +239,9 @@ static void refresh_index_quietly(void)\n \tfd = repo_hold_locked_index(the_repository, &lock_file, 0);\n \tif (fd < 0)\n \t\treturn;\n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \trepo_read_index(the_repository);\n-\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL,\n+\trefresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL,\n \t\t      NULL);\n \trepo_update_index_if_able(the_repository, &lock_file);\n }\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex a3c72b8258..a130faae4f 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -117,7 +117,7 @@ static int use_wt_file(const char *workdir, const char *name,\n \t\tint fd = open(buf.buf, O_RDONLY);\n \n \t\tif (fd >= 0 &&\n-\t\t    !index_fd(&the_index, &wt_oid, fd, &st, OBJ_BLOB, name, 0)) {\n+\t\t    !index_fd(the_repository->index, &wt_oid, fd, &st, OBJ_BLOB, name, 0)) {\n \t\t\tif (is_null_oid(oid)) {\n \t\t\t\toidcpy(oid, &wt_oid);\n \t\t\t\tuse = 1;\ndiff --git a/builtin/merge-index.c b/builtin/merge-index.c\nindex 270d5f644a..0fabe3f6bb 100644\n--- a/builtin/merge-index.c\n+++ b/builtin/merge-index.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"hex.h\"\n #include \"read-cache-ll.h\"\n@@ -18,11 +17,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 >= the_index.cache_nr)\n+\tif (pos >= the_repository->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 = the_index.cache[pos];\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[pos];\n \t\tint stage = ce_stage(ce);\n \n \t\tif (strcmp(ce->name, path))\n@@ -32,7 +31,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 < the_index.cache_nr);\n+\t} while (++pos < the_repository->index->cache_nr);\n \tif (!found)\n \t\tdie(\"git merge-index: %s not in the cache\", path);\n \n@@ -51,7 +50,7 @@ static int merge_entry(int pos, const char *path)\n \n static void merge_one_path(const char *path)\n {\n-\tint pos = index_name_pos(&the_index, path, strlen(path));\n+\tint pos = index_name_pos(the_repository->index, path, strlen(path));\n \n \t/*\n \t * If it already exists in the cache as stage0, it's\n@@ -65,9 +64,9 @@ static void merge_all(void)\n {\n \tint i;\n \t/* TODO: audit for interaction with sparse-index. */\n-\tensure_full_index(&the_index);\n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tconst struct cache_entry *ce = the_index.cache[i];\n+\tensure_full_index(the_repository->index);\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[i];\n \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \t\ti += merge_entry(i, ce->name)-1;\n@@ -89,7 +88,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED)\n \trepo_read_index(the_repository);\n \n \t/* TODO: audit for interaction with sparse-index. */\n-\tensure_full_index(&the_index);\n+\tensure_full_index(the_repository->index);\n \n \ti = 1;\n \tif (!strcmp(argv[i], \"-o\")) {\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex 8bdb439131..1082d919fd 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"tree-walk.h\"\n #include \"xdiff-interface.h\"\n@@ -364,7 +363,7 @@ static void trivial_merge_trees(struct tree_desc t[3], const char *base)\n \n \tsetup_traverse_info(&info, base);\n \tinfo.fn = threeway_callback;\n-\ttraverse_trees(&the_index, 3, t, &info);\n+\ttraverse_trees(the_repository->index, 3, t, &info);\n }\n \n static void *get_tree_descriptor(struct repository *r,\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 6f4fec87fc..6a6d379885 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -6,7 +6,6 @@\n  * Based on git-merge.sh by Junio C Hamano.\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n@@ -300,7 +299,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_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n+\trefresh_index(the_repository->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@@ -372,7 +371,7 @@ static void restore_state(const struct object_id *head,\n \trun_command(&cmd);\n \n refresh_cache:\n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"could not read index\"));\n }\n@@ -657,8 +656,8 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 2;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \topts.update = 1;\n \topts.verbose_update = 1;\n \topts.trivial_merges_only = 1;\n@@ -674,7 +673,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(&the_index.cache_tree);\n+\tcache_tree_free(&the_repository->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]->object.oid,\n@@ -687,7 +686,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,\n \n static void write_tree_trivial(struct object_id *oid)\n {\n-\tif (write_index_as_tree(oid, &the_index, get_index_file(), 0, NULL))\n+\tif (write_index_as_tree(oid, the_repository->index, get_index_file(), 0, NULL))\n \t\tdie(_(\"git write-tree failed to write a tree\"));\n }\n \n@@ -745,7 +744,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,\n \t\t\trollback_lock_file(&lock);\n \t\t\treturn 2;\n \t\t}\n-\t\tif (write_locked_index(&the_index, &lock,\n+\t\tif (write_locked_index(the_repository->index, &lock,\n \t\t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\t\tdie(_(\"unable to write %s\"), get_index_file());\n \t\treturn clean ? 0 : 1;\n@@ -768,8 +767,8 @@ static int count_unmerged_entries(void)\n {\n \tint i, ret = 0;\n \n-\tfor (i = 0; i < the_index.cache_nr; i++)\n-\t\tif (ce_stage(the_index.cache[i]))\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++)\n+\t\tif (ce_stage(the_repository->index->cache[i]))\n \t\t\tret++;\n \n \treturn ret;\n@@ -843,9 +842,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_index(&the_index);\n+\t\t\tdiscard_index(the_repository->index);\n \t}\n-\tread_index_from(&the_index, index_file, get_git_dir());\n+\tread_index_from(the_repository->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@@ -957,7 +956,7 @@ static int suggest_conflicts(void)\n \t * Thus, we will get the cleanup mode which is returned when we _are_\n \t * using an editor.\n \t */\n-\tappend_conflicts_hint(&the_index, &msgbuf,\n+\tappend_conflicts_hint(the_repository->index, &msgbuf,\n \t\t\t      get_cleanup_mode(cleanup_arg, 1));\n \tfputs(msgbuf.buf, fp);\n \tstrbuf_release(&msgbuf);\n@@ -1386,7 +1385,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_index(&the_index);\n+\tresolve_undo_clear_index(the_repository->index);\n \n \tif (option_edit < 0)\n \t\toption_edit = default_edit_option();\n@@ -1595,7 +1594,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_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n+\t\trefresh_index(the_repository->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@@ -1784,6 +1783,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t}\n \tstrbuf_release(&buf);\n \tfree(branch_to_free);\n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \treturn ret;\n }\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 22e64fc290..74aa9746aa 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) 2006 Johannes Schindelin\n  */\n-#define USE_THE_INDEX_VARIABLE\n+\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n@@ -95,9 +95,9 @@ 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(the_index.cache[first]->ce_mode))\n+\tif (!S_ISGITLINK(the_repository->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+\tif (!is_staging_gitmodules_ok(the_repository->index))\n \t\tdie(_(\"Please stage your changes to .gitmodules or stash them to proceed\"));\n \tstrbuf_addf(&submodule_dotgit, \"%s/.git\", src);\n \t*submodule_gitfile = read_gitfile(submodule_dotgit.buf);\n@@ -114,13 +114,13 @@ 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 = index_name_pos(&the_index, src_w_slash, len_w_slash);\n+\tfirst = index_name_pos(the_repository->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 \tfirst = -1 - first;\n-\tfor (last = first; last < the_index.cache_nr; last++) {\n-\t\tconst char *path = the_index.cache[last]->name;\n+\tfor (last = first; last < the_repository->index->cache_nr; last++) {\n+\t\tconst char *path = the_repository->index->cache[last]->name;\n \t\tif (strncmp(path, src_w_slash, len_w_slash))\n \t\t\tbreak;\n \t}\n@@ -144,14 +144,14 @@ 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 = index_name_pos(&the_index, with_slash, length);\n+\tint pos = index_name_pos(the_repository->index, with_slash, length);\n \tconst struct cache_entry *ce;\n \n \tif (pos < 0) {\n \t\tpos = -pos - 1;\n-\t\tif (pos >= the_index.cache_nr)\n+\t\tif (pos >= the_repository->index->cache_nr)\n \t\t\tgoto free_return;\n-\t\tce = the_index.cache[pos];\n+\t\tce = the_repository->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@@ -223,7 +223,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tS_ISDIR(st.st_mode)) {\n \t\tdestination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME);\n \t} else {\n-\t\tif (!path_in_sparse_checkout(dst_w_slash, &the_index) &&\n+\t\tif (!path_in_sparse_checkout(dst_w_slash, the_repository->index) &&\n \t\t    empty_dir_has_sparse_contents(dst_w_slash)) {\n \t\t\tdestination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME);\n \t\t\tdst_mode = SKIP_WORKTREE_DIR;\n@@ -239,7 +239,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t * is deprecated at this point) sparse-checkout. As\n \t\t\t * SPARSE here is only considering cone-mode situation.\n \t\t\t */\n-\t\t\tif (!path_in_cone_mode_sparse_checkout(destination[0], &the_index))\n+\t\t\tif (!path_in_cone_mode_sparse_checkout(destination[0], the_repository->index))\n \t\t\t\tdst_mode = SPARSE;\n \t\t}\n \t}\n@@ -263,10 +263,10 @@ 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 = index_name_pos(&the_index, src, length);\n+\t\t\tpos = index_name_pos(the_repository->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+\t\t\t\tif (!path_in_sparse_checkout(src_w_slash, the_repository->index) &&\n \t\t\t\t    empty_dir_has_sparse_contents(src)) {\n \t\t\t\t\tmodes[i] |= SKIP_WORKTREE_DIR;\n \t\t\t\t\tgoto dir_check;\n@@ -276,7 +276,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 = the_index.cache[pos];\n+\t\t\tce = the_repository->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@@ -286,7 +286,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 (index_name_pos(&the_index, dst, strlen(dst)) < 0) {\n+\t\t\tif (index_name_pos(the_repository->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@@ -311,7 +311,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 = index_name_pos(&the_index, src, length), last;\n+\t\t\tint first = index_name_pos(the_repository->index, src, length), last;\n \n \t\t\tif (first >= 0) {\n \t\t\t\tprepare_move_submodule(src, first,\n@@ -339,7 +339,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 = the_index.cache[first + j];\n+\t\t\t\tconst struct cache_entry *ce = the_repository->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@@ -351,7 +351,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 = index_file_exists(&the_index, src, length, 0))) {\n+\t\tif (!(ce = index_file_exists(the_repository->index, src, length, 0))) {\n \t\t\tbad = _(\"not under version control\");\n \t\t\tgoto act_on_entry;\n \t\t}\n@@ -387,7 +387,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \n \t\tif (ignore_sparse &&\n \t\t    (dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&\n-\t\t    index_entry_exists(&the_index, dst, strlen(dst))) {\n+\t\t    index_entry_exists(the_repository->index, dst, strlen(dst))) {\n \t\t\tbad = _(\"destination exists in the index\");\n \t\t\tif (force) {\n \t\t\t\tif (verbose)\n@@ -404,12 +404,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t * option as a way to have a successful run.\n \t\t */\n \t\tif (!ignore_sparse &&\n-\t\t    !path_in_sparse_checkout(src, &the_index)) {\n+\t\t    !path_in_sparse_checkout(src, the_repository->index)) {\n \t\t\tstring_list_append(&only_match_skip_worktree, src);\n \t\t\tskip_sparse = 1;\n \t\t}\n \t\tif (!ignore_sparse &&\n-\t\t    !path_in_sparse_checkout(dst, &the_index)) {\n+\t\t    !path_in_sparse_checkout(dst, the_repository->index)) {\n \t\t\tstring_list_append(&only_match_skip_worktree, dst);\n \t\t\tskip_sparse = 1;\n \t\t}\n@@ -449,7 +449,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tint pos;\n \t\tint sparse_and_dirty = 0;\n \t\tstruct checkout state = CHECKOUT_INIT;\n-\t\tstate.istate = &the_index;\n+\t\tstate.istate = the_repository->index;\n \n \t\tif (force)\n \t\t\tstate.force = 1;\n@@ -476,14 +476,14 @@ 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 = index_name_pos(&the_index, src, strlen(src));\n+\t\tpos = index_name_pos(the_repository->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-\t\t\t\t\t\t       the_index.cache[pos],\n+\t\t\tsparse_and_dirty = ie_modified(the_repository->index,\n+\t\t\t\t\t\t       the_repository->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+\t\trename_index_entry_at(the_repository->index, pos, dst);\n \n \t\tif (ignore_sparse &&\n \t\t    core_apply_sparse_checkout &&\n@@ -495,11 +495,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t * should be added in a future patch.\n \t\t\t */\n \t\t\tif ((mode & SPARSE) &&\n-\t\t\t    path_in_sparse_checkout(dst, &the_index)) {\n+\t\t\t    path_in_sparse_checkout(dst, the_repository->index)) {\n \t\t\t\t/* from out-of-cone to in-cone */\n-\t\t\t\tint dst_pos = index_name_pos(&the_index, dst,\n+\t\t\t\tint dst_pos = index_name_pos(the_repository->index, dst,\n \t\t\t\t\t\t\t     strlen(dst));\n-\t\t\t\tstruct cache_entry *dst_ce = the_index.cache[dst_pos];\n+\t\t\t\tstruct cache_entry *dst_ce = the_repository->index->cache[dst_pos];\n \n \t\t\t\tdst_ce->ce_flags &= ~CE_SKIP_WORKTREE;\n \n@@ -507,11 +507,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tdie(_(\"cannot checkout %s\"), dst_ce->name);\n \t\t\t} else if ((dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&\n \t\t\t\t   !(mode & SPARSE) &&\n-\t\t\t\t   !path_in_sparse_checkout(dst, &the_index)) {\n+\t\t\t\t   !path_in_sparse_checkout(dst, the_repository->index)) {\n \t\t\t\t/* from in-cone to out-of-cone */\n-\t\t\t\tint dst_pos = index_name_pos(&the_index, dst,\n+\t\t\t\tint dst_pos = index_name_pos(the_repository->index, dst,\n \t\t\t\t\t\t\t     strlen(dst));\n-\t\t\t\tstruct cache_entry *dst_ce = the_index.cache[dst_pos];\n+\t\t\t\tstruct cache_entry *dst_ce = the_repository->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\n@@ -559,9 +559,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tadvise_on_moving_dirty_path(&dirty_paths);\n \n \tif (gitmodules_modified)\n-\t\tstage_updated_gitmodules(&the_index);\n+\t\tstage_updated_gitmodules(the_repository->index);\n \n-\tif (write_locked_index(&the_index, &lock_file,\n+\tif (write_locked_index(the_repository->index, &lock_file,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\tdie(_(\"Unable to write new index file\"));\n \ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 72cbb76d52..66869210db 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -1044,7 +1044,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_index_unborn(&the_index))\n+\t\tif (is_null_oid(&orig_head) && !is_index_unborn(the_repository->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 6f89cec0fb..a8cf8504b8 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -4,7 +4,6 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -159,8 +158,8 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = -1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \n \tgit_config(git_read_tree_config, NULL);\n \n@@ -197,7 +196,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_index(&the_index);\n+\tresolve_undo_clear_index(the_repository->index);\n \n \tfor (i = 0; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n@@ -225,7 +224,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \t\tsetup_work_tree();\n \n \tif (opts.skip_sparse_checkout)\n-\t\tensure_full_index(&the_index);\n+\t\tensure_full_index(the_repository->index);\n \n \tif (opts.merge) {\n \t\tswitch (stage - 1) {\n@@ -237,7 +236,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_index_unborn(&the_index);\n+\t\t\topts.initial_checkout = is_index_unborn(the_repository->index);\n \t\t\tbreak;\n \t\tcase 3:\n \t\tdefault:\n@@ -258,7 +257,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(&the_index.cache_tree);\n+\tcache_tree_free(&the_repository->index->cache_tree);\n \tfor (i = 0; i < nr_trees; i++) {\n \t\tstruct tree *tree = trees[i];\n \t\tif (parse_tree(tree) < 0)\n@@ -282,7 +281,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \t\t\t\t the_repository->index,\n \t\t\t\t trees[0]);\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(\"unable to write new index file\");\n \treturn 0;\n }\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 891f28468e..fe17d562a8 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -4,7 +4,6 @@\n  * Copyright (c) 2018 Pratik Karki\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"environment.h\"\n@@ -295,7 +294,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_index(&the_index);\n+\t\tdiscard_index(the_repository->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\");\ndiff --git a/builtin/replay.c b/builtin/replay.c\nindex 6bc4b47f09..6bf0691f15 100644\n--- a/builtin/replay.c\n+++ b/builtin/replay.c\n@@ -2,7 +2,6 @@\n  * \"git replay\" builtin command\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"git-compat-util.h\"\n \n #include \"builtin.h\"\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 1d62ff6332..b6dacf9678 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -66,8 +66,8 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \topts.fn = oneway_merge;\n \topts.merge = 1;\n \tinit_checkout_metadata(&opts.meta, ref, oid, NULL);\n@@ -159,11 +159,11 @@ 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_index(&the_index, one->path);\n+\t\t\tremove_file_from_index(the_repository->index, one->path);\n \t\t\tcontinue;\n \t\t}\n \n-\t\tce = make_cache_entry(&the_index, one->mode, &one->oid, one->path,\n+\t\tce = make_cache_entry(the_repository->index, one->mode, &one->oid, one->path,\n \t\t\t\t      0, 0);\n \n \t\t/*\n@@ -174,9 +174,9 @@ 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 = 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\tpos = index_name_pos(the_repository->index, one->path, strlen(one->path));\n+\t\tif ((pos >= 0 && ce_skip_worktree(the_repository->index->cache[pos])) ||\n+\t\t    (pos < 0 && !path_in_sparse_checkout(one->path, the_repository->index)))\n \t\t\tce->ce_flags |= CE_SKIP_WORKTREE;\n \n \t\tif (!ce)\n@@ -186,7 +186,7 @@ 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_index_entry(&the_index, ce,\n+\t\tadd_index_entry(the_repository->index, ce,\n \t\t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \t}\n }\n@@ -208,8 +208,8 @@ static int read_from_tree(const struct pathspec *pathspec,\n \topt.change = diff_change;\n \topt.add_remove = diff_addremove;\n \n-\tif (pathspec->nr && pathspec_needs_expanded_index(&the_index, pathspec))\n-\t\tensure_full_index(&the_index);\n+\tif (pathspec->nr && pathspec_needs_expanded_index(the_repository->index, pathspec))\n+\t\tensure_full_index(the_repository->index);\n \n \tif (do_diff_cache(tree_oid, &opt))\n \t\treturn 1;\n@@ -235,7 +235,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_index(&the_index))\n+\tif (is_merge() || unmerged_index(the_repository->index))\n \t\tdie(_(\"Cannot do a %s reset in the middle of a merge.\"),\n \t\t    _(reset_type_names[reset_type]));\n \n@@ -470,12 +470,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \t\t\t\tupdate_ref_status = 1;\n \t\t\t\tgoto cleanup;\n \t\t\t}\n-\t\t\tthe_index.updated_skipworktree = 1;\n+\t\t\tthe_repository->index->updated_skipworktree = 1;\n \t\t\tif (!no_refresh && get_git_work_tree()) {\n \t\t\t\tuint64_t t_begin, t_delta_in_ms;\n \n \t\t\t\tt_begin = getnanotime();\n-\t\t\t\trefresh_index(&the_index, flags, NULL, NULL,\n+\t\t\t\trefresh_index(the_repository->index, flags, NULL, NULL,\n \t\t\t\t\t      _(\"Unstaged changes after reset:\"));\n \t\t\t\tt_delta_in_ms = (getnanotime() - t_begin) / 1000000;\n \t\t\t\tif (!quiet && advice_enabled(ADVICE_RESET_NO_REFRESH_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) {\n@@ -501,7 +501,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \t\t\tfree(ref);\n \t\t}\n \n-\t\tif (write_locked_index(&the_index, &lock, COMMIT_LOCK))\n+\t\tif (write_locked_index(the_repository->index, &lock, COMMIT_LOCK))\n \t\t\tdie(_(\"Could not write new index file.\"));\n \t}\n \n@@ -516,7 +516,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \tif (!pathspec.nr)\n \t\tremove_branch_state(the_repository, 0);\n \n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \n cleanup:\n \tclear_pathspec(&pathspec);\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 624182e507..af79538632 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -1049,8 +1049,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\tif (!strcmp(arg, \"--shared-index-path\")) {\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+\t\t\t\tif (the_repository->index->split_index) {\n+\t\t\t\t\tconst struct object_id *oid = &the_repository->index->split_index->base_oid;\n \t\t\t\t\tconst char *path = git_path(\"sharedindex.%s\", oid_to_hex(oid));\n \t\t\t\t\tprint_path(path, prefix, format, DEFAULT_RELATIVE);\n \t\t\t\t}\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex fd130cea2d..d195c16e74 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds 2006\n  */\n-#define USE_THE_INDEX_VARIABLE\n+\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -41,8 +41,8 @@ static int get_ours_cache_pos(const char *path, int pos)\n {\n \tint i = -pos - 1;\n \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+\twhile ((i < the_repository->index->cache_nr) && !strcmp(the_repository->index->cache[i]->name, path)) {\n+\t\tif (ce_stage(the_repository->index->cache[i]) == 2)\n \t\t\treturn i;\n \t\ti++;\n \t}\n@@ -78,13 +78,13 @@ static void submodules_absorb_gitdir_if_needed(void)\n \t\tint pos;\n \t\tconst struct cache_entry *ce;\n \n-\t\tpos = index_name_pos(&the_index, name, strlen(name));\n+\t\tpos = index_name_pos(the_repository->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 \t\t\t\tcontinue;\n \t\t}\n-\t\tce = the_index.cache[pos];\n+\t\tce = the_repository->index->cache[pos];\n \n \t\tif (!S_ISGITLINK(ce->ce_mode) ||\n \t\t    !file_exists(ce->name) ||\n@@ -122,7 +122,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 = index_name_pos(&the_index, name, strlen(name));\n+\t\tpos = index_name_pos(the_repository->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@@ -132,11 +132,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(the_index.cache[pos]->ce_mode) ||\n+\t\t\tif (!S_ISGITLINK(the_repository->index->cache[pos]->ce_mode) ||\n \t\t\t    is_empty_dir(name))\n \t\t\t\tcontinue;\n \t\t}\n-\t\tce = the_index.cache[pos];\n+\t\tce = the_repository->index->cache[pos];\n \n \t\tif (lstat(ce->name, &st) < 0) {\n \t\t\tif (!is_missing_file_error(errno))\n@@ -173,7 +173,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 (ie_match_stat(&the_index, ce, &st, 0) ||\n+\t\tif (ie_match_stat(the_repository->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@@ -301,27 +301,27 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\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+\trefresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);\n \n \tseen = xcalloc(pathspec.nr, 1);\n \n-\tif (pathspec_needs_expanded_index(&the_index, &pathspec))\n-\t\tensure_full_index(&the_index);\n+\tif (pathspec_needs_expanded_index(the_repository->index, &pathspec))\n+\t\tensure_full_index(the_repository->index);\n \n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tconst struct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[i];\n \n \t\tif (!include_sparse &&\n \t\t    (ce_skip_worktree(ce) ||\n-\t\t     !path_in_sparse_checkout(ce->name, &the_index)))\n+\t\t     !path_in_sparse_checkout(ce->name, the_repository->index)))\n \t\t\tcontinue;\n-\t\tif (!ce_path_match(&the_index, ce, &pathspec, seen))\n+\t\tif (!ce_path_match(the_repository->index, ce, &pathspec, seen))\n \t\t\tcontinue;\n \t\tALLOC_GROW(list.entry, list.nr + 1, list.alloc);\n \t\tlist.entry[list.nr].name = xstrdup(ce->name);\n \t\tlist.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode);\n \t\tif (list.entry[list.nr++].is_submodule &&\n-\t\t    !is_staging_gitmodules_ok(&the_index))\n+\t\t    !is_staging_gitmodules_ok(the_repository->index))\n \t\t\tdie(_(\"please stage your changes to .gitmodules or stash them to proceed\"));\n \t}\n \n@@ -391,7 +391,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_index(&the_index, path))\n+\t\tif (remove_file_from_index(the_repository->index, path))\n \t\t\tdie(_(\"git rm: unable to remove %s\"), path);\n \t}\n \n@@ -432,10 +432,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t}\n \t\tstrbuf_release(&buf);\n \t\tif (gitmodules_modified)\n-\t\t\tstage_updated_gitmodules(&the_index);\n+\t\t\tstage_updated_gitmodules(the_repository->index);\n \t}\n \n-\tif (write_locked_index(&the_index, &lock_file,\n+\tif (write_locked_index(the_repository->index, &lock_file,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\tdie(_(\"Unable to write new index file\"));\n \ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex 062be1fbc0..69c01ba136 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -273,7 +272,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)\n \tstruct lock_file lock_file = LOCK_INIT;\n \n \trepo_read_index_preload(the_repository, NULL, 0);\n-\tif (refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL))\n+\tif (refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL))\n \t\treturn -1;\n \n \trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n@@ -287,8 +286,8 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)\n \tinit_tree_desc(t, &tree->object.oid, tree->buffer, tree->size);\n \n \topts.head_idx = 1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \topts.merge = 1;\n \topts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;\n \topts.update = update;\n@@ -299,7 +298,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)\n \tif (unpack_trees(nr_trees, t, &opts))\n \t\treturn -1;\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\treturn error(_(\"unable to write new index file\"));\n \n \treturn 0;\n@@ -430,7 +429,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)\n \tstate.force = 1;\n \tstate.quiet = 1;\n \tstate.refresh_cache = 1;\n-\tstate.istate = &the_index;\n+\tstate.istate = the_repository->index;\n \n \t/*\n \t * Step 1: get a difference between orig_tree (which corresponding\n@@ -454,7 +453,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)\n \n \t\t/* Look up the path's position in the current index. */\n \t\tp = diff_queued_diff.queue[i];\n-\t\tpos = index_name_pos(&the_index, p->two->path,\n+\t\tpos = index_name_pos(the_repository->index, p->two->path,\n \t\t\t\t     strlen(p->two->path));\n \n \t\t/*\n@@ -465,10 +464,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(the_index.cache[pos])) {\n+\t\tif (pos >= 0 && ce_skip_worktree(the_repository->index->cache[pos])) {\n \t\t\tstruct stat st;\n \n-\t\t\tce = the_index.cache[pos];\n+\t\t\tce = the_repository->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@@ -504,12 +503,12 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)\n \t\t\tif (pos < 0)\n \t\t\t\toption = ADD_CACHE_OK_TO_ADD;\n \n-\t\t\tce = make_cache_entry(&the_index,\n+\t\t\tce = make_cache_entry(the_repository->index,\n \t\t\t\t\t      p->one->mode,\n \t\t\t\t\t      &p->one->oid,\n \t\t\t\t\t      p->one->path,\n \t\t\t\t\t      0, 0);\n-\t\t\tadd_index_entry(&the_index, ce, option);\n+\t\t\tadd_index_entry(the_repository->index, ce, option);\n \t\t}\n \t}\n \tdiff_flush(&diff_opts);\n@@ -518,7 +517,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)\n \t * Step 4: write the new index to disk\n \t */\n \trepo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);\n-\tif (write_locked_index(&the_index, &lock,\n+\tif (write_locked_index(the_repository->index, &lock,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\tdie(_(\"could not write index\"));\n }\n@@ -539,7 +538,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,\n \t\t\t\t\t NULL, NULL, NULL))\n \t\treturn error(_(\"could not write index\"));\n \n-\tif (write_index_as_tree(&c_tree, &the_index, get_index_file(), 0,\n+\tif (write_index_as_tree(&c_tree, the_repository->index, get_index_file(), 0,\n \t\t\t\tNULL))\n \t\treturn error(_(\"cannot apply a stash in the middle of a merge\"));\n \n@@ -562,14 +561,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_index(&the_index);\n+\t\t\tdiscard_index(the_repository->index);\n \t\t\trepo_read_index(the_repository);\n-\t\t\tif (write_index_as_tree(&index_tree, &the_index,\n+\t\t\tif (write_index_as_tree(&index_tree, the_repository->index,\n \t\t\t\t\t\tget_index_file(), 0, NULL))\n \t\t\t\treturn error(_(\"could not save index tree\"));\n \n \t\t\treset_head();\n-\t\t\tdiscard_index(&the_index);\n+\t\t\tdiscard_index(the_repository->index);\n \t\t\trepo_read_index(the_repository);\n \t\t}\n \t}\n@@ -875,8 +874,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op\n \t}\n \n \tunpack_tree_opt.head_idx = -1;\n-\tunpack_tree_opt.src_index = &the_index;\n-\tunpack_tree_opt.dst_index = &the_index;\n+\tunpack_tree_opt.src_index = the_repository->index;\n+\tunpack_tree_opt.dst_index = the_repository->index;\n \tunpack_tree_opt.merge = 1;\n \tunpack_tree_opt.fn = stash_worktree_untracked_merge;\n \n@@ -1395,7 +1394,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b\n \n \tstrbuf_addf(&commit_tree_label, \"index on %s\\n\", msg.buf);\n \tcommit_list_insert(head_commit, &parents);\n-\tif (write_index_as_tree(&info->i_tree, &the_index, get_index_file(), 0,\n+\tif (write_index_as_tree(&info->i_tree, the_repository->index, get_index_file(), 0,\n \t\t\t\tNULL) ||\n \t    commit_tree(commit_tree_label.buf, commit_tree_label.len,\n \t\t\t&info->i_tree, parents, &info->i_commit, NULL, NULL)) {\n@@ -1540,9 +1539,9 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q\n \t\tchar *ps_matched = xcalloc(ps->nr, 1);\n \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++)\n-\t\t\tce_path_match(&the_index, the_index.cache[i], ps,\n+\t\tensure_full_index(the_repository->index);\n+\t\tfor (i = 0; i < the_repository->index->cache_nr; i++)\n+\t\t\tce_path_match(the_repository->index, the_repository->index->cache[i], ps,\n \t\t\t\t      ps_matched);\n \n \t\tif (report_path_error(ps_matched, ps)) {\n@@ -1612,7 +1611,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_index(&the_index);\n+\t\tdiscard_index(the_repository->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 e4e18adb57..93f4b9d726 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"environment.h\"\n@@ -207,18 +206,18 @@ static int module_list_compute(const char **argv,\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-\t\tconst struct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[i];\n \n-\t\tif (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),\n+\t\tif (!match_pathspec(the_repository->index, pathspec, ce->name, ce_namelen(ce),\n \t\t\t\t    0, ps_matched, 1) ||\n \t\t    !S_ISGITLINK(ce->ce_mode))\n \t\t\tcontinue;\n \n \t\tALLOC_GROW(list->entries, list->nr + 1, list->alloc);\n \t\tlist->entries[list->nr++] = ce;\n-\t\twhile (i + 1 < the_index.cache_nr &&\n-\t\t       !strcmp(ce->name, the_index.cache[i + 1]->name))\n+\t\twhile (i + 1 < the_repository->index->cache_nr &&\n+\t\t       !strcmp(ce->name, the_repository->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@@ -907,7 +906,7 @@ static void generate_submodule_summary(struct summary_cb *info,\n \t\t\tint fd = open(p->sm_path, O_RDONLY);\n \n \t\t\tif (fd < 0 || fstat(fd, &st) < 0 ||\n-\t\t\t    index_fd(&the_index, &p->oid_dst, fd, &st, OBJ_BLOB,\n+\t\t\t    index_fd(the_repository->index, &p->oid_dst, fd, &st, OBJ_BLOB,\n \t\t\t\t     p->sm_path, 0))\n \t\t\t\terror(_(\"couldn't hash object from '%s'\"), p->sm_path);\n \t\t} else {\n@@ -3243,21 +3242,21 @@ static void die_on_index_match(const char *path, int force)\n \t\tchar *ps_matched = xcalloc(ps.nr, 1);\n \n \t\t/* TODO: audit for interaction with sparse-index. */\n-\t\tensure_full_index(&the_index);\n+\t\tensure_full_index(the_repository->index);\n \n \t\t/*\n \t\t * Since there is only one pathspec, we just need to\n \t\t * check ps_matched[0] to know if a cache entry matched.\n \t\t */\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\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\t\tce_path_match(the_repository->index, the_repository->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(the_index.cache[i]->ce_mode))\n+\t\t\t\tif (!S_ISGITLINK(the_repository->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 7bcaa1476c..6321810006 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_VARIABLE\n+\n #include \"builtin.h\"\n #include \"bulk-checkin.h\"\n #include \"config.h\"\n@@ -247,16 +247,16 @@ 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 = index_name_pos(&the_index, path, namelen);\n+\tint pos = index_name_pos(the_repository->index, path, namelen);\n \tif (0 <= pos) {\n-\t\tmark_fsmonitor_invalid(&the_index, the_index.cache[pos]);\n+\t\tmark_fsmonitor_invalid(the_repository->index, the_repository->index->cache[pos]);\n \t\tif (mark)\n-\t\t\tthe_index.cache[pos]->ce_flags |= flag;\n+\t\t\tthe_repository->index->cache[pos]->ce_flags |= flag;\n \t\telse\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\tthe_index.cache_changed |= CE_ENTRY_CHANGED;\n+\t\t\tthe_repository->index->cache[pos]->ce_flags &= ~flag;\n+\t\tthe_repository->index->cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;\n+\t\tcache_tree_invalidate_path(the_repository->index, path);\n+\t\tthe_repository->index->cache_changed |= CE_ENTRY_CHANGED;\n \t\treturn 0;\n \t}\n \treturn -1;\n@@ -266,7 +266,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_index(&the_index, path))\n+\tif (remove_file_from_index(the_repository->index, path))\n \t\treturn error(\"%s: cannot remove from the index\", path);\n \treturn 0;\n }\n@@ -291,24 +291,24 @@ 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) && !ie_match_stat(&the_index, old, st, 0))\n+\tif (old && !ce_stage(old) && !ie_match_stat(the_repository->index, old, st, 0))\n \t\treturn 0;\n \n-\tce = make_empty_cache_entry(&the_index, len);\n+\tce = make_empty_cache_entry(the_repository->index, len);\n \tmemcpy(ce->name, path, len);\n \tce->ce_flags = create_ce_flags(0);\n \tce->ce_namelen = len;\n-\tfill_stat_cache_info(&the_index, ce, st);\n+\tfill_stat_cache_info(the_repository->index, ce, st);\n \tce->ce_mode = ce_mode_from_stat(old, st->st_mode);\n \n-\tif (index_path(&the_index, &ce->oid, path, st,\n+\tif (index_path(the_repository->index, &ce->oid, path, st,\n \t\t       info_only ? 0 : HASH_WRITE_OBJECT)) {\n \t\tdiscard_cache_entry(ce);\n \t\treturn -1;\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_index_entry(&the_index, ce, option)) {\n+\tif (add_index_entry(the_repository->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@@ -341,11 +341,11 @@ 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 = index_name_pos(&the_index, path, len);\n+\tint pos = index_name_pos(the_repository->index, path, len);\n \n \t/* Exact match: file or existing gitlink */\n \tif (pos >= 0) {\n-\t\tconst struct cache_entry *ce = the_index.cache[pos];\n+\t\tconst struct cache_entry *ce = the_repository->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@@ -360,8 +360,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 < the_index.cache_nr) {\n-\t\tconst struct cache_entry *ce = the_index.cache[pos++];\n+\twhile (pos < the_repository->index->cache_nr) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[pos++];\n \n \t\tif (strncmp(ce->name, path, len))\n \t\t\tbreak;\n@@ -391,8 +391,8 @@ static int process_path(const char *path, struct stat *st, int stat_errno)\n \tif (has_symlink_leading_path(path, len))\n \t\treturn error(\"'%s' is beyond a symbolic link\", path);\n \n-\tpos = index_name_pos(&the_index, path, len);\n-\tce = pos < 0 ? NULL : the_index.cache[pos];\n+\tpos = index_name_pos(the_repository->index, path, len);\n+\tce = pos < 0 ? NULL : the_repository->index->cache[pos];\n \tif (ce && ce_skip_worktree(ce)) {\n \t\t/*\n \t\t * working directory version is assumed \"good\"\n@@ -400,7 +400,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_index(&the_index, path))\n+\t\t    remove_file_from_index(the_repository->index, path))\n \t\t\treturn error(\"%s: cannot remove from the index\", path);\n \t\treturn 0;\n \t}\n@@ -428,7 +428,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,\n \t\treturn error(\"Invalid path '%s'\", path);\n \n \tlen = strlen(path);\n-\tce = make_empty_cache_entry(&the_index, len);\n+\tce = make_empty_cache_entry(the_repository->index, len);\n \n \toidcpy(&ce->oid, oid);\n \tmemcpy(ce->name, path, len);\n@@ -439,7 +439,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_index_entry(&the_index, ce, option))\n+\tif (add_index_entry(the_repository->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@@ -451,11 +451,11 @@ static void chmod_path(char flip, const char *path)\n \tint pos;\n \tstruct cache_entry *ce;\n \n-\tpos = index_name_pos(&the_index, path, strlen(path));\n+\tpos = index_name_pos(the_repository->index, path, strlen(path));\n \tif (pos < 0)\n \t\tgoto fail;\n-\tce = the_index.cache[pos];\n-\tif (chmod_index_entry(&the_index, ce, flip) < 0)\n+\tce = the_repository->index->cache[pos];\n+\tif (chmod_index_entry(the_repository->index, ce, flip) < 0)\n \t\tgoto fail;\n \n \treport(\"chmod %cx '%s'\", flip, path);\n@@ -498,7 +498,7 @@ static void update_one(const char *path)\n \t}\n \n \tif (force_remove) {\n-\t\tif (remove_file_from_index(&the_index, path))\n+\t\tif (remove_file_from_index(the_repository->index, path))\n \t\t\tdie(\"git update-index: unable to remove %s\", path);\n \t\treport(\"remove '%s'\", path);\n \t\treturn;\n@@ -581,7 +581,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_index(&the_index, path_name))\n+\t\t\tif (remove_file_from_index(the_repository->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@@ -622,12 +622,12 @@ static struct cache_entry *read_one_ent(const char *which,\n \t\t\terror(\"%s: not in %s branch.\", path, which);\n \t\treturn NULL;\n \t}\n-\tif (!the_index.sparse_index && mode == S_IFDIR) {\n+\tif (!the_repository->index->sparse_index && mode == S_IFDIR) {\n \t\tif (which)\n \t\t\terror(\"%s: not a blob in %s branch.\", path, which);\n \t\treturn NULL;\n \t}\n-\tce = make_empty_cache_entry(&the_index, namelen);\n+\tce = make_empty_cache_entry(the_repository->index, namelen);\n \n \toidcpy(&ce->oid, &oid);\n \tmemcpy(ce->name, path, namelen);\n@@ -642,12 +642,12 @@ static int unresolve_one(const char *path)\n \tstruct string_list_item *item;\n \tint res = 0;\n \n-\tif (!the_index.resolve_undo)\n+\tif (!the_repository->index->resolve_undo)\n \t\treturn res;\n-\titem = string_list_lookup(the_index.resolve_undo, path);\n+\titem = string_list_lookup(the_repository->index->resolve_undo, path);\n \tif (!item)\n \t\treturn res; /* no resolve-undo record for the path */\n-\tres = unmerge_index_entry(&the_index, path, item->util, 0);\n+\tres = unmerge_index_entry(the_repository->index, path, item->util, 0);\n \tFREE_AND_NULL(item->util);\n \treturn res;\n }\n@@ -688,13 +688,13 @@ static int do_reupdate(const char **paths,\n \t\t */\n \t\thas_head = 0;\n  redo:\n-\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n-\t\tconst struct cache_entry *ce = the_index.cache[pos];\n+\tfor (pos = 0; pos < the_repository->index->cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[pos];\n \t\tstruct cache_entry *old = NULL;\n \t\tint save_nr;\n \t\tchar *path;\n \n-\t\tif (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL))\n+\t\tif (ce_stage(ce) || !ce_path_match(the_repository->index, ce, &pathspec, NULL))\n \t\t\tcontinue;\n \t\tif (has_head)\n \t\t\told = read_one_ent(NULL, &head_oid,\n@@ -710,7 +710,7 @@ static int do_reupdate(const char **paths,\n \t\t * to process each path individually\n \t\t */\n \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n-\t\t\tensure_full_index(&the_index);\n+\t\t\tensure_full_index(the_repository->index);\n \t\t\tgoto redo;\n \t\t}\n \n@@ -718,12 +718,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 = the_index.cache_nr;\n+\t\tsave_nr = the_repository->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 != the_index.cache_nr)\n+\t\tif (save_nr != the_repository->index->cache_nr)\n \t\t\tgoto redo;\n \t}\n \tclear_pathspec(&pathspec);\n@@ -739,9 +739,9 @@ static int refresh(struct refresh_params *o, unsigned int flag)\n {\n \tsetup_work_tree();\n \trepo_read_index(the_repository);\n-\t*o->has_errors |= refresh_index(&the_index, o->flags | flag, NULL,\n+\t*o->has_errors |= refresh_index(the_repository->index, o->flags | flag, NULL,\n \t\t\t\t\tNULL, NULL);\n-\tif (has_racy_timestamp(&the_index)) {\n+\tif (has_racy_timestamp(the_repository->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@@ -750,7 +750,7 @@ static int refresh(struct refresh_params *o, unsigned int flag)\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+\t\tthe_repository->index->cache_changed |= SOMETHING_CHANGED;\n \t}\n \treturn 0;\n }\n@@ -787,7 +787,7 @@ static int resolve_undo_clear_callback(const struct option *opt UNUSED,\n {\n \tBUG_ON_OPT_NEG(unset);\n \tBUG_ON_OPT_ARG(arg);\n-\tresolve_undo_clear_index(&the_index);\n+\tresolve_undo_clear_index(the_repository->index);\n \treturn 0;\n }\n \n@@ -888,7 +888,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\tthe_index.cache_changed = 0;\n+\t\tthe_repository->index->cache_changed = 0;\n \n \tctx->argv += ctx->argc - 1;\n \tctx->argc = 1;\n@@ -909,7 +909,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\tthe_index.cache_changed = 0;\n+\t\tthe_repository->index->cache_changed = 0;\n \n \tctx->argv += ctx->argc - 1;\n \tctx->argc = 1;\n@@ -1056,7 +1056,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \tif (entries < 0)\n \t\tdie(\"cache corrupted\");\n \n-\tthe_index.updated_skipworktree = 1;\n+\tthe_repository->index->updated_skipworktree = 1;\n \n \t/*\n \t * Custom copy of parse_options() because we want to handle\n@@ -1111,18 +1111,18 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \tgetline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;\n \tif (preferred_index_format) {\n \t\tif (preferred_index_format < 0) {\n-\t\t\tprintf(_(\"%d\\n\"), the_index.version);\n+\t\t\tprintf(_(\"%d\\n\"), the_repository->index->version);\n \t\t} else if (preferred_index_format < INDEX_FORMAT_LB ||\n \t\t\t   INDEX_FORMAT_UB < preferred_index_format) {\n \t\t\tdie(\"index-version %d not in range: %d..%d\",\n \t\t\t    preferred_index_format,\n \t\t\t    INDEX_FORMAT_LB, INDEX_FORMAT_UB);\n \t\t} else {\n-\t\t\tif (the_index.version != preferred_index_format)\n-\t\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n+\t\t\tif (the_repository->index->version != preferred_index_format)\n+\t\t\t\tthe_repository->index->cache_changed |= SOMETHING_CHANGED;\n \t\t\treport(_(\"index-version: was %d, set to %d\"),\n-\t\t\t       the_index.version, preferred_index_format);\n-\t\t\tthe_index.version = preferred_index_format;\n+\t\t\t       the_repository->index->version, preferred_index_format);\n+\t\t\tthe_repository->index->version = preferred_index_format;\n \t\t}\n \t}\n \n@@ -1159,16 +1159,16 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\twarning(_(\"core.splitIndex is set to false; \"\n \t\t\t\t  \"remove or change it, if you really want to \"\n \t\t\t\t  \"enable split index\"));\n-\t\tif (the_index.split_index)\n-\t\t\tthe_index.cache_changed |= SPLIT_INDEX_ORDERED;\n+\t\tif (the_repository->index->split_index)\n+\t\t\tthe_repository->index->cache_changed |= SPLIT_INDEX_ORDERED;\n \t\telse\n-\t\t\tadd_split_index(&the_index);\n+\t\t\tadd_split_index(the_repository->index);\n \t} else if (!split_index) {\n \t\tif (git_config_get_split_index() == 1)\n \t\t\twarning(_(\"core.splitIndex is set to true; \"\n \t\t\t\t  \"remove or change it, if you really want to \"\n \t\t\t\t  \"disable split index\"));\n-\t\tremove_split_index(&the_index);\n+\t\tremove_split_index(the_repository->index);\n \t}\n \n \tprepare_repo_settings(r);\n@@ -1180,7 +1180,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\twarning(_(\"core.untrackedCache is set to true; \"\n \t\t\t\t  \"remove or change it, if you really want to \"\n \t\t\t\t  \"disable the untracked cache\"));\n-\t\tremove_untracked_cache(&the_index);\n+\t\tremove_untracked_cache(the_repository->index);\n \t\treport(_(\"Untracked cache disabled\"));\n \t\tbreak;\n \tcase UC_TEST:\n@@ -1192,7 +1192,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\twarning(_(\"core.untrackedCache is set to false; \"\n \t\t\t\t  \"remove or change it, if you really want to \"\n \t\t\t\t  \"enable the untracked cache\"));\n-\t\tadd_untracked_cache(&the_index);\n+\t\tadd_untracked_cache(the_repository->index);\n \t\treport(_(\"Untracked cache enabled for '%s'\"), get_git_work_tree());\n \t\tbreak;\n \tdefault:\n@@ -1222,7 +1222,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\t\t\"set it if you really want to \"\n \t\t\t\t\"enable fsmonitor\"));\n \t\t}\n-\t\tadd_fsmonitor(&the_index);\n+\t\tadd_fsmonitor(the_repository->index);\n \t\treport(_(\"fsmonitor enabled\"));\n \t} else if (!fsmonitor) {\n \t\tenum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);\n@@ -1230,17 +1230,17 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\twarning(_(\"core.fsmonitor is set; \"\n \t\t\t\t\"remove it if you really want to \"\n \t\t\t\t\"disable fsmonitor\"));\n-\t\tremove_fsmonitor(&the_index);\n+\t\tremove_fsmonitor(the_repository->index);\n \t\treport(_(\"fsmonitor disabled\"));\n \t}\n \n-\tif (the_index.cache_changed || force_write) {\n+\tif (the_repository->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);\n \t\t\tunable_to_lock_die(get_index_file(), lock_error);\n \t\t}\n-\t\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\t\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\t\tdie(\"Unable to write new index file\");\n \t}\n \ndiff --git a/builtin/write-tree.c b/builtin/write-tree.c\nindex 66e83d0ecb..8c75b4609b 100644\n--- a/builtin/write-tree.c\n+++ b/builtin/write-tree.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_VARIABLE\n+\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"environment.h\"\n@@ -44,8 +44,8 @@ int cmd_write_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-\tret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,\n-\t\t\t\t  tree_prefix);\n+\tret = write_index_as_tree(&oid, the_repository->index, get_index_file(),\n+\t\t\t\t  flags, tree_prefix);\n \tswitch (ret) {\n \tcase 0:\n \t\tprintf(\"%s\\n\", oid_to_hex(&oid));\n-- \n2.44.GIT\n\n"},{"id":"492939","messageId":"96256f9eb30e5aca632942169d5c311b1f245b40.1713180749.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713180749.git.ps@pks.im","subject":"[PATCH 3/5] repository: initialize index in `repo_init()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-15T11:42:52Z","receivedAt":"2024-04-15T11:42:56Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"When Git starts, one of the first things it will do is to call\n`initialize_the_repository()`. This function sets up both the global\n`the_repository` and `the_index` variables as required. Part of that\nsetup is also to set `the_repository.index = &the_index` so that the\nindex can be accessed via the repository.\n\nWhen calling `repo_init()` on a repository though we set the complete\nstruct to all-zeroes, which will also cause us to unset the `index`\npointer. And as we don't re-initialize the index in that function, we\nwill end up with a `NULL` pointer here.\n\nThis has been fine until now becaues this function is only used to\ncreate a new repository. git-init(1) does not access the index at all\nafter initializing the repository, whereas git-checkout(1) only uses\n`the_index` directly. We are about to remove `the_index` though, which\nwill uncover this partially-initialized repository structure.\n\nRefactor the code and create a common `initialize_repository()` function\nthat gets called from `repo_init()` and `initialize_the_repository()`.\nThis function sets up both the repository and the index as required.\nLike this, we can easily special-case when `repo_init()` gets called\nwith `the_repository`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n repository.c | 28 +++++++++++++++++-----------\n 1 file changed, 17 insertions(+), 11 deletions(-)\n\ndiff --git a/repository.c b/repository.c\nindex e15b416944..d64d15d952 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -25,17 +25,20 @@ static struct repository the_repo;\n struct repository *the_repository;\n struct index_state the_index;\n \n+static void initialize_repository(struct repository *repo,\n+\t\t\t\t  struct index_state *index)\n+{\n+\trepo->index = index;\n+\trepo->objects = raw_object_store_new();\n+\trepo->remote_state = remote_state_new();\n+\trepo->parsed_objects = parsed_object_pool_new();\n+\tindex_state_init(index, repo);\n+}\n+\n void initialize_the_repository(void)\n {\n \tthe_repository = &the_repo;\n-\n-\tthe_repo.index = &the_index;\n-\tthe_repo.objects = raw_object_store_new();\n-\tthe_repo.remote_state = remote_state_new();\n-\tthe_repo.parsed_objects = parsed_object_pool_new();\n-\n-\tindex_state_init(&the_index, the_repository);\n-\n+\tinitialize_repository(the_repository, &the_index);\n \trepo_set_hash_algo(&the_repo, GIT_HASH_SHA1);\n }\n \n@@ -188,9 +191,12 @@ int repo_init(struct repository *repo,\n \tstruct repository_format format = REPOSITORY_FORMAT_INIT;\n \tmemset(repo, 0, sizeof(*repo));\n \n-\trepo->objects = raw_object_store_new();\n-\trepo->parsed_objects = parsed_object_pool_new();\n-\trepo->remote_state = remote_state_new();\n+\tif (repo == the_repository) {\n+\t\tinitialize_repository(the_repository, &the_index);\n+\t} else {\n+\t\tALLOC_ARRAY(repo->index, 1);\n+\t\tinitialize_repository(repo, repo->index);\n+\t}\n \n \tif (repo_init_gitdir(repo, gitdir))\n \t\tgoto error;\n-- \n2.44.GIT\n\n"},{"id":"492940","messageId":"881b6d2f7df61dc685939b83ab660bb741e9716c.1713180749.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713180749.git.ps@pks.im","subject":"[PATCH 4/5] builtin/clone: stop using `the_index`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-15T11:43:01Z","receivedAt":"2024-04-15T11:43:05Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Convert git-clone(1) to use `the_repository->index` instead of\n`the_index`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/clone.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 74ec14542e..93fdfc945a 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -8,7 +8,6 @@\n  * Clone a repository into a different directory that does not yet exist.\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n@@ -731,8 +730,8 @@ static int checkout(int submodule_progress, int filter_submodules)\n \topts.preserve_ignored = 0;\n \topts.fn = oneway_merge;\n \topts.verbose_update = (option_verbosity >= 0);\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \tinit_checkout_metadata(&opts.meta, head, &oid, NULL);\n \n \ttree = parse_tree_indirect(&oid);\n@@ -746,7 +745,7 @@ static int checkout(int submodule_progress, int filter_submodules)\n \n \tfree(head);\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write new index file\"));\n \n \terr |= run_hooks_l(\"post-checkout\", oid_to_hex(null_oid()),\n-- \n2.44.GIT\n\n"},{"id":"492941","messageId":"80c36225bc9ae9a79710213e1fb30cdb2a924e8d.1713180749.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713180749.git.ps@pks.im","subject":"[PATCH 5/5] repository: drop global `the_index` variable","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-15T11:43:07Z","receivedAt":"2024-04-15T11:43:11Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"All users of `the_index` have been converted to use either a custom\n`struct index_state *` or the index provided by `the_repository`. We can\nthus drop the globally-accessible declaration of this variable.\n\nThis concludes the quest to make Git `the_index` free, which has started\nwith 4aab5b46f4 (Make read-cache.c \"the_index\" free., 2007-04-01).\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n repository.c | 4 ++--\n repository.h | 3 ---\n 2 files changed, 2 insertions(+), 5 deletions(-)\n\ndiff --git a/repository.c b/repository.c\nindex d64d15d952..cbaa6ef7ee 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_VARIABLE\n+\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"repository.h\"\n@@ -23,7 +23,7 @@\n /* The main repository */\n static struct repository the_repo;\n struct repository *the_repository;\n-struct index_state the_index;\n+static struct index_state the_index;\n \n static void initialize_repository(struct repository *repo,\n \t\t\t\t  struct index_state *index)\ndiff --git a/repository.h b/repository.h\nindex 268436779c..6f4af15417 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -187,9 +187,6 @@ struct repository {\n };\n \n extern struct repository *the_repository;\n-#ifdef USE_THE_INDEX_VARIABLE\n-extern struct index_state the_index;\n-#endif\n \n /*\n  * Define a custom repository layout. Any field can be NULL, which\n-- \n2.44.GIT\n\n"},{"id":"492942","messageId":"28541f00-9054-4aa0-8e47-348043b5f863@gmail.com","threadId":"61321","inReplyTo":"cover.1713180749.git.ps@pks.im","subject":"Re: [PATCH 0/5] global: drop external `the_index` variable","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2024-04-15T13:55:07Z","receivedAt":"2024-04-15T13:55:22Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Patrick\n\nOn 15/04/2024 12:42, Patrick Steinhardt wrote:\n> The motivation of these patches comes from the introduction of the ref\n> format extension. I found it really hard to reason about the state of\n> `the_repository` and would like to continue its deprecation in favor of\n> explicitly passing down a `struct repository *`. Getting rid of\n> `the_index` is a first easy step into that direction to make things more\n> self-contained.\n\nMaybe I've got the wrong end of the stick but my impression is that it \nis the use of \"the_repository\" in library code (i.e. the files outside \nbuiltin/) that causes most of the pain. With that in mind would be we \nbetter focusing contributor and reviewer effort on eliminating \n\"the_repository\" from those files instead? It would need to be done in \ncarefully in stages but would bring real benefits.\n\nBest Wishes\n\nPhillip\n\n> Patrick\n> \n> Patrick Steinhardt (5):\n>    t/helper: stop using `the_index`\n>    builtin: stop using `the_index`\n>    repository: initialize index in `repo_init()`\n>    builtin/clone: stop using `the_index`\n>    repository: drop global `the_index` variable\n> \n>   builtin/add.c                        |  48 +++++------\n>   builtin/am.c                         |  36 ++++----\n>   builtin/cat-file.c                   |   3 +-\n>   builtin/check-attr.c                 |   5 +-\n>   builtin/check-ignore.c               |   7 +-\n>   builtin/checkout-index.c             |  22 ++---\n>   builtin/checkout.c                   |  87 ++++++++++---------\n>   builtin/clean.c                      |   7 +-\n>   builtin/clone.c                      |   7 +-\n>   builtin/commit.c                     |  81 +++++++++---------\n>   builtin/describe.c                   |   3 +-\n>   builtin/diff-tree.c                  |   3 +-\n>   builtin/diff.c                       |   6 +-\n>   builtin/difftool.c                   |   4 +-\n>   builtin/merge-index.c                |  17 ++--\n>   builtin/merge-tree.c                 |   3 +-\n>   builtin/merge.c                      |  31 ++++---\n>   builtin/mv.c                         |  68 +++++++--------\n>   builtin/pull.c                       |   4 +-\n>   builtin/read-tree.c                  |  15 ++--\n>   builtin/rebase.c                     |   3 +-\n>   builtin/replay.c                     |   1 -\n>   builtin/reset.c                      |  32 +++----\n>   builtin/rev-parse.c                  |   6 +-\n>   builtin/rm.c                         |  40 ++++-----\n>   builtin/stash.c                      |  45 +++++-----\n>   builtin/submodule--helper.c          |  21 +++--\n>   builtin/update-index.c               | 122 +++++++++++++--------------\n>   builtin/write-tree.c                 |   6 +-\n>   repository.c                         |  32 ++++---\n>   repository.h                         |   3 -\n>   t/helper/test-cache-tree.c           |  17 ++--\n>   t/helper/test-dump-cache-tree.c      |   5 +-\n>   t/helper/test-dump-split-index.c     |  11 ++-\n>   t/helper/test-dump-untracked-cache.c |   3 +-\n>   t/helper/test-lazy-init-name-hash.c  |  39 +++++----\n>   t/helper/test-read-cache.c           |   9 +-\n>   t/helper/test-scrap-cache-tree.c     |   7 +-\n>   t/helper/test-write-cache.c          |   3 +-\n>   39 files changed, 420 insertions(+), 442 deletions(-)\n> \n"},{"id":"492946","messageId":"Zh02ZpS8x9H7FpHJ@tanuki","threadId":"61321","inReplyTo":"28541f00-9054-4aa0-8e47-348043b5f863@gmail.com","subject":"Re: [PATCH 0/5] global: drop external `the_index` variable","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-15T14:15:02Z","receivedAt":"2024-04-15T14:15:11Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Apr 15, 2024 at 02:55:07PM +0100, Phillip Wood wrote:\n> Hi Patrick\n> \n> On 15/04/2024 12:42, Patrick Steinhardt wrote:\n> > The motivation of these patches comes from the introduction of the ref\n> > format extension. I found it really hard to reason about the state of\n> > `the_repository` and would like to continue its deprecation in favor of\n> > explicitly passing down a `struct repository *`. Getting rid of\n> > `the_index` is a first easy step into that direction to make things more\n> > self-contained.\n> \n> Maybe I've got the wrong end of the stick but my impression is that it is\n> the use of \"the_repository\" in library code (i.e. the files outside\n> builtin/) that causes most of the pain. With that in mind would be we better\n> focusing contributor and reviewer effort on eliminating \"the_repository\"\n> from those files instead? It would need to be done in carefully in stages\n> but would bring real benefits.\n\nI see these two things as orthogonal. Overall, the target is to have as\nfew global state as possible. This requires us to over time remove both\n`the_repository`, but also `the_index`. Removing the latter is a ton\neasier to achieve than removing the former, and so I took the easier\nstep first.\n\nWhatever we do, we have to do things gradually anyway and thus we have\nto start somewhere. I've already got more things in the pipeline, where\nthe next step for me is to touch up \"refs.h\" so that we always pass in\nthe `struct ref_store *`. And here we will be introducing more uses of\n`the_repository`, as well. But I think this is okay, and by working from\nthe bottom up we will over time get to a state where the lower levels of\nGit don't require globals anymore, whereas higher levels like e.g. the\nbuiltins still do use them.\n\nEventually, we can then introduce a macro `USE_THE_REPOSITORY_VARIABLE`,\nsimilar to `USE_THE_INDEX_VARIABLE` that I have just removed in this\npatch series.\n\nPatrick\n"},{"id":"492956","messageId":"xmqq8r1eo6pz.fsf@gitster.g","threadId":"61321","inReplyTo":"28541f00-9054-4aa0-8e47-348043b5f863@gmail.com","subject":"Re: [PATCH 0/5] global: drop external `the_index` variable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-04-15T17:50:48Z","receivedAt":"2024-04-15T17:53:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n> Maybe I've got the wrong end of the stick but my impression is that it\n> is the use of \"the_repository\" in library code (i.e. the files outside\n> builtin/) that causes most of the pain. With that in mind would be we\n> better focusing contributor and reviewer effort on eliminating\n> \"the_repository\" from those files instead? It would need to be done in\n> carefully in stages but would bring real benefits.\n\nI am afraid that it would take a much larger effort.\n\nI have a suspicion that many of the users of the_index do not have\nto even need that the index_state they work on is connected to any\ninstance of a repository object (in other words, I tend to think\nthat the value of having a pointer to an index_state in an instance\nof a repository structure is dubious), so in a sense, this rewrite\nof code that use the_index to use the_repository may be going in a\nwrong direction.  In other words, these functions may eventually\nwant to take a pointer to an index_state structure as their\nparameters, without having to deal with the whole repository\nstructure, but this rewrite assumes they would eventually want to\nall work with a repository structure when the_repository dependency\nis lifted.  I'll need to see the codepaths involved more carefully\nand think about it.\n\nThanks.\n\n\n"},{"id":"492982","messageId":"Zh4MOkyOrM8kYeiK@tanuki","threadId":"61321","inReplyTo":"xmqq8r1eo6pz.fsf@gitster.g","subject":"Re: [PATCH 0/5] global: drop external `the_index` variable","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-16T05:27:22Z","receivedAt":"2024-04-16T05:27:28Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Apr 15, 2024 at 10:50:48AM -0700, Junio C Hamano wrote:\n> Phillip Wood <phillip.wood123@gmail.com> writes:\n> \n> > Maybe I've got the wrong end of the stick but my impression is that it\n> > is the use of \"the_repository\" in library code (i.e. the files outside\n> > builtin/) that causes most of the pain. With that in mind would be we\n> > better focusing contributor and reviewer effort on eliminating\n> > \"the_repository\" from those files instead? It would need to be done in\n> > carefully in stages but would bring real benefits.\n> \n> I am afraid that it would take a much larger effort.\n> \n> I have a suspicion that many of the users of the_index do not have\n> to even need that the index_state they work on is connected to any\n> instance of a repository object (in other words, I tend to think\n> that the value of having a pointer to an index_state in an instance\n> of a repository structure is dubious), so in a sense, this rewrite\n> of code that use the_index to use the_repository may be going in a\n> wrong direction.\n\nI wouldn't say it's going in a wrong direction. It simply makes explicit\nwhat already is implicit and thus simplifies our ability to reason about\nthe code.\n\nAt least it does that for me -- if others disagree then I will rethink\nmy approach. But the third patch demonstrates that the current approach\nalso causes weird inconsistencies in how we track the state of both\n`the_index` and `the_repository` in tandem.\n\n> In other words, these functions may eventually want to take a pointer\n> to an index_state structure as their parameters, without having to\n> deal with the whole repository structure, but this rewrite assumes\n> they would eventually want to all work with a repository structure\n> when the_repository dependency is lifted.  I'll need to see the\n> codepaths involved more carefully and think about it.\n\nYes, that's something that we will have to do eventually. I simply think\nthat the easiest way to approach this is bottom-up by moving the level\nat which we inject the index one level up at a time. And with every\nlevel that we move up we should figure out the intent of the code so\nthat we can decide whether it should use a local copy, the index of the\nrepository or something else.\n\nPatrick\n"},{"id":"493104","messageId":"CAOLa=ZQMcxHqXwEZGTAaa4Em6wx_Bx5OWR4qqy79woh2n-bwHw@mail.gmail.com","threadId":"61321","inReplyTo":"7b5ec04efc89af6874461d967bf5f61939e054dd.1713180749.git.ps@pks.im","subject":"Re: [PATCH 1/5] t/helper: stop using `the_index`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-04-17T17:23:00Z","receivedAt":"2024-04-17T17:23:02Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> Convert test-helper tools to use `the_repository->index` instead of\n> `the_index`.\n>\n> Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> ---\n>  t/helper/test-cache-tree.c           | 17 ++++++------\n>  t/helper/test-dump-cache-tree.c      |  5 ++--\n>  t/helper/test-dump-split-index.c     | 11 ++++----\n>  t/helper/test-dump-untracked-cache.c |  3 +--\n>  t/helper/test-lazy-init-name-hash.c  | 39 ++++++++++++++--------------\n>  t/helper/test-read-cache.c           |  9 +++----\n>  t/helper/test-scrap-cache-tree.c     |  7 +++--\n>  t/helper/test-write-cache.c          |  3 +--\n>  8 files changed, 43 insertions(+), 51 deletions(-)\n>\n> diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c\n> index e7236392c8..dc89ecfd71 100644\n> --- a/t/helper/test-cache-tree.c\n> +++ b/t/helper/test-cache-tree.c\n> @@ -1,4 +1,3 @@\n> -#define USE_THE_INDEX_VARIABLE\n>\n\nNit: It would've been nice to mention what this macro is used for.\nPerhaps maybe in the cover letter since its removed from all the commits.\n"},{"id":"493105","messageId":"CAOLa=ZS2S4=bC=s=vFnSfgvB0jZoKmH2Pi00V1Asyxo_yKSHPA@mail.gmail.com","threadId":"61321","inReplyTo":"9d5f2eff8ab2a9d7a994a2031a31d4fa6f4791d2.1713180749.git.ps@pks.im","subject":"Re: [PATCH 2/5] builtin: stop using `the_index`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-04-17T17:32:50Z","receivedAt":"2024-04-17T17:32:52Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"[snip]\n\n> diff --git a/builtin/cat-file.c b/builtin/cat-file.c\n> index 0c948f40fb..fe873807ed 100644\n> --- a/builtin/cat-file.c\n> +++ b/builtin/cat-file.c\n> @@ -3,7 +3,6 @@\n>   *\n>   * Copyright (C) Linus Torvalds, 2005\n>   */\n> -#define USE_THE_INDEX_VARIABLE\n\nNit: The other changes have a newline after the header.\n"},{"id":"493107","messageId":"CAOLa=ZQHGSvpzupNPTBQ=j8rd7txMWt9mbGQpQUSJTgr-pP5uA@mail.gmail.com","threadId":"61321","inReplyTo":"96256f9eb30e5aca632942169d5c311b1f245b40.1713180749.git.ps@pks.im","subject":"Re: [PATCH 3/5] repository: initialize index in `repo_init()`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-04-17T17:38:29Z","receivedAt":"2024-04-17T17:38:30Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> Refactor the code and create a common `initialize_repository()` function\n> that gets called from `repo_init()` and `initialize_the_repository()`.\n> This function sets up both the repository and the index as required.\n> Like this, we can easily special-case when `repo_init()` gets called\n> with `the_repository`.\n>\n\nNit: `initialize_the_repository()` calling `initialize_repository()`\ndoesn't really indicate what each of them does and why we have two\nfunctions which are similarly named but calling each other. Maybe we\nshould rename them?\n"},{"id":"493108","messageId":"CAOLa=ZQmCWh_UHJ+JWbzd_b=Ob=gUE=5wEKy3gpaxu=Bru+Wvg@mail.gmail.com","threadId":"61321","inReplyTo":"cover.1713180749.git.ps@pks.im","subject":"Re: [PATCH 0/5] global: drop external `the_index` variable","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-04-17T17:40:24Z","receivedAt":"2024-04-17T17:40:28Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Hello,\n\nPatrick Steinhardt <ps@pks.im> writes:\n\n> Hi,\n>\n> this patch series converts remaining users of `the_index` to stop using\n> it, instead using `the_repository->index`. This gets rid of one more\n> global variable and brings a project over the finish line that has\n> started back in 2007.\n>\n> I realize that this patch series is quite large, and that reviewers will\n> eventually start to just gloss over things because the conversions are\n> kind of boring, too. Also, due to the size it's quite likely to conflict\n> with in-flight topics. So if you think that this is too large, please\n> let me know and I will happily split this up into multiple series.\n\nI gave it a glance review. I also wanted to run the tests on each\ncommit, but couldn't apply the series cleanly on either master or next.\n"},{"id":"493119","messageId":"cover.1713442061.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713180749.git.ps@pks.im","subject":"[PATCH v2 0/6] global: drop `the_index` variable","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-18T12:14:04Z","receivedAt":"2024-04-18T12:14:10Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nthis is the second version of my patch series that aims to drop\n`the_index`.\n\nChanges compared to v1:\n\n  - This version goes a bit further now and completely drops the\n    static `the_index` variable, as well. The repository's index gets\n    allocated dynamically now, like all the other sub-structures like\n    the ODB.\n\n  - This also allows this series to remove `initialize_the_repository()`\n    now. Instead, callers call `initialize_repository()` now.\n\nThere is still quite an ugly hack in `initialize_repository()` which\nrequires us to treat `the_repository` specially. This is because\n`the_hash_algo` maps to `the_repository->hash_algo`, and we rely on it\nbeing initialized to SHA1. So we need call `repo_set_hash_algo()` on\n`the_repository`. On the other hand, we cannot set the hash algo on\nrepos which are not `the_repository`, because that breaks stuff, as\nwell.\n\nI'm currently prepping another patch series that builds on top of this\nseries and cleans up this mess. It surfaces several bugs that got masked\nby our setup, like for example `git rev-parse --short=` not working\ncorrectly with SHA256 because we always truncate to the maximum length\nof SHA1.\n\nPatrick\n\nPatrick Steinhardt (6):\n  t/helper: stop using `the_index`\n  builtin: stop using `the_index`\n  repository: initialize index in `repo_init()`\n  builtin/clone: stop using `the_index`\n  repository: drop `the_index` variable\n  repository: drop `initialize_the_repository()`\n\n builtin/add.c                        |  48 +++++------\n builtin/am.c                         |  36 ++++----\n builtin/cat-file.c                   |   4 +-\n builtin/check-attr.c                 |   5 +-\n builtin/check-ignore.c               |   7 +-\n builtin/checkout-index.c             |  22 ++---\n builtin/checkout.c                   |  87 ++++++++++---------\n builtin/clean.c                      |   7 +-\n builtin/clone.c                      |   7 +-\n builtin/commit.c                     |  81 +++++++++---------\n builtin/describe.c                   |   3 +-\n builtin/diff-tree.c                  |   3 +-\n builtin/diff.c                       |   6 +-\n builtin/difftool.c                   |   4 +-\n builtin/merge-index.c                |  17 ++--\n builtin/merge-tree.c                 |   3 +-\n builtin/merge.c                      |  31 ++++---\n builtin/mv.c                         |  68 +++++++--------\n builtin/pull.c                       |   4 +-\n builtin/read-tree.c                  |  15 ++--\n builtin/rebase.c                     |   3 +-\n builtin/replay.c                     |   1 -\n builtin/reset.c                      |  32 +++----\n builtin/rev-parse.c                  |   6 +-\n builtin/rm.c                         |  40 ++++-----\n builtin/stash.c                      |  45 +++++-----\n builtin/submodule--helper.c          |  21 +++--\n builtin/update-index.c               | 122 +++++++++++++--------------\n builtin/write-tree.c                 |   6 +-\n common-main.c                        |   2 +-\n oss-fuzz/fuzz-commit-graph.c         |   3 +-\n repository.c                         |  50 ++++++-----\n repository.h                         |   5 +-\n t/helper/test-cache-tree.c           |  17 ++--\n t/helper/test-dump-cache-tree.c      |   5 +-\n t/helper/test-dump-split-index.c     |  11 ++-\n t/helper/test-dump-untracked-cache.c |   3 +-\n t/helper/test-lazy-init-name-hash.c  |  39 +++++----\n t/helper/test-read-cache.c           |  11 ++-\n t/helper/test-scrap-cache-tree.c     |   7 +-\n t/helper/test-write-cache.c          |   3 +-\n 41 files changed, 435 insertions(+), 455 deletions(-)\n\nRange-diff against v1:\n1:  7b5ec04efc = 1:  1baacc1fd8 t/helper: stop using `the_index`\n2:  9d5f2eff8a ! 2:  371f69a2c9 builtin: stop using `the_index`\n    @@ builtin/cat-file.c\n       * Copyright (C) Linus Torvalds, 2005\n       */\n     -#define USE_THE_INDEX_VARIABLE\n    ++\n      #include \"builtin.h\"\n      #include \"config.h\"\n      #include \"convert.h\"\n    @@ builtin/commit.c: static const char *prepare_index(const char **argv, const char\n      \t\t} else\n      \t\t\twarning(_(\"Failed to update main cache tree\"));\n     @@ builtin/commit.c: static const char *prepare_index(const char **argv, const char *prefix,\n    - \t\tadd_files_to_cache(the_repository, also ? prefix : NULL,\n    - \t\t\t\t   &pathspec, 0, 0);\n    + \t\t\texit(128);\n    + \n      \t\trefresh_cache_or_die(refresh_flags);\n     -\t\tcache_tree_update(&the_index, WRITE_TREE_SILENT);\n     -\t\tif (write_locked_index(&the_index, &index_lock, 0))\n3:  96256f9eb3 = 3:  416612e7e3 repository: initialize index in `repo_init()`\n4:  881b6d2f7d = 4:  6fb1492018 builtin/clone: stop using `the_index`\n5:  80c36225bc < -:  ---------- repository: drop global `the_index` variable\n-:  ---------- > 5:  549f8c048f repository: drop `the_index` variable\n-:  ---------- > 6:  ed722b9b4b repository: drop `initialize_the_repository()`\n-- \n2.44.GIT\n\n"},{"id":"493120","messageId":"1baacc1fd8367b120d034f3832d47abd472f8153.1713442061.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713442061.git.ps@pks.im","subject":"[PATCH v2 1/6] t/helper: stop using `the_index`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-18T12:14:09Z","receivedAt":"2024-04-18T12:14:14Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Convert test-helper tools to use `the_repository->index` instead of\n`the_index`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n t/helper/test-cache-tree.c           | 17 ++++++------\n t/helper/test-dump-cache-tree.c      |  5 ++--\n t/helper/test-dump-split-index.c     | 11 ++++----\n t/helper/test-dump-untracked-cache.c |  3 +--\n t/helper/test-lazy-init-name-hash.c  | 39 ++++++++++++++--------------\n t/helper/test-read-cache.c           |  9 +++----\n t/helper/test-scrap-cache-tree.c     |  7 +++--\n t/helper/test-write-cache.c          |  3 +--\n 8 files changed, 43 insertions(+), 51 deletions(-)\n\ndiff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c\nindex e7236392c8..dc89ecfd71 100644\n--- a/t/helper/test-cache-tree.c\n+++ b/t/helper/test-cache-tree.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n@@ -38,29 +37,29 @@ int cmd__cache_tree(int argc, const char **argv)\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+\toidcpy(&oid, &the_repository->index->cache_tree->oid);\n \ttree = parse_tree_indirect(&oid);\n \tif (!tree)\n \t\tdie(_(\"not a tree object: %s\"), oid_to_hex(&oid));\n \n \tif (empty) {\n \t\t/* clear the cache tree & allocate a new one */\n-\t\tcache_tree_free(&the_index.cache_tree);\n-\t\tthe_index.cache_tree = cache_tree();\n+\t\tcache_tree_free(&the_repository->index->cache_tree);\n+\t\tthe_repository->index->cache_tree = cache_tree();\n \t} else if (invalidate_qty) {\n \t\t/* invalidate the specified number of unique paths */\n-\t\tfloat f_interval = (float)the_index.cache_nr / invalidate_qty;\n+\t\tfloat f_interval = (float)the_repository->index->cache_nr / invalidate_qty;\n \t\tint interval = f_interval < 1.0 ? 1 : (int)f_interval;\n-\t\tfor (i = 0; i < invalidate_qty && i * interval < the_index.cache_nr; i++)\n-\t\t\tcache_tree_invalidate_path(&the_index, the_index.cache[i * interval]->name);\n+\t\tfor (i = 0; i < invalidate_qty && i * interval < the_repository->index->cache_nr; i++)\n+\t\t\tcache_tree_invalidate_path(the_repository->index, the_repository->index->cache[i * interval]->name);\n \t}\n \n \tif (argc != 1)\n \t\tusage_with_options(test_cache_tree_usage, options);\n \telse if (!strcmp(argv[0], \"prime\"))\n-\t\tprime_cache_tree(the_repository, &the_index, tree);\n+\t\tprime_cache_tree(the_repository, the_repository->index, tree);\n \telse if (!strcmp(argv[0], \"update\"))\n-\t\tcache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n+\t\tcache_tree_update(the_repository->index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n \t/* use \"control\" subcommand to specify no-op */\n \telse if (!!strcmp(argv[0], \"control\"))\n \t\tdie(_(\"Unhandled subcommand '%s'\"), argv[0]);\ndiff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c\nindex c38f546e4f..02b0b46c3f 100644\n--- a/t/helper/test-dump-cache-tree.c\n+++ b/t/helper/test-dump-cache-tree.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"hash.h\"\n #include \"hex.h\"\n@@ -68,10 +67,10 @@ int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED)\n \tsetup_git_directory();\n \tif (repo_read_index(the_repository) < 0)\n \t\tdie(\"unable to read index file\");\n-\tistate = the_index;\n+\tistate = *the_repository->index;\n \tistate.cache_tree = another;\n \tcache_tree_update(&istate, WRITE_TREE_DRY_RUN);\n-\tret = dump_cache_tree(the_index.cache_tree, another, \"\");\n+\tret = dump_cache_tree(the_repository->index->cache_tree, another, \"\");\n \tcache_tree_free(&another);\n \n \treturn ret;\ndiff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c\nindex f29d18ef94..f472691a3c 100644\n--- a/t/helper/test-dump-split-index.c\n+++ b/t/helper/test-dump-split-index.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"hex.h\"\n #include \"read-cache-ll.h\"\n@@ -19,16 +18,16 @@ int cmd__dump_split_index(int ac UNUSED, const char **av)\n \n \tsetup_git_directory();\n \n-\tdo_read_index(&the_index, av[1], 1);\n-\tprintf(\"own %s\\n\", oid_to_hex(&the_index.oid));\n-\tsi = the_index.split_index;\n+\tdo_read_index(the_repository->index, av[1], 1);\n+\tprintf(\"own %s\\n\", oid_to_hex(&the_repository->index->oid));\n+\tsi = the_repository->index->split_index;\n \tif (!si) {\n \t\tprintf(\"not a split index\\n\");\n \t\treturn 0;\n \t}\n \tprintf(\"base %s\\n\", oid_to_hex(&si->base_oid));\n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tstruct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n \t\tprintf(\"%06o %s %d\\t%s\\n\", ce->ce_mode,\n \t\t       oid_to_hex(&ce->oid), ce_stage(ce), ce->name);\n \t}\ndiff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c\nindex b4af9712fe..9ff67c3967 100644\n--- a/t/helper/test-dump-untracked-cache.c\n+++ b/t/helper/test-dump-untracked-cache.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"dir.h\"\n #include \"hex.h\"\n@@ -56,7 +55,7 @@ int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED)\n \tsetup_git_directory();\n \tif (repo_read_index(the_repository) < 0)\n \t\tdie(\"unable to read index file\");\n-\tuc = the_index.untracked;\n+\tuc = the_repository->index->untracked;\n \tif (!uc) {\n \t\tprintf(\"no untracked cache\\n\");\n \t\treturn 0;\ndiff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c\nindex 187a115d57..5f33bb7b8f 100644\n--- a/t/helper/test-lazy-init-name-hash.c\n+++ b/t/helper/test-lazy-init-name-hash.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"environment.h\"\n #include \"name-hash.h\"\n@@ -40,22 +39,22 @@ static void dump_run(void)\n \n \trepo_read_index(the_repository);\n \tif (single) {\n-\t\ttest_lazy_init_name_hash(&the_index, 0);\n+\t\ttest_lazy_init_name_hash(the_repository->index, 0);\n \t} else {\n-\t\tint nr_threads_used = test_lazy_init_name_hash(&the_index, 1);\n+\t\tint nr_threads_used = test_lazy_init_name_hash(the_repository->index, 1);\n \t\tif (!nr_threads_used)\n \t\t\tdie(\"non-threaded code path used\");\n \t}\n \n-\thashmap_for_each_entry(&the_index.dir_hash, &iter_dir, dir,\n+\thashmap_for_each_entry(&the_repository->index->dir_hash, &iter_dir, dir,\n \t\t\t\tent /* member name */)\n \t\tprintf(\"dir %08x %7d %s\\n\", dir->ent.hash, dir->nr, dir->name);\n \n-\thashmap_for_each_entry(&the_index.name_hash, &iter_cache, ce,\n+\thashmap_for_each_entry(&the_repository->index->name_hash, &iter_cache, ce,\n \t\t\t\tent /* member name */)\n \t\tprintf(\"name %08x %s\\n\", ce->ent.hash, ce->name);\n \n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n }\n \n /*\n@@ -74,7 +73,7 @@ static uint64_t time_runs(int try_threaded)\n \t\tt0 = getnanotime();\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\tnr_threads_used = test_lazy_init_name_hash(the_repository->index, try_threaded);\n \t\tt2 = getnanotime();\n \n \t\tsum += (t2 - t1);\n@@ -86,16 +85,16 @@ static uint64_t time_runs(int try_threaded)\n \t\t\tprintf(\"%f %f %d multi %d\\n\",\n \t\t\t\t   ((double)(t1 - t0))/1000000000,\n \t\t\t\t   ((double)(t2 - t1))/1000000000,\n-\t\t\t\t   the_index.cache_nr,\n+\t\t\t\t   the_repository->index->cache_nr,\n \t\t\t\t   nr_threads_used);\n \t\telse\n \t\t\tprintf(\"%f %f %d single\\n\",\n \t\t\t\t   ((double)(t1 - t0))/1000000000,\n \t\t\t\t   ((double)(t2 - t1))/1000000000,\n-\t\t\t\t   the_index.cache_nr);\n+\t\t\t\t   the_repository->index->cache_nr);\n \t\tfflush(stdout);\n \n-\t\tdiscard_index(&the_index);\n+\t\tdiscard_index(the_repository->index);\n \t}\n \n \tavg = sum / count;\n@@ -120,8 +119,8 @@ static void analyze_run(void)\n \tint nr;\n \n \trepo_read_index(the_repository);\n-\tcache_nr_limit = the_index.cache_nr;\n-\tdiscard_index(&the_index);\n+\tcache_nr_limit = the_repository->index->cache_nr;\n+\tdiscard_index(the_repository->index);\n \n \tnr = analyze;\n \twhile (1) {\n@@ -135,22 +134,22 @@ static void analyze_run(void)\n \n \t\tfor (i = 0; i < count; i++) {\n \t\t\trepo_read_index(the_repository);\n-\t\t\tthe_index.cache_nr = nr; /* cheap truncate of index */\n+\t\t\tthe_repository->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\ttest_lazy_init_name_hash(the_repository->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_index(&the_index);\n+\t\t\tthe_repository->index->cache_nr = cache_nr_limit;\n+\t\t\tdiscard_index(the_repository->index);\n \n \t\t\trepo_read_index(the_repository);\n-\t\t\tthe_index.cache_nr = nr; /* cheap truncate of index */\n+\t\t\tthe_repository->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\tnr_threads_used = test_lazy_init_name_hash(the_repository->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_index(&the_index);\n+\t\t\tthe_repository->index->cache_nr = cache_nr_limit;\n+\t\t\tdiscard_index(the_repository->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 1acd362346..458efa88a6 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"config.h\"\n #include \"read-cache-ll.h\"\n@@ -27,16 +26,16 @@ int cmd__read_cache(int argc, const char **argv)\n \t\tif (name) {\n \t\t\tint pos;\n \n-\t\t\trefresh_index(&the_index, REFRESH_QUIET,\n+\t\t\trefresh_index(the_repository->index, REFRESH_QUIET,\n \t\t\t\t      NULL, NULL, NULL);\n-\t\t\tpos = index_name_pos(&the_index, name, strlen(name));\n+\t\t\tpos = index_name_pos(the_repository->index, name, strlen(name));\n \t\t\tif (pos < 0)\n \t\t\t\tdie(\"%s not in index\", name);\n \t\t\tprintf(\"%s is%s up to date\\n\", name,\n-\t\t\t       ce_uptodate(the_index.cache[pos]) ? \"\" : \" not\");\n+\t\t\t       ce_uptodate(the_repository->index->cache[pos]) ? \"\" : \" not\");\n \t\t\twrite_file(name, \"%d\\n\", i);\n \t\t}\n-\t\tdiscard_index(&the_index);\n+\t\tdiscard_index(the_repository->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 0a816a96e2..737cbe475b 100644\n--- a/t/helper/test-scrap-cache-tree.c\n+++ b/t/helper/test-scrap-cache-tree.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"lockfile.h\"\n #include \"read-cache-ll.h\"\n@@ -15,9 +14,9 @@ int cmd__scrap_cache_tree(int ac UNUSED, const char **av UNUSED)\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;\n-\tif (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))\n+\tcache_tree_free(&the_repository->index->cache_tree);\n+\tthe_repository->index->cache_tree = NULL;\n+\tif (write_locked_index(the_repository->index, &index_lock, COMMIT_LOCK))\n \t\tdie(\"unable to write index file\");\n \treturn 0;\n }\ndiff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c\nindex f084034d38..7e3da380a9 100644\n--- a/t/helper/test-write-cache.c\n+++ b/t/helper/test-write-cache.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"test-tool.h\"\n #include \"lockfile.h\"\n #include \"read-cache-ll.h\"\n@@ -16,7 +15,7 @@ int cmd__write_cache(int argc, const char **argv)\n \tfor (i = 0; i < cnt; i++) {\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\tif (write_locked_index(the_repository->index, &index_lock, COMMIT_LOCK))\n \t\t\tdie(\"unable to write index file\");\n \t}\n \n-- \n2.44.GIT\n\n"},{"id":"493121","messageId":"371f69a2c9023d72aab11d1b573b8fc6864df193.1713442061.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713442061.git.ps@pks.im","subject":"[PATCH v2 2/6] builtin: stop using `the_index`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-18T12:14:14Z","receivedAt":"2024-04-18T12:14:18Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Convert builtins to use `the_repository->index` instead of `the_index`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/add.c               |  48 +++++++-------\n builtin/am.c                |  36 +++++------\n builtin/cat-file.c          |   4 +-\n builtin/check-attr.c        |   5 +-\n builtin/check-ignore.c      |   7 +--\n builtin/checkout-index.c    |  22 +++----\n builtin/checkout.c          |  87 +++++++++++++------------\n builtin/clean.c             |   7 +--\n builtin/commit.c            |  81 ++++++++++++------------\n builtin/describe.c          |   3 +-\n builtin/diff-tree.c         |   3 +-\n builtin/diff.c              |   6 +-\n builtin/difftool.c          |   4 +-\n builtin/merge-index.c       |  17 +++--\n builtin/merge-tree.c        |   3 +-\n builtin/merge.c             |  31 +++++----\n builtin/mv.c                |  68 ++++++++++----------\n builtin/pull.c              |   4 +-\n builtin/read-tree.c         |  15 +++--\n builtin/rebase.c            |   3 +-\n builtin/replay.c            |   1 -\n builtin/reset.c             |  32 +++++-----\n builtin/rev-parse.c         |   6 +-\n builtin/rm.c                |  40 ++++++------\n builtin/stash.c             |  45 +++++++------\n builtin/submodule--helper.c |  21 +++----\n builtin/update-index.c      | 122 ++++++++++++++++++------------------\n builtin/write-tree.c        |   6 +-\n 28 files changed, 356 insertions(+), 371 deletions(-)\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex ae723bc85e..7689d8e7c5 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -40,20 +40,20 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)\n {\n \tint i, ret = 0;\n \n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tstruct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n \t\tint err;\n \n \t\tif (!include_sparse &&\n \t\t    (ce_skip_worktree(ce) ||\n-\t\t     !path_in_sparse_checkout(ce->name, &the_index)))\n+\t\t     !path_in_sparse_checkout(ce->name, the_repository->index)))\n \t\t\tcontinue;\n \n-\t\tif (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))\n+\t\tif (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))\n \t\t\tcontinue;\n \n \t\tif (!show_only)\n-\t\t\terr = chmod_index_entry(&the_index, ce, flip);\n+\t\t\terr = chmod_index_entry(the_repository->index, ce, flip);\n \t\telse\n \t\t\terr = S_ISREG(ce->ce_mode) ? 0 : -1;\n \n@@ -68,20 +68,20 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)\n {\n \tint i, retval = 0;\n \n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tstruct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n \n \t\tif (!include_sparse &&\n \t\t    (ce_skip_worktree(ce) ||\n-\t\t     !path_in_sparse_checkout(ce->name, &the_index)))\n+\t\t     !path_in_sparse_checkout(ce->name, the_repository->index)))\n \t\t\tcontinue;\n \t\tif (ce_stage(ce))\n \t\t\tcontinue; /* do not touch unmerged paths */\n \t\tif (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))\n \t\t\tcontinue; /* do not touch non blobs */\n-\t\tif (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))\n+\t\tif (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))\n \t\t\tcontinue;\n-\t\tretval |= add_file_to_index(&the_index, ce->name,\n+\t\tretval |= add_file_to_index(the_repository->index, ce->name,\n \t\t\t\t\t    flags | ADD_CACHE_RENORMALIZE);\n \t}\n \n@@ -100,11 +100,11 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,\n \ti = dir->nr;\n \twhile (--i >= 0) {\n \t\tstruct dir_entry *entry = *src++;\n-\t\tif (dir_path_match(&the_index, entry, pathspec, prefix, seen))\n+\t\tif (dir_path_match(the_repository->index, entry, pathspec, prefix, seen))\n \t\t\t*dst++ = entry;\n \t}\n \tdir->nr = dst - dir->entries;\n-\tadd_pathspec_matches_against_index(pathspec, &the_index, seen,\n+\tadd_pathspec_matches_against_index(pathspec, the_repository->index, seen,\n \t\t\t\t\t   PS_IGNORE_SKIP_WORKTREE);\n \treturn seen;\n }\n@@ -119,14 +119,14 @@ static int refresh(int verbose, const struct pathspec *pathspec)\n \t\t    (verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);\n \n \tseen = xcalloc(pathspec->nr, 1);\n-\trefresh_index(&the_index, flags, pathspec, seen,\n+\trefresh_index(the_repository->index, flags, pathspec, seen,\n \t\t      _(\"Unstaged changes after refreshing the index:\"));\n \tfor (i = 0; i < pathspec->nr; i++) {\n \t\tif (!seen[i]) {\n \t\t\tconst char *path = pathspec->items[i].original;\n \n \t\t\tif (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||\n-\t\t\t    !path_in_sparse_checkout(path, &the_index)) {\n+\t\t\t    !path_in_sparse_checkout(path, the_repository->index)) {\n \t\t\t\tstring_list_append(&only_match_skip_worktree,\n \t\t\t\t\t\t   pathspec->items[i].original);\n \t\t\t} else {\n@@ -335,12 +335,12 @@ static int add_files(struct dir_struct *dir, int flags)\n \n \tfor (i = 0; i < dir->nr; i++) {\n \t\tif (!include_sparse &&\n-\t\t    !path_in_sparse_checkout(dir->entries[i]->name, &the_index)) {\n+\t\t    !path_in_sparse_checkout(dir->entries[i]->name, the_repository->index)) {\n \t\t\tstring_list_append(&matched_sparse_paths,\n \t\t\t\t\t   dir->entries[i]->name);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (add_file_to_index(&the_index, dir->entries[i]->name, flags)) {\n+\t\tif (add_file_to_index(the_repository->index, dir->entries[i]->name, flags)) {\n \t\t\tif (!ignore_add_errors)\n \t\t\t\tdie(_(\"adding files failed\"));\n \t\t\texit_status = 1;\n@@ -458,8 +458,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)\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);\n-\tdie_path_inside_submodule(&the_index, &pathspec);\n+\tdie_in_unpopulated_submodule(the_repository->index, prefix);\n+\tdie_path_inside_submodule(the_repository->index, &pathspec);\n \n \tif (add_new_files) {\n \t\tint baselen;\n@@ -471,7 +471,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t\t}\n \n \t\t/* This picks up the paths that are not tracked */\n-\t\tbaselen = fill_directory(&dir, &the_index, &pathspec);\n+\t\tbaselen = fill_directory(&dir, the_repository->index, &pathspec);\n \t\tif (pathspec.nr)\n \t\t\tseen = prune_directory(&dir, &pathspec, baselen);\n \t}\n@@ -488,7 +488,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \n \t\tif (!seen)\n \t\t\tseen = find_pathspecs_matching_against_index(&pathspec,\n-\t\t\t\t\t&the_index, PS_IGNORE_SKIP_WORKTREE);\n+\t\t\t\t\tthe_repository->index, PS_IGNORE_SKIP_WORKTREE);\n \n \t\t/*\n \t\t * file_exists() assumes exact match\n@@ -524,8 +524,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t\t\t    !file_exists(path)) {\n \t\t\t\tif (ignore_missing) {\n \t\t\t\t\tint dtype = DT_UNKNOWN;\n-\t\t\t\t\tif (is_excluded(&dir, &the_index, path, &dtype))\n-\t\t\t\t\t\tdir_add_ignored(&dir, &the_index,\n+\t\t\t\t\tif (is_excluded(&dir, the_repository->index, path, &dtype))\n+\t\t\t\t\t\tdir_add_ignored(&dir, the_repository->index,\n \t\t\t\t\t\t\t\tpath, pathspec.items[i].len);\n \t\t\t\t} else\n \t\t\t\t\tdie(_(\"pathspec '%s' did not match any files\"),\n@@ -566,7 +566,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \tend_odb_transaction();\n \n finish:\n-\tif (write_locked_index(&the_index, &lock_file,\n+\tif (write_locked_index(the_repository->index, &lock_file,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\tdie(_(\"unable to write new index file\"));\n \ndiff --git a/builtin/am.c b/builtin/am.c\nindex 022cae2e8d..4db2bc3c2f 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -3,7 +3,7 @@\n  *\n  * Based on git-am.sh by Junio C Hamano.\n  */\n-#define USE_THE_INDEX_VARIABLE\n+\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n@@ -1536,8 +1536,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_index(&the_index);\n-\t\tread_index_from(&the_index, index_file, get_git_dir());\n+\t\tdiscard_index(the_repository->index);\n+\t\tread_index_from(the_repository->index, index_file, get_git_dir());\n \t}\n \n \treturn 0;\n@@ -1579,10 +1579,10 @@ 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_index(&the_index);\n-\tread_index_from(&the_index, index_path, get_git_dir());\n+\tdiscard_index(the_repository->index);\n+\tread_index_from(the_repository->index, index_path, get_git_dir());\n \n-\tif (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))\n+\tif (write_index_as_tree(&orig_tree, the_repository->index, index_path, 0, NULL))\n \t\treturn error(_(\"Repository lacks necessary blobs to fall back on 3-way merge.\"));\n \n \tsay(state, stdout, _(\"Using index info to reconstruct a base tree...\"));\n@@ -1608,12 +1608,12 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \t\treturn error(_(\"Did you hand edit your patch?\\n\"\n \t\t\t\t\"It does not apply to blobs recorded in its index.\"));\n \n-\tif (write_index_as_tree(&their_tree, &the_index, index_path, 0, NULL))\n+\tif (write_index_as_tree(&their_tree, the_repository->index, index_path, 0, NULL))\n \t\treturn error(\"could not write tree\");\n \n \tsay(state, stdout, _(\"Falling back to patching base and 3-way merge...\"));\n \n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \trepo_read_index(the_repository);\n \n \t/*\n@@ -1660,7 +1660,7 @@ static void do_commit(const struct am_state *state)\n \tif (!state->no_verify && run_hooks(\"pre-applypatch\"))\n \t\texit(1);\n \n-\tif (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL))\n+\tif (write_index_as_tree(&tree, the_repository->index, get_index_file(), 0, NULL))\n \t\tdie(_(\"git write-tree failed to write a tree\"));\n \n \tif (!repo_get_oid_commit(the_repository, \"HEAD\", &parent)) {\n@@ -1948,7 +1948,7 @@ static void am_resolve(struct am_state *state, int allow_empty)\n \t\t}\n \t}\n \n-\tif (unmerged_index(&the_index)) {\n+\tif (unmerged_index(the_repository->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@@ -1987,12 +1987,12 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)\n \n \trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \n-\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n+\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \topts.update = 1;\n \topts.merge = 1;\n \topts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;\n@@ -2006,7 +2006,7 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)\n \t\treturn -1;\n \t}\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write new index file\"));\n \n \treturn 0;\n@@ -2029,8 +2029,8 @@ static int merge_tree(struct tree *tree)\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \topts.merge = 1;\n \topts.fn = oneway_merge;\n \tinit_tree_desc(&t[0], &tree->object.oid, tree->buffer, tree->size);\n@@ -2040,7 +2040,7 @@ static int merge_tree(struct tree *tree)\n \t\treturn -1;\n \t}\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write new index file\"));\n \n \treturn 0;\n@@ -2068,7 +2068,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem\n \tif (fast_forward_to(head_tree, head_tree, 1))\n \t\treturn -1;\n \n-\tif (write_index_as_tree(&index, &the_index, get_index_file(), 0, NULL))\n+\tif (write_index_as_tree(&index, the_repository->index, get_index_file(), 0, NULL))\n \t\treturn -1;\n \n \tindex_tree = parse_tree_indirect(&index);\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 0c948f40fb..43a1d7ac49 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"convert.h\"\n@@ -77,7 +77,7 @@ static int filter_object(const char *path, unsigned mode,\n \t\tstruct checkout_metadata meta;\n \n \t\tinit_checkout_metadata(&meta, NULL, NULL, oid);\n-\t\tif (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf, &meta)) {\n+\t\tif (convert_to_working_tree(the_repository->index, path, *buf, *size, &strbuf, &meta)) {\n \t\t\tfree(*buf);\n \t\t\t*size = strbuf.len;\n \t\t\t*buf = strbuf_detach(&strbuf, NULL);\ndiff --git a/builtin/check-attr.c b/builtin/check-attr.c\nindex c1da1d184e..9376810710 100644\n--- a/builtin/check-attr.c\n+++ b/builtin/check-attr.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"attr.h\"\n@@ -71,9 +70,9 @@ static void check_attr(const char *prefix, struct attr_check *check,\n \t\tprefix_path(prefix, prefix ? strlen(prefix) : 0, file);\n \n \tif (collect_all) {\n-\t\tgit_all_attrs(&the_index, full_path, check);\n+\t\tgit_all_attrs(the_repository->index, full_path, check);\n \t} else {\n-\t\tgit_check_attr(&the_index, full_path, check);\n+\t\tgit_check_attr(the_repository->index, full_path, check);\n \t}\n \toutput_attr(check, file);\n \ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex 906cd96753..6c43430ec4 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"dir.h\"\n@@ -95,21 +94,21 @@ static int check_ignore(struct dir_struct *dir,\n \t\t       PATHSPEC_KEEP_ORDER,\n \t\t       prefix, argv);\n \n-\tdie_path_inside_submodule(&the_index, &pathspec);\n+\tdie_path_inside_submodule(the_repository->index, &pathspec);\n \n \t/*\n \t * look for pathspecs matching entries in the index, since these\n \t * should not be ignored, in order to be consistent with\n \t * 'git status', 'git add' etc.\n \t */\n-\tseen = find_pathspecs_matching_against_index(&pathspec, &the_index,\n+\tseen = find_pathspecs_matching_against_index(&pathspec, the_repository->index,\n \t\t\t\t\t\t     PS_HEED_SKIP_WORKTREE);\n \tfor (i = 0; i < pathspec.nr; i++) {\n \t\tfull_path = pathspec.items[i].match;\n \t\tpattern = NULL;\n \t\tif (!seen[i]) {\n \t\t\tint dtype = DT_UNKNOWN;\n-\t\t\tpattern = last_matching_pattern(dir, &the_index,\n+\t\t\tpattern = last_matching_pattern(dir, the_repository->index,\n \t\t\t\t\t\t\tfull_path, &dtype);\n \t\t\tif (!verbose && pattern &&\n \t\t\t    pattern->flags & PATTERN_FLAG_NEGATIVE)\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex 2e086a204d..29e744d11b 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -69,7 +69,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 = index_name_pos(&the_index, name, namelen);\n+\tint pos = index_name_pos(the_repository->index, name, namelen);\n \tint has_same_name = 0;\n \tint is_file = 0;\n \tint is_skipped = 1;\n@@ -79,8 +79,8 @@ static int checkout_file(const char *name, const char *prefix)\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n \n-\twhile (pos < the_index.cache_nr) {\n-\t\tstruct cache_entry *ce = the_index.cache[pos];\n+\twhile (pos <the_repository->index->cache_nr) {\n+\t\tstruct cache_entry *ce =the_repository->index->cache[pos];\n \t\tif (ce_namelen(ce) != namelen ||\n \t\t    memcmp(ce->name, name, namelen))\n \t\t\tbreak;\n@@ -140,8 +140,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 < the_index.cache_nr ; i++) {\n-\t\tstruct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr ; i++) {\n+\t\tstruct cache_entry *ce = the_repository->index->cache[i];\n \n \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n \t\t\tif (!ce_skip_worktree(ce))\n@@ -154,8 +154,8 @@ static int checkout_all(const char *prefix, int prefix_length)\n \t\t\t * first entry inside the expanded sparse directory).\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 = the_index.cache[i];\n+\t\t\t\tensure_full_index(the_repository->index);\n+\t\t\t\tce = the_repository->index->cache[i];\n \t\t\t}\n \t\t}\n \n@@ -260,7 +260,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \n \targc = parse_options(argc, argv, prefix, builtin_checkout_index_options,\n \t\t\tbuiltin_checkout_index_usage, 0);\n-\tstate.istate = &the_index;\n+\tstate.istate = the_repository->index;\n \tstate.force = force;\n \tstate.quiet = quiet;\n \tstate.not_new = not_new;\n@@ -280,7 +280,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \t */\n \tif (index_opt && !state.base_dir_len && !to_tempfile) {\n \t\tstate.refresh_cache = 1;\n-\t\tstate.istate = &the_index;\n+\t\tstate.istate = the_repository->index;\n \t\trepo_hold_locked_index(the_repository, &lock_file,\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n \t}\n@@ -339,7 +339,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \t\treturn 1;\n \n \tif (is_lock_file_locked(&lock_file) &&\n-\t    write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\t    write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(\"Unable to write new index file\");\n \treturn 0;\n }\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 71e6036aab..8a1d13b399 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"branch.h\"\n@@ -146,7 +145,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \t\treturn READ_TREE_RECURSIVE;\n \n \tlen = base->len + strlen(pathname);\n-\tce = make_empty_cache_entry(&the_index, len);\n+\tce = make_empty_cache_entry(the_repository->index, len);\n \toidcpy(&ce->oid, oid);\n \tmemcpy(ce->name, base->buf, base->len);\n \tmemcpy(ce->name + base->len, pathname, len - base->len);\n@@ -159,9 +158,9 @@ 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 = index_name_pos(&the_index, ce->name, ce->ce_namelen);\n+\tpos = index_name_pos(the_repository->index, ce->name, ce->ce_namelen);\n \tif (pos >= 0) {\n-\t\tstruct cache_entry *old = the_index.cache[pos];\n+\t\tstruct cache_entry *old = the_repository->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@@ -171,7 +170,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \t\t}\n \t}\n \n-\tadd_index_entry(&the_index, ce,\n+\tadd_index_entry(the_repository->index, ce,\n \t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \treturn 0;\n }\n@@ -190,8 +189,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 < the_index.cache_nr &&\n-\t       !strcmp(the_index.cache[pos]->name, ce->name))\n+\twhile (++pos < the_repository->index->cache_nr &&\n+\t       !strcmp(the_repository->index->cache[pos]->name, ce->name))\n \t\t; /* skip */\n \treturn pos;\n }\n@@ -199,9 +198,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 < 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+\twhile (pos < the_repository->index->cache_nr &&\n+\t       !strcmp(the_repository->index->cache[pos]->name, ce->name)) {\n+\t\tif (ce_stage(the_repository->index->cache[pos]) == stage)\n \t\t\treturn 0;\n \t\tpos++;\n \t}\n@@ -218,8 +217,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 < the_index.cache_nr) {\n-\t\tce = the_index.cache[pos];\n+\twhile (pos < the_repository->index->cache_nr) {\n+\t\tce = the_repository->index->cache[pos];\n \t\tif (strcmp(name, ce->name))\n \t\t\tbreak;\n \t\tseen |= (1 << ce_stage(ce));\n@@ -235,10 +234,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 < 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+\twhile (pos < the_repository->index->cache_nr &&\n+\t       !strcmp(the_repository->index->cache[pos]->name, ce->name)) {\n+\t\tif (ce_stage(the_repository->index->cache[pos]) == stage)\n+\t\t\treturn checkout_entry(the_repository->index->cache[pos], state,\n \t\t\t\t\t      NULL, nr_checkouts);\n \t\tpos++;\n \t}\n@@ -256,7 +255,7 @@ static int checkout_merged(int pos, const struct checkout *state,\n \t\t\t   int *nr_checkouts, struct mem_pool *ce_mem_pool,\n \t\t\t   int conflict_style)\n {\n-\tstruct cache_entry *ce = the_index.cache[pos];\n+\tstruct cache_entry *ce = the_repository->index->cache[pos];\n \tconst char *path = ce->name;\n \tmmfile_t ancestor, ours, theirs;\n \tenum ll_merge_result merge_status;\n@@ -269,7 +268,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 < the_index.cache_nr) {\n+\twhile (pos < the_repository->index->cache_nr) {\n \t\tint stage;\n \t\tstage = ce_stage(ce);\n \t\tif (!stage || strcmp(path, ce->name))\n@@ -278,7 +277,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 = the_index.cache[pos];\n+\t\tce = the_repository->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@@ -356,7 +355,7 @@ static void mark_ce_for_checkout_overlay(struct cache_entry *ce,\n \t * match_pathspec() for _all_ entries when\n \t * opts->source_tree != NULL.\n \t */\n-\tif (ce_path_match(&the_index, ce, &opts->pathspec, ps_matched))\n+\tif (ce_path_match(the_repository->index, ce, &opts->pathspec, ps_matched))\n \t\tce->ce_flags |= CE_MATCHED;\n }\n \n@@ -367,7 +366,7 @@ static void mark_ce_for_checkout_no_overlay(struct cache_entry *ce,\n \tce->ce_flags &= ~CE_MATCHED;\n \tif (!opts->ignore_skipworktree && ce_skip_worktree(ce))\n \t\treturn;\n-\tif (ce_path_match(&the_index, ce, &opts->pathspec, ps_matched)) {\n+\tif (ce_path_match(the_repository->index, ce, &opts->pathspec, ps_matched)) {\n \t\tce->ce_flags |= CE_MATCHED;\n \t\tif (opts->source_tree && !(ce->ce_flags & CE_UPDATE))\n \t\t\t/*\n@@ -391,7 +390,7 @@ static int checkout_worktree(const struct checkout_opts *opts,\n \n \tstate.force = 1;\n \tstate.refresh_cache = 1;\n-\tstate.istate = &the_index;\n+\tstate.istate = the_repository->index;\n \n \tmem_pool_init(&ce_mem_pool, 0);\n \tget_parallel_checkout_configs(&pc_workers, &pc_threshold);\n@@ -404,8 +403,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 < the_index.cache_nr; pos++) {\n-\t\tstruct cache_entry *ce = the_index.cache[pos];\n+\tfor (pos = 0; pos < the_repository->index->cache_nr; pos++) {\n+\t\tstruct cache_entry *ce = the_repository->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@@ -429,7 +428,7 @@ static int checkout_worktree(const struct checkout_opts *opts,\n \t\terrs |= run_parallel_checkout(&state, pc_workers, pc_threshold,\n \t\t\t\t\t      NULL, NULL);\n \tmem_pool_discard(&ce_mem_pool, should_validate_cache_entries());\n-\tremove_marked_cache_entries(&the_index, 1);\n+\tremove_marked_cache_entries(the_repository->index, 1);\n \tremove_scheduled_dirs();\n \terrs |= finish_delayed_checkout(&state, opts->show_progress);\n \n@@ -571,7 +570,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \tif (opts->source_tree)\n \t\tread_tree_some(opts->source_tree, &opts->pathspec);\n \tif (opts->merge)\n-\t\tunmerge_index(&the_index, &opts->pathspec, CE_MATCHED);\n+\t\tunmerge_index(the_repository->index, &opts->pathspec, CE_MATCHED);\n \n \tps_matched = xcalloc(opts->pathspec.nr, 1);\n \n@@ -579,13 +578,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 < the_index.cache_nr; pos++)\n+\tfor (pos = 0; pos < the_repository->index->cache_nr; pos++)\n \t\tif (opts->overlay_mode)\n-\t\t\tmark_ce_for_checkout_overlay(the_index.cache[pos],\n+\t\t\tmark_ce_for_checkout_overlay(the_repository->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(the_index.cache[pos],\n+\t\t\tmark_ce_for_checkout_no_overlay(the_repository->index->cache[pos],\n \t\t\t\t\t\t\tps_matched,\n \t\t\t\t\t\t\topts);\n \n@@ -596,8 +595,8 @@ static int checkout_paths(const struct checkout_opts *opts,\n \tfree(ps_matched);\n \n \t/* Any unmerged paths? */\n-\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n-\t\tconst struct cache_entry *ce = the_index.cache[pos];\n+\tfor (pos = 0; pos < the_repository->index->cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[pos];\n \t\tif (ce->ce_flags & CE_MATCHED) {\n \t\t\tif (!ce_stage(ce))\n \t\t\t\tcontinue;\n@@ -622,7 +621,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \tif (opts->checkout_worktree)\n \t\terrs |= checkout_worktree(opts, new_branch_info);\n \telse\n-\t\tremove_marked_cache_entries(&the_index, 1);\n+\t\tremove_marked_cache_entries(the_repository->index, 1);\n \n \t/*\n \t * Allow updating the index when checking out from the index.\n@@ -634,7 +633,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t\tcheckout_index = opts->checkout_index;\n \n \tif (checkout_index) {\n-\t\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\t\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\t\tdie(_(\"unable to write new index file\"));\n \t} else {\n \t\t/*\n@@ -703,8 +702,8 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,\n \topts.merge = 1;\n \topts.fn = oneway_merge;\n \topts.verbose_update = o->show_progress;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \tinit_checkout_metadata(&opts.meta, info->refname,\n \t\t\t       info->commit ? &info->commit->object.oid : null_oid(),\n \t\t\t       NULL);\n@@ -756,12 +755,12 @@ static void init_topts(struct unpack_trees_options *topts, int merge,\n {\n \tmemset(topts, 0, sizeof(*topts));\n \ttopts->head_idx = -1;\n-\ttopts->src_index = &the_index;\n-\ttopts->dst_index = &the_index;\n+\ttopts->src_index = the_repository->index;\n+\ttopts->dst_index = the_repository->index;\n \n \tsetup_unpack_trees_porcelain(topts, \"checkout\");\n \n-\ttopts->initial_checkout = is_index_unborn(&the_index);\n+\ttopts->initial_checkout = is_index_unborn(the_repository->index);\n \ttopts->update = 1;\n \ttopts->merge = 1;\n \ttopts->quiet = merge && old_commit;\n@@ -783,7 +782,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\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+\tresolve_undo_clear_index(the_repository->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\");\n@@ -807,9 +806,9 @@ 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_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n+\t\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);\n \n-\t\tif (unmerged_index(&the_index)) {\n+\t\tif (unmerged_index(the_repository->index)) {\n \t\t\terror(_(\"you need to resolve your current index first\"));\n \t\t\treturn 1;\n \t\t}\n@@ -919,10 +918,10 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \t\t}\n \t}\n \n-\tif (!cache_tree_fully_valid(the_index.cache_tree))\n-\t\tcache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n+\tif (!cache_tree_fully_valid(the_repository->index->cache_tree))\n+\t\tcache_tree_update(the_repository->index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write new index file\"));\n \n \tif (!opts->discard_changes && !opts->quiet && new_branch_info->commit)\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex 29efe84153..ded5a91534 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -6,7 +6,6 @@\n  * Based on git-clean.sh by Pavel Roskin\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -714,7 +713,7 @@ static int filter_by_patterns_cmd(void)\n \t\tfor_each_string_list_item(item, &del_list) {\n \t\t\tint dtype = DT_UNKNOWN;\n \n-\t\t\tif (is_excluded(&dir, &the_index, item->string, &dtype)) {\n+\t\t\tif (is_excluded(&dir, the_repository->index, item->string, &dtype)) {\n \t\t\t\t*item->string = '\\0';\n \t\t\t\tchanged++;\n \t\t\t}\n@@ -1021,7 +1020,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \t\t       PATHSPEC_PREFER_CWD,\n \t\t       prefix, argv);\n \n-\tfill_directory(&dir, &the_index, &pathspec);\n+\tfill_directory(&dir, the_repository->index, &pathspec);\n \tcorrect_untracked_entries(&dir);\n \n \tfor (i = 0; i < dir.nr; i++) {\n@@ -1029,7 +1028,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 (!index_name_is_other(&the_index, ent->name, ent->len))\n+\t\tif (!index_name_is_other(the_repository->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 6e1484446b..c2943055ef 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -5,7 +5,6 @@\n  * Based on git-commit.sh by Junio C Hamano and Linus Torvalds\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -266,19 +265,19 @@ static int list_paths(struct string_list *list, const char *with_tree,\n \n \tif (with_tree) {\n \t\tchar *max_prefix = common_prefix(pattern);\n-\t\toverlay_tree_on_index(&the_index, with_tree, max_prefix);\n+\t\toverlay_tree_on_index(the_repository->index, with_tree, max_prefix);\n \t\tfree(max_prefix);\n \t}\n \n \t/* TODO: audit for interaction with sparse-index. */\n-\tensure_full_index(&the_index);\n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tconst struct cache_entry *ce = the_index.cache[i];\n+\tensure_full_index(the_repository->index);\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[i];\n \t\tstruct string_list_item *item;\n \n \t\tif (ce->ce_flags & CE_UPDATE)\n \t\t\tcontinue;\n-\t\tif (!ce_path_match(&the_index, ce, pattern, m))\n+\t\tif (!ce_path_match(the_repository->index, ce, pattern, m))\n \t\t\tcontinue;\n \t\titem = string_list_insert(list, ce->name);\n \t\tif (ce_skip_worktree(ce))\n@@ -302,10 +301,10 @@ 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_index(&the_index, p->string, &st, 0))\n+\t\t\tif (add_to_index(the_repository->index, p->string, &st, 0))\n \t\t\t\tdie(_(\"updating files failed\"));\n \t\t} else\n-\t\t\tremove_file_from_index(&the_index, p->string);\n+\t\t\tremove_file_from_index(the_repository->index, p->string);\n \t}\n }\n \n@@ -316,7 +315,7 @@ static void create_base_index(const struct commit *current_head)\n \tstruct tree_desc t;\n \n \tif (!current_head) {\n-\t\tdiscard_index(&the_index);\n+\t\tdiscard_index(the_repository->index);\n \t\treturn;\n \t}\n \n@@ -324,8 +323,8 @@ static void create_base_index(const struct commit *current_head)\n \topts.head_idx = 1;\n \topts.index_only = 1;\n \topts.merge = 1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \n \topts.fn = oneway_merge;\n \ttree = parse_tree_indirect(&current_head->object.oid);\n@@ -344,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_index(&the_index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))\n+\tif (refresh_index(the_repository->index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))\n \t\tdie_resolve_conflict(\"commit\");\n }\n \n@@ -393,7 +392,7 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \n \t\trefresh_cache_or_die(refresh_flags);\n \n-\t\tif (write_locked_index(&the_index, &index_lock, 0))\n+\t\tif (write_locked_index(the_repository->index, &index_lock, 0))\n \t\t\tdie(_(\"unable to create temporary index\"));\n \n \t\told_repo_index_file = the_repository->index_file;\n@@ -412,13 +411,13 @@ 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_index(&the_index);\n-\t\tread_index_from(&the_index, get_lock_file_path(&index_lock),\n+\t\tdiscard_index(the_repository->index);\n+\t\tread_index_from(the_repository->index, get_lock_file_path(&index_lock),\n \t\t\t\tget_git_dir());\n-\t\tif (cache_tree_update(&the_index, WRITE_TREE_SILENT) == 0) {\n+\t\tif (cache_tree_update(the_repository->index, 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-\t\t\tif (write_locked_index(&the_index, &index_lock, 0))\n+\t\t\tif (write_locked_index(the_repository->index, &index_lock, 0))\n \t\t\t\tdie(_(\"unable to update temporary index\"));\n \t\t} else\n \t\t\twarning(_(\"Failed to update main cache tree\"));\n@@ -450,8 +449,8 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \t\t\texit(128);\n \n \t\trefresh_cache_or_die(refresh_flags);\n-\t\tcache_tree_update(&the_index, WRITE_TREE_SILENT);\n-\t\tif (write_locked_index(&the_index, &index_lock, 0))\n+\t\tcache_tree_update(the_repository->index, WRITE_TREE_SILENT);\n+\t\tif (write_locked_index(the_repository->index, &index_lock, 0))\n \t\t\tdie(_(\"unable to write new index file\"));\n \t\tcommit_style = COMMIT_NORMAL;\n \t\tret = get_lock_file_path(&index_lock);\n@@ -472,10 +471,10 @@ static const char *prepare_index(const char **argv, const char *prefix,\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-\t\t\tcache_tree_update(&the_index, WRITE_TREE_SILENT);\n-\t\tif (write_locked_index(&the_index, &index_lock,\n+\t\tif (the_repository->index->cache_changed\n+\t\t    || !cache_tree_fully_valid(the_repository->index->cache_tree))\n+\t\t\tcache_tree_update(the_repository->index, WRITE_TREE_SILENT);\n+\t\tif (write_locked_index(the_repository->index, &index_lock,\n \t\t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\t\tdie(_(\"unable to write new index file\"));\n \t\tcommit_style = COMMIT_AS_IS;\n@@ -516,15 +515,15 @@ 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_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"cannot read the index\"));\n \n \trepo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);\n \tadd_remove_files(&partial);\n-\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n-\tcache_tree_update(&the_index, WRITE_TREE_SILENT);\n-\tif (write_locked_index(&the_index, &index_lock, 0))\n+\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);\n+\tcache_tree_update(the_repository->index, WRITE_TREE_SILENT);\n+\tif (write_locked_index(the_repository->index, &index_lock, 0))\n \t\tdie(_(\"unable to write new index file\"));\n \n \thold_lock_file_for_update(&false_lock,\n@@ -534,14 +533,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_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n+\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);\n \n-\tif (write_locked_index(&the_index, &false_lock, 0))\n+\tif (write_locked_index(the_repository->index, &false_lock, 0))\n \t\tdie(_(\"unable to write temporary index file\"));\n \n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \tret = get_lock_file_path(&false_lock);\n-\tread_index_from(&the_index, ret, get_git_dir());\n+\tread_index_from(the_repository->index, ret, get_git_dir());\n out:\n \tstring_list_clear(&partial, 0);\n \tclear_pathspec(&pathspec);\n@@ -999,7 +998,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\tstruct object_id oid;\n \t\tconst char *parent = \"HEAD\";\n \n-\t\tif (!the_index.initialized && repo_read_index(the_repository) < 0)\n+\t\tif (!the_repository->index->initialized && repo_read_index(the_repository) < 0)\n \t\t\tdie(_(\"Cannot read index\"));\n \n \t\tif (amend)\n@@ -1009,11 +1008,11 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\t\tint i, ita_nr = 0;\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 < the_index.cache_nr; i++)\n-\t\t\t\tif (ce_intent_to_add(the_index.cache[i]))\n+\t\t\tensure_full_index(the_repository->index);\n+\t\t\tfor (i = 0; i < the_repository->index->cache_nr; i++)\n+\t\t\t\tif (ce_intent_to_add(the_repository->index->cache[i]))\n \t\t\t\t\tita_nr++;\n-\t\t\tcommittable = the_index.cache_nr - ita_nr > 0;\n+\t\t\tcommittable = the_repository->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@@ -1081,11 +1080,11 @@ 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_index(&the_index);\n+\t\tdiscard_index(the_repository->index);\n \t}\n-\tread_index_from(&the_index, index_file, get_git_dir());\n+\tread_index_from(the_repository->index, index_file, get_git_dir());\n \n-\tif (cache_tree_update(&the_index, 0)) {\n+\tif (cache_tree_update(the_repository->index, 0)) {\n \t\terror(_(\"Error building trees\"));\n \t\treturn 0;\n \t}\n@@ -1586,7 +1585,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \t    status_format != STATUS_FORMAT_PORCELAIN_V2)\n \t\tprogress_flag = REFRESH_PROGRESS;\n \trepo_read_index(the_repository);\n-\trefresh_index(&the_index,\n+\trefresh_index(the_repository->index,\n \t\t      REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,\n \t\t      &s.pathspec, NULL, NULL);\n \n@@ -1856,7 +1855,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, &the_index.cache_tree->oid,\n+\tif (commit_tree_extended(sb.buf, sb.len, &the_repository->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/describe.c b/builtin/describe.c\nindex d6c77a714f..c0e3301e3c 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"environment.h\"\n@@ -674,7 +673,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tprepare_repo_settings(the_repository);\n \t\t\tthe_repository->settings.command_requires_full_index = 0;\n \t\t\trepo_read_index(the_repository);\n-\t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n+\t\t\trefresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\n \t\t\tfd = repo_hold_locked_index(the_repository,\n \t\t\t\t\t\t    &index_lock, 0);\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex a8e68ce8ef..0d3c611aac 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"diff.h\"\n@@ -206,7 +205,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)\n \t\topt->diffopt.rotate_to_strict = 0;\n \t\topt->diffopt.no_free = 1;\n \t\tif (opt->diffopt.detect_rename) {\n-\t\t\tif (!the_index.cache)\n+\t\t\tif (the_repository->index->cache)\n \t\t\t\trepo_read_index(the_repository);\n \t\t\topt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;\n \t\t}\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 6e196e0c7d..efc37483b3 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"ewah/ewok.h\"\n@@ -239,9 +239,9 @@ static void refresh_index_quietly(void)\n \tfd = repo_hold_locked_index(the_repository, &lock_file, 0);\n \tif (fd < 0)\n \t\treturn;\n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \trepo_read_index(the_repository);\n-\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL,\n+\trefresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL,\n \t\t      NULL);\n \trepo_update_index_if_able(the_repository, &lock_file);\n }\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex a3c72b8258..a130faae4f 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -117,7 +117,7 @@ static int use_wt_file(const char *workdir, const char *name,\n \t\tint fd = open(buf.buf, O_RDONLY);\n \n \t\tif (fd >= 0 &&\n-\t\t    !index_fd(&the_index, &wt_oid, fd, &st, OBJ_BLOB, name, 0)) {\n+\t\t    !index_fd(the_repository->index, &wt_oid, fd, &st, OBJ_BLOB, name, 0)) {\n \t\t\tif (is_null_oid(oid)) {\n \t\t\t\toidcpy(oid, &wt_oid);\n \t\t\t\tuse = 1;\ndiff --git a/builtin/merge-index.c b/builtin/merge-index.c\nindex 270d5f644a..0fabe3f6bb 100644\n--- a/builtin/merge-index.c\n+++ b/builtin/merge-index.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"hex.h\"\n #include \"read-cache-ll.h\"\n@@ -18,11 +17,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 >= the_index.cache_nr)\n+\tif (pos >= the_repository->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 = the_index.cache[pos];\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[pos];\n \t\tint stage = ce_stage(ce);\n \n \t\tif (strcmp(ce->name, path))\n@@ -32,7 +31,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 < the_index.cache_nr);\n+\t} while (++pos < the_repository->index->cache_nr);\n \tif (!found)\n \t\tdie(\"git merge-index: %s not in the cache\", path);\n \n@@ -51,7 +50,7 @@ static int merge_entry(int pos, const char *path)\n \n static void merge_one_path(const char *path)\n {\n-\tint pos = index_name_pos(&the_index, path, strlen(path));\n+\tint pos = index_name_pos(the_repository->index, path, strlen(path));\n \n \t/*\n \t * If it already exists in the cache as stage0, it's\n@@ -65,9 +64,9 @@ static void merge_all(void)\n {\n \tint i;\n \t/* TODO: audit for interaction with sparse-index. */\n-\tensure_full_index(&the_index);\n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tconst struct cache_entry *ce = the_index.cache[i];\n+\tensure_full_index(the_repository->index);\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[i];\n \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \t\ti += merge_entry(i, ce->name)-1;\n@@ -89,7 +88,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED)\n \trepo_read_index(the_repository);\n \n \t/* TODO: audit for interaction with sparse-index. */\n-\tensure_full_index(&the_index);\n+\tensure_full_index(the_repository->index);\n \n \ti = 1;\n \tif (!strcmp(argv[i], \"-o\")) {\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex 8bdb439131..1082d919fd 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"tree-walk.h\"\n #include \"xdiff-interface.h\"\n@@ -364,7 +363,7 @@ static void trivial_merge_trees(struct tree_desc t[3], const char *base)\n \n \tsetup_traverse_info(&info, base);\n \tinfo.fn = threeway_callback;\n-\ttraverse_trees(&the_index, 3, t, &info);\n+\ttraverse_trees(the_repository->index, 3, t, &info);\n }\n \n static void *get_tree_descriptor(struct repository *r,\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 6f4fec87fc..6a6d379885 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -6,7 +6,6 @@\n  * Based on git-merge.sh by Junio C Hamano.\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n@@ -300,7 +299,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_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n+\trefresh_index(the_repository->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@@ -372,7 +371,7 @@ static void restore_state(const struct object_id *head,\n \trun_command(&cmd);\n \n refresh_cache:\n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"could not read index\"));\n }\n@@ -657,8 +656,8 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 2;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \topts.update = 1;\n \topts.verbose_update = 1;\n \topts.trivial_merges_only = 1;\n@@ -674,7 +673,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(&the_index.cache_tree);\n+\tcache_tree_free(&the_repository->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]->object.oid,\n@@ -687,7 +686,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,\n \n static void write_tree_trivial(struct object_id *oid)\n {\n-\tif (write_index_as_tree(oid, &the_index, get_index_file(), 0, NULL))\n+\tif (write_index_as_tree(oid, the_repository->index, get_index_file(), 0, NULL))\n \t\tdie(_(\"git write-tree failed to write a tree\"));\n }\n \n@@ -745,7 +744,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,\n \t\t\trollback_lock_file(&lock);\n \t\t\treturn 2;\n \t\t}\n-\t\tif (write_locked_index(&the_index, &lock,\n+\t\tif (write_locked_index(the_repository->index, &lock,\n \t\t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\t\tdie(_(\"unable to write %s\"), get_index_file());\n \t\treturn clean ? 0 : 1;\n@@ -768,8 +767,8 @@ static int count_unmerged_entries(void)\n {\n \tint i, ret = 0;\n \n-\tfor (i = 0; i < the_index.cache_nr; i++)\n-\t\tif (ce_stage(the_index.cache[i]))\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++)\n+\t\tif (ce_stage(the_repository->index->cache[i]))\n \t\t\tret++;\n \n \treturn ret;\n@@ -843,9 +842,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_index(&the_index);\n+\t\t\tdiscard_index(the_repository->index);\n \t}\n-\tread_index_from(&the_index, index_file, get_git_dir());\n+\tread_index_from(the_repository->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@@ -957,7 +956,7 @@ static int suggest_conflicts(void)\n \t * Thus, we will get the cleanup mode which is returned when we _are_\n \t * using an editor.\n \t */\n-\tappend_conflicts_hint(&the_index, &msgbuf,\n+\tappend_conflicts_hint(the_repository->index, &msgbuf,\n \t\t\t      get_cleanup_mode(cleanup_arg, 1));\n \tfputs(msgbuf.buf, fp);\n \tstrbuf_release(&msgbuf);\n@@ -1386,7 +1385,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_index(&the_index);\n+\tresolve_undo_clear_index(the_repository->index);\n \n \tif (option_edit < 0)\n \t\toption_edit = default_edit_option();\n@@ -1595,7 +1594,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_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n+\t\trefresh_index(the_repository->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@@ -1784,6 +1783,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t}\n \tstrbuf_release(&buf);\n \tfree(branch_to_free);\n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \treturn ret;\n }\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 22e64fc290..74aa9746aa 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) 2006 Johannes Schindelin\n  */\n-#define USE_THE_INDEX_VARIABLE\n+\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n@@ -95,9 +95,9 @@ 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(the_index.cache[first]->ce_mode))\n+\tif (!S_ISGITLINK(the_repository->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+\tif (!is_staging_gitmodules_ok(the_repository->index))\n \t\tdie(_(\"Please stage your changes to .gitmodules or stash them to proceed\"));\n \tstrbuf_addf(&submodule_dotgit, \"%s/.git\", src);\n \t*submodule_gitfile = read_gitfile(submodule_dotgit.buf);\n@@ -114,13 +114,13 @@ 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 = index_name_pos(&the_index, src_w_slash, len_w_slash);\n+\tfirst = index_name_pos(the_repository->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 \tfirst = -1 - first;\n-\tfor (last = first; last < the_index.cache_nr; last++) {\n-\t\tconst char *path = the_index.cache[last]->name;\n+\tfor (last = first; last < the_repository->index->cache_nr; last++) {\n+\t\tconst char *path = the_repository->index->cache[last]->name;\n \t\tif (strncmp(path, src_w_slash, len_w_slash))\n \t\t\tbreak;\n \t}\n@@ -144,14 +144,14 @@ 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 = index_name_pos(&the_index, with_slash, length);\n+\tint pos = index_name_pos(the_repository->index, with_slash, length);\n \tconst struct cache_entry *ce;\n \n \tif (pos < 0) {\n \t\tpos = -pos - 1;\n-\t\tif (pos >= the_index.cache_nr)\n+\t\tif (pos >= the_repository->index->cache_nr)\n \t\t\tgoto free_return;\n-\t\tce = the_index.cache[pos];\n+\t\tce = the_repository->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@@ -223,7 +223,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tS_ISDIR(st.st_mode)) {\n \t\tdestination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME);\n \t} else {\n-\t\tif (!path_in_sparse_checkout(dst_w_slash, &the_index) &&\n+\t\tif (!path_in_sparse_checkout(dst_w_slash, the_repository->index) &&\n \t\t    empty_dir_has_sparse_contents(dst_w_slash)) {\n \t\t\tdestination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME);\n \t\t\tdst_mode = SKIP_WORKTREE_DIR;\n@@ -239,7 +239,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t * is deprecated at this point) sparse-checkout. As\n \t\t\t * SPARSE here is only considering cone-mode situation.\n \t\t\t */\n-\t\t\tif (!path_in_cone_mode_sparse_checkout(destination[0], &the_index))\n+\t\t\tif (!path_in_cone_mode_sparse_checkout(destination[0], the_repository->index))\n \t\t\t\tdst_mode = SPARSE;\n \t\t}\n \t}\n@@ -263,10 +263,10 @@ 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 = index_name_pos(&the_index, src, length);\n+\t\t\tpos = index_name_pos(the_repository->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+\t\t\t\tif (!path_in_sparse_checkout(src_w_slash, the_repository->index) &&\n \t\t\t\t    empty_dir_has_sparse_contents(src)) {\n \t\t\t\t\tmodes[i] |= SKIP_WORKTREE_DIR;\n \t\t\t\t\tgoto dir_check;\n@@ -276,7 +276,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 = the_index.cache[pos];\n+\t\t\tce = the_repository->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@@ -286,7 +286,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 (index_name_pos(&the_index, dst, strlen(dst)) < 0) {\n+\t\t\tif (index_name_pos(the_repository->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@@ -311,7 +311,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 = index_name_pos(&the_index, src, length), last;\n+\t\t\tint first = index_name_pos(the_repository->index, src, length), last;\n \n \t\t\tif (first >= 0) {\n \t\t\t\tprepare_move_submodule(src, first,\n@@ -339,7 +339,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 = the_index.cache[first + j];\n+\t\t\t\tconst struct cache_entry *ce = the_repository->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@@ -351,7 +351,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 = index_file_exists(&the_index, src, length, 0))) {\n+\t\tif (!(ce = index_file_exists(the_repository->index, src, length, 0))) {\n \t\t\tbad = _(\"not under version control\");\n \t\t\tgoto act_on_entry;\n \t\t}\n@@ -387,7 +387,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \n \t\tif (ignore_sparse &&\n \t\t    (dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&\n-\t\t    index_entry_exists(&the_index, dst, strlen(dst))) {\n+\t\t    index_entry_exists(the_repository->index, dst, strlen(dst))) {\n \t\t\tbad = _(\"destination exists in the index\");\n \t\t\tif (force) {\n \t\t\t\tif (verbose)\n@@ -404,12 +404,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t * option as a way to have a successful run.\n \t\t */\n \t\tif (!ignore_sparse &&\n-\t\t    !path_in_sparse_checkout(src, &the_index)) {\n+\t\t    !path_in_sparse_checkout(src, the_repository->index)) {\n \t\t\tstring_list_append(&only_match_skip_worktree, src);\n \t\t\tskip_sparse = 1;\n \t\t}\n \t\tif (!ignore_sparse &&\n-\t\t    !path_in_sparse_checkout(dst, &the_index)) {\n+\t\t    !path_in_sparse_checkout(dst, the_repository->index)) {\n \t\t\tstring_list_append(&only_match_skip_worktree, dst);\n \t\t\tskip_sparse = 1;\n \t\t}\n@@ -449,7 +449,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tint pos;\n \t\tint sparse_and_dirty = 0;\n \t\tstruct checkout state = CHECKOUT_INIT;\n-\t\tstate.istate = &the_index;\n+\t\tstate.istate = the_repository->index;\n \n \t\tif (force)\n \t\t\tstate.force = 1;\n@@ -476,14 +476,14 @@ 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 = index_name_pos(&the_index, src, strlen(src));\n+\t\tpos = index_name_pos(the_repository->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-\t\t\t\t\t\t       the_index.cache[pos],\n+\t\t\tsparse_and_dirty = ie_modified(the_repository->index,\n+\t\t\t\t\t\t       the_repository->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+\t\trename_index_entry_at(the_repository->index, pos, dst);\n \n \t\tif (ignore_sparse &&\n \t\t    core_apply_sparse_checkout &&\n@@ -495,11 +495,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t * should be added in a future patch.\n \t\t\t */\n \t\t\tif ((mode & SPARSE) &&\n-\t\t\t    path_in_sparse_checkout(dst, &the_index)) {\n+\t\t\t    path_in_sparse_checkout(dst, the_repository->index)) {\n \t\t\t\t/* from out-of-cone to in-cone */\n-\t\t\t\tint dst_pos = index_name_pos(&the_index, dst,\n+\t\t\t\tint dst_pos = index_name_pos(the_repository->index, dst,\n \t\t\t\t\t\t\t     strlen(dst));\n-\t\t\t\tstruct cache_entry *dst_ce = the_index.cache[dst_pos];\n+\t\t\t\tstruct cache_entry *dst_ce = the_repository->index->cache[dst_pos];\n \n \t\t\t\tdst_ce->ce_flags &= ~CE_SKIP_WORKTREE;\n \n@@ -507,11 +507,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tdie(_(\"cannot checkout %s\"), dst_ce->name);\n \t\t\t} else if ((dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&\n \t\t\t\t   !(mode & SPARSE) &&\n-\t\t\t\t   !path_in_sparse_checkout(dst, &the_index)) {\n+\t\t\t\t   !path_in_sparse_checkout(dst, the_repository->index)) {\n \t\t\t\t/* from in-cone to out-of-cone */\n-\t\t\t\tint dst_pos = index_name_pos(&the_index, dst,\n+\t\t\t\tint dst_pos = index_name_pos(the_repository->index, dst,\n \t\t\t\t\t\t\t     strlen(dst));\n-\t\t\t\tstruct cache_entry *dst_ce = the_index.cache[dst_pos];\n+\t\t\t\tstruct cache_entry *dst_ce = the_repository->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\n@@ -559,9 +559,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tadvise_on_moving_dirty_path(&dirty_paths);\n \n \tif (gitmodules_modified)\n-\t\tstage_updated_gitmodules(&the_index);\n+\t\tstage_updated_gitmodules(the_repository->index);\n \n-\tif (write_locked_index(&the_index, &lock_file,\n+\tif (write_locked_index(the_repository->index, &lock_file,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\tdie(_(\"Unable to write new index file\"));\n \ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 72cbb76d52..66869210db 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -1044,7 +1044,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_index_unborn(&the_index))\n+\t\tif (is_null_oid(&orig_head) && !is_index_unborn(the_repository->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 6f89cec0fb..a8cf8504b8 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -4,7 +4,6 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -159,8 +158,8 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = -1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \n \tgit_config(git_read_tree_config, NULL);\n \n@@ -197,7 +196,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_index(&the_index);\n+\tresolve_undo_clear_index(the_repository->index);\n \n \tfor (i = 0; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n@@ -225,7 +224,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \t\tsetup_work_tree();\n \n \tif (opts.skip_sparse_checkout)\n-\t\tensure_full_index(&the_index);\n+\t\tensure_full_index(the_repository->index);\n \n \tif (opts.merge) {\n \t\tswitch (stage - 1) {\n@@ -237,7 +236,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_index_unborn(&the_index);\n+\t\t\topts.initial_checkout = is_index_unborn(the_repository->index);\n \t\t\tbreak;\n \t\tcase 3:\n \t\tdefault:\n@@ -258,7 +257,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(&the_index.cache_tree);\n+\tcache_tree_free(&the_repository->index->cache_tree);\n \tfor (i = 0; i < nr_trees; i++) {\n \t\tstruct tree *tree = trees[i];\n \t\tif (parse_tree(tree) < 0)\n@@ -282,7 +281,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)\n \t\t\t\t the_repository->index,\n \t\t\t\t trees[0]);\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(\"unable to write new index file\");\n \treturn 0;\n }\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 891f28468e..fe17d562a8 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -4,7 +4,6 @@\n  * Copyright (c) 2018 Pratik Karki\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"environment.h\"\n@@ -295,7 +294,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_index(&the_index);\n+\t\tdiscard_index(the_repository->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\");\ndiff --git a/builtin/replay.c b/builtin/replay.c\nindex 6bc4b47f09..6bf0691f15 100644\n--- a/builtin/replay.c\n+++ b/builtin/replay.c\n@@ -2,7 +2,6 @@\n  * \"git replay\" builtin command\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"git-compat-util.h\"\n \n #include \"builtin.h\"\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 1d62ff6332..b6dacf9678 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -66,8 +66,8 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \topts.fn = oneway_merge;\n \topts.merge = 1;\n \tinit_checkout_metadata(&opts.meta, ref, oid, NULL);\n@@ -159,11 +159,11 @@ 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_index(&the_index, one->path);\n+\t\t\tremove_file_from_index(the_repository->index, one->path);\n \t\t\tcontinue;\n \t\t}\n \n-\t\tce = make_cache_entry(&the_index, one->mode, &one->oid, one->path,\n+\t\tce = make_cache_entry(the_repository->index, one->mode, &one->oid, one->path,\n \t\t\t\t      0, 0);\n \n \t\t/*\n@@ -174,9 +174,9 @@ 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 = 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\tpos = index_name_pos(the_repository->index, one->path, strlen(one->path));\n+\t\tif ((pos >= 0 && ce_skip_worktree(the_repository->index->cache[pos])) ||\n+\t\t    (pos < 0 && !path_in_sparse_checkout(one->path, the_repository->index)))\n \t\t\tce->ce_flags |= CE_SKIP_WORKTREE;\n \n \t\tif (!ce)\n@@ -186,7 +186,7 @@ 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_index_entry(&the_index, ce,\n+\t\tadd_index_entry(the_repository->index, ce,\n \t\t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \t}\n }\n@@ -208,8 +208,8 @@ static int read_from_tree(const struct pathspec *pathspec,\n \topt.change = diff_change;\n \topt.add_remove = diff_addremove;\n \n-\tif (pathspec->nr && pathspec_needs_expanded_index(&the_index, pathspec))\n-\t\tensure_full_index(&the_index);\n+\tif (pathspec->nr && pathspec_needs_expanded_index(the_repository->index, pathspec))\n+\t\tensure_full_index(the_repository->index);\n \n \tif (do_diff_cache(tree_oid, &opt))\n \t\treturn 1;\n@@ -235,7 +235,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_index(&the_index))\n+\tif (is_merge() || unmerged_index(the_repository->index))\n \t\tdie(_(\"Cannot do a %s reset in the middle of a merge.\"),\n \t\t    _(reset_type_names[reset_type]));\n \n@@ -470,12 +470,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \t\t\t\tupdate_ref_status = 1;\n \t\t\t\tgoto cleanup;\n \t\t\t}\n-\t\t\tthe_index.updated_skipworktree = 1;\n+\t\t\tthe_repository->index->updated_skipworktree = 1;\n \t\t\tif (!no_refresh && get_git_work_tree()) {\n \t\t\t\tuint64_t t_begin, t_delta_in_ms;\n \n \t\t\t\tt_begin = getnanotime();\n-\t\t\t\trefresh_index(&the_index, flags, NULL, NULL,\n+\t\t\t\trefresh_index(the_repository->index, flags, NULL, NULL,\n \t\t\t\t\t      _(\"Unstaged changes after reset:\"));\n \t\t\t\tt_delta_in_ms = (getnanotime() - t_begin) / 1000000;\n \t\t\t\tif (!quiet && advice_enabled(ADVICE_RESET_NO_REFRESH_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) {\n@@ -501,7 +501,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \t\t\tfree(ref);\n \t\t}\n \n-\t\tif (write_locked_index(&the_index, &lock, COMMIT_LOCK))\n+\t\tif (write_locked_index(the_repository->index, &lock, COMMIT_LOCK))\n \t\t\tdie(_(\"Could not write new index file.\"));\n \t}\n \n@@ -516,7 +516,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \tif (!pathspec.nr)\n \t\tremove_branch_state(the_repository, 0);\n \n-\tdiscard_index(&the_index);\n+\tdiscard_index(the_repository->index);\n \n cleanup:\n \tclear_pathspec(&pathspec);\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 624182e507..af79538632 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_VARIABLE\n+\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -1049,8 +1049,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\tif (!strcmp(arg, \"--shared-index-path\")) {\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+\t\t\t\tif (the_repository->index->split_index) {\n+\t\t\t\t\tconst struct object_id *oid = &the_repository->index->split_index->base_oid;\n \t\t\t\t\tconst char *path = git_path(\"sharedindex.%s\", oid_to_hex(oid));\n \t\t\t\t\tprint_path(path, prefix, format, DEFAULT_RELATIVE);\n \t\t\t\t}\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex fd130cea2d..d195c16e74 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds 2006\n  */\n-#define USE_THE_INDEX_VARIABLE\n+\n #include \"builtin.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -41,8 +41,8 @@ static int get_ours_cache_pos(const char *path, int pos)\n {\n \tint i = -pos - 1;\n \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+\twhile ((i < the_repository->index->cache_nr) && !strcmp(the_repository->index->cache[i]->name, path)) {\n+\t\tif (ce_stage(the_repository->index->cache[i]) == 2)\n \t\t\treturn i;\n \t\ti++;\n \t}\n@@ -78,13 +78,13 @@ static void submodules_absorb_gitdir_if_needed(void)\n \t\tint pos;\n \t\tconst struct cache_entry *ce;\n \n-\t\tpos = index_name_pos(&the_index, name, strlen(name));\n+\t\tpos = index_name_pos(the_repository->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 \t\t\t\tcontinue;\n \t\t}\n-\t\tce = the_index.cache[pos];\n+\t\tce = the_repository->index->cache[pos];\n \n \t\tif (!S_ISGITLINK(ce->ce_mode) ||\n \t\t    !file_exists(ce->name) ||\n@@ -122,7 +122,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 = index_name_pos(&the_index, name, strlen(name));\n+\t\tpos = index_name_pos(the_repository->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@@ -132,11 +132,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(the_index.cache[pos]->ce_mode) ||\n+\t\t\tif (!S_ISGITLINK(the_repository->index->cache[pos]->ce_mode) ||\n \t\t\t    is_empty_dir(name))\n \t\t\t\tcontinue;\n \t\t}\n-\t\tce = the_index.cache[pos];\n+\t\tce = the_repository->index->cache[pos];\n \n \t\tif (lstat(ce->name, &st) < 0) {\n \t\t\tif (!is_missing_file_error(errno))\n@@ -173,7 +173,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 (ie_match_stat(&the_index, ce, &st, 0) ||\n+\t\tif (ie_match_stat(the_repository->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@@ -301,27 +301,27 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\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+\trefresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);\n \n \tseen = xcalloc(pathspec.nr, 1);\n \n-\tif (pathspec_needs_expanded_index(&the_index, &pathspec))\n-\t\tensure_full_index(&the_index);\n+\tif (pathspec_needs_expanded_index(the_repository->index, &pathspec))\n+\t\tensure_full_index(the_repository->index);\n \n-\tfor (i = 0; i < the_index.cache_nr; i++) {\n-\t\tconst struct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[i];\n \n \t\tif (!include_sparse &&\n \t\t    (ce_skip_worktree(ce) ||\n-\t\t     !path_in_sparse_checkout(ce->name, &the_index)))\n+\t\t     !path_in_sparse_checkout(ce->name, the_repository->index)))\n \t\t\tcontinue;\n-\t\tif (!ce_path_match(&the_index, ce, &pathspec, seen))\n+\t\tif (!ce_path_match(the_repository->index, ce, &pathspec, seen))\n \t\t\tcontinue;\n \t\tALLOC_GROW(list.entry, list.nr + 1, list.alloc);\n \t\tlist.entry[list.nr].name = xstrdup(ce->name);\n \t\tlist.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode);\n \t\tif (list.entry[list.nr++].is_submodule &&\n-\t\t    !is_staging_gitmodules_ok(&the_index))\n+\t\t    !is_staging_gitmodules_ok(the_repository->index))\n \t\t\tdie(_(\"please stage your changes to .gitmodules or stash them to proceed\"));\n \t}\n \n@@ -391,7 +391,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_index(&the_index, path))\n+\t\tif (remove_file_from_index(the_repository->index, path))\n \t\t\tdie(_(\"git rm: unable to remove %s\"), path);\n \t}\n \n@@ -432,10 +432,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t}\n \t\tstrbuf_release(&buf);\n \t\tif (gitmodules_modified)\n-\t\t\tstage_updated_gitmodules(&the_index);\n+\t\t\tstage_updated_gitmodules(the_repository->index);\n \t}\n \n-\tif (write_locked_index(&the_index, &lock_file,\n+\tif (write_locked_index(the_repository->index, &lock_file,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\tdie(_(\"Unable to write new index file\"));\n \ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex 062be1fbc0..69c01ba136 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -273,7 +272,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)\n \tstruct lock_file lock_file = LOCK_INIT;\n \n \trepo_read_index_preload(the_repository, NULL, 0);\n-\tif (refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL))\n+\tif (refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL))\n \t\treturn -1;\n \n \trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n@@ -287,8 +286,8 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)\n \tinit_tree_desc(t, &tree->object.oid, tree->buffer, tree->size);\n \n \topts.head_idx = 1;\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \topts.merge = 1;\n \topts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;\n \topts.update = update;\n@@ -299,7 +298,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)\n \tif (unpack_trees(nr_trees, t, &opts))\n \t\treturn -1;\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\treturn error(_(\"unable to write new index file\"));\n \n \treturn 0;\n@@ -430,7 +429,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)\n \tstate.force = 1;\n \tstate.quiet = 1;\n \tstate.refresh_cache = 1;\n-\tstate.istate = &the_index;\n+\tstate.istate = the_repository->index;\n \n \t/*\n \t * Step 1: get a difference between orig_tree (which corresponding\n@@ -454,7 +453,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)\n \n \t\t/* Look up the path's position in the current index. */\n \t\tp = diff_queued_diff.queue[i];\n-\t\tpos = index_name_pos(&the_index, p->two->path,\n+\t\tpos = index_name_pos(the_repository->index, p->two->path,\n \t\t\t\t     strlen(p->two->path));\n \n \t\t/*\n@@ -465,10 +464,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(the_index.cache[pos])) {\n+\t\tif (pos >= 0 && ce_skip_worktree(the_repository->index->cache[pos])) {\n \t\t\tstruct stat st;\n \n-\t\t\tce = the_index.cache[pos];\n+\t\t\tce = the_repository->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@@ -504,12 +503,12 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)\n \t\t\tif (pos < 0)\n \t\t\t\toption = ADD_CACHE_OK_TO_ADD;\n \n-\t\t\tce = make_cache_entry(&the_index,\n+\t\t\tce = make_cache_entry(the_repository->index,\n \t\t\t\t\t      p->one->mode,\n \t\t\t\t\t      &p->one->oid,\n \t\t\t\t\t      p->one->path,\n \t\t\t\t\t      0, 0);\n-\t\t\tadd_index_entry(&the_index, ce, option);\n+\t\t\tadd_index_entry(the_repository->index, ce, option);\n \t\t}\n \t}\n \tdiff_flush(&diff_opts);\n@@ -518,7 +517,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)\n \t * Step 4: write the new index to disk\n \t */\n \trepo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);\n-\tif (write_locked_index(&the_index, &lock,\n+\tif (write_locked_index(the_repository->index, &lock,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\tdie(_(\"could not write index\"));\n }\n@@ -539,7 +538,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,\n \t\t\t\t\t NULL, NULL, NULL))\n \t\treturn error(_(\"could not write index\"));\n \n-\tif (write_index_as_tree(&c_tree, &the_index, get_index_file(), 0,\n+\tif (write_index_as_tree(&c_tree, the_repository->index, get_index_file(), 0,\n \t\t\t\tNULL))\n \t\treturn error(_(\"cannot apply a stash in the middle of a merge\"));\n \n@@ -562,14 +561,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_index(&the_index);\n+\t\t\tdiscard_index(the_repository->index);\n \t\t\trepo_read_index(the_repository);\n-\t\t\tif (write_index_as_tree(&index_tree, &the_index,\n+\t\t\tif (write_index_as_tree(&index_tree, the_repository->index,\n \t\t\t\t\t\tget_index_file(), 0, NULL))\n \t\t\t\treturn error(_(\"could not save index tree\"));\n \n \t\t\treset_head();\n-\t\t\tdiscard_index(&the_index);\n+\t\t\tdiscard_index(the_repository->index);\n \t\t\trepo_read_index(the_repository);\n \t\t}\n \t}\n@@ -875,8 +874,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op\n \t}\n \n \tunpack_tree_opt.head_idx = -1;\n-\tunpack_tree_opt.src_index = &the_index;\n-\tunpack_tree_opt.dst_index = &the_index;\n+\tunpack_tree_opt.src_index = the_repository->index;\n+\tunpack_tree_opt.dst_index = the_repository->index;\n \tunpack_tree_opt.merge = 1;\n \tunpack_tree_opt.fn = stash_worktree_untracked_merge;\n \n@@ -1395,7 +1394,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b\n \n \tstrbuf_addf(&commit_tree_label, \"index on %s\\n\", msg.buf);\n \tcommit_list_insert(head_commit, &parents);\n-\tif (write_index_as_tree(&info->i_tree, &the_index, get_index_file(), 0,\n+\tif (write_index_as_tree(&info->i_tree, the_repository->index, get_index_file(), 0,\n \t\t\t\tNULL) ||\n \t    commit_tree(commit_tree_label.buf, commit_tree_label.len,\n \t\t\t&info->i_tree, parents, &info->i_commit, NULL, NULL)) {\n@@ -1540,9 +1539,9 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q\n \t\tchar *ps_matched = xcalloc(ps->nr, 1);\n \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++)\n-\t\t\tce_path_match(&the_index, the_index.cache[i], ps,\n+\t\tensure_full_index(the_repository->index);\n+\t\tfor (i = 0; i < the_repository->index->cache_nr; i++)\n+\t\t\tce_path_match(the_repository->index, the_repository->index->cache[i], ps,\n \t\t\t\t      ps_matched);\n \n \t\tif (report_path_error(ps_matched, ps)) {\n@@ -1612,7 +1611,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_index(&the_index);\n+\t\tdiscard_index(the_repository->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 e4e18adb57..93f4b9d726 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"environment.h\"\n@@ -207,18 +206,18 @@ static int module_list_compute(const char **argv,\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-\t\tconst struct cache_entry *ce = the_index.cache[i];\n+\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[i];\n \n-\t\tif (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),\n+\t\tif (!match_pathspec(the_repository->index, pathspec, ce->name, ce_namelen(ce),\n \t\t\t\t    0, ps_matched, 1) ||\n \t\t    !S_ISGITLINK(ce->ce_mode))\n \t\t\tcontinue;\n \n \t\tALLOC_GROW(list->entries, list->nr + 1, list->alloc);\n \t\tlist->entries[list->nr++] = ce;\n-\t\twhile (i + 1 < the_index.cache_nr &&\n-\t\t       !strcmp(ce->name, the_index.cache[i + 1]->name))\n+\t\twhile (i + 1 < the_repository->index->cache_nr &&\n+\t\t       !strcmp(ce->name, the_repository->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@@ -907,7 +906,7 @@ static void generate_submodule_summary(struct summary_cb *info,\n \t\t\tint fd = open(p->sm_path, O_RDONLY);\n \n \t\t\tif (fd < 0 || fstat(fd, &st) < 0 ||\n-\t\t\t    index_fd(&the_index, &p->oid_dst, fd, &st, OBJ_BLOB,\n+\t\t\t    index_fd(the_repository->index, &p->oid_dst, fd, &st, OBJ_BLOB,\n \t\t\t\t     p->sm_path, 0))\n \t\t\t\terror(_(\"couldn't hash object from '%s'\"), p->sm_path);\n \t\t} else {\n@@ -3243,21 +3242,21 @@ static void die_on_index_match(const char *path, int force)\n \t\tchar *ps_matched = xcalloc(ps.nr, 1);\n \n \t\t/* TODO: audit for interaction with sparse-index. */\n-\t\tensure_full_index(&the_index);\n+\t\tensure_full_index(the_repository->index);\n \n \t\t/*\n \t\t * Since there is only one pathspec, we just need to\n \t\t * check ps_matched[0] to know if a cache entry matched.\n \t\t */\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\tfor (i = 0; i < the_repository->index->cache_nr; i++) {\n+\t\t\tce_path_match(the_repository->index, the_repository->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(the_index.cache[i]->ce_mode))\n+\t\t\t\tif (!S_ISGITLINK(the_repository->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 7bcaa1476c..6321810006 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_VARIABLE\n+\n #include \"builtin.h\"\n #include \"bulk-checkin.h\"\n #include \"config.h\"\n@@ -247,16 +247,16 @@ 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 = index_name_pos(&the_index, path, namelen);\n+\tint pos = index_name_pos(the_repository->index, path, namelen);\n \tif (0 <= pos) {\n-\t\tmark_fsmonitor_invalid(&the_index, the_index.cache[pos]);\n+\t\tmark_fsmonitor_invalid(the_repository->index, the_repository->index->cache[pos]);\n \t\tif (mark)\n-\t\t\tthe_index.cache[pos]->ce_flags |= flag;\n+\t\t\tthe_repository->index->cache[pos]->ce_flags |= flag;\n \t\telse\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\tthe_index.cache_changed |= CE_ENTRY_CHANGED;\n+\t\t\tthe_repository->index->cache[pos]->ce_flags &= ~flag;\n+\t\tthe_repository->index->cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;\n+\t\tcache_tree_invalidate_path(the_repository->index, path);\n+\t\tthe_repository->index->cache_changed |= CE_ENTRY_CHANGED;\n \t\treturn 0;\n \t}\n \treturn -1;\n@@ -266,7 +266,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_index(&the_index, path))\n+\tif (remove_file_from_index(the_repository->index, path))\n \t\treturn error(\"%s: cannot remove from the index\", path);\n \treturn 0;\n }\n@@ -291,24 +291,24 @@ 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) && !ie_match_stat(&the_index, old, st, 0))\n+\tif (old && !ce_stage(old) && !ie_match_stat(the_repository->index, old, st, 0))\n \t\treturn 0;\n \n-\tce = make_empty_cache_entry(&the_index, len);\n+\tce = make_empty_cache_entry(the_repository->index, len);\n \tmemcpy(ce->name, path, len);\n \tce->ce_flags = create_ce_flags(0);\n \tce->ce_namelen = len;\n-\tfill_stat_cache_info(&the_index, ce, st);\n+\tfill_stat_cache_info(the_repository->index, ce, st);\n \tce->ce_mode = ce_mode_from_stat(old, st->st_mode);\n \n-\tif (index_path(&the_index, &ce->oid, path, st,\n+\tif (index_path(the_repository->index, &ce->oid, path, st,\n \t\t       info_only ? 0 : HASH_WRITE_OBJECT)) {\n \t\tdiscard_cache_entry(ce);\n \t\treturn -1;\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_index_entry(&the_index, ce, option)) {\n+\tif (add_index_entry(the_repository->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@@ -341,11 +341,11 @@ 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 = index_name_pos(&the_index, path, len);\n+\tint pos = index_name_pos(the_repository->index, path, len);\n \n \t/* Exact match: file or existing gitlink */\n \tif (pos >= 0) {\n-\t\tconst struct cache_entry *ce = the_index.cache[pos];\n+\t\tconst struct cache_entry *ce = the_repository->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@@ -360,8 +360,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 < the_index.cache_nr) {\n-\t\tconst struct cache_entry *ce = the_index.cache[pos++];\n+\twhile (pos < the_repository->index->cache_nr) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[pos++];\n \n \t\tif (strncmp(ce->name, path, len))\n \t\t\tbreak;\n@@ -391,8 +391,8 @@ static int process_path(const char *path, struct stat *st, int stat_errno)\n \tif (has_symlink_leading_path(path, len))\n \t\treturn error(\"'%s' is beyond a symbolic link\", path);\n \n-\tpos = index_name_pos(&the_index, path, len);\n-\tce = pos < 0 ? NULL : the_index.cache[pos];\n+\tpos = index_name_pos(the_repository->index, path, len);\n+\tce = pos < 0 ? NULL : the_repository->index->cache[pos];\n \tif (ce && ce_skip_worktree(ce)) {\n \t\t/*\n \t\t * working directory version is assumed \"good\"\n@@ -400,7 +400,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_index(&the_index, path))\n+\t\t    remove_file_from_index(the_repository->index, path))\n \t\t\treturn error(\"%s: cannot remove from the index\", path);\n \t\treturn 0;\n \t}\n@@ -428,7 +428,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,\n \t\treturn error(\"Invalid path '%s'\", path);\n \n \tlen = strlen(path);\n-\tce = make_empty_cache_entry(&the_index, len);\n+\tce = make_empty_cache_entry(the_repository->index, len);\n \n \toidcpy(&ce->oid, oid);\n \tmemcpy(ce->name, path, len);\n@@ -439,7 +439,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_index_entry(&the_index, ce, option))\n+\tif (add_index_entry(the_repository->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@@ -451,11 +451,11 @@ static void chmod_path(char flip, const char *path)\n \tint pos;\n \tstruct cache_entry *ce;\n \n-\tpos = index_name_pos(&the_index, path, strlen(path));\n+\tpos = index_name_pos(the_repository->index, path, strlen(path));\n \tif (pos < 0)\n \t\tgoto fail;\n-\tce = the_index.cache[pos];\n-\tif (chmod_index_entry(&the_index, ce, flip) < 0)\n+\tce = the_repository->index->cache[pos];\n+\tif (chmod_index_entry(the_repository->index, ce, flip) < 0)\n \t\tgoto fail;\n \n \treport(\"chmod %cx '%s'\", flip, path);\n@@ -498,7 +498,7 @@ static void update_one(const char *path)\n \t}\n \n \tif (force_remove) {\n-\t\tif (remove_file_from_index(&the_index, path))\n+\t\tif (remove_file_from_index(the_repository->index, path))\n \t\t\tdie(\"git update-index: unable to remove %s\", path);\n \t\treport(\"remove '%s'\", path);\n \t\treturn;\n@@ -581,7 +581,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_index(&the_index, path_name))\n+\t\t\tif (remove_file_from_index(the_repository->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@@ -622,12 +622,12 @@ static struct cache_entry *read_one_ent(const char *which,\n \t\t\terror(\"%s: not in %s branch.\", path, which);\n \t\treturn NULL;\n \t}\n-\tif (!the_index.sparse_index && mode == S_IFDIR) {\n+\tif (!the_repository->index->sparse_index && mode == S_IFDIR) {\n \t\tif (which)\n \t\t\terror(\"%s: not a blob in %s branch.\", path, which);\n \t\treturn NULL;\n \t}\n-\tce = make_empty_cache_entry(&the_index, namelen);\n+\tce = make_empty_cache_entry(the_repository->index, namelen);\n \n \toidcpy(&ce->oid, &oid);\n \tmemcpy(ce->name, path, namelen);\n@@ -642,12 +642,12 @@ static int unresolve_one(const char *path)\n \tstruct string_list_item *item;\n \tint res = 0;\n \n-\tif (!the_index.resolve_undo)\n+\tif (!the_repository->index->resolve_undo)\n \t\treturn res;\n-\titem = string_list_lookup(the_index.resolve_undo, path);\n+\titem = string_list_lookup(the_repository->index->resolve_undo, path);\n \tif (!item)\n \t\treturn res; /* no resolve-undo record for the path */\n-\tres = unmerge_index_entry(&the_index, path, item->util, 0);\n+\tres = unmerge_index_entry(the_repository->index, path, item->util, 0);\n \tFREE_AND_NULL(item->util);\n \treturn res;\n }\n@@ -688,13 +688,13 @@ static int do_reupdate(const char **paths,\n \t\t */\n \t\thas_head = 0;\n  redo:\n-\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n-\t\tconst struct cache_entry *ce = the_index.cache[pos];\n+\tfor (pos = 0; pos < the_repository->index->cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = the_repository->index->cache[pos];\n \t\tstruct cache_entry *old = NULL;\n \t\tint save_nr;\n \t\tchar *path;\n \n-\t\tif (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL))\n+\t\tif (ce_stage(ce) || !ce_path_match(the_repository->index, ce, &pathspec, NULL))\n \t\t\tcontinue;\n \t\tif (has_head)\n \t\t\told = read_one_ent(NULL, &head_oid,\n@@ -710,7 +710,7 @@ static int do_reupdate(const char **paths,\n \t\t * to process each path individually\n \t\t */\n \t\tif (S_ISSPARSEDIR(ce->ce_mode)) {\n-\t\t\tensure_full_index(&the_index);\n+\t\t\tensure_full_index(the_repository->index);\n \t\t\tgoto redo;\n \t\t}\n \n@@ -718,12 +718,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 = the_index.cache_nr;\n+\t\tsave_nr = the_repository->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 != the_index.cache_nr)\n+\t\tif (save_nr != the_repository->index->cache_nr)\n \t\t\tgoto redo;\n \t}\n \tclear_pathspec(&pathspec);\n@@ -739,9 +739,9 @@ static int refresh(struct refresh_params *o, unsigned int flag)\n {\n \tsetup_work_tree();\n \trepo_read_index(the_repository);\n-\t*o->has_errors |= refresh_index(&the_index, o->flags | flag, NULL,\n+\t*o->has_errors |= refresh_index(the_repository->index, o->flags | flag, NULL,\n \t\t\t\t\tNULL, NULL);\n-\tif (has_racy_timestamp(&the_index)) {\n+\tif (has_racy_timestamp(the_repository->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@@ -750,7 +750,7 @@ static int refresh(struct refresh_params *o, unsigned int flag)\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+\t\tthe_repository->index->cache_changed |= SOMETHING_CHANGED;\n \t}\n \treturn 0;\n }\n@@ -787,7 +787,7 @@ static int resolve_undo_clear_callback(const struct option *opt UNUSED,\n {\n \tBUG_ON_OPT_NEG(unset);\n \tBUG_ON_OPT_ARG(arg);\n-\tresolve_undo_clear_index(&the_index);\n+\tresolve_undo_clear_index(the_repository->index);\n \treturn 0;\n }\n \n@@ -888,7 +888,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\tthe_index.cache_changed = 0;\n+\t\tthe_repository->index->cache_changed = 0;\n \n \tctx->argv += ctx->argc - 1;\n \tctx->argc = 1;\n@@ -909,7 +909,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\tthe_index.cache_changed = 0;\n+\t\tthe_repository->index->cache_changed = 0;\n \n \tctx->argv += ctx->argc - 1;\n \tctx->argc = 1;\n@@ -1056,7 +1056,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \tif (entries < 0)\n \t\tdie(\"cache corrupted\");\n \n-\tthe_index.updated_skipworktree = 1;\n+\tthe_repository->index->updated_skipworktree = 1;\n \n \t/*\n \t * Custom copy of parse_options() because we want to handle\n@@ -1111,18 +1111,18 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \tgetline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;\n \tif (preferred_index_format) {\n \t\tif (preferred_index_format < 0) {\n-\t\t\tprintf(_(\"%d\\n\"), the_index.version);\n+\t\t\tprintf(_(\"%d\\n\"), the_repository->index->version);\n \t\t} else if (preferred_index_format < INDEX_FORMAT_LB ||\n \t\t\t   INDEX_FORMAT_UB < preferred_index_format) {\n \t\t\tdie(\"index-version %d not in range: %d..%d\",\n \t\t\t    preferred_index_format,\n \t\t\t    INDEX_FORMAT_LB, INDEX_FORMAT_UB);\n \t\t} else {\n-\t\t\tif (the_index.version != preferred_index_format)\n-\t\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n+\t\t\tif (the_repository->index->version != preferred_index_format)\n+\t\t\t\tthe_repository->index->cache_changed |= SOMETHING_CHANGED;\n \t\t\treport(_(\"index-version: was %d, set to %d\"),\n-\t\t\t       the_index.version, preferred_index_format);\n-\t\t\tthe_index.version = preferred_index_format;\n+\t\t\t       the_repository->index->version, preferred_index_format);\n+\t\t\tthe_repository->index->version = preferred_index_format;\n \t\t}\n \t}\n \n@@ -1159,16 +1159,16 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\twarning(_(\"core.splitIndex is set to false; \"\n \t\t\t\t  \"remove or change it, if you really want to \"\n \t\t\t\t  \"enable split index\"));\n-\t\tif (the_index.split_index)\n-\t\t\tthe_index.cache_changed |= SPLIT_INDEX_ORDERED;\n+\t\tif (the_repository->index->split_index)\n+\t\t\tthe_repository->index->cache_changed |= SPLIT_INDEX_ORDERED;\n \t\telse\n-\t\t\tadd_split_index(&the_index);\n+\t\t\tadd_split_index(the_repository->index);\n \t} else if (!split_index) {\n \t\tif (git_config_get_split_index() == 1)\n \t\t\twarning(_(\"core.splitIndex is set to true; \"\n \t\t\t\t  \"remove or change it, if you really want to \"\n \t\t\t\t  \"disable split index\"));\n-\t\tremove_split_index(&the_index);\n+\t\tremove_split_index(the_repository->index);\n \t}\n \n \tprepare_repo_settings(r);\n@@ -1180,7 +1180,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\twarning(_(\"core.untrackedCache is set to true; \"\n \t\t\t\t  \"remove or change it, if you really want to \"\n \t\t\t\t  \"disable the untracked cache\"));\n-\t\tremove_untracked_cache(&the_index);\n+\t\tremove_untracked_cache(the_repository->index);\n \t\treport(_(\"Untracked cache disabled\"));\n \t\tbreak;\n \tcase UC_TEST:\n@@ -1192,7 +1192,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\twarning(_(\"core.untrackedCache is set to false; \"\n \t\t\t\t  \"remove or change it, if you really want to \"\n \t\t\t\t  \"enable the untracked cache\"));\n-\t\tadd_untracked_cache(&the_index);\n+\t\tadd_untracked_cache(the_repository->index);\n \t\treport(_(\"Untracked cache enabled for '%s'\"), get_git_work_tree());\n \t\tbreak;\n \tdefault:\n@@ -1222,7 +1222,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\t\t\"set it if you really want to \"\n \t\t\t\t\"enable fsmonitor\"));\n \t\t}\n-\t\tadd_fsmonitor(&the_index);\n+\t\tadd_fsmonitor(the_repository->index);\n \t\treport(_(\"fsmonitor enabled\"));\n \t} else if (!fsmonitor) {\n \t\tenum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);\n@@ -1230,17 +1230,17 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\twarning(_(\"core.fsmonitor is set; \"\n \t\t\t\t\"remove it if you really want to \"\n \t\t\t\t\"disable fsmonitor\"));\n-\t\tremove_fsmonitor(&the_index);\n+\t\tremove_fsmonitor(the_repository->index);\n \t\treport(_(\"fsmonitor disabled\"));\n \t}\n \n-\tif (the_index.cache_changed || force_write) {\n+\tif (the_repository->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);\n \t\t\tunable_to_lock_die(get_index_file(), lock_error);\n \t\t}\n-\t\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\t\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\t\tdie(\"Unable to write new index file\");\n \t}\n \ndiff --git a/builtin/write-tree.c b/builtin/write-tree.c\nindex 66e83d0ecb..8c75b4609b 100644\n--- a/builtin/write-tree.c\n+++ b/builtin/write-tree.c\n@@ -3,7 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define USE_THE_INDEX_VARIABLE\n+\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"environment.h\"\n@@ -44,8 +44,8 @@ int cmd_write_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-\tret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,\n-\t\t\t\t  tree_prefix);\n+\tret = write_index_as_tree(&oid, the_repository->index, get_index_file(),\n+\t\t\t\t  flags, tree_prefix);\n \tswitch (ret) {\n \tcase 0:\n \t\tprintf(\"%s\\n\", oid_to_hex(&oid));\n-- \n2.44.GIT\n\n"},{"id":"493122","messageId":"416612e7e31a4b055b3fe17a5cdf78f8d07bd9e2.1713442061.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713442061.git.ps@pks.im","subject":"[PATCH v2 3/6] repository: initialize index in `repo_init()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-18T12:14:19Z","receivedAt":"2024-04-18T12:14:22Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"When Git starts, one of the first things it will do is to call\n`initialize_the_repository()`. This function sets up both the global\n`the_repository` and `the_index` variables as required. Part of that\nsetup is also to set `the_repository.index = &the_index` so that the\nindex can be accessed via the repository.\n\nWhen calling `repo_init()` on a repository though we set the complete\nstruct to all-zeroes, which will also cause us to unset the `index`\npointer. And as we don't re-initialize the index in that function, we\nwill end up with a `NULL` pointer here.\n\nThis has been fine until now becaues this function is only used to\ncreate a new repository. git-init(1) does not access the index at all\nafter initializing the repository, whereas git-checkout(1) only uses\n`the_index` directly. We are about to remove `the_index` though, which\nwill uncover this partially-initialized repository structure.\n\nRefactor the code and create a common `initialize_repository()` function\nthat gets called from `repo_init()` and `initialize_the_repository()`.\nThis function sets up both the repository and the index as required.\nLike this, we can easily special-case when `repo_init()` gets called\nwith `the_repository`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n repository.c | 28 +++++++++++++++++-----------\n 1 file changed, 17 insertions(+), 11 deletions(-)\n\ndiff --git a/repository.c b/repository.c\nindex e15b416944..d64d15d952 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -25,17 +25,20 @@ static struct repository the_repo;\n struct repository *the_repository;\n struct index_state the_index;\n \n+static void initialize_repository(struct repository *repo,\n+\t\t\t\t  struct index_state *index)\n+{\n+\trepo->index = index;\n+\trepo->objects = raw_object_store_new();\n+\trepo->remote_state = remote_state_new();\n+\trepo->parsed_objects = parsed_object_pool_new();\n+\tindex_state_init(index, repo);\n+}\n+\n void initialize_the_repository(void)\n {\n \tthe_repository = &the_repo;\n-\n-\tthe_repo.index = &the_index;\n-\tthe_repo.objects = raw_object_store_new();\n-\tthe_repo.remote_state = remote_state_new();\n-\tthe_repo.parsed_objects = parsed_object_pool_new();\n-\n-\tindex_state_init(&the_index, the_repository);\n-\n+\tinitialize_repository(the_repository, &the_index);\n \trepo_set_hash_algo(&the_repo, GIT_HASH_SHA1);\n }\n \n@@ -188,9 +191,12 @@ int repo_init(struct repository *repo,\n \tstruct repository_format format = REPOSITORY_FORMAT_INIT;\n \tmemset(repo, 0, sizeof(*repo));\n \n-\trepo->objects = raw_object_store_new();\n-\trepo->parsed_objects = parsed_object_pool_new();\n-\trepo->remote_state = remote_state_new();\n+\tif (repo == the_repository) {\n+\t\tinitialize_repository(the_repository, &the_index);\n+\t} else {\n+\t\tALLOC_ARRAY(repo->index, 1);\n+\t\tinitialize_repository(repo, repo->index);\n+\t}\n \n \tif (repo_init_gitdir(repo, gitdir))\n \t\tgoto error;\n-- \n2.44.GIT\n\n"},{"id":"493123","messageId":"6fb14920181d9d53fe6db09378cb10f7377880f1.1713442061.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713442061.git.ps@pks.im","subject":"[PATCH v2 4/6] builtin/clone: stop using `the_index`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-18T12:14:24Z","receivedAt":"2024-04-18T12:14:28Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Convert git-clone(1) to use `the_repository->index` instead of\n`the_index`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/clone.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 74ec14542e..93fdfc945a 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -8,7 +8,6 @@\n  * Clone a repository into a different directory that does not yet exist.\n  */\n \n-#define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n@@ -731,8 +730,8 @@ static int checkout(int submodule_progress, int filter_submodules)\n \topts.preserve_ignored = 0;\n \topts.fn = oneway_merge;\n \topts.verbose_update = (option_verbosity >= 0);\n-\topts.src_index = &the_index;\n-\topts.dst_index = &the_index;\n+\topts.src_index = the_repository->index;\n+\topts.dst_index = the_repository->index;\n \tinit_checkout_metadata(&opts.meta, head, &oid, NULL);\n \n \ttree = parse_tree_indirect(&oid);\n@@ -746,7 +745,7 @@ static int checkout(int submodule_progress, int filter_submodules)\n \n \tfree(head);\n \n-\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\tif (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write new index file\"));\n \n \terr |= run_hooks_l(\"post-checkout\", oid_to_hex(null_oid()),\n-- \n2.44.GIT\n\n"},{"id":"493124","messageId":"549f8c048fb13a4b0b004c5dc72a39fb24a70c7f.1713442061.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713442061.git.ps@pks.im","subject":"[PATCH v2 5/6] repository: drop `the_index` variable","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-18T12:14:29Z","receivedAt":"2024-04-18T12:14:33Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"All users of `the_index` have been converted to use either a custom\n`struct index_state *` or the index provided by `the_repository`. We can\nthus drop the globally-accessible declaration of this variable. In fact,\nwe can go further than that and drop `the_index` completely now and have\nit be allocated dynamically in `initialize_repository()` as all the\nother data structures in it are.\n\nThis concludes the quest to make Git `the_index` free, which has started\nwith 4aab5b46f4 (Make read-cache.c \"the_index\" free., 2007-04-01).\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n repository.c | 25 ++++++-------------------\n repository.h |  3 ---\n 2 files changed, 6 insertions(+), 22 deletions(-)\n\ndiff --git a/repository.c b/repository.c\nindex d64d15d952..089edbffa2 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -1,8 +1,3 @@\n-/*\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_VARIABLE\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"repository.h\"\n@@ -23,22 +18,20 @@\n /* The main repository */\n static struct repository the_repo;\n struct repository *the_repository;\n-struct index_state the_index;\n \n-static void initialize_repository(struct repository *repo,\n-\t\t\t\t  struct index_state *index)\n+static void initialize_repository(struct repository *repo)\n {\n-\trepo->index = index;\n \trepo->objects = raw_object_store_new();\n \trepo->remote_state = remote_state_new();\n \trepo->parsed_objects = parsed_object_pool_new();\n-\tindex_state_init(index, repo);\n+\tALLOC_ARRAY(repo->index, 1);\n+\tindex_state_init(repo->index, repo);\n }\n \n void initialize_the_repository(void)\n {\n \tthe_repository = &the_repo;\n-\tinitialize_repository(the_repository, &the_index);\n+\tinitialize_repository(the_repository);\n \trepo_set_hash_algo(&the_repo, GIT_HASH_SHA1);\n }\n \n@@ -191,12 +184,7 @@ int repo_init(struct repository *repo,\n \tstruct repository_format format = REPOSITORY_FORMAT_INIT;\n \tmemset(repo, 0, sizeof(*repo));\n \n-\tif (repo == the_repository) {\n-\t\tinitialize_repository(the_repository, &the_index);\n-\t} else {\n-\t\tALLOC_ARRAY(repo->index, 1);\n-\t\tinitialize_repository(repo, repo->index);\n-\t}\n+\tinitialize_repository(repo);\n \n \tif (repo_init_gitdir(repo, gitdir))\n \t\tgoto error;\n@@ -313,8 +301,7 @@ void repo_clear(struct repository *repo)\n \n \tif (repo->index) {\n \t\tdiscard_index(repo->index);\n-\t\tif (repo->index != &the_index)\n-\t\t\tFREE_AND_NULL(repo->index);\n+\t\tFREE_AND_NULL(repo->index);\n \t}\n \n \tif (repo->promisor_remote_config) {\ndiff --git a/repository.h b/repository.h\nindex 268436779c..6f4af15417 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -187,9 +187,6 @@ struct repository {\n };\n \n extern struct repository *the_repository;\n-#ifdef USE_THE_INDEX_VARIABLE\n-extern struct index_state the_index;\n-#endif\n \n /*\n  * Define a custom repository layout. Any field can be NULL, which\n-- \n2.44.GIT\n\n"},{"id":"493125","messageId":"ed722b9b4b2d0d173eff2945812e6a15d6470c38.1713442061.git.ps@pks.im","threadId":"61321","inReplyTo":"cover.1713442061.git.ps@pks.im","subject":"[PATCH v2 6/6] repository: drop `initialize_the_repository()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-18T12:14:33Z","receivedAt":"2024-04-18T12:14:38Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Now that we have dropped `the_index`, `initialize_the_repository()`\ndoesn't really do a lot anymore except for setting up the pointer for\n`the_repository` and then calling `initialize_repository()`. The former\ncan be replaced by statically initializing the pointer though, which\nbasically makes this function moot.\n\nConvert callers to instead call `initialize_repository(the_repository)`\nand drop `initialize_thee_repository()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n common-main.c                |  2 +-\n oss-fuzz/fuzz-commit-graph.c |  3 ++-\n repository.c                 | 29 +++++++++++++++++++++--------\n repository.h                 |  2 +-\n t/helper/test-read-cache.c   |  2 +-\n 5 files changed, 26 insertions(+), 12 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 033778b3c5..b86f40600f 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -48,7 +48,7 @@ int main(int argc, const char **argv)\n \tsetlocale(LC_CTYPE, \"\");\n \tgit_setup_gettext();\n \n-\tinitialize_the_repository();\n+\tinitialize_repository(the_repository);\n \n \tattr_start();\n \ndiff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c\nindex 2992079dd9..fe15e2c225 100644\n--- a/oss-fuzz/fuzz-commit-graph.c\n+++ b/oss-fuzz/fuzz-commit-graph.c\n@@ -11,7 +11,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)\n {\n \tstruct commit_graph *g;\n \n-\tinitialize_the_repository();\n+\tinitialize_repository(the_repository);\n+\n \t/*\n \t * Initialize the_repository with commit-graph settings that would\n \t * normally be read from the repository's gitdir. We want to avoid\ndiff --git a/repository.c b/repository.c\nindex 089edbffa2..2118f563e3 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -17,22 +17,35 @@\n \n /* The main repository */\n static struct repository the_repo;\n-struct repository *the_repository;\n+struct repository *the_repository = &the_repo;\n \n-static void initialize_repository(struct repository *repo)\n+void initialize_repository(struct repository *repo)\n {\n \trepo->objects = raw_object_store_new();\n \trepo->remote_state = remote_state_new();\n \trepo->parsed_objects = parsed_object_pool_new();\n \tALLOC_ARRAY(repo->index, 1);\n \tindex_state_init(repo->index, repo);\n-}\n \n-void initialize_the_repository(void)\n-{\n-\tthe_repository = &the_repo;\n-\tinitialize_repository(the_repository);\n-\trepo_set_hash_algo(&the_repo, GIT_HASH_SHA1);\n+\t/*\n+\t * Unfortunately, we need to keep this hack around for the time being:\n+\t *\n+\t *   - Not setting up the hash algorithm for `the_repository` leads to\n+\t *     crashes because `the_hash_algo` is a macro that expands to\n+\t *     `the_repository->hash_algo`. So if Git commands try to access\n+\t *     `the_hash_algo` without a Git directory we crash.\n+\t *\n+\t *   - Setting up the hash algorithm to be SHA1 by default breaks other\n+\t *     commands when running with SHA256.\n+\t *\n+\t * This is another point in case why having global state is a bad idea.\n+\t * Eventually, we should remove this hack and stop setting the hash\n+\t * algorithm in this function altogether. Instead, it should only ever\n+\t * be set via our repository setup procedures. But that requires more\n+\t * work.\n+\t */\n+\tif (repo == the_repository)\n+\t\trepo_set_hash_algo(repo, GIT_HASH_SHA1);\n }\n \n static void expand_base_dir(char **out, const char *in,\ndiff --git a/repository.h b/repository.h\nindex 6f4af15417..41ed22543a 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -207,7 +207,7 @@ void repo_set_worktree(struct repository *repo, const char *path);\n void repo_set_hash_algo(struct repository *repo, int algo);\n void repo_set_compat_hash_algo(struct repository *repo, int compat_algo);\n void repo_set_ref_storage_format(struct repository *repo, unsigned int format);\n-void initialize_the_repository(void);\n+void initialize_repository(struct repository *repo);\n RESULT_MUST_BE_USED\n int repo_init(struct repository *r, const char *gitdir, const char *worktree);\n \ndiff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c\nindex 458efa88a6..e803c43ece 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -9,7 +9,7 @@ int cmd__read_cache(int argc, const char **argv)\n \tint i, cnt = 1;\n \tconst char *name = NULL;\n \n-\tinitialize_the_repository();\n+\tinitialize_repository(the_repository);\n \n \tif (argc > 1 && skip_prefix(argv[1], \"--print-and-refresh=\", &name)) {\n \t\targc--;\n-- \n2.44.GIT\n\n"},{"id":"493126","messageId":"ZiEPF59Ra27ORJ7w@tanuki","threadId":"61321","inReplyTo":"CAOLa=ZQmCWh_UHJ+JWbzd_b=Ob=gUE=5wEKy3gpaxu=Bru+Wvg@mail.gmail.com","subject":"Re: [PATCH 0/5] global: drop external `the_index` variable","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-18T12:16:23Z","receivedAt":"2024-04-18T12:16:27Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Apr 17, 2024 at 10:40:24AM -0700, Karthik Nayak wrote:\n> Hello,\n> \n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > Hi,\n> >\n> > this patch series converts remaining users of `the_index` to stop using\n> > it, instead using `the_repository->index`. This gets rid of one more\n> > global variable and brings a project over the finish line that has\n> > started back in 2007.\n> >\n> > I realize that this patch series is quite large, and that reviewers will\n> > eventually start to just gloss over things because the conversions are\n> > kind of boring, too. Also, due to the size it's quite likely to conflict\n> > with in-flight topics. So if you think that this is too large, please\n> > let me know and I will happily split this up into multiple series.\n> \n> I gave it a glance review. I also wanted to run the tests on each\n> commit, but couldn't apply the series cleanly on either master or next.\n\nHuh, weird. It applies cleanly on top of both 21306a098c (The twentieth\nbatch, 2024-04-16) and 701ccded8b (Merge branch 'rs/apply-reject-long-name'\ninto next, 2024-04-17) for me.\n\nPatrick\n"},{"id":"493127","messageId":"ZiEPHLVhedJCjQjI@tanuki","threadId":"61321","inReplyTo":"CAOLa=ZQHGSvpzupNPTBQ=j8rd7txMWt9mbGQpQUSJTgr-pP5uA@mail.gmail.com","subject":"Re: [PATCH 3/5] repository: initialize index in `repo_init()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-18T12:16:28Z","receivedAt":"2024-04-18T12:16:32Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Apr 17, 2024 at 05:38:29PM +0000, Karthik Nayak wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > Refactor the code and create a common `initialize_repository()` function\n> > that gets called from `repo_init()` and `initialize_the_repository()`.\n> > This function sets up both the repository and the index as required.\n> > Like this, we can easily special-case when `repo_init()` gets called\n> > with `the_repository`.\n> >\n> \n> Nit: `initialize_the_repository()` calling `initialize_repository()`\n> doesn't really indicate what each of them does and why we have two\n> functions which are similarly named but calling each other. Maybe we\n> should rename them?\n\nI think once you know about `the_repository` it isn't all that bad.\nWhereas `initialize_repository()` initializes any repository,\n`initialize_the_repository()` only initializes `the_repository`.\n\nBut you know, let's further simplify this and move all initialization\nlogic into `initialize_repository()` to make this hopefully clearer. And\non top of that we can then also drop `initialize_the_repository()`\ncompletely by statically initializing the `the_repository` pointer so\nthat callers can simply call `initialize_repository(&the_repository)`\ninstead.\n\nPatrick\n"},{"id":"493128","messageId":"ZiEPI-ef8qXD3SqR@tanuki","threadId":"61321","inReplyTo":"CAOLa=ZS2S4=bC=s=vFnSfgvB0jZoKmH2Pi00V1Asyxo_yKSHPA@mail.gmail.com","subject":"Re: [PATCH 2/5] builtin: stop using `the_index`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-18T12:16:35Z","receivedAt":"2024-04-18T12:16:38Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Apr 17, 2024 at 05:32:50PM +0000, Karthik Nayak wrote:\n> [snip]\n> \n> > diff --git a/builtin/cat-file.c b/builtin/cat-file.c\n> > index 0c948f40fb..fe873807ed 100644\n> > --- a/builtin/cat-file.c\n> > +++ b/builtin/cat-file.c\n> > @@ -3,7 +3,6 @@\n> >   *\n> >   * Copyright (C) Linus Torvalds, 2005\n> >   */\n> > -#define USE_THE_INDEX_VARIABLE\n> \n> Nit: The other changes have a newline after the header.\n\nGood catch.\n\nPatrick\n"},{"id":"493154","messageId":"xmqq34ritqdb.fsf@gitster.g","threadId":"61321","inReplyTo":"cover.1713442061.git.ps@pks.im","subject":"Re: [PATCH v2 0/6] global: drop `the_index` variable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-04-18T19:36:32Z","receivedAt":"2024-04-18T19:36:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> this is the second version of my patch series that aims to drop\n> `the_index`.\n>\n> Changes compared to v1:\n>\n>   - This version goes a bit further now and completely drops the\n>     static `the_index` variable, as well. The repository's index gets\n>     allocated dynamically now, like all the other sub-structures like\n>     the ODB.\n>\n>   - This also allows this series to remove `initialize_the_repository()`\n>     now. Instead, callers call `initialize_repository()` now.\n>\n> There is still quite an ugly hack in `initialize_repository()` which\n> requires us to treat `the_repository` specially. This is because\n> `the_hash_algo` maps to `the_repository->hash_algo`, and we rely on it\n> being initialized to SHA1. So we need call `repo_set_hash_algo()` on\n> `the_repository`. On the other hand, we cannot set the hash algo on\n> repos which are not `the_repository`, because that breaks stuff, as\n> well.\n>\n> I'm currently prepping another patch series that builds on top of this\n> series and cleans up this mess. It surfaces several bugs that got masked\n> by our setup, like for example `git rev-parse --short=` not working\n> correctly with SHA256 because we always truncate to the maximum length\n> of SHA1.\n\nI'll take a look, and may even comment on them later, but let me\notherwise place this series on the back burner, not because I am in\nlove with the_index (I am not) and not because I think the \"index\"\nmember in the repository struct is a mistake (I suspect it is, but I\nam not convinced either way), but because I'd prefer to see our tree\nto be quiescent when we apply a tree-wide patch like [2/6], but\nwe'll be in -rc period soonish, during which time we'd want to be\nable to concentrate on fixing regressions without having to worry\nabout being able to reapply such tree-wide changes to keep 'next'\nand 'seen' building.\n\nThanks.\n"},{"id":"493184","messageId":"ZiHyTgb9QrfptexL@tanuki","threadId":"61321","inReplyTo":"xmqq34ritqdb.fsf@gitster.g","subject":"Re: [PATCH v2 0/6] global: drop `the_index` variable","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-04-19T04:25:50Z","receivedAt":"2024-04-19T04:25:54Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Apr 18, 2024 at 12:36:32PM -0700, Junio C Hamano wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > this is the second version of my patch series that aims to drop\n> > `the_index`.\n> >\n> > Changes compared to v1:\n> >\n> >   - This version goes a bit further now and completely drops the\n> >     static `the_index` variable, as well. The repository's index gets\n> >     allocated dynamically now, like all the other sub-structures like\n> >     the ODB.\n> >\n> >   - This also allows this series to remove `initialize_the_repository()`\n> >     now. Instead, callers call `initialize_repository()` now.\n> >\n> > There is still quite an ugly hack in `initialize_repository()` which\n> > requires us to treat `the_repository` specially. This is because\n> > `the_hash_algo` maps to `the_repository->hash_algo`, and we rely on it\n> > being initialized to SHA1. So we need call `repo_set_hash_algo()` on\n> > `the_repository`. On the other hand, we cannot set the hash algo on\n> > repos which are not `the_repository`, because that breaks stuff, as\n> > well.\n> >\n> > I'm currently prepping another patch series that builds on top of this\n> > series and cleans up this mess. It surfaces several bugs that got masked\n> > by our setup, like for example `git rev-parse --short=` not working\n> > correctly with SHA256 because we always truncate to the maximum length\n> > of SHA1.\n> \n> I'll take a look, and may even comment on them later, but let me\n> otherwise place this series on the back burner, not because I am in\n> love with the_index (I am not) and not because I think the \"index\"\n> member in the repository struct is a mistake (I suspect it is, but I\n> am not convinced either way), but because I'd prefer to see our tree\n> to be quiescent when we apply a tree-wide patch like [2/6], but\n> we'll be in -rc period soonish, during which time we'd want to be\n> able to concentrate on fixing regressions without having to worry\n> about being able to reapply such tree-wide changes to keep 'next'\n> and 'seen' building.\n\nMakes sense, thanks!\n\nPatrick\n"}]}