{"thread":{"id":"48719","subject":"[PATCH 00/15] Kill the_index part 1, expose it","startedAt":"2018-06-16T05:42:09Z","lastAt":"2018-07-23T12:56:29Z","messageCount":32,"participants":["Nguyễn Thái Ngọc Duy","Elijah Newren","Duy Nguyen","Brandon Williams","Derrick Stolee","Ben Peart","Junio C Hamano","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":15},"messages":[{"id":"350307","messageId":"20180616054157.32433-1-pclouds@gmail.com","threadId":"48719","inReplyTo":null,"subject":"[PATCH 00/15] Kill the_index part 1, expose it","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:42Z","receivedAt":"2018-06-16T05:42:09Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This is the beginning of the end of the_index. The problem with\nthe_index is it lets library code anywhere access it freely. This is\nnot good because from high level you may not realize that the_index is\nbeing used while you don't want to touch index at all, or you want to\nuse a different index instead.\n\nThis is a long series, 86 patches [1], so I'm going to split and\nsubmit it in 15-20 patches at a time. The first two parts are trivial\nthough and could be safely fast tracked if needed.\n\nThis is the first part, which kills the use of index compat macros\noutside builtin/ and expose the_index in all library code. Later on we\nwill ban the_index from one file each time until it's gone for good.\n\n\"struct index_state *\" will be passed from builtin/ through the call\nchain to the function that needs it. In some cases, \"struct\nrepository *\" will be passed instead when the whole operation spans\nmore than just the index.  By the end, the_index becomes part of\n\"index compat macros\" and cannot be used outside builtin/\n\nPart one is mechanical conversion with the help of coccinelle. The\nonly real patches are the first and the last one.\n\n[1] https://gitlab.com/pclouds/git/commits/really-kill-the-index\n\nNguyễn Thái Ngọc Duy (15):\n  contrib: add cocci script to replace index compat macros\n  apply.c: stop using index compat macros\n  blame.c: stop using index compat macros\n  check-racy.c: stop using index compat macros\n  diff-lib.c: stop using index compat macros\n  diff.c: stop using index compat macros\n  entry.c: stop using index compat macros\n  merge-recursive.c: stop using index compat macros\n  merge.c: stop using index compat macros\n  rerere.c: stop using index compat macros\n  revision.c: stop using index compat macros\n  sequencer.c: stop using index compat macros\n  sha1-name.c: stop using index compat macros\n  wt-status.c: stop using index compat macros\n  cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch\n\n apply.c                               |  34 ++---\n attr.c                                |   1 -\n blame.c                               |  19 +--\n builtin/add.c                         |   1 +\n builtin/am.c                          |   1 +\n builtin/check-attr.c                  |   1 +\n builtin/check-ignore.c                |   1 +\n builtin/checkout-index.c              |   1 +\n builtin/checkout.c                    |   1 +\n builtin/clean.c                       |   1 +\n builtin/commit.c                      |   1 +\n builtin/describe.c                    |   1 +\n builtin/diff-files.c                  |   1 +\n builtin/diff-index.c                  |   1 +\n builtin/diff-tree.c                   |   1 +\n builtin/diff.c                        |   1 +\n builtin/fsck.c                        |   1 +\n builtin/ls-files.c                    |   1 -\n builtin/merge-index.c                 |   1 +\n builtin/merge-ours.c                  |   1 +\n builtin/merge.c                       |   1 +\n builtin/mv.c                          |   1 +\n builtin/pull.c                        |   1 +\n builtin/read-tree.c                   |   1 +\n builtin/reset.c                       |   1 +\n builtin/rev-parse.c                   |   1 +\n builtin/rm.c                          |   1 +\n builtin/submodule--helper.c           |   1 +\n builtin/update-index.c                |   1 +\n cache.h                               |   2 +-\n check-racy.c                          |  10 +-\n contrib/coccinelle/index-compat.cocci | 184 ++++++++++++++++++++++++++\n convert.c                             |   1 -\n diff-lib.c                            |   8 +-\n diff.c                                |  12 +-\n dir.c                                 |   1 -\n entry.c                               |   3 +-\n merge-recursive.c                     |  65 ++++-----\n merge.c                               |  14 +-\n name-hash.c                           |   1 -\n pathspec.c                            |   1 -\n read-cache.c                          |   1 -\n rerere.c                              |  36 ++---\n revision.c                            |  14 +-\n sequencer.c                           |  32 ++---\n sha1-name.c                           |  22 +--\n submodule.c                           |   1 -\n t/helper/test-dump-untracked-cache.c  |   1 +\n t/helper/test-tool.h                  |   2 +\n tree.c                                |   1 -\n unpack-trees.c                        |   1 -\n wt-status.c                           |  24 ++--\n 52 files changed, 363 insertions(+), 154 deletions(-)\n create mode 100644 contrib/coccinelle/index-compat.cocci\n\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350308","messageId":"20180616054157.32433-2-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 01/15] contrib: add cocci script to replace index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:43Z","receivedAt":"2018-06-16T05:42:09Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Index compat macros are going to be removed to expose the_index and\nthen reorganized to use the right index instead of simply the_index\nbecause sometimes we want to use a different index.\n\nThis cocci script can help with the first step. It can be used later\non on even builtin/ when we start to reorganize code in there, but for\nnow this is the script that performs all the conversion outside\nbuiltin/\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n contrib/coccinelle/index-compat.cocci | 184 ++++++++++++++++++++++++++\n 1 file changed, 184 insertions(+)\n create mode 100644 contrib/coccinelle/index-compat.cocci\n\ndiff --git a/contrib/coccinelle/index-compat.cocci b/contrib/coccinelle/index-compat.cocci\nnew file mode 100644\nindex 0000000000..ca46711eb6\n--- /dev/null\n+++ b/contrib/coccinelle/index-compat.cocci\n@@ -0,0 +1,184 @@\n+@@\n+@@\n+-active_cache\n++the_index.cache\n+\n+@@\n+@@\n+-active_nr\n++the_index.cache_nr\n+\n+@@\n+@@\n+-active_alloc\n++the_index.cache_alloc\n+\n+@@\n+@@\n+-active_cache_changed\n++the_index.cache_changed\n+\n+@@\n+@@\n+-active_cache_tree\n++the_index.cache_tree\n+\n+@@\n+@@\n+- read_cache()\n++ read_index(&the_index)\n+\n+@@\n+expression path;\n+@@\n+- read_cache_from(path)\n++ read_index_from(&the_index, path, get_git_dir())\n+\n+@@\n+expression pathspec;\n+@@\n+- read_cache_preload(pathspec)\n++ read_index_preload(&the_index, pathspec)\n+\n+@@\n+@@\n+- is_cache_unborn()\n++ is_index_unborn(&the_index)\n+\n+@@\n+@@\n+- read_cache_unmerged()\n++ read_index_unmerged(&the_index)\n+\n+@@\n+@@\n+- discard_cache()\n++ discard_index(&the_index)\n+\n+@@\n+@@\n+- unmerged_cache()\n++ unmerged_index(&the_index)\n+\n+@@\n+expression name;\n+expression namelen;\n+@@\n+- cache_name_pos(name, namelen)\n++ index_name_pos(&the_index, name, namelen)\n+\n+@@\n+expression ce;\n+expression option;\n+@@\n+- add_cache_entry(ce, option)\n++ add_index_entry(&the_index, ce, option)\n+\n+@@\n+expression pos;\n+expression new_name;\n+@@\n+- rename_cache_entry_at(pos, new_name)\n++ rename_index_entry_at(&the_index, pos, new_name)\n+\n+@@\n+expression pos;\n+@@\n+- remove_cache_entry_at(pos)\n++ remove_index_entry_at(&the_index, pos)\n+\n+@@\n+expression path;\n+@@\n+- remove_file_from_cache(path)\n++ remove_file_from_index(&the_index, path)\n+\n+@@\n+expression path;\n+expression st;\n+expression flags;\n+@@\n+- add_to_cache(path, st, flags)\n++ add_to_index(&the_index, path, st, flags)\n+\n+@@\n+expression path;\n+expression flags;\n+@@\n+- add_file_to_cache(path, flags)\n++ add_file_to_index(&the_index, path, flags)\n+\n+@@\n+expression ce;\n+expression flip;\n+@@\n+-chmod_cache_entry(ce, flip)\n++chmod_index_entry(&the_index, ce, flip)\n+\n+@@\n+expression flags;\n+@@\n+-refresh_cache(flags)\n++refresh_index(&the_index, flags, NULL, NULL, NULL)\n+\n+@@\n+expression ce;\n+expression st;\n+expression options;\n+@@\n+-ce_match_stat(ce, st, options)\n++ie_match_stat(&the_index, ce, st, options)\n+\n+@@\n+expression ce;\n+expression st;\n+expression options;\n+@@\n+-ce_modified(ce, st, options)\n++ie_modified(&the_index, ce, st, options)\n+\n+@@\n+expression name;\n+expression namelen;\n+@@\n+-cache_dir_exists(name, namelen)\n++index_dir_exists(&the_index, name, namelen)\n+\n+@@\n+expression name;\n+expression namelen;\n+expression igncase;\n+@@\n+-cache_file_exists(name, namelen, igncase)\n++index_file_exists(&the_index, name, namelen, igncase)\n+\n+@@\n+expression name;\n+expression namelen;\n+@@\n+-cache_name_is_other(name, namelen)\n++index_name_is_other(&the_index, name, namelen)\n+\n+@@\n+@@\n+-resolve_undo_clear()\n++resolve_undo_clear_index(&the_index)\n+\n+@@\n+expression at;\n+@@\n+-unmerge_cache_entry_at(at)\n++unmerge_index_entry_at(&the_index, at)\n+\n+@@\n+expression pathspec;\n+@@\n+-unmerge_cache(pathspec)\n++unmerge_index(&the_index, pathspec)\n+\n+@@\n+expression path;\n+expression sz;\n+@@\n+-read_blob_data_from_cache(path, sz)\n++read_blob_data_from_index(&the_index, path, sz)\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350309","messageId":"20180616054157.32433-6-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 05/15] diff-lib.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:47Z","receivedAt":"2018-06-16T05:42:16Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff-lib.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/diff-lib.c b/diff-lib.c\nindex 104f954a25..56387e1f63 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -70,7 +70,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt,\n \t\t\t\t     struct stat *st, unsigned ce_option,\n \t\t\t\t     unsigned *dirty_submodule)\n {\n-\tint changed = ce_match_stat(ce, st, ce_option);\n+\tint changed = ie_match_stat(&the_index, ce, st, ce_option);\n \tif (S_ISGITLINK(ce->ce_mode)) {\n \t\tstruct diff_flags orig_flags = diffopt->flags;\n \t\tif (!diffopt->flags.override_submodule_config)\n@@ -98,10 +98,10 @@ int run_diff_files(struct rev_info *revs, unsigned int option)\n \n \tif (diff_unmerged_stage < 0)\n \t\tdiff_unmerged_stage = 2;\n-\tentries = active_nr;\n+\tentries = the_index.cache_nr;\n \tfor (i = 0; i < entries; i++) {\n \t\tunsigned int oldmode, newmode;\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \t\tint changed;\n \t\tunsigned dirty_submodule = 0;\n \t\tconst struct object_id *old_oid, *new_oid;\n@@ -145,7 +145,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)\n \t\t\tdpath->mode = wt_mode;\n \n \t\t\twhile (i < entries) {\n-\t\t\t\tstruct cache_entry *nce = active_cache[i];\n+\t\t\t\tstruct cache_entry *nce = the_index.cache[i];\n \t\t\t\tint stage;\n \n \t\t\t\tif (strcmp(ce->name, nce->name))\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350310","messageId":"20180616054157.32433-12-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 11/15] revision.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:53Z","receivedAt":"2018-06-16T05:42:19Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n revision.c | 14 +++++++-------\n 1 file changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/revision.c b/revision.c\nindex 40fd91ff2b..d56ca57717 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1354,7 +1354,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)\n {\n \tstruct worktree **worktrees, **p;\n \n-\tread_cache();\n+\tread_index(&the_index);\n \tdo_add_index_objects_to_pending(revs, &the_index);\n \n \tif (revs->single_worktree)\n@@ -1495,10 +1495,10 @@ static void prepare_show_merge(struct rev_info *revs)\n \tfree_commit_list(bases);\n \thead->object.flags |= SYMMETRIC_LEFT;\n \n-\tif (!active_nr)\n-\t\tread_cache();\n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tif (!the_index.cache_nr)\n+\t\tread_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 \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \t\tif (ce_path_match(ce, &revs->prune_data, NULL)) {\n@@ -1507,8 +1507,8 @@ static void prepare_show_merge(struct rev_info *revs)\n \t\t\tprune[prune_num-2] = ce->name;\n \t\t\tprune[prune_num-1] = NULL;\n \t\t}\n-\t\twhile ((i+1 < active_nr) &&\n-\t\t       ce_same_name(ce, active_cache[i+1]))\n+\t\twhile ((i+1 < the_index.cache_nr) &&\n+\t\t       ce_same_name(ce, the_index.cache[i+1]))\n \t\t\ti++;\n \t}\n \tclear_pathspec(&revs->prune_data);\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350311","messageId":"20180616054157.32433-5-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 04/15] check-racy.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:46Z","receivedAt":"2018-06-16T05:42:23Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n check-racy.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/check-racy.c b/check-racy.c\nindex 24b6542352..485d7ab8f8 100644\n--- a/check-racy.c\n+++ b/check-racy.c\n@@ -6,9 +6,9 @@ int main(int ac, char **av)\n \tint dirty, clean, racy;\n \n \tdirty = clean = racy = 0;\n-\tread_cache();\n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tread_index(&the_index);\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \t\tstruct stat st;\n \n \t\tif (lstat(ce->name, &st)) {\n@@ -16,9 +16,9 @@ int main(int ac, char **av)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (ce_match_stat(ce, &st, 0))\n+\t\tif (ie_match_stat(&the_index, ce, &st, 0))\n \t\t\tdirty++;\n-\t\telse if (ce_match_stat(ce, &st, CE_MATCH_RACY_IS_DIRTY))\n+\t\telse if (ie_match_stat(&the_index, ce, &st, CE_MATCH_RACY_IS_DIRTY))\n \t\t\tracy++;\n \t\telse\n \t\t\tclean++;\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350312","messageId":"20180616054157.32433-15-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 14/15] wt-status.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:56Z","receivedAt":"2018-06-16T05:42:23Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n wt-status.c | 24 ++++++++++++------------\n 1 file changed, 12 insertions(+), 12 deletions(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex d1c05145a4..9859a43ec8 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -499,14 +499,14 @@ static int unmerged_mask(const char *path)\n \tint pos, mask;\n \tconst struct cache_entry *ce;\n \n-\tpos = cache_name_pos(path, strlen(path));\n+\tpos = index_name_pos(&the_index, path, strlen(path));\n \tif (0 <= pos)\n \t\treturn 0;\n \n \tmask = 0;\n \tpos = -pos-1;\n-\twhile (pos < active_nr) {\n-\t\tce = active_cache[pos++];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tce = the_index.cache[pos++];\n \t\tif (strcmp(ce->name, path) || !ce_stage(ce))\n \t\t\tbreak;\n \t\tmask |= (1 << (ce_stage(ce) - 1));\n@@ -642,10 +642,10 @@ static void wt_status_collect_changes_initial(struct wt_status *s)\n {\n \tint i;\n \n-\tfor (i = 0; i < active_nr; i++) {\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n \t\tstruct string_list_item *it;\n \t\tstruct wt_status_change_data *d;\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \n \t\tif (!ce_path_match(ce, &s->pathspec, NULL))\n \t\t\tcontinue;\n@@ -702,7 +702,7 @@ static void wt_status_collect_untracked(struct wt_status *s)\n \n \tfor (i = 0; i < dir.nr; i++) {\n \t\tstruct dir_entry *ent = dir.entries[i];\n-\t\tif (cache_name_is_other(ent->name, ent->len) &&\n+\t\tif (index_name_is_other(&the_index, ent->name, ent->len) &&\n \t\t    dir_path_match(ent, &s->pathspec, 0, NULL))\n \t\t\tstring_list_insert(&s->untracked, ent->name);\n \t\tfree(ent);\n@@ -710,7 +710,7 @@ static void wt_status_collect_untracked(struct wt_status *s)\n \n \tfor (i = 0; i < dir.ignored_nr; i++) {\n \t\tstruct dir_entry *ent = dir.ignored[i];\n-\t\tif (cache_name_is_other(ent->name, ent->len) &&\n+\t\tif (index_name_is_other(&the_index, ent->name, ent->len) &&\n \t\t    dir_path_match(ent, &s->pathspec, 0, NULL))\n \t\t\tstring_list_insert(&s->ignored, ent->name);\n \t\tfree(ent);\n@@ -2180,11 +2180,11 @@ static void wt_porcelain_v2_print_unmerged_entry(\n \t */\n \tmemset(stages, 0, sizeof(stages));\n \tsum = 0;\n-\tpos = cache_name_pos(it->string, strlen(it->string));\n+\tpos = index_name_pos(&the_index, it->string, strlen(it->string));\n \tassert(pos < 0);\n \tpos = -pos-1;\n-\twhile (pos < active_nr) {\n-\t\tce = active_cache[pos++];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tce = the_index.cache[pos++];\n \t\tstage = ce_stage(ce);\n \t\tif (strcmp(ce->name, it->string) || !stage)\n \t\t\tbreak;\n@@ -2333,7 +2333,7 @@ int has_uncommitted_changes(int ignore_submodules)\n \tstruct rev_info rev_info;\n \tint result;\n \n-\tif (is_cache_unborn())\n+\tif (is_index_unborn(&the_index))\n \t\treturn 0;\n \n \tinit_revisions(&rev_info, NULL);\n@@ -2356,7 +2356,7 @@ int require_clean_work_tree(const char *action, const char *hint, int ignore_sub\n \tint err = 0, fd;\n \n \tfd = hold_locked_index(&lock_file, 0);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \tif (0 <= fd)\n \t\tupdate_index_if_able(&the_index, &lock_file);\n \trollback_lock_file(&lock_file);\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350313","messageId":"20180616054157.32433-11-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 10/15] rerere.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:52Z","receivedAt":"2018-06-16T05:42:27Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n rerere.c | 36 ++++++++++++++++++------------------\n 1 file changed, 18 insertions(+), 18 deletions(-)\n\ndiff --git a/rerere.c b/rerere.c\nindex e0862e2778..810e86d246 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -524,7 +524,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output\n  */\n static int check_one_conflict(int i, int *type)\n {\n-\tconst struct cache_entry *e = active_cache[i];\n+\tconst struct cache_entry *e = the_index.cache[i];\n \n \tif (!ce_stage(e)) {\n \t\t*type = RESOLVED;\n@@ -532,13 +532,13 @@ static int check_one_conflict(int i, int *type)\n \t}\n \n \t*type = PUNTED;\n-\twhile (ce_stage(active_cache[i]) == 1)\n+\twhile (ce_stage(the_index.cache[i]) == 1)\n \t\ti++;\n \n \t/* Only handle regular files with both stages #2 and #3 */\n-\tif (i + 1 < active_nr) {\n-\t\tconst struct cache_entry *e2 = active_cache[i];\n-\t\tconst struct cache_entry *e3 = active_cache[i + 1];\n+\tif (i + 1 < the_index.cache_nr) {\n+\t\tconst struct cache_entry *e2 = the_index.cache[i];\n+\t\tconst struct cache_entry *e3 = the_index.cache[i + 1];\n \t\tif (ce_stage(e2) == 2 &&\n \t\t    ce_stage(e3) == 3 &&\n \t\t    ce_same_name(e, e3) &&\n@@ -548,7 +548,7 @@ static int check_one_conflict(int i, int *type)\n \t}\n \n \t/* Skip the entries with the same name */\n-\twhile (i < active_nr && ce_same_name(e, active_cache[i]))\n+\twhile (i < the_index.cache_nr && ce_same_name(e, the_index.cache[i]))\n \t\ti++;\n \treturn i;\n }\n@@ -567,12 +567,12 @@ static int check_one_conflict(int i, int *type)\n static int find_conflict(struct string_list *conflict)\n {\n \tint i;\n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\treturn error(\"Could not read index\");\n \n-\tfor (i = 0; i < active_nr;) {\n+\tfor (i = 0; i < the_index.cache_nr;) {\n \t\tint conflict_type;\n-\t\tconst struct cache_entry *e = active_cache[i];\n+\t\tconst struct cache_entry *e = the_index.cache[i];\n \t\ti = check_one_conflict(i, &conflict_type);\n \t\tif (conflict_type == THREE_STAGED)\n \t\t\tstring_list_insert(conflict, (const char *)e->name);\n@@ -600,12 +600,12 @@ int rerere_remaining(struct string_list *merge_rr)\n \tint i;\n \tif (setup_rerere(merge_rr, RERERE_READONLY))\n \t\treturn 0;\n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\treturn error(\"Could not read index\");\n \n-\tfor (i = 0; i < active_nr;) {\n+\tfor (i = 0; i < the_index.cache_nr;) {\n \t\tint conflict_type;\n-\t\tconst struct cache_entry *e = active_cache[i];\n+\t\tconst struct cache_entry *e = the_index.cache[i];\n \t\ti = check_one_conflict(i, &conflict_type);\n \t\tif (conflict_type == PUNTED)\n \t\t\tstring_list_insert(merge_rr, (const char *)e->name);\n@@ -712,7 +712,7 @@ static void update_paths(struct string_list *update)\n \n \tfor (i = 0; i < update->nr; i++) {\n \t\tstruct string_list_item *item = &update->items[i];\n-\t\tif (add_file_to_cache(item->string, 0))\n+\t\tif (add_file_to_index(&the_index, item->string, 0))\n \t\t\texit(128);\n \t\tfprintf(stderr, \"Staged '%s' using previous resolution.\\n\",\n \t\t\titem->string);\n@@ -964,16 +964,16 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu\n \t * Reproduce the conflicted merge in-core\n \t */\n \tlen = strlen(path);\n-\tpos = cache_name_pos(path, len);\n+\tpos = index_name_pos(&the_index, path, len);\n \tif (0 <= pos)\n \t\treturn -1;\n \tpos = -pos - 1;\n \n-\twhile (pos < active_nr) {\n+\twhile (pos < the_index.cache_nr) {\n \t\tenum object_type type;\n \t\tunsigned long size;\n \n-\t\tce = active_cache[pos++];\n+\t\tce = the_index.cache[pos++];\n \t\tif (ce_namelen(ce) != len || memcmp(ce->name, path, len))\n \t\t\tbreak;\n \t\ti = ce_stage(ce) - 1;\n@@ -1102,7 +1102,7 @@ int rerere_forget(struct pathspec *pathspec)\n \tstruct string_list conflict = STRING_LIST_INIT_DUP;\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\treturn error(\"Could not read index\");\n \n \tfd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE);\n@@ -1114,7 +1114,7 @@ int rerere_forget(struct pathspec *pathspec)\n \t * recover the original conflicted state and then\n \t * find the conflicted paths.\n \t */\n-\tunmerge_cache(pathspec);\n+\tunmerge_index(&the_index, pathspec);\n \tfind_conflict(&conflict);\n \tfor (i = 0; i < conflict.nr; i++) {\n \t\tstruct string_list_item *it = &conflict.items[i];\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350314","messageId":"20180616054157.32433-13-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 12/15] sequencer.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:54Z","receivedAt":"2018-06-16T05:42:29Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n sequencer.c | 32 ++++++++++++++++----------------\n 1 file changed, 16 insertions(+), 16 deletions(-)\n\ndiff --git a/sequencer.c b/sequencer.c\nindex cca968043e..ed8af2a4cd 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -435,7 +435,7 @@ static struct tree *empty_tree(void)\n \n static int error_dirty_index(struct replay_opts *opts)\n {\n-\tif (read_cache_unmerged())\n+\tif (read_index_unmerged(&the_index))\n \t\treturn error_resolve_conflict(_(action_name(opts)));\n \n \terror(_(\"your local changes would be overwritten by %s.\"),\n@@ -467,7 +467,7 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct strbuf err = STRBUF_INIT;\n \n-\tread_cache();\n+\tread_index(&the_index);\n \tif (checkout_fast_forward(from, to, 1))\n \t\treturn -1; /* the callee should have complained already */\n \n@@ -500,12 +500,12 @@ void append_conflicts_hint(struct strbuf *msgbuf)\n \n \tstrbuf_addch(msgbuf, '\\n');\n \tstrbuf_commented_addf(msgbuf, \"Conflicts:\\n\");\n-\tfor (i = 0; i < active_nr;) {\n-\t\tconst struct cache_entry *ce = active_cache[i++];\n+\tfor (i = 0; i < the_index.cache_nr;) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i++];\n \t\tif (ce_stage(ce)) {\n \t\t\tstrbuf_commented_addf(msgbuf, \"\\t%s\\n\", ce->name);\n-\t\t\twhile (i < active_nr && !strcmp(ce->name,\n-\t\t\t\t\t\t\tactive_cache[i]->name))\n+\t\t\twhile (i < the_index.cache_nr && !strcmp(ce->name,\n+\t\t\t\t\t\t\t\t the_index.cache[i]->name))\n \t\t\t\ti++;\n \t\t}\n \t}\n@@ -525,7 +525,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,\n \tif (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n \n-\tread_cache();\n+\tread_index(&the_index);\n \n \tinit_merge_options(&o);\n \to.ancestor = base ? base_label : \"(empty tree)\";\n@@ -571,16 +571,16 @@ static int do_recursive_merge(struct commit *base, struct commit *next,\n \n static struct object_id *get_cache_tree_oid(void)\n {\n-\tif (!active_cache_tree)\n-\t\tactive_cache_tree = cache_tree();\n+\tif (!the_index.cache_tree)\n+\t\tthe_index.cache_tree = cache_tree();\n \n-\tif (!cache_tree_fully_valid(active_cache_tree))\n+\tif (!cache_tree_fully_valid(the_index.cache_tree))\n \t\tif (cache_tree_update(&the_index, 0)) {\n \t\t\terror(_(\"unable to update cache tree\"));\n \t\t\treturn NULL;\n \t\t}\n \n-\treturn &active_cache_tree->oid;\n+\treturn &the_index.cache_tree->oid;\n }\n \n static int is_index_unchanged(void)\n@@ -1644,7 +1644,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\t\t\t       NULL, 0))\n \t\t\treturn error_dirty_index(opts);\n \t}\n-\tdiscard_cache();\n+\tdiscard_index(&the_index);\n \n \tif (!commit->parents)\n \t\tparent = NULL;\n@@ -2637,7 +2637,7 @@ static int do_exec(const char *command_line)\n \t\t\t\t\t  child_env.argv);\n \n \t/* force re-reading of the cache */\n-\tif (discard_cache() < 0 || read_cache() < 0)\n+\tif (discard_index(&the_index) < 0 || read_index(&the_index) < 0)\n \t\treturn error(_(\"could not read index\"));\n \n \tdirty = require_clean_work_tree(\"rebase\", NULL, 1, 1);\n@@ -2801,7 +2801,7 @@ static int do_reset(const char *name, int len, struct replay_opts *opts)\n \tunpack_tree_opts.merge = 1;\n \tunpack_tree_opts.update = 1;\n \n-\tif (read_cache_unmerged()) {\n+\tif (read_index_unmerged(&the_index)) {\n \t\trollback_lock_file(&lock);\n \t\tstrbuf_release(&ref_name);\n \t\treturn error_resolve_conflict(_(action_name(opts)));\n@@ -2991,7 +2991,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t\tcommit_list_insert(j->item, &reversed);\n \tfree_commit_list(bases);\n \n-\tread_cache();\n+\tread_index(&the_index);\n \tinit_merge_options(&o);\n \to.branch1 = \"HEAD\";\n \to.branch2 = ref_name.buf;\n@@ -3016,7 +3016,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t */\n \tret = !ret;\n \n-\tif (active_cache_changed &&\n+\tif (the_index.cache_changed &&\n \t    write_locked_index(&the_index, &lock, COMMIT_LOCK)) {\n \t\tret = error(_(\"merge: Unable to write new index file\"));\n \t\tgoto leave_merge;\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350315","messageId":"20180616054157.32433-14-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 13/15] sha1-name.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:55Z","receivedAt":"2018-06-16T05:42:32Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n sha1-name.c | 22 +++++++++++-----------\n 1 file changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 60d9ef3c7e..8344d9a9e0 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1560,11 +1560,11 @@ static void diagnose_invalid_index_path(int stage,\n \t\tprefix = \"\";\n \n \t/* Wrong stage number? */\n-\tpos = cache_name_pos(filename, namelen);\n+\tpos = index_name_pos(&the_index, filename, namelen);\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n-\tif (pos < active_nr) {\n-\t\tce = active_cache[pos];\n+\tif (pos < the_index.cache_nr) {\n+\t\tce = the_index.cache[pos];\n \t\tif (ce_namelen(ce) == namelen &&\n \t\t    !memcmp(ce->name, filename, namelen))\n \t\t\tdie(\"Path '%s' is in the index, but not at stage %d.\\n\"\n@@ -1576,11 +1576,11 @@ static void diagnose_invalid_index_path(int stage,\n \t/* Confusion between relative and absolute filenames? */\n \tstrbuf_addstr(&fullname, prefix);\n \tstrbuf_addstr(&fullname, filename);\n-\tpos = cache_name_pos(fullname.buf, fullname.len);\n+\tpos = index_name_pos(&the_index, fullname.buf, fullname.len);\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n-\tif (pos < active_nr) {\n-\t\tce = active_cache[pos];\n+\tif (pos < the_index.cache_nr) {\n+\t\tce = the_index.cache[pos];\n \t\tif (ce_namelen(ce) == fullname.len &&\n \t\t    !memcmp(ce->name, fullname.buf, fullname.len))\n \t\t\tdie(\"Path '%s' is in the index, but not '%s'.\\n\"\n@@ -1672,13 +1672,13 @@ static int get_oid_with_context_1(const char *name,\n \t\tif (flags & GET_OID_RECORD_PATH)\n \t\t\toc->path = xstrdup(cp);\n \n-\t\tif (!active_cache)\n-\t\t\tread_cache();\n-\t\tpos = cache_name_pos(cp, namelen);\n+\t\tif (!the_index.cache)\n+\t\t\tread_index(&the_index);\n+\t\tpos = index_name_pos(&the_index, cp, namelen);\n \t\tif (pos < 0)\n \t\t\tpos = -pos - 1;\n-\t\twhile (pos < active_nr) {\n-\t\t\tce = active_cache[pos];\n+\t\twhile (pos < the_index.cache_nr) {\n+\t\t\tce = the_index.cache[pos];\n \t\t\tif (ce_namelen(ce) != namelen ||\n \t\t\t    memcmp(ce->name, cp, namelen))\n \t\t\t\tbreak;\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350316","messageId":"20180616054157.32433-4-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 03/15] blame.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:45Z","receivedAt":"2018-06-16T05:42:35Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n blame.c | 19 ++++++++++---------\n 1 file changed, 10 insertions(+), 9 deletions(-)\n\ndiff --git a/blame.c b/blame.c\nindex 14d0e0b575..c357cf2f49 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -85,11 +85,11 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)\n \t\t\treturn;\n \t}\n \n-\tpos = cache_name_pos(path, strlen(path));\n+\tpos = index_name_pos(&the_index, path, strlen(path));\n \tif (pos >= 0)\n \t\t; /* path is in the index */\n-\telse if (-1 - pos < active_nr &&\n-\t\t !strcmp(active_cache[-1 - pos]->name, path))\n+\telse if (-1 - pos < the_index.cache_nr &&\n+\t\t !strcmp(the_index.cache[-1 - pos]->name, path))\n \t\t; /* path is in the index, unmerged */\n \telse\n \t\tdie(\"no such path '%s' in HEAD\", path);\n@@ -159,7 +159,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \tunsigned mode;\n \tstruct strbuf msg = STRBUF_INIT;\n \n-\tread_cache();\n+\tread_index(&the_index);\n \ttime(&now);\n \tcommit = alloc_commit_node();\n \tcommit->object.parsed = 1;\n@@ -240,14 +240,14 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \t * bits; we are not going to write this index out -- we just\n \t * want to run \"diff-index --cached\".\n \t */\n-\tdiscard_cache();\n-\tread_cache();\n+\tdiscard_index(&the_index);\n+\tread_index(&the_index);\n \n \tlen = strlen(path);\n \tif (!mode) {\n-\t\tint pos = cache_name_pos(path, len);\n+\t\tint pos = index_name_pos(&the_index, path, len);\n \t\tif (0 <= pos)\n-\t\t\tmode = active_cache[pos]->ce_mode;\n+\t\t\tmode = the_index.cache[pos]->ce_mode;\n \t\telse\n \t\t\t/* Let's not bother reading from HEAD tree */\n \t\t\tmode = S_IFREG | 0644;\n@@ -259,7 +259,8 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \tce->ce_flags = create_ce_flags(0);\n \tce->ce_namelen = len;\n \tce->ce_mode = create_ce_mode(mode);\n-\tadd_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);\n+\tadd_index_entry(&the_index, ce,\n+\t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \n \tcache_tree_invalidate_path(&the_index, path);\n \n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350317","messageId":"20180616054157.32433-9-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 08/15] merge-recursive.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:50Z","receivedAt":"2018-06-16T05:42:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n merge-recursive.c | 65 ++++++++++++++++++++++++-----------------------\n 1 file changed, 33 insertions(+), 32 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 5eb907f46e..2a9dfe3b33 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -319,7 +319,7 @@ static int add_cacheinfo(struct merge_options *o,\n \tif (!ce)\n \t\treturn err(o, _(\"add_cacheinfo failed for path '%s'; merge aborting.\"), path);\n \n-\tret = add_cache_entry(ce, options);\n+\tret = add_index_entry(&the_index, ce, options);\n \tif (refresh) {\n \t\tstruct cache_entry *nce;\n \n@@ -327,7 +327,7 @@ static int add_cacheinfo(struct merge_options *o,\n \t\tif (!nce)\n \t\t\treturn err(o, _(\"add_cacheinfo failed to refresh for path '%s'; merge aborting.\"), path);\n \t\tif (nce != ce)\n-\t\t\tret = add_cache_entry(nce, options);\n+\t\t\tret = add_index_entry(&the_index, nce, options);\n \t}\n \treturn ret;\n }\n@@ -365,7 +365,7 @@ static int unpack_trees_start(struct merge_options *o,\n \tinit_tree_desc_from_tree(t+2, merge);\n \n \trc = unpack_trees(3, t, &o->unpack_opts);\n-\tcache_tree_free(&active_cache_tree);\n+\tcache_tree_free(&the_index.cache_tree);\n \n \t/*\n \t * Update the_index to match the new results, AFTER saving a copy\n@@ -390,11 +390,11 @@ struct tree *write_tree_from_memory(struct merge_options *o)\n {\n \tstruct tree *result = NULL;\n \n-\tif (unmerged_cache()) {\n+\tif (unmerged_index(&the_index)) {\n \t\tint i;\n \t\tfprintf(stderr, \"BUG: There are unmerged index entries:\\n\");\n-\t\tfor (i = 0; i < active_nr; i++) {\n-\t\t\tconst struct cache_entry *ce = active_cache[i];\n+\t\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\t\tconst struct cache_entry *ce = the_index.cache[i];\n \t\t\tif (ce_stage(ce))\n \t\t\t\tfprintf(stderr, \"BUG: %d %.*s\\n\", ce_stage(ce),\n \t\t\t\t\t(int)ce_namelen(ce), ce->name);\n@@ -402,16 +402,16 @@ struct tree *write_tree_from_memory(struct merge_options *o)\n \t\tBUG(\"unmerged index entries in merge-recursive.c\");\n \t}\n \n-\tif (!active_cache_tree)\n-\t\tactive_cache_tree = cache_tree();\n+\tif (!the_index.cache_tree)\n+\t\tthe_index.cache_tree = cache_tree();\n \n-\tif (!cache_tree_fully_valid(active_cache_tree) &&\n+\tif (!cache_tree_fully_valid(the_index.cache_tree) &&\n \t    cache_tree_update(&the_index, 0) < 0) {\n \t\terr(o, _(\"error building trees\"));\n \t\treturn NULL;\n \t}\n \n-\tresult = lookup_tree(&active_cache_tree->oid);\n+\tresult = lookup_tree(&the_index.cache_tree->oid);\n \n \treturn result;\n }\n@@ -488,10 +488,10 @@ static struct string_list *get_unmerged(void)\n \n \tunmerged->strdup_strings = 1;\n \n-\tfor (i = 0; i < active_nr; i++) {\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n \t\tstruct string_list_item *item;\n \t\tstruct stage_data *e;\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \n@@ -651,7 +651,7 @@ static int update_stages(struct merge_options *opt, const char *path,\n \tint clear = 1;\n \tint options = ADD_CACHE_OK_TO_ADD | ADD_CACHE_SKIP_DFCHECK;\n \tif (clear)\n-\t\tif (remove_file_from_cache(path))\n+\t\tif (remove_file_from_index(&the_index, path))\n \t\t\treturn -1;\n \tif (o)\n \t\tif (add_cacheinfo(opt, o->mode, &o->oid, path, 1, 0, options))\n@@ -707,13 +707,14 @@ static int remove_file(struct merge_options *o, int clean,\n \tint update_working_directory = !o->call_depth && !no_wd;\n \n \tif (update_cache) {\n-\t\tif (remove_file_from_cache(path))\n+\t\tif (remove_file_from_index(&the_index, path))\n \t\t\treturn -1;\n \t}\n \tif (update_working_directory) {\n \t\tif (ignore_case) {\n \t\t\tstruct cache_entry *ce;\n-\t\t\tce = cache_file_exists(path, strlen(path), ignore_case);\n+\t\t\tce = index_file_exists(&the_index, path, strlen(path),\n+\t\t\t\t\t       ignore_case);\n \t\t\tif (ce && ce_stage(ce) == 0 && strcmp(path, ce->name))\n \t\t\t\treturn 0;\n \t\t}\n@@ -772,12 +773,12 @@ static int dir_in_way(const char *path, int check_working_copy, int empty_ok)\n \tstrbuf_addstr(&dirpath, path);\n \tstrbuf_addch(&dirpath, '/');\n \n-\tpos = cache_name_pos(dirpath.buf, dirpath.len);\n+\tpos = index_name_pos(&the_index, dirpath.buf, dirpath.len);\n \n \tif (pos < 0)\n \t\tpos = -1 - pos;\n-\tif (pos < active_nr &&\n-\t    !strncmp(dirpath.buf, active_cache[pos]->name, dirpath.len)) {\n+\tif (pos < the_index.cache_nr &&\n+\t    !strncmp(dirpath.buf, the_index.cache[pos]->name, dirpath.len)) {\n \t\tstrbuf_release(&dirpath);\n \t\treturn 1;\n \t}\n@@ -839,19 +840,19 @@ static int would_lose_untracked(const char *path)\n \t * update_file()/would_lose_untracked(); see every comment in this\n \t * file which mentions \"update_stages\".\n \t */\n-\tint pos = cache_name_pos(path, strlen(path));\n+\tint pos = index_name_pos(&the_index, path, strlen(path));\n \n \tif (pos < 0)\n \t\tpos = -1 - pos;\n-\twhile (pos < active_nr &&\n-\t       !strcmp(path, active_cache[pos]->name)) {\n+\twhile (pos < the_index.cache_nr &&\n+\t       !strcmp(path, the_index.cache[pos]->name)) {\n \t\t/*\n \t\t * If stage #0, it is definitely tracked.\n \t\t * If it has stage #2 then it was tracked\n \t\t * before this merge started.  All other\n \t\t * cases the path was not tracked.\n \t\t */\n-\t\tswitch (ce_stage(active_cache[pos])) {\n+\t\tswitch (ce_stage(the_index.cache[pos])) {\n \t\tcase 0:\n \t\tcase 2:\n \t\t\treturn 0;\n@@ -1466,7 +1467,7 @@ static int handle_change_delete(struct merge_options *o,\n \t\t * correct; since there is no true \"middle point\" between\n \t\t * them, simply reuse the base version for virtual merge base.\n \t\t */\n-\t\tret = remove_file_from_cache(path);\n+\t\tret = remove_file_from_index(&the_index, path);\n \t\tif (!ret)\n \t\t\tret = update_file(o, 0, o_oid, o_mode, update_path);\n \t} else {\n@@ -1527,7 +1528,7 @@ static int conflict_rename_delete(struct merge_options *o,\n \t\treturn -1;\n \n \tif (o->call_depth)\n-\t\treturn remove_file_from_cache(dest->path);\n+\t\treturn remove_file_from_index(&the_index, dest->path);\n \telse\n \t\treturn update_stages(o, dest->path, NULL,\n \t\t\t\t     rename_branch == o->branch1 ? dest : NULL,\n@@ -1662,14 +1663,14 @@ static int conflict_rename_rename_1to2(struct merge_options *o,\n \t\t\t\treturn -1;\n \t\t}\n \t\telse\n-\t\t\tremove_file_from_cache(a->path);\n+\t\t\tremove_file_from_index(&the_index, a->path);\n \t\tadd = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);\n \t\tif (add) {\n \t\t\tif (update_file(o, 0, &add->oid, add->mode, b->path))\n \t\t\t\treturn -1;\n \t\t}\n \t\telse\n-\t\t\tremove_file_from_cache(b->path);\n+\t\t\tremove_file_from_index(&the_index, b->path);\n \t} else if (handle_file(o, a, 2, ci) || handle_file(o, b, 3, ci))\n \t\treturn -1;\n \n@@ -3063,7 +3064,7 @@ static int merge_content(struct merge_options *o,\n \tif (df_conflict_remains || is_dirty) {\n \t\tchar *new_path;\n \t\tif (o->call_depth) {\n-\t\t\tremove_file_from_cache(path);\n+\t\t\tremove_file_from_index(&the_index, path);\n \t\t} else {\n \t\t\tif (!mfi.clean) {\n \t\t\t\tif (update_stages(o, path, &one, &a, &b))\n@@ -3220,7 +3221,7 @@ static int process_entry(struct merge_options *o,\n \t\t\tif (update_file(o, 0, oid, mode, new_path))\n \t\t\t\tclean_merge = -1;\n \t\t\telse if (o->call_depth)\n-\t\t\t\tremove_file_from_cache(path);\n+\t\t\t\tremove_file_from_index(&the_index, path);\n \t\t\tfree(new_path);\n \t\t} else {\n \t\t\toutput(o, 2, _(\"Adding %s\"), path);\n@@ -3284,7 +3285,7 @@ int merge_trees(struct merge_options *o,\n \t\treturn -1;\n \t}\n \n-\tif (unmerged_cache()) {\n+\tif (unmerged_index(&the_index)) {\n \t\tstruct string_list *entries;\n \t\tstruct rename_info re_info;\n \t\tint i;\n@@ -3415,7 +3416,7 @@ int merge_recursive(struct merge_options *o,\n \t\t * overwritten it: the committed \"conflicts\" were\n \t\t * already resolved.\n \t\t */\n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t\tsaved_b1 = o->branch1;\n \t\tsaved_b2 = o->branch2;\n \t\to->branch1 = \"Temporary merge branch 1\";\n@@ -3431,9 +3432,9 @@ int merge_recursive(struct merge_options *o,\n \t\t\treturn err(o, _(\"merge returned no commit\"));\n \t}\n \n-\tdiscard_cache();\n+\tdiscard_index(&the_index);\n \tif (!o->call_depth)\n-\t\tread_cache();\n+\t\tread_index(&the_index);\n \n \to->ancestor = \"merged common ancestors\";\n \tclean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350318","messageId":"20180616054157.32433-10-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 09/15] merge.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:51Z","receivedAt":"2018-06-16T05:42:41Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n merge.c | 14 +++++++-------\n 1 file changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/merge.c b/merge.c\nindex 0783858739..21e6dc09be 100644\n--- a/merge.c\n+++ b/merge.c\n@@ -36,12 +36,12 @@ int index_has_changes(struct strbuf *sb)\n \t\tdiff_flush(&opt);\n \t\treturn opt.flags.has_changes != 0;\n \t} else {\n-\t\tfor (i = 0; sb && i < active_nr; i++) {\n+\t\tfor (i = 0; sb && i < the_index.cache_nr; i++) {\n \t\t\tif (i)\n \t\t\t\tstrbuf_addch(sb, ' ');\n-\t\t\tstrbuf_addstr(sb, active_cache[i]->name);\n+\t\t\tstrbuf_addstr(sb, the_index.cache[i]->name);\n \t\t}\n-\t\treturn !!active_nr;\n+\t\treturn !!the_index.cache_nr;\n \t}\n }\n \n@@ -66,10 +66,10 @@ int try_merge_command(const char *strategy, size_t xopts_nr,\n \tret = run_command_v_opt(args.argv, RUN_GIT_CMD);\n \targv_array_clear(&args);\n \n-\tdiscard_cache();\n-\tif (read_cache() < 0)\n+\tdiscard_index(&the_index);\n+\tif (read_index(&the_index) < 0)\n \t\tdie(_(\"failed to read the cache\"));\n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \n \treturn ret;\n }\n@@ -85,7 +85,7 @@ int checkout_fast_forward(const struct object_id *head,\n \tstruct dir_struct dir;\n \tstruct lock_file lock_file = LOCK_INIT;\n \n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \n \tif (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350319","messageId":"20180616054157.32433-16-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 15/15] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:57Z","receivedAt":"2018-06-16T05:42:42Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"From now on, by default index compat macros are off because they could\nhide the_index dependency. Only those in builtin can use it (and even\nso should be avoided if possible).\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n attr.c                               | 1 -\n builtin/add.c                        | 1 +\n builtin/am.c                         | 1 +\n builtin/check-attr.c                 | 1 +\n builtin/check-ignore.c               | 1 +\n builtin/checkout-index.c             | 1 +\n builtin/checkout.c                   | 1 +\n builtin/clean.c                      | 1 +\n builtin/commit.c                     | 1 +\n builtin/describe.c                   | 1 +\n builtin/diff-files.c                 | 1 +\n builtin/diff-index.c                 | 1 +\n builtin/diff-tree.c                  | 1 +\n builtin/diff.c                       | 1 +\n builtin/fsck.c                       | 1 +\n builtin/ls-files.c                   | 1 -\n builtin/merge-index.c                | 1 +\n builtin/merge-ours.c                 | 1 +\n builtin/merge.c                      | 1 +\n builtin/mv.c                         | 1 +\n builtin/pull.c                       | 1 +\n builtin/read-tree.c                  | 1 +\n builtin/reset.c                      | 1 +\n builtin/rev-parse.c                  | 1 +\n builtin/rm.c                         | 1 +\n builtin/submodule--helper.c          | 1 +\n builtin/update-index.c               | 1 +\n cache.h                              | 2 +-\n convert.c                            | 1 -\n dir.c                                | 1 -\n name-hash.c                          | 1 -\n pathspec.c                           | 1 -\n read-cache.c                         | 1 -\n submodule.c                          | 1 -\n t/helper/test-dump-untracked-cache.c | 1 +\n t/helper/test-tool.h                 | 2 ++\n tree.c                               | 1 -\n unpack-trees.c                       | 1 -\n 38 files changed, 29 insertions(+), 11 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex 067fb9e0c0..d16625661d 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -7,7 +7,6 @@\n  * an insanely large number of attributes.\n  */\n \n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"exec-cmd.h\"\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 8a155dd41e..b93193c3fe 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -3,6 +3,7 @@\n  *\n  * Copyright (C) 2006 Linus Torvalds\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 2fc2d1e82c..28af59d183 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -3,6 +3,7 @@\n  *\n  * Based on git-am.sh by Junio C Hamano.\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/check-attr.c b/builtin/check-attr.c\nindex 91444dc044..d9cebd5382 100644\n--- a/builtin/check-attr.c\n+++ b/builtin/check-attr.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex ec9a959e08..599097304b 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex a730f6a1aa..e38ad42dbf 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -4,6 +4,7 @@\n  * Copyright (C) 2005 Linus Torvalds\n  *\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 2e1d2376d2..2250611407 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"checkout.h\"\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex fad533a0a7..2258379ecc 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -6,6 +6,7 @@\n  * Based on git-clean.sh by Pavel Roskin\n  */\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex a842fea666..98a5b4a8c8 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -5,6 +5,7 @@\n  * Based on git-commit.sh by Junio C Hamano and Linus Torvalds\n  */\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex cf1ae77d7c..4ca234972e 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/diff-files.c b/builtin/diff-files.c\nindex e88493ffe5..af706b4fce 100644\n--- a/builtin/diff-files.c\n+++ b/builtin/diff-files.c\n@@ -3,6 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"diff.h\"\ndiff --git a/builtin/diff-index.c b/builtin/diff-index.c\nindex 522f4fdffd..c026ffb95e 100644\n--- a/builtin/diff-index.c\n+++ b/builtin/diff-index.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"diff.h\"\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex 473615117e..bd2264ed5c 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"diff.h\"\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex bfefff3a84..17d7d5c9f5 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -3,6 +3,7 @@\n  *\n  * Copyright (c) 2006 Junio C Hamano\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 3ad4f160f9..33cb71d269 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"repository.h\"\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 88bb2019ad..dbf5d13d91 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -5,7 +5,6 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"repository.h\"\n #include \"config.h\"\ndiff --git a/builtin/merge-index.c b/builtin/merge-index.c\nindex c99443b095..38ea6ad6ca 100644\n--- a/builtin/merge-index.c\n+++ b/builtin/merge-index.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"run-command.h\"\n \ndiff --git a/builtin/merge-ours.c b/builtin/merge-ours.c\nindex c84c6e05e9..7c4a80ed3b 100644\n--- a/builtin/merge-ours.c\n+++ b/builtin/merge-ours.c\n@@ -7,6 +7,7 @@\n  *\n  * Pretend we resolved the heads, but declare our tree trumps everybody else.\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"git-compat-util.h\"\n #include \"builtin.h\"\n #include \"diff.h\"\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex b00d6f4821..1b540e2194 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -6,6 +6,7 @@\n  * Based on git-merge.sh by Junio C Hamano.\n  */\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 80bb967a63..be15ba7044 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -3,6 +3,7 @@\n  *\n  * Copyright (C) 2006 Johannes Schindelin\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"pathspec.h\"\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 1f2ecf3a88..1c3657dee2 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -5,6 +5,7 @@\n  *\n  * Fetch one or more remote refs and merge it/them into the current HEAD.\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/read-tree.c b/builtin/read-tree.c\nindex ebc43eb805..ae6ca3a8c5 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -4,6 +4,7 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex a862c70fab..dd60eec9d6 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -7,6 +7,7 @@\n  *\n  * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 4f49e96bfd..b5f8d6a83d 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -3,6 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"commit.h\"\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 65b448ef8e..e5b77e429d 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -3,6 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds 2006\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex bd250ca216..8abe15144b 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"repository.h\"\n #include \"cache.h\"\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex a8709a26ec..36e837248f 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -3,6 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/cache.h b/cache.h\nindex 89a107a7f7..b3a6d14a36 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -339,7 +339,7 @@ extern void remove_name_hash(struct index_state *istate, struct cache_entry *ce)\n extern void free_name_hash(struct index_state *istate);\n \n \n-#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS\n+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n #define active_cache (the_index.cache)\n #define active_nr (the_index.cache_nr)\n #define active_alloc (the_index.cache_alloc)\ndiff --git a/convert.c b/convert.c\nindex 64d0d30e08..0895dc5994 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -1,4 +1,3 @@\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"attr.h\"\ndiff --git a/dir.c b/dir.c\nindex ccf8b4975e..473c47eb2f 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -7,7 +7,6 @@\n  * Copyright (C) Linus Torvalds, 2005-2006\n  *\t\t Junio Hamano, 2005-2006\n  */\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"dir.h\"\ndiff --git a/name-hash.c b/name-hash.c\nindex 163849831c..12eaa62980 100644\n--- a/name-hash.c\n+++ b/name-hash.c\n@@ -5,7 +5,6 @@\n  *\n  * Copyright (C) 2008 Linus Torvalds\n  */\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n \n struct dir_entry {\ndiff --git a/pathspec.c b/pathspec.c\nindex 27cd606786..6997707477 100644\n--- a/pathspec.c\n+++ b/pathspec.c\n@@ -1,4 +1,3 @@\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"dir.h\"\ndiff --git a/read-cache.c b/read-cache.c\nindex 372588260e..2a84ad0797 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -3,7 +3,6 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"tempfile.h\"\ndiff --git a/submodule.c b/submodule.c\nindex 939d6870ec..c6ae29379d 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1,4 +1,3 @@\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n \n #include \"cache.h\"\n #include \"repository.h\"\ndiff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c\nindex bd92fb305a..56a5ce8abb 100644\n--- a/t/helper/test-dump-untracked-cache.c\n+++ b/t/helper/test-dump-untracked-cache.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"dir.h\"\n \ndiff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\nindex 7116ddfb94..a7ff69e9f3 100644\n--- a/t/helper/test-tool.h\n+++ b/t/helper/test-tool.h\n@@ -1,6 +1,8 @@\n #ifndef __TEST_TOOL_H__\n #define __TEST_TOOL_H__\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n+\n int cmd__chmtime(int argc, const char **argv);\n int cmd__config(int argc, const char **argv);\n int cmd__ctype(int argc, const char **argv);\ndiff --git a/tree.c b/tree.c\nindex 244eb5e665..b5ed7bc22b 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -1,4 +1,3 @@\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"cache-tree.h\"\n #include \"tree.h\"\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 3a85a02a77..fd09e812a2 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -1,4 +1,3 @@\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"argv-array.h\"\n #include \"repository.h\"\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350320","messageId":"20180616054157.32433-3-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 02/15] apply.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:44Z","receivedAt":"2018-06-16T05:42:46Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n apply.c | 34 +++++++++++++++++++---------------\n 1 file changed, 19 insertions(+), 15 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex d79e61591b..57a7d3cafd 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -3378,7 +3378,8 @@ static int verify_index_match(const struct cache_entry *ce, struct stat *st)\n \t\t\treturn -1;\n \t\treturn 0;\n \t}\n-\treturn ce_match_stat(ce, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);\n+\treturn ie_match_stat(&the_index, ce, st,\n+\t\t\t     CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);\n }\n \n #define SUBMODULE_PATCH_WITHOUT_INDEX 1\n@@ -3511,10 +3512,10 @@ static int load_current(struct apply_state *state,\n \tif (!patch->is_new)\n \t\tBUG(\"patch to %s is not a creation\", patch->old_name);\n \n-\tpos = cache_name_pos(name, strlen(name));\n+\tpos = index_name_pos(&the_index, name, strlen(name));\n \tif (pos < 0)\n \t\treturn error(_(\"%s: does not exist in index\"), name);\n-\tce = active_cache[pos];\n+\tce = the_index.cache[pos];\n \tif (lstat(name, &st)) {\n \t\tif (errno != ENOENT)\n \t\t\treturn error_errno(\"%s\", name);\n@@ -3680,13 +3681,14 @@ static int check_preimage(struct apply_state *state,\n \t}\n \n \tif (state->check_index && !previous) {\n-\t\tint pos = cache_name_pos(old_name, strlen(old_name));\n+\t\tint pos = index_name_pos(&the_index, old_name,\n+\t\t\t\t\t strlen(old_name));\n \t\tif (pos < 0) {\n \t\t\tif (patch->is_new < 0)\n \t\t\t\tgoto is_new;\n \t\t\treturn error(_(\"%s: does not exist in index\"), old_name);\n \t\t}\n-\t\t*ce = active_cache[pos];\n+\t\t*ce = the_index.cache[pos];\n \t\tif (stat_ret < 0) {\n \t\t\tif (checkout_target(&the_index, *ce, st))\n \t\t\t\treturn -1;\n@@ -3735,7 +3737,7 @@ static int check_to_create(struct apply_state *state,\n \tstruct stat nst;\n \n \tif (state->check_index &&\n-\t    cache_name_pos(new_name, strlen(new_name)) >= 0 &&\n+\t    index_name_pos(&the_index, new_name, strlen(new_name)) >= 0 &&\n \t    !ok_if_exists)\n \t\treturn EXISTS_IN_INDEX;\n \tif (state->cached)\n@@ -3824,7 +3826,8 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *na\n \t\tif (state->check_index) {\n \t\t\tstruct cache_entry *ce;\n \n-\t\t\tce = cache_file_exists(name->buf, name->len, ignore_case);\n+\t\t\tce = index_file_exists(&the_index, name->buf,\n+\t\t\t\t\t       name->len, ignore_case);\n \t\t\tif (ce && S_ISLNK(ce->ce_mode))\n \t\t\t\treturn 1;\n \t\t} else {\n@@ -3999,9 +4002,10 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)\n static int read_apply_cache(struct apply_state *state)\n {\n \tif (state->index_file)\n-\t\treturn read_cache_from(state->index_file);\n+\t\treturn read_index_from(&the_index, state->index_file,\n+\t\t\t\t       get_git_dir());\n \telse\n-\t\treturn read_cache();\n+\t\treturn read_index(&the_index);\n }\n \n /* This function tries to read the object name from the current index */\n@@ -4012,10 +4016,10 @@ static int get_current_oid(struct apply_state *state, const char *path,\n \n \tif (read_apply_cache(state) < 0)\n \t\treturn -1;\n-\tpos = cache_name_pos(path, strlen(path));\n+\tpos = index_name_pos(&the_index, path, strlen(path));\n \tif (pos < 0)\n \t\treturn -1;\n-\toidcpy(oid, &active_cache[pos]->oid);\n+\toidcpy(oid, &the_index.cache[pos]->oid);\n \treturn 0;\n }\n \n@@ -4243,7 +4247,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)\n static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)\n {\n \tif (state->update_index) {\n-\t\tif (remove_file_from_cache(patch->old_name) < 0)\n+\t\tif (remove_file_from_index(&the_index, patch->old_name) < 0)\n \t\t\treturn error(_(\"unable to remove %s from index\"), patch->old_name);\n \t}\n \tif (!state->cached) {\n@@ -4297,7 +4301,7 @@ static int add_index_file(struct apply_state *state,\n \t\t\t\t       \"for newly created file %s\"), path);\n \t\t}\n \t}\n-\tif (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {\n+\tif (add_index_entry(&the_index, ce, ADD_CACHE_OK_TO_ADD) < 0) {\n \t\tfree(ce);\n \t\treturn error(_(\"unable to add cache entry for %s\"), path);\n \t}\n@@ -4431,7 +4435,7 @@ static int add_conflicted_stages_file(struct apply_state *state,\n \tce_size = cache_entry_size(namelen);\n \tmode = patch->new_mode ? patch->new_mode : (S_IFREG | 0644);\n \n-\tremove_file_from_cache(patch->new_name);\n+\tremove_file_from_index(&the_index, patch->new_name);\n \tfor (stage = 1; stage < 4; stage++) {\n \t\tif (is_null_oid(&patch->threeway_stage[stage - 1]))\n \t\t\tcontinue;\n@@ -4441,7 +4445,7 @@ static int add_conflicted_stages_file(struct apply_state *state,\n \t\tce->ce_flags = create_ce_flags(stage);\n \t\tce->ce_namelen = namelen;\n \t\toidcpy(&ce->oid, &patch->threeway_stage[stage - 1]);\n-\t\tif (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {\n+\t\tif (add_index_entry(&the_index, ce, ADD_CACHE_OK_TO_ADD) < 0) {\n \t\t\tfree(ce);\n \t\t\treturn error(_(\"unable to add cache entry for %s\"),\n \t\t\t\t     patch->new_name);\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350321","messageId":"20180616054157.32433-8-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 07/15] entry.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:49Z","receivedAt":"2018-06-16T05:42:48Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n entry.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/entry.c b/entry.c\nindex 2101201a11..ec588289fb 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -421,7 +421,8 @@ int checkout_entry(struct cache_entry *ce,\n \n \tif (!check_path(path.buf, path.len, &st, state->base_dir_len)) {\n \t\tconst struct submodule *sub;\n-\t\tunsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);\n+\t\tunsigned changed = ie_match_stat(&the_index, ce, &st,\n+\t\t\t\t\t\t CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);\n \t\t/*\n \t\t * Needs to be checked before !changed returns early,\n \t\t * as the possibly empty directory was not changed\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350322","messageId":"20180616054157.32433-7-pclouds@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"[PATCH 06/15] diff.c: stop using index compat macros","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-16T05:41:48Z","receivedAt":"2018-06-16T05:42:52Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 136d44b455..975e095ed2 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3460,7 +3460,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in\n \t * by diff-cache --cached, which does read the cache before\n \t * calling us.\n \t */\n-\tif (!active_cache)\n+\tif (!the_index.cache)\n \t\treturn 0;\n \n \t/* We want to avoid the working directory if our caller\n@@ -3483,10 +3483,10 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in\n \t\treturn 0;\n \n \tlen = strlen(name);\n-\tpos = cache_name_pos(name, len);\n+\tpos = index_name_pos(&the_index, name, len);\n \tif (pos < 0)\n \t\treturn 0;\n-\tce = active_cache[pos];\n+\tce = the_index.cache[pos];\n \n \t/*\n \t * This is not the sha1 we are looking for, or\n@@ -3506,7 +3506,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in\n \t * If ce matches the file in the work tree, we can reuse it.\n \t */\n \tif (ce_uptodate(ce) ||\n-\t    (!lstat(name, &st) && !ce_match_stat(ce, &st, 0)))\n+\t    (!lstat(name, &st) && !ie_match_stat(&the_index, ce, &st, 0)))\n \t\treturn 1;\n \n \treturn 0;\n@@ -4216,14 +4216,14 @@ void diff_setup_done(struct diff_options *options)\n \tif (options->detect_rename && options->rename_limit < 0)\n \t\toptions->rename_limit = diff_rename_limit_default;\n \tif (options->setup & DIFF_SETUP_USE_CACHE) {\n-\t\tif (!active_cache)\n+\t\tif (!the_index.cache)\n \t\t\t/* read-cache does not die even when it fails\n \t\t\t * so it is safe for us to do this here.  Also\n \t\t\t * it does not smudge active_cache or active_nr\n \t\t\t * when it fails, so we do not have to worry about\n \t\t\t * cleaning it up ourselves either.\n \t\t\t */\n-\t\t\tread_cache();\n+\t\t\tread_index(&the_index);\n \t}\n \tif (hexsz < options->abbrev)\n \t\toptions->abbrev = hexsz; /* full */\n-- \n2.18.0.rc0.333.g22e6ee6cdf\n\n"},{"id":"350350","messageId":"CABPp-BG1n4u78JScxrnUc1gecXFjKbwLWMxKKs+ZO17DdH3zvg@mail.gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"Re: [PATCH 00/15] Kill the_index part 1, expose it","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2018-06-17T07:02:58Z","receivedAt":"2018-06-17T07:03:02Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Fri, Jun 15, 2018 at 10:41 PM, Nguyễn Thái Ngọc Duy\n<pclouds@gmail.com> wrote:\n> This is the beginning of the end of the_index. The problem with\n> the_index is it lets library code anywhere access it freely. This is\n> not good because from high level you may not realize that the_index is\n> being used while you don't want to touch index at all, or you want to\n> use a different index instead.\n>\n> This is a long series, 86 patches [1], so I'm going to split and\n> submit it in 15-20 patches at a time. The first two parts are trivial\n> though and could be safely fast tracked if needed.\n\nYou post this small little patch about unpack-trees.c, mentioning you\ndon't know if it's even correct, and bait me into reviewing it and\nthen spring on me that it's actually nearly 100 patches that need\nreview...   Very sneaky.  ;-)\n\n> This is the first part, which kills the use of index compat macros\n> outside builtin/ and expose the_index in all library code. Later on we\n> will ban the_index from one file each time until it's gone for good.\n>\n> \"struct index_state *\" will be passed from builtin/ through the call\n> chain to the function that needs it. In some cases, \"struct\n> repository *\" will be passed instead when the whole operation spans\n> more than just the index.  By the end, the_index becomes part of\n> \"index compat macros\" and cannot be used outside builtin/\n>\n> Part one is mechanical conversion with the help of coccinelle. The\n> only real patches are the first and the last one.\n\nThanks for the nice division.  I read through all 15 patches, though I\nlooked at the first and the last a bit closer.  I'm not familiar with\ncoccinelle yet, but it at least looked relatively straightforward;\nwould be good to have someone else double check that patch.  Other\nthan that, the changes look good to me.\n\nThanks for working on this!\n"},{"id":"350351","messageId":"CACsJy8Bib-CFxUs5YBzcgo7LPDospdgSAn+-asCf-YrYnUxqXA@mail.gmail.com","threadId":"48719","inReplyTo":"CABPp-BG1n4u78JScxrnUc1gecXFjKbwLWMxKKs+ZO17DdH3zvg@mail.gmail.com","subject":"Re: [PATCH 00/15] Kill the_index part 1, expose it","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-17T08:49:12Z","receivedAt":"2018-06-17T08:49:42Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Jun 17, 2018 at 9:02 AM Elijah Newren <newren@gmail.com> wrote:\n>\n> On Fri, Jun 15, 2018 at 10:41 PM, Nguyễn Thái Ngọc Duy\n> <pclouds@gmail.com> wrote:\n> > This is the beginning of the end of the_index. The problem with\n> > the_index is it lets library code anywhere access it freely. This is\n> > not good because from high level you may not realize that the_index is\n> > being used while you don't want to touch index at all, or you want to\n> > use a different index instead.\n> >\n> > This is a long series, 86 patches [1], so I'm going to split and\n> > submit it in 15-20 patches at a time. The first two parts are trivial\n> > though and could be safely fast tracked if needed.\n>\n> You post this small little patch about unpack-trees.c, mentioning you\n> don't know if it's even correct, and bait me into reviewing it and\n> then spring on me that it's actually nearly 100 patches that need\n> review...   Very sneaky.  ;-)\n\nTo be fair, it's all Brandon's fault. If he didn't kick the_index out\nof dir.c, it would not conflict with one of my out-of-tree patches in\nunpack-trees.c, catch my attention and make me go down this rabbit\nhole :D\n-- \nDuy\n"},{"id":"350408","messageId":"20180618184111.GC73085@google.com","threadId":"48719","inReplyTo":"CACsJy8Bib-CFxUs5YBzcgo7LPDospdgSAn+-asCf-YrYnUxqXA@mail.gmail.com","subject":"Re: [PATCH 00/15] Kill the_index part 1, expose it","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2018-06-18T18:41:11Z","receivedAt":"2018-06-18T18:41:17Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 06/17, Duy Nguyen wrote:\n> On Sun, Jun 17, 2018 at 9:02 AM Elijah Newren <newren@gmail.com> wrote:\n> >\n> > On Fri, Jun 15, 2018 at 10:41 PM, Nguyễn Thái Ngọc Duy\n> > <pclouds@gmail.com> wrote:\n> > > This is the beginning of the end of the_index. The problem with\n> > > the_index is it lets library code anywhere access it freely. This is\n> > > not good because from high level you may not realize that the_index is\n> > > being used while you don't want to touch index at all, or you want to\n> > > use a different index instead.\n> > >\n> > > This is a long series, 86 patches [1], so I'm going to split and\n> > > submit it in 15-20 patches at a time. The first two parts are trivial\n> > > though and could be safely fast tracked if needed.\n> >\n> > You post this small little patch about unpack-trees.c, mentioning you\n> > don't know if it's even correct, and bait me into reviewing it and\n> > then spring on me that it's actually nearly 100 patches that need\n> > review...   Very sneaky.  ;-)\n> \n> To be fair, it's all Brandon's fault. If he didn't kick the_index out\n> of dir.c, it would not conflict with one of my out-of-tree patches in\n> unpack-trees.c, catch my attention and make me go down this rabbit\n> hole :D\n\nHaha well this is something I've wanted to do for over a year now, glad\nyou've decided to run with it :)\n\nI guess I've gotten pretty good at getting people to go down rabbit\nholes.  First Stefan with the object store refactoring and now you with\nthe index stuff.  All because I wanted git to be more object oriented\nand have less global state ;) \n\n-- \nBrandon Williams\n"},{"id":"350411","messageId":"20180618185356.GD73085@google.com","threadId":"48719","inReplyTo":"20180616054157.32433-16-pclouds@gmail.com","subject":"Re: [PATCH 15/15] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2018-06-18T18:53:56Z","receivedAt":"2018-06-18T18:54:03Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 06/16, Nguyễn Thái Ngọc Duy wrote:\n> From now on, by default index compat macros are off because they could\n> hide the_index dependency. Only those in builtin can use it (and even\n> so should be avoided if possible).\n\nThis is awesome! Now there aren't any compat macros left in the lib code\nand the next set of patches has a good base to work from the eliminate\nthe_index (which I assume based on other mails from you will become part\nof the new USE_THE_INDEX_COMPATIBILITY_MACROS macro once its eliminated\nfrom the lib code).\n\n> \n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  attr.c                               | 1 -\n>  builtin/add.c                        | 1 +\n>  builtin/am.c                         | 1 +\n>  builtin/check-attr.c                 | 1 +\n>  builtin/check-ignore.c               | 1 +\n>  builtin/checkout-index.c             | 1 +\n>  builtin/checkout.c                   | 1 +\n>  builtin/clean.c                      | 1 +\n>  builtin/commit.c                     | 1 +\n>  builtin/describe.c                   | 1 +\n>  builtin/diff-files.c                 | 1 +\n>  builtin/diff-index.c                 | 1 +\n>  builtin/diff-tree.c                  | 1 +\n>  builtin/diff.c                       | 1 +\n>  builtin/fsck.c                       | 1 +\n>  builtin/ls-files.c                   | 1 -\n>  builtin/merge-index.c                | 1 +\n>  builtin/merge-ours.c                 | 1 +\n>  builtin/merge.c                      | 1 +\n>  builtin/mv.c                         | 1 +\n>  builtin/pull.c                       | 1 +\n>  builtin/read-tree.c                  | 1 +\n>  builtin/reset.c                      | 1 +\n>  builtin/rev-parse.c                  | 1 +\n>  builtin/rm.c                         | 1 +\n>  builtin/submodule--helper.c          | 1 +\n>  builtin/update-index.c               | 1 +\n>  cache.h                              | 2 +-\n>  convert.c                            | 1 -\n>  dir.c                                | 1 -\n>  name-hash.c                          | 1 -\n>  pathspec.c                           | 1 -\n>  read-cache.c                         | 1 -\n>  submodule.c                          | 1 -\n>  t/helper/test-dump-untracked-cache.c | 1 +\n>  t/helper/test-tool.h                 | 2 ++\n>  tree.c                               | 1 -\n>  unpack-trees.c                       | 1 -\n>  38 files changed, 29 insertions(+), 11 deletions(-)\n> \n> diff --git a/attr.c b/attr.c\n> index 067fb9e0c0..d16625661d 100644\n> --- a/attr.c\n> +++ b/attr.c\n> @@ -7,7 +7,6 @@\n>   * an insanely large number of attributes.\n>   */\n>  \n> -#define NO_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"exec-cmd.h\"\n> diff --git a/builtin/add.c b/builtin/add.c\n> index 8a155dd41e..b93193c3fe 100644\n> --- a/builtin/add.c\n> +++ b/builtin/add.c\n> @@ -3,6 +3,7 @@\n>   *\n>   * Copyright (C) 2006 Linus Torvalds\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"builtin.h\"\n> diff --git a/builtin/am.c b/builtin/am.c\n> index 2fc2d1e82c..28af59d183 100644\n> --- a/builtin/am.c\n> +++ b/builtin/am.c\n> @@ -3,6 +3,7 @@\n>   *\n>   * Based on git-am.sh by Junio C Hamano.\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"builtin.h\"\n> diff --git a/builtin/check-attr.c b/builtin/check-attr.c\n> index 91444dc044..d9cebd5382 100644\n> --- a/builtin/check-attr.c\n> +++ b/builtin/check-attr.c\n> @@ -1,3 +1,4 @@\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"cache.h\"\n>  #include \"config.h\"\n> diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\n> index ec9a959e08..599097304b 100644\n> --- a/builtin/check-ignore.c\n> +++ b/builtin/check-ignore.c\n> @@ -1,3 +1,4 @@\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"cache.h\"\n>  #include \"config.h\"\n> diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\n> index a730f6a1aa..e38ad42dbf 100644\n> --- a/builtin/checkout-index.c\n> +++ b/builtin/checkout-index.c\n> @@ -4,6 +4,7 @@\n>   * Copyright (C) 2005 Linus Torvalds\n>   *\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"config.h\"\n>  #include \"lockfile.h\"\n> diff --git a/builtin/checkout.c b/builtin/checkout.c\n> index 2e1d2376d2..2250611407 100644\n> --- a/builtin/checkout.c\n> +++ b/builtin/checkout.c\n> @@ -1,3 +1,4 @@\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"config.h\"\n>  #include \"checkout.h\"\n> diff --git a/builtin/clean.c b/builtin/clean.c\n> index fad533a0a7..2258379ecc 100644\n> --- a/builtin/clean.c\n> +++ b/builtin/clean.c\n> @@ -6,6 +6,7 @@\n>   * Based on git-clean.sh by Pavel Roskin\n>   */\n>  \n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"cache.h\"\n>  #include \"config.h\"\n> diff --git a/builtin/commit.c b/builtin/commit.c\n> index a842fea666..98a5b4a8c8 100644\n> --- a/builtin/commit.c\n> +++ b/builtin/commit.c\n> @@ -5,6 +5,7 @@\n>   * Based on git-commit.sh by Junio C Hamano and Linus Torvalds\n>   */\n>  \n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"lockfile.h\"\n> diff --git a/builtin/describe.c b/builtin/describe.c\n> index cf1ae77d7c..4ca234972e 100644\n> --- a/builtin/describe.c\n> +++ b/builtin/describe.c\n> @@ -1,3 +1,4 @@\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"lockfile.h\"\n> diff --git a/builtin/diff-files.c b/builtin/diff-files.c\n> index e88493ffe5..af706b4fce 100644\n> --- a/builtin/diff-files.c\n> +++ b/builtin/diff-files.c\n> @@ -3,6 +3,7 @@\n>   *\n>   * Copyright (C) Linus Torvalds, 2005\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"diff.h\"\n> diff --git a/builtin/diff-index.c b/builtin/diff-index.c\n> index 522f4fdffd..c026ffb95e 100644\n> --- a/builtin/diff-index.c\n> +++ b/builtin/diff-index.c\n> @@ -1,3 +1,4 @@\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"diff.h\"\n> diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\n> index 473615117e..bd2264ed5c 100644\n> --- a/builtin/diff-tree.c\n> +++ b/builtin/diff-tree.c\n> @@ -1,3 +1,4 @@\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"diff.h\"\n> diff --git a/builtin/diff.c b/builtin/diff.c\n> index bfefff3a84..17d7d5c9f5 100644\n> --- a/builtin/diff.c\n> +++ b/builtin/diff.c\n> @@ -3,6 +3,7 @@\n>   *\n>   * Copyright (c) 2006 Junio C Hamano\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"lockfile.h\"\n> diff --git a/builtin/fsck.c b/builtin/fsck.c\n> index 3ad4f160f9..33cb71d269 100644\n> --- a/builtin/fsck.c\n> +++ b/builtin/fsck.c\n> @@ -1,3 +1,4 @@\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"cache.h\"\n>  #include \"repository.h\"\n> diff --git a/builtin/ls-files.c b/builtin/ls-files.c\n> index 88bb2019ad..dbf5d13d91 100644\n> --- a/builtin/ls-files.c\n> +++ b/builtin/ls-files.c\n> @@ -5,7 +5,6 @@\n>   *\n>   * Copyright (C) Linus Torvalds, 2005\n>   */\n> -#define NO_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"repository.h\"\n>  #include \"config.h\"\n> diff --git a/builtin/merge-index.c b/builtin/merge-index.c\n> index c99443b095..38ea6ad6ca 100644\n> --- a/builtin/merge-index.c\n> +++ b/builtin/merge-index.c\n> @@ -1,3 +1,4 @@\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"run-command.h\"\n>  \n> diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c\n> index c84c6e05e9..7c4a80ed3b 100644\n> --- a/builtin/merge-ours.c\n> +++ b/builtin/merge-ours.c\n> @@ -7,6 +7,7 @@\n>   *\n>   * Pretend we resolved the heads, but declare our tree trumps everybody else.\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"git-compat-util.h\"\n>  #include \"builtin.h\"\n>  #include \"diff.h\"\n> diff --git a/builtin/merge.c b/builtin/merge.c\n> index b00d6f4821..1b540e2194 100644\n> --- a/builtin/merge.c\n> +++ b/builtin/merge.c\n> @@ -6,6 +6,7 @@\n>   * Based on git-merge.sh by Junio C Hamano.\n>   */\n>  \n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"parse-options.h\"\n> diff --git a/builtin/mv.c b/builtin/mv.c\n> index 80bb967a63..be15ba7044 100644\n> --- a/builtin/mv.c\n> +++ b/builtin/mv.c\n> @@ -3,6 +3,7 @@\n>   *\n>   * Copyright (C) 2006 Johannes Schindelin\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"config.h\"\n>  #include \"pathspec.h\"\n> diff --git a/builtin/pull.c b/builtin/pull.c\n> index 1f2ecf3a88..1c3657dee2 100644\n> --- a/builtin/pull.c\n> +++ b/builtin/pull.c\n> @@ -5,6 +5,7 @@\n>   *\n>   * Fetch one or more remote refs and merge it/them into the current HEAD.\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"builtin.h\"\n> diff --git a/builtin/read-tree.c b/builtin/read-tree.c\n> index ebc43eb805..ae6ca3a8c5 100644\n> --- a/builtin/read-tree.c\n> +++ b/builtin/read-tree.c\n> @@ -4,6 +4,7 @@\n>   * Copyright (C) Linus Torvalds, 2005\n>   */\n>  \n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"lockfile.h\"\n> diff --git a/builtin/reset.c b/builtin/reset.c\n> index a862c70fab..dd60eec9d6 100644\n> --- a/builtin/reset.c\n> +++ b/builtin/reset.c\n> @@ -7,6 +7,7 @@\n>   *\n>   * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"config.h\"\n>  #include \"lockfile.h\"\n> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\n> index 4f49e96bfd..b5f8d6a83d 100644\n> --- a/builtin/rev-parse.c\n> +++ b/builtin/rev-parse.c\n> @@ -3,6 +3,7 @@\n>   *\n>   * Copyright (C) Linus Torvalds, 2005\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"commit.h\"\n> diff --git a/builtin/rm.c b/builtin/rm.c\n> index 65b448ef8e..e5b77e429d 100644\n> --- a/builtin/rm.c\n> +++ b/builtin/rm.c\n> @@ -3,6 +3,7 @@\n>   *\n>   * Copyright (C) Linus Torvalds 2006\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"config.h\"\n>  #include \"lockfile.h\"\n> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\n> index bd250ca216..8abe15144b 100644\n> --- a/builtin/submodule--helper.c\n> +++ b/builtin/submodule--helper.c\n> @@ -1,3 +1,4 @@\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"builtin.h\"\n>  #include \"repository.h\"\n>  #include \"cache.h\"\n> diff --git a/builtin/update-index.c b/builtin/update-index.c\n> index a8709a26ec..36e837248f 100644\n> --- a/builtin/update-index.c\n> +++ b/builtin/update-index.c\n> @@ -3,6 +3,7 @@\n>   *\n>   * Copyright (C) Linus Torvalds, 2005\n>   */\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"lockfile.h\"\n> diff --git a/cache.h b/cache.h\n> index 89a107a7f7..b3a6d14a36 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -339,7 +339,7 @@ extern void remove_name_hash(struct index_state *istate, struct cache_entry *ce)\n>  extern void free_name_hash(struct index_state *istate);\n>  \n>  \n> -#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS\n> +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #define active_cache (the_index.cache)\n>  #define active_nr (the_index.cache_nr)\n>  #define active_alloc (the_index.cache_alloc)\n> diff --git a/convert.c b/convert.c\n> index 64d0d30e08..0895dc5994 100644\n> --- a/convert.c\n> +++ b/convert.c\n> @@ -1,4 +1,3 @@\n> -#define NO_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"attr.h\"\n> diff --git a/dir.c b/dir.c\n> index ccf8b4975e..473c47eb2f 100644\n> --- a/dir.c\n> +++ b/dir.c\n> @@ -7,7 +7,6 @@\n>   * Copyright (C) Linus Torvalds, 2005-2006\n>   *\t\t Junio Hamano, 2005-2006\n>   */\n> -#define NO_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"dir.h\"\n> diff --git a/name-hash.c b/name-hash.c\n> index 163849831c..12eaa62980 100644\n> --- a/name-hash.c\n> +++ b/name-hash.c\n> @@ -5,7 +5,6 @@\n>   *\n>   * Copyright (C) 2008 Linus Torvalds\n>   */\n> -#define NO_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  \n>  struct dir_entry {\n> diff --git a/pathspec.c b/pathspec.c\n> index 27cd606786..6997707477 100644\n> --- a/pathspec.c\n> +++ b/pathspec.c\n> @@ -1,4 +1,3 @@\n> -#define NO_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"dir.h\"\n> diff --git a/read-cache.c b/read-cache.c\n> index 372588260e..2a84ad0797 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -3,7 +3,6 @@\n>   *\n>   * Copyright (C) Linus Torvalds, 2005\n>   */\n> -#define NO_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"config.h\"\n>  #include \"tempfile.h\"\n> diff --git a/submodule.c b/submodule.c\n> index 939d6870ec..c6ae29379d 100644\n> --- a/submodule.c\n> +++ b/submodule.c\n> @@ -1,4 +1,3 @@\n> -#define NO_THE_INDEX_COMPATIBILITY_MACROS\n>  \n>  #include \"cache.h\"\n>  #include \"repository.h\"\n> diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c\n> index bd92fb305a..56a5ce8abb 100644\n> --- a/t/helper/test-dump-untracked-cache.c\n> +++ b/t/helper/test-dump-untracked-cache.c\n> @@ -1,3 +1,4 @@\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"dir.h\"\n>  \n> diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\n> index 7116ddfb94..a7ff69e9f3 100644\n> --- a/t/helper/test-tool.h\n> +++ b/t/helper/test-tool.h\n> @@ -1,6 +1,8 @@\n>  #ifndef __TEST_TOOL_H__\n>  #define __TEST_TOOL_H__\n>  \n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n> +\n>  int cmd__chmtime(int argc, const char **argv);\n>  int cmd__config(int argc, const char **argv);\n>  int cmd__ctype(int argc, const char **argv);\n> diff --git a/tree.c b/tree.c\n> index 244eb5e665..b5ed7bc22b 100644\n> --- a/tree.c\n> +++ b/tree.c\n> @@ -1,4 +1,3 @@\n> -#define NO_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"cache-tree.h\"\n>  #include \"tree.h\"\n> diff --git a/unpack-trees.c b/unpack-trees.c\n> index 3a85a02a77..fd09e812a2 100644\n> --- a/unpack-trees.c\n> +++ b/unpack-trees.c\n> @@ -1,4 +1,3 @@\n> -#define NO_THE_INDEX_COMPATIBILITY_MACROS\n>  #include \"cache.h\"\n>  #include \"argv-array.h\"\n>  #include \"repository.h\"\n> -- \n> 2.18.0.rc0.333.g22e6ee6cdf\n> \n\n-- \nBrandon Williams\n"},{"id":"350466","messageId":"a7e0bcd5-5bef-097e-f032-d152d51515aa@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-2-pclouds@gmail.com","subject":"Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2018-06-19T11:35:07Z","receivedAt":"2018-06-19T11:35:13Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 6/16/2018 1:41 AM, Nguyễn Thái Ngọc Duy wrote:\n> Index compat macros are going to be removed to expose the_index and\n> then reorganized to use the right index instead of simply the_index\n> because sometimes we want to use a different index.\n>\n> This cocci script can help with the first step. It can be used later\n> on on even builtin/ when we start to reorganize code in there, but for\n> now this is the script that performs all the conversion outside\n> builtin/\n\nI pulled your code and ran `make coccicheck` and got quite a large patch \nas a result.\n\nPerhaps reorder the commits in your large patch with this one at the \nend? It's helpful to see what your mechanical changes are going to be, \nbut let's save it for when `make coccicheck` is stable.\n\n>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>   contrib/coccinelle/index-compat.cocci | 184 ++++++++++++++++++++++++++\n>   1 file changed, 184 insertions(+)\n>   create mode 100644 contrib/coccinelle/index-compat.cocci\n>\n> diff --git a/contrib/coccinelle/index-compat.cocci b/contrib/coccinelle/index-compat.cocci\n> new file mode 100644\n> index 0000000000..ca46711eb6\n> --- /dev/null\n> +++ b/contrib/coccinelle/index-compat.cocci\n> @@ -0,0 +1,184 @@\n> +@@\n> +@@\n> +-active_cache\n> ++the_index.cache\n> +\n> +@@\n> +@@\n> +-active_nr\n> ++the_index.cache_nr\n> +\n> +@@\n> +@@\n> +-active_alloc\n> ++the_index.cache_alloc\n> +\n> +@@\n> +@@\n> +-active_cache_changed\n> ++the_index.cache_changed\n> +\n> +@@\n> +@@\n> +-active_cache_tree\n> ++the_index.cache_tree\n> +\n> +@@\n> +@@\n> +- read_cache()\n> ++ read_index(&the_index)\n> +\n> +@@\n> +expression path;\n> +@@\n> +- read_cache_from(path)\n> ++ read_index_from(&the_index, path, get_git_dir())\n> +\n> +@@\n> +expression pathspec;\n> +@@\n> +- read_cache_preload(pathspec)\n> ++ read_index_preload(&the_index, pathspec)\n> +\n> +@@\n> +@@\n> +- is_cache_unborn()\n> ++ is_index_unborn(&the_index)\n> +\n> +@@\n> +@@\n> +- read_cache_unmerged()\n> ++ read_index_unmerged(&the_index)\n> +\n> +@@\n> +@@\n> +- discard_cache()\n> ++ discard_index(&the_index)\n> +\n> +@@\n> +@@\n> +- unmerged_cache()\n> ++ unmerged_index(&the_index)\n> +\n> +@@\n> +expression name;\n> +expression namelen;\n> +@@\n> +- cache_name_pos(name, namelen)\n> ++ index_name_pos(&the_index, name, namelen)\n> +\n> +@@\n> +expression ce;\n> +expression option;\n> +@@\n> +- add_cache_entry(ce, option)\n> ++ add_index_entry(&the_index, ce, option)\n> +\n> +@@\n> +expression pos;\n> +expression new_name;\n> +@@\n> +- rename_cache_entry_at(pos, new_name)\n> ++ rename_index_entry_at(&the_index, pos, new_name)\n> +\n> +@@\n> +expression pos;\n> +@@\n> +- remove_cache_entry_at(pos)\n> ++ remove_index_entry_at(&the_index, pos)\n> +\n> +@@\n> +expression path;\n> +@@\n> +- remove_file_from_cache(path)\n> ++ remove_file_from_index(&the_index, path)\n> +\n> +@@\n> +expression path;\n> +expression st;\n> +expression flags;\n> +@@\n> +- add_to_cache(path, st, flags)\n> ++ add_to_index(&the_index, path, st, flags)\n> +\n> +@@\n> +expression path;\n> +expression flags;\n> +@@\n> +- add_file_to_cache(path, flags)\n> ++ add_file_to_index(&the_index, path, flags)\n> +\n> +@@\n> +expression ce;\n> +expression flip;\n> +@@\n> +-chmod_cache_entry(ce, flip)\n> ++chmod_index_entry(&the_index, ce, flip)\n> +\n> +@@\n> +expression flags;\n> +@@\n> +-refresh_cache(flags)\n> ++refresh_index(&the_index, flags, NULL, NULL, NULL)\n> +\n> +@@\n> +expression ce;\n> +expression st;\n> +expression options;\n> +@@\n> +-ce_match_stat(ce, st, options)\n> ++ie_match_stat(&the_index, ce, st, options)\n> +\n> +@@\n> +expression ce;\n> +expression st;\n> +expression options;\n> +@@\n> +-ce_modified(ce, st, options)\n> ++ie_modified(&the_index, ce, st, options)\n> +\n> +@@\n> +expression name;\n> +expression namelen;\n> +@@\n> +-cache_dir_exists(name, namelen)\n> ++index_dir_exists(&the_index, name, namelen)\n> +\n> +@@\n> +expression name;\n> +expression namelen;\n> +expression igncase;\n> +@@\n> +-cache_file_exists(name, namelen, igncase)\n> ++index_file_exists(&the_index, name, namelen, igncase)\n> +\n> +@@\n> +expression name;\n> +expression namelen;\n> +@@\n> +-cache_name_is_other(name, namelen)\n> ++index_name_is_other(&the_index, name, namelen)\n> +\n> +@@\n> +@@\n> +-resolve_undo_clear()\n> ++resolve_undo_clear_index(&the_index)\n> +\n> +@@\n> +expression at;\n> +@@\n> +-unmerge_cache_entry_at(at)\n> ++unmerge_index_entry_at(&the_index, at)\n> +\n> +@@\n> +expression pathspec;\n> +@@\n> +-unmerge_cache(pathspec)\n> ++unmerge_index(&the_index, pathspec)\n> +\n> +@@\n> +expression path;\n> +expression sz;\n> +@@\n> +-read_blob_data_from_cache(path, sz)\n> ++read_blob_data_from_index(&the_index, path, sz)\n\n"},{"id":"350467","messageId":"20180619114143.206568-1-dstolee@microsoft.com","threadId":"48719","inReplyTo":"a7e0bcd5-5bef-097e-f032-d152d51515aa@gmail.com","subject":"Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2018-06-19T11:41:43Z","receivedAt":"2018-06-19T11:41:53Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"Duy,\n\nHere is the patch that was generated by `make coccicheck`.\n\nThanks,\n-Stolee\n\n-->8--\n\n--- builtin/add.c\n+++ /tmp/cocci-output-206193-4c91ec-add.c\n@@ -38,13 +38,13 @@ static void chmod_pathspec(struct pathsp\n {\n \tint i;\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \n \t\tif (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))\n \t\t\tcontinue;\n \n-\t\tif (chmod_cache_entry(ce, flip) < 0)\n+\t\tif (chmod_index_entry(&the_index, ce, flip) < 0)\n \t\t\tfprintf(stderr, \"cannot chmod %cx '%s'\\n\", flip, ce->name);\n \t}\n }\n@@ -129,8 +129,8 @@ static int renormalize_tracked_files(con\n {\n \tint i, retval = 0;\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \n \t\tif (ce_stage(ce))\n \t\t\tcontinue; /* do not touch unmerged paths */\n@@ -138,7 +138,8 @@ static int renormalize_tracked_files(con\n \t\t\tcontinue; /* do not touch non blobs */\n \t\tif (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))\n \t\t\tcontinue;\n-\t\tretval |= add_file_to_cache(ce->name, flags | HASH_RENORMALIZE);\n+\t\tretval |= add_file_to_index(&the_index, ce->name,\n+\t\t\t\t\t    flags | HASH_RENORMALIZE);\n \t}\n \n \treturn retval;\n@@ -230,7 +231,7 @@ static int edit_patch(int argc, const ch\n \n \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n \n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(_(\"Could not read the index\"));\n \n \tinit_revisions(&rev, the_repository, prefix);\n@@ -445,7 +446,7 @@ int cmd_add(int argc, const char **argv,\n \t\treturn 0;\n \t}\n \n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tdie_in_unpopulated_submodule(&the_index, prefix);\n--- builtin/am.c\n+++ /tmp/cocci-output-206198-3fcbd5-am.c\n@@ -1144,7 +1144,7 @@ static void refresh_and_write_cache(void\n \tstruct lock_file lock_file = LOCK_INIT;\n \n \thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write index file\"));\n }\n@@ -1505,8 +1505,8 @@ static int run_apply(const struct am_sta\n \n \tif (index_file) {\n \t\t/* Reload index as apply_all_patches() will have modified it. */\n-\t\tdiscard_cache();\n-\t\tread_cache_from(index_file);\n+\t\tdiscard_index(&the_index);\n+\t\tread_index_from(&the_index, index_file, get_git_dir());\n \t}\n \n \treturn 0;\n@@ -1548,8 +1548,8 @@ static int fall_back_threeway(const stru\n \tif (build_fake_ancestor(state, index_path))\n \t\treturn error(\"could not build fake ancestor\");\n \n-\tdiscard_cache();\n-\tread_cache_from(index_path);\n+\tdiscard_index(&the_index);\n+\tread_index_from(&the_index, index_path, get_git_dir());\n \n \tif (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))\n \t\treturn error(_(\"Repository lacks necessary blobs to fall back on 3-way merge.\"));\n@@ -1581,8 +1581,8 @@ static int fall_back_threeway(const stru\n \n \tsay(state, stdout, _(\"Falling back to patching base and 3-way merge...\"));\n \n-\tdiscard_cache();\n-\tread_cache();\n+\tdiscard_index(&the_index);\n+\tread_index(&the_index);\n \n \t/*\n \t * This is not so wrong. Depending on which base we picked, orig_tree\n@@ -1886,7 +1886,7 @@ static void am_resolve(struct am_state *\n \t\tdie_user_resolve(state);\n \t}\n \n-\tif (unmerged_cache()) {\n+\tif (unmerged_index(&the_index)) {\n \t\tprintf_ln(_(\"You still have unmerged paths in your index.\\n\"\n \t\t\t\"You should 'git add' each file with resolved conflicts to mark them as such.\\n\"\n \t\t\t\"You might run `git rm` on a file to accept \\\"deleted by them\\\" for it.\"));\n@@ -1925,7 +1925,7 @@ static int fast_forward_to(struct tree *\n \n \thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n \n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \n \tmemset(&opts, 0, sizeof(opts));\n \topts.head_idx = 1;\n@@ -2000,7 +2000,7 @@ static int clean_index(const struct obje\n \tif (!remote_tree)\n \t\treturn error(_(\"Could not parse object '%s'.\"), oid_to_hex(remote));\n \n-\tread_cache_unmerged();\n+\tread_index_unmerged(&the_index);\n \n \tif (fast_forward_to(head_tree, head_tree, 1))\n \t\treturn -1;\n--- builtin/check-attr.c\n+++ /tmp/cocci-output-206211-cd89a4-check-attr.c\n@@ -116,7 +116,7 @@ int cmd_check_attr(int argc, const char\n \targc = parse_options(argc, argv, prefix, check_attr_options,\n \t\t\t     check_attr_usage, PARSE_OPT_KEEP_DASHDASH);\n \n-\tif (read_cache() < 0) {\n+\tif (read_index(&the_index) < 0) {\n \t\tdie(\"invalid cache\");\n \t}\n \n--- builtin/check-ignore.c\n+++ /tmp/cocci-output-206216-286c84-check-ignore.c\n@@ -174,7 +174,7 @@ int cmd_check_ignore(int argc, const cha\n \t\tdie(_(\"--non-matching is only valid with --verbose\"));\n \n \t/* read_cache() is only necessary so we can watch out for submodules. */\n-\tif (!no_index && read_cache() < 0)\n+\tif (!no_index && read_index(&the_index) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tmemset(&dir, 0, sizeof(dir));\n--- builtin/checkout-index.c\n+++ /tmp/cocci-output-206223-d5d099-checkout-index.c\n@@ -48,7 +48,7 @@ static void write_tempfile_record(const\n static int checkout_file(const char *name, const char *prefix)\n {\n \tint namelen = strlen(name);\n-\tint pos = cache_name_pos(name, namelen);\n+\tint pos = index_name_pos(&the_index, name, namelen);\n \tint has_same_name = 0;\n \tint did_checkout = 0;\n \tint errs = 0;\n@@ -56,8 +56,8 @@ static int checkout_file(const char *nam\n \tif (pos < 0)\n \t\tpos = -pos - 1;\n \n-\twhile (pos < active_nr) {\n-\t\tstruct cache_entry *ce = active_cache[pos];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tstruct cache_entry *ce = the_index.cache[pos];\n \t\tif (ce_namelen(ce) != namelen ||\n \t\t    memcmp(ce->name, name, namelen))\n \t\t\tbreak;\n@@ -97,8 +97,8 @@ static void checkout_all(const char *pre\n \tint i, errs = 0;\n \tstruct cache_entry *last_ce = NULL;\n \n-\tfor (i = 0; i < active_nr ; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr ; i++) {\n+\t\tstruct cache_entry *ce = the_index.cache[i];\n \t\tif (ce_stage(ce) != checkout_stage\n \t\t    && (CHECKOUT_ALL != checkout_stage || !ce_stage(ce)))\n \t\t\tcontinue;\n@@ -185,7 +185,7 @@ int cmd_checkout_index(int argc, const c\n \tgit_config(git_default_config, NULL);\n \tprefix_length = prefix ? strlen(prefix) : 0;\n \n-\tif (read_cache() < 0) {\n+\tif (read_index(&the_index) < 0) {\n \t\tdie(\"invalid cache\");\n \t}\n \n--- builtin/checkout.c\n+++ /tmp/cocci-output-206228-3a013e-checkout.c\n@@ -91,9 +91,9 @@ static int update_some(const struct obje\n \t * entry in place. Whether it is UPTODATE or not, checkout_entry will\n \t * do the right thing.\n \t */\n-\tpos = cache_name_pos(ce->name, ce->ce_namelen);\n+\tpos = index_name_pos(&the_index, ce->name, ce->ce_namelen);\n \tif (pos >= 0) {\n-\t\tstruct cache_entry *old = active_cache[pos];\n+\t\tstruct cache_entry *old = the_index.cache[pos];\n \t\tif (ce->ce_mode == old->ce_mode &&\n \t\t    !oidcmp(&ce->oid, &old->oid)) {\n \t\t\told->ce_flags |= CE_UPDATE;\n@@ -102,7 +102,8 @@ static int update_some(const struct obje\n \t\t}\n \t}\n \n-\tadd_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n+\tadd_index_entry(&the_index, ce,\n+\t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \treturn 0;\n }\n \n@@ -119,17 +120,17 @@ static int read_tree_some(struct tree *t\n \n static int skip_same_name(const struct cache_entry *ce, int pos)\n {\n-\twhile (++pos < active_nr &&\n-\t       !strcmp(active_cache[pos]->name, ce->name))\n+\twhile (++pos < the_index.cache_nr &&\n+\t       !strcmp(the_index.cache[pos]->name, ce->name))\n \t\t; /* skip */\n \treturn pos;\n }\n \n static int check_stage(int stage, const struct cache_entry *ce, int pos)\n {\n-\twhile (pos < active_nr &&\n-\t       !strcmp(active_cache[pos]->name, ce->name)) {\n-\t\tif (ce_stage(active_cache[pos]) == stage)\n+\twhile (pos < the_index.cache_nr &&\n+\t       !strcmp(the_index.cache[pos]->name, ce->name)) {\n+\t\tif (ce_stage(the_index.cache[pos]) == stage)\n \t\t\treturn 0;\n \t\tpos++;\n \t}\n@@ -144,8 +145,8 @@ static int check_stages(unsigned stages,\n \tunsigned seen = 0;\n \tconst char *name = ce->name;\n \n-\twhile (pos < active_nr) {\n-\t\tce = active_cache[pos];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tce = the_index.cache[pos];\n \t\tif (strcmp(name, ce->name))\n \t\t\tbreak;\n \t\tseen |= (1 << ce_stage(ce));\n@@ -160,10 +161,11 @@ static int check_stages(unsigned stages,\n static int checkout_stage(int stage, const struct cache_entry *ce, int pos,\n \t\t\t  const struct checkout *state)\n {\n-\twhile (pos < active_nr &&\n-\t       !strcmp(active_cache[pos]->name, ce->name)) {\n-\t\tif (ce_stage(active_cache[pos]) == stage)\n-\t\t\treturn checkout_entry(active_cache[pos], state, NULL);\n+\twhile (pos < the_index.cache_nr &&\n+\t       !strcmp(the_index.cache[pos]->name, ce->name)) {\n+\t\tif (ce_stage(the_index.cache[pos]) == stage)\n+\t\t\treturn checkout_entry(the_index.cache[pos], state,\n+\t\t\t\t              NULL);\n \t\tpos++;\n \t}\n \tif (stage == 2)\n@@ -174,7 +176,7 @@ static int checkout_stage(int stage, con\n \n static int checkout_merged(int pos, const struct checkout *state)\n {\n-\tstruct cache_entry *ce = active_cache[pos];\n+\tstruct cache_entry *ce = the_index.cache[pos];\n \tconst char *path = ce->name;\n \tmmfile_t ancestor, ours, theirs;\n \tint status;\n@@ -184,7 +186,7 @@ static int checkout_merged(int pos, cons\n \tunsigned mode = 0;\n \n \tmemset(threeway, 0, sizeof(threeway));\n-\twhile (pos < active_nr) {\n+\twhile (pos < the_index.cache_nr) {\n \t\tint stage;\n \t\tstage = ce_stage(ce);\n \t\tif (!stage || strcmp(path, ce->name))\n@@ -193,7 +195,7 @@ static int checkout_merged(int pos, cons\n \t\tif (stage == 2)\n \t\t\tmode = create_ce_mode(ce->ce_mode);\n \t\tpos++;\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \t}\n \tif (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))\n \t\treturn error(_(\"path '%s' does not have necessary versions\"), path);\n@@ -278,7 +280,7 @@ static int checkout_paths(const struct c\n \t\t\t\t\t   &opts->pathspec);\n \n \thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n-\tif (read_cache_preload(&opts->pathspec) < 0)\n+\tif (read_index_preload(&the_index, &opts->pathspec) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n \tif (opts->source_tree)\n@@ -290,8 +292,8 @@ static int checkout_paths(const struct c\n \t * Make sure all pathspecs participated in locating the paths\n \t * to be checked out.\n \t */\n-\tfor (pos = 0; pos < active_nr; pos++) {\n-\t\tstruct cache_entry *ce = active_cache[pos];\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n+\t\tstruct cache_entry *ce = the_index.cache[pos];\n \t\tce->ce_flags &= ~CE_MATCHED;\n \t\tif (!opts->ignore_skipworktree && ce_skip_worktree(ce))\n \t\t\tcontinue;\n@@ -333,8 +335,8 @@ static int checkout_paths(const struct c\n \t\tunmerge_marked_index(&the_index);\n \n \t/* Any unmerged paths? */\n-\tfor (pos = 0; pos < active_nr; pos++) {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tif (ce->ce_flags & CE_MATCHED) {\n \t\t\tif (!ce_stage(ce))\n \t\t\t\tcontinue;\n@@ -360,8 +362,8 @@ static int checkout_paths(const struct c\n \tstate.istate = &the_index;\n \n \tenable_delayed_checkout(&state);\n-\tfor (pos = 0; pos < active_nr; pos++) {\n-\t\tstruct cache_entry *ce = active_cache[pos];\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n+\t\tstruct cache_entry *ce = the_index.cache[pos];\n \t\tif (ce->ce_flags & CE_MATCHED) {\n \t\t\tif (!ce_stage(ce)) {\n \t\t\t\terrs |= checkout_entry(ce, &state, NULL);\n@@ -481,10 +483,10 @@ static int merge_working_tree(const stru\n \tstruct lock_file lock_file = LOCK_INIT;\n \n \thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n-\tif (read_cache_preload(NULL) < 0)\n+\tif (read_index_preload(&the_index, NULL) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \tif (opts->force) {\n \t\tret = reset_tree(get_commit_tree(new_branch_info->commit),\n \t\t\t\t opts, 1, writeout_error);\n@@ -502,15 +504,15 @@ static int merge_working_tree(const stru\n \n \t\tsetup_unpack_trees_porcelain(&topts, \"checkout\");\n \n-\t\trefresh_cache(REFRESH_QUIET);\n+\t\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \n-\t\tif (unmerged_cache()) {\n+\t\tif (unmerged_index(&the_index)) {\n \t\t\terror(_(\"you need to resolve your current index first\"));\n \t\t\treturn 1;\n \t\t}\n \n \t\t/* 2-way merge to the new branch */\n-\t\ttopts.initial_checkout = is_cache_unborn();\n+\t\ttopts.initial_checkout = is_index_unborn(&the_index);\n \t\ttopts.update = 1;\n \t\ttopts.merge = 1;\n \t\ttopts.gently = opts->merge && old_branch_info->commit;\n@@ -598,10 +600,10 @@ static int merge_working_tree(const stru\n \t\t}\n \t}\n \n-\tif (!active_cache_tree)\n-\t\tactive_cache_tree = cache_tree();\n+\tif (!the_index.cache_tree)\n+\t\tthe_index.cache_tree = cache_tree();\n \n-\tif (!cache_tree_fully_valid(active_cache_tree))\n+\tif (!cache_tree_fully_valid(the_index.cache_tree))\n \t\tcache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);\n \n \tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n--- builtin/clean.c\n+++ /tmp/cocci-output-206233-6cec8a-clean.c\n@@ -955,7 +955,7 @@ int cmd_clean(int argc, const char **arg\n \tif (remove_directories)\n \t\tdir.flags |= DIR_SHOW_IGNORED_TOO | DIR_KEEP_UNTRACKED_CONTENTS;\n \n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tif (!ignored)\n@@ -978,7 +978,7 @@ int cmd_clean(int argc, const char **arg\n \t\tstruct stat st;\n \t\tconst char *rel;\n \n-\t\tif (!cache_name_is_other(ent->name, ent->len))\n+\t\tif (!index_name_is_other(&the_index, ent->name, ent->len))\n \t\t\tcontinue;\n \n \t\tif (pathspec.nr)\n--- builtin/commit.c\n+++ /tmp/cocci-output-206241-02f1a7-commit.c\n@@ -233,8 +233,8 @@ static int list_paths(struct string_list\n \t\tfree(max_prefix);\n \t}\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \t\tstruct string_list_item *item;\n \n \t\tif (ce->ce_flags & CE_UPDATE)\n@@ -263,10 +263,10 @@ static void add_remove_files(struct stri\n \t\t\tcontinue;\n \n \t\tif (!lstat(p->string, &st)) {\n-\t\t\tif (add_to_cache(p->string, &st, 0))\n+\t\t\tif (add_to_index(&the_index, p->string, &st, 0))\n \t\t\t\tdie(_(\"updating files failed\"));\n \t\t} else\n-\t\t\tremove_file_from_cache(p->string);\n+\t\t\tremove_file_from_index(&the_index, p->string);\n \t}\n }\n \n@@ -277,7 +277,7 @@ static void create_base_index(const stru\n \tstruct tree_desc t;\n \n \tif (!current_head) {\n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t\treturn;\n \t}\n \n@@ -304,7 +304,7 @@ static void refresh_cache_or_die(int ref\n \t * refresh_flags contains REFRESH_QUIET, so the only errors\n \t * are for unmerged entries.\n \t */\n-\tif (refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN))\n+\tif (refresh_index(&the_index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))\n \t\tdie_resolve_conflict(\"commit\");\n }\n \n@@ -322,7 +322,7 @@ static const char *prepare_index(int arg\n \t\t       PATHSPEC_PREFER_FULL,\n \t\t       prefix, argv);\n \n-\tif (read_cache_preload(&pathspec) < 0)\n+\tif (read_index_preload(&the_index, &pathspec) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tif (interactive) {\n@@ -345,8 +345,9 @@ static const char *prepare_index(int arg\n \t\telse\n \t\t\tunsetenv(INDEX_ENVIRONMENT);\n \n-\t\tdiscard_cache();\n-\t\tread_cache_from(get_lock_file_path(&index_lock));\n+\t\tdiscard_index(&the_index);\n+\t\tread_index_from(&the_index, get_lock_file_path(&index_lock),\n+\t\t\t\tget_git_dir());\n \t\tif (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {\n \t\t\tif (reopen_lock_file(&index_lock) < 0)\n \t\t\t\tdie(_(\"unable to write index file\"));\n@@ -396,8 +397,8 @@ static const char *prepare_index(int arg\n \tif (!only && !pathspec.nr) {\n \t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n \t\trefresh_cache_or_die(refresh_flags);\n-\t\tif (active_cache_changed\n-\t\t    || !cache_tree_fully_valid(active_cache_tree))\n+\t\tif (the_index.cache_changed\n+\t\t    || !cache_tree_fully_valid(the_index.cache_tree))\n \t\t\tupdate_main_cache_tree(WRITE_TREE_SILENT);\n \t\tif (write_locked_index(&the_index, &index_lock,\n \t\t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n@@ -438,13 +439,13 @@ static const char *prepare_index(int arg\n \tif (list_paths(&partial, !current_head ? NULL : \"HEAD\", prefix, &pathspec))\n \t\texit(1);\n \n-\tdiscard_cache();\n-\tif (read_cache() < 0)\n+\tdiscard_index(&the_index);\n+\tif (read_index(&the_index) < 0)\n \t\tdie(_(\"cannot read the index\"));\n \n \thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n \tadd_remove_files(&partial);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \tupdate_main_cache_tree(WRITE_TREE_SILENT);\n \tif (write_locked_index(&the_index, &index_lock, 0))\n \t\tdie(_(\"unable to write new_index file\"));\n@@ -456,14 +457,14 @@ static const char *prepare_index(int arg\n \n \tcreate_base_index(current_head);\n \tadd_remove_files(&partial);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \n \tif (write_locked_index(&the_index, &false_lock, 0))\n \t\tdie(_(\"unable to write temporary index file\"));\n \n-\tdiscard_cache();\n+\tdiscard_index(&the_index);\n \tret = get_lock_file_path(&false_lock);\n-\tread_cache_from(ret);\n+\tread_index_from(&the_index, ret, get_git_dir());\n out:\n \tstring_list_clear(&partial, 0);\n \tclear_pathspec(&pathspec);\n@@ -864,7 +865,7 @@ static int prepare_to_commit(const char\n \t\tstruct object_id oid;\n \t\tconst char *parent = \"HEAD\";\n \n-\t\tif (!active_nr && read_cache() < 0)\n+\t\tif (!the_index.cache_nr && read_index(&the_index) < 0)\n \t\t\tdie(_(\"Cannot read index\"));\n \n \t\tif (amend)\n@@ -873,10 +874,10 @@ static int prepare_to_commit(const char\n \t\tif (get_oid(parent, &oid)) {\n \t\t\tint i, ita_nr = 0;\n \n-\t\t\tfor (i = 0; i < active_nr; i++)\n-\t\t\t\tif (ce_intent_to_add(active_cache[i]))\n+\t\t\tfor (i = 0; i < the_index.cache_nr; i++)\n+\t\t\t\tif (ce_intent_to_add(the_index.cache[i]))\n \t\t\t\t\tita_nr++;\n-\t\t\tcommitable = active_nr - ita_nr > 0;\n+\t\t\tcommitable = the_index.cache_nr - ita_nr > 0;\n \t\t} else {\n \t\t\t/*\n \t\t\t * Unless the user did explicitly request a submodule\n@@ -926,9 +927,9 @@ static int prepare_to_commit(const char\n \t\t * and write it out as a tree.  We must do this before we invoke\n \t\t * the editor and after we invoke run_status above.\n \t\t */\n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t}\n-\tread_cache_from(index_file);\n+\tread_index_from(&the_index, index_file, get_git_dir());\n \n \tif (update_main_cache_tree(0)) {\n \t\terror(_(\"Error building trees\"));\n--- builtin/diff-files.c\n+++ /tmp/cocci-output-206251-46b008-diff-files.c\n@@ -66,7 +66,7 @@ int cmd_diff_files(int argc, const char\n \t    (rev.diffopt.output_format & DIFF_FORMAT_PATCH))\n \t\trev.combine_merges = rev.dense_combined_merges = 1;\n \n-\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n+\tif (read_index_preload(&the_index, &rev.diffopt.pathspec) < 0) {\n \t\tperror(\"read_cache_preload\");\n \t\treturn -1;\n \t}\n--- builtin/diff-index.c\n+++ /tmp/cocci-output-206256-83e320-diff-index.c\n@@ -48,11 +48,11 @@ int cmd_diff_index(int argc, const char\n \t\tusage(diff_cache_usage);\n \tif (!cached) {\n \t\tsetup_work_tree();\n-\t\tif (read_cache_preload(&rev.diffopt.pathspec) < 0) {\n+\t\tif (read_index_preload(&the_index, &rev.diffopt.pathspec) < 0) {\n \t\t\tperror(\"read_cache_preload\");\n \t\t\treturn -1;\n \t\t}\n-\t} else if (read_cache() < 0) {\n+\t} else if (read_index(&the_index) < 0) {\n \t\tperror(\"read_cache\");\n \t\treturn -1;\n \t}\n--- builtin/diff-tree.c\n+++ /tmp/cocci-output-206261-e5cd9c-diff-tree.c\n@@ -111,7 +111,7 @@ int cmd_diff_tree(int argc, const char *\n \n \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n \tinit_revisions(opt, the_repository, prefix);\n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \topt->abbrev = 0;\n \topt->diff = 1;\n--- builtin/diff.c\n+++ /tmp/cocci-output-206266-07f964-diff.c\n@@ -146,11 +146,11 @@ static int builtin_diff_index(struct rev\n \t\tusage(builtin_diff_usage);\n \tif (!cached) {\n \t\tsetup_work_tree();\n-\t\tif (read_cache_preload(&revs->diffopt.pathspec) < 0) {\n+\t\tif (read_index_preload(&the_index, &revs->diffopt.pathspec) < 0) {\n \t\t\tperror(\"read_cache_preload\");\n \t\t\treturn -1;\n \t\t}\n-\t} else if (read_cache() < 0) {\n+\t} else if (read_index(&the_index) < 0) {\n \t\tperror(\"read_cache\");\n \t\treturn -1;\n \t}\n@@ -211,9 +211,10 @@ static void refresh_index_quietly(void)\n \tfd = hold_locked_index(&lock_file, 0);\n \tif (fd < 0)\n \t\treturn;\n-\tdiscard_cache();\n-\tread_cache();\n-\trefresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);\n+\tdiscard_index(&the_index);\n+\tread_index(&the_index);\n+\trefresh_index(&the_index, REFRESH_QUIET | REFRESH_UNMERGED, NULL,\n+\t\t      NULL, NULL);\n \trepo_update_index_if_able(the_repository, &lock_file);\n }\n \n@@ -248,7 +249,7 @@ static int builtin_diff_files(struct rev\n \t\trevs->combine_merges = revs->dense_combined_merges = 1;\n \n \tsetup_work_tree();\n-\tif (read_cache_preload(&revs->diffopt.pathspec) < 0) {\n+\tif (read_index_preload(&the_index, &revs->diffopt.pathspec) < 0) {\n \t\tperror(\"read_cache_preload\");\n \t\treturn -1;\n \t}\n--- builtin/fsck.c\n+++ /tmp/cocci-output-206277-317c6c-fsck.c\n@@ -798,16 +798,16 @@ int cmd_fsck(int argc, const char **argv\n \tif (keep_cache_objects) {\n \t\tverify_index_checksum = 1;\n \t\tverify_ce_order = 1;\n-\t\tread_cache();\n-\t\tfor (i = 0; i < active_nr; i++) {\n+\t\tread_index(&the_index);\n+\t\tfor (i = 0; i < the_index.cache_nr; i++) {\n \t\t\tunsigned int mode;\n \t\t\tstruct blob *blob;\n \t\t\tstruct object *obj;\n \n-\t\t\tmode = active_cache[i]->ce_mode;\n+\t\t\tmode = the_index.cache[i]->ce_mode;\n \t\t\tif (S_ISGITLINK(mode))\n \t\t\t\tcontinue;\n-\t\t\tblob = lookup_blob(&active_cache[i]->oid);\n+\t\t\tblob = lookup_blob(&the_index.cache[i]->oid);\n \t\t\tif (!blob)\n \t\t\t\tcontinue;\n \t\t\tobj = &blob->object;\n@@ -815,11 +815,11 @@ int cmd_fsck(int argc, const char **argv\n \t\t\tif (name_objects)\n \t\t\t\tadd_decoration(fsck_walk_options.object_names,\n \t\t\t\t\tobj,\n-\t\t\t\t\txstrfmt(\":%s\", active_cache[i]->name));\n+\t\t\t\t\txstrfmt(\":%s\", the_index.cache[i]->name));\n \t\t\tmark_object_reachable(obj);\n \t\t}\n-\t\tif (active_cache_tree)\n-\t\t\tfsck_cache_tree(active_cache_tree);\n+\t\tif (the_index.cache_tree)\n+\t\t\tfsck_cache_tree(the_index.cache_tree);\n \t}\n \n \tcheck_connectivity();\n--- builtin/merge.c\n+++ /tmp/cocci-output-206296-4e0c70-merge.c\n@@ -338,7 +338,7 @@ static void restore_state(const struct o\n \trun_command_v_opt(args, RUN_GIT_CMD);\n \n \tstrbuf_release(&sb);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n }\n \n /* This is called when no merge was necessary. */\n@@ -630,7 +630,7 @@ static int read_tree_trivial(struct obje\n \tif (!trees[nr_trees++])\n \t\treturn -1;\n \topts.fn = threeway_merge;\n-\tcache_tree_free(&active_cache_tree);\n+\tcache_tree_free(&the_index.cache_tree);\n \tfor (i = 0; i < nr_trees; i++) {\n \t\tparse_tree(trees[i]);\n \t\tinit_tree_desc(t+i, trees[i]->buffer, trees[i]->size);\n@@ -654,7 +654,7 @@ static int try_merge_strategy(const char\n \tconst char *head_arg = \"HEAD\";\n \n \thold_locked_index(&lock, LOCK_DIE_ON_ERROR);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \tif (write_locked_index(&the_index, &lock,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\treturn error(_(\"Unable to write index.\"));\n@@ -717,8 +717,8 @@ static int count_unmerged_entries(void)\n {\n \tint i, ret = 0;\n \n-\tfor (i = 0; i < active_nr; i++)\n-\t\tif (ce_stage(active_cache[i]))\n+\tfor (i = 0; i < the_index.cache_nr; i++)\n+\t\tif (ce_stage(the_index.cache[i]))\n \t\t\tret++;\n \n \treturn ret;\n@@ -812,7 +812,7 @@ static int merge_trivial(struct commit *\n \tstruct lock_file lock = LOCK_INIT;\n \n \thold_locked_index(&lock, LOCK_DIE_ON_ERROR);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \tif (write_locked_index(&the_index, &lock,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\treturn error(_(\"Unable to write index.\"));\n@@ -1237,7 +1237,7 @@ int cmd_merge(int argc, const char **arg\n \t\tgoto done;\n \t}\n \n-\tif (read_cache_unmerged())\n+\tif (read_index_unmerged(&the_index))\n \t\tdie_resolve_conflict(\"merge\");\n \n \tif (file_exists(git_path_merge_head())) {\n@@ -1258,7 +1258,7 @@ int cmd_merge(int argc, const char **arg\n \t\telse\n \t\t\tdie(_(\"You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\"));\n \t}\n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \n \tif (verbosity < 0)\n \t\tshow_diffstat = 0;\n@@ -1458,7 +1458,7 @@ int cmd_merge(int argc, const char **arg\n \t\t * We are not doing octopus, not fast-forward, and have\n \t\t * only one common.\n \t\t */\n-\t\trefresh_cache(REFRESH_QUIET);\n+\t\trefresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);\n \t\tif (allow_trivial && fast_forward != FF_ONLY) {\n \t\t\t/* See if it is really trivial. */\n \t\t\tgit_committer_info(IDENT_STRICT);\n--- builtin/merge-index.c\n+++ /tmp/cocci-output-206303-7bfaf2-merge-index.c\n@@ -13,11 +13,11 @@ static int merge_entry(int pos, const ch\n \tchar hexbuf[4][GIT_MAX_HEXSZ + 1];\n \tchar ownbuf[4][60];\n \n-\tif (pos >= active_nr)\n+\tif (pos >= the_index.cache_nr)\n \t\tdie(\"git merge-index: %s not in the cache\", path);\n \tfound = 0;\n \tdo {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tint stage = ce_stage(ce);\n \n \t\tif (strcmp(ce->name, path))\n@@ -27,7 +27,7 @@ static int merge_entry(int pos, const ch\n \t\txsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), \"%o\", ce->ce_mode);\n \t\targuments[stage] = hexbuf[stage];\n \t\targuments[stage + 4] = ownbuf[stage];\n-\t} while (++pos < active_nr);\n+\t} while (++pos < the_index.cache_nr);\n \tif (!found)\n \t\tdie(\"git merge-index: %s not in the cache\", path);\n \n@@ -45,7 +45,7 @@ static int merge_entry(int pos, const ch\n \n static void merge_one_path(const char *path)\n {\n-\tint pos = cache_name_pos(path, strlen(path));\n+\tint pos = index_name_pos(&the_index, path, strlen(path));\n \n \t/*\n \t * If it already exists in the cache as stage0, it's\n@@ -58,8 +58,8 @@ static void merge_one_path(const char *p\n static void merge_all(void)\n {\n \tint i;\n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \t\ti += merge_entry(i, ce->name)-1;\n@@ -78,7 +78,7 @@ int cmd_merge_index(int argc, const char\n \tif (argc < 3)\n \t\tusage(\"git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])\");\n \n-\tread_cache();\n+\tread_index(&the_index);\n \n \ti = 1;\n \tif (!strcmp(argv[i], \"-o\")) {\n--- builtin/merge-ours.c\n+++ /tmp/cocci-output-206308-f9d113-merge-ours.c\n@@ -25,7 +25,7 @@ int cmd_merge_ours(int argc, const char\n \t * commit.  The index must match HEAD, or this merge cannot go\n \t * through.\n \t */\n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie_errno(\"read_cache failed\");\n \tif (index_differs_from(\"HEAD\", NULL, 0))\n \t\texit(2);\n--- builtin/mv.c\n+++ /tmp/cocci-output-206317-dcc551-mv.c\n@@ -79,7 +79,7 @@ static void prepare_move_submodule(const\n \t\t\t\t   const char **submodule_gitfile)\n {\n \tstruct strbuf submodule_dotgit = STRBUF_INIT;\n-\tif (!S_ISGITLINK(active_cache[first]->ce_mode))\n+\tif (!S_ISGITLINK(the_index.cache[first]->ce_mode))\n \t\tdie(_(\"Directory %s is in index and no submodule?\"), src);\n \tif (!is_staging_gitmodules_ok(&the_index))\n \t\tdie(_(\"Please stage your changes to .gitmodules or stash them to proceed\"));\n@@ -98,13 +98,13 @@ static int index_range_of_same_dir(const\n \tconst char *src_w_slash = add_slash(src);\n \tint first, last, len_w_slash = length + 1;\n \n-\tfirst = cache_name_pos(src_w_slash, len_w_slash);\n+\tfirst = index_name_pos(&the_index, src_w_slash, len_w_slash);\n \tif (first >= 0)\n \t\tdie(_(\"%.*s is in index\"), len_w_slash, src_w_slash);\n \n \tfirst = -1 - first;\n-\tfor (last = first; last < active_nr; last++) {\n-\t\tconst char *path = active_cache[last]->name;\n+\tfor (last = first; last < the_index.cache_nr; last++) {\n+\t\tconst char *path = the_index.cache[last]->name;\n \t\tif (strncmp(path, src_w_slash, len_w_slash))\n \t\t\tbreak;\n \t}\n@@ -141,7 +141,7 @@ int cmd_mv(int argc, const char **argv,\n \t\tusage_with_options(builtin_mv_usage, builtin_mv_options);\n \n \thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tsource = internal_prefix_pathspec(prefix, argv, argc, 0);\n@@ -189,7 +189,7 @@ int cmd_mv(int argc, const char **argv,\n \t\t\t\t&& lstat(dst, &st) == 0)\n \t\t\tbad = _(\"cannot move directory over file\");\n \t\telse if (src_is_dir) {\n-\t\t\tint first = cache_name_pos(src, length), last;\n+\t\t\tint first = index_name_pos(&the_index, src, length), last;\n \n \t\t\tif (first >= 0)\n \t\t\t\tprepare_move_submodule(src, first,\n@@ -211,7 +211,7 @@ int cmd_mv(int argc, const char **argv,\n \t\t\t\tdst_len = strlen(dst);\n \n \t\t\t\tfor (j = 0; j < last - first; j++) {\n-\t\t\t\t\tconst char *path = active_cache[first + j]->name;\n+\t\t\t\t\tconst char *path = the_index.cache[first + j]->name;\n \t\t\t\t\tsource[argc + j] = path;\n \t\t\t\t\tdestination[argc + j] =\n \t\t\t\t\t\tprefix_path(dst, dst_len, path + length + 1);\n@@ -220,7 +220,7 @@ int cmd_mv(int argc, const char **argv,\n \t\t\t\t}\n \t\t\t\targc += last - first;\n \t\t\t}\n-\t\t} else if (cache_name_pos(src, length) < 0)\n+\t\t} else if (index_name_pos(&the_index, src, length) < 0)\n \t\t\tbad = _(\"not under version control\");\n \t\telse if (lstat(dst, &st) == 0 &&\n \t\t\t (!ignore_case || strcasecmp(src, dst))) {\n@@ -288,9 +288,9 @@ int cmd_mv(int argc, const char **argv,\n \t\tif (mode == WORKING_DIRECTORY)\n \t\t\tcontinue;\n \n-\t\tpos = cache_name_pos(src, strlen(src));\n+\t\tpos = index_name_pos(&the_index, src, strlen(src));\n \t\tassert(pos >= 0);\n-\t\trename_cache_entry_at(pos, dst);\n+\t\trename_index_entry_at(&the_index, pos, dst);\n \t}\n \n \tif (gitmodules_modified)\n--- builtin/pull.c\n+++ /tmp/cocci-output-206330-aaaaf5-pull.c\n@@ -864,7 +864,7 @@ int cmd_pull(int argc, const char **argv\n \tif (opt_rebase < 0)\n \t\topt_rebase = config_get_rebase();\n \n-\tif (read_cache_unmerged())\n+\tif (read_index_unmerged(&the_index))\n \t\tdie_resolve_conflict(\"pull\");\n \n \tif (file_exists(git_path_merge_head()))\n@@ -881,7 +881,7 @@ int cmd_pull(int argc, const char **argv\n \t\tif (opt_autostash != -1)\n \t\t\tautostash = opt_autostash;\n \n-\t\tif (is_null_oid(&orig_head) && !is_cache_unborn())\n+\t\tif (is_null_oid(&orig_head) && !is_index_unborn(&the_index))\n \t\t\tdie(_(\"Updating an unborn branch with changes added to the index.\"));\n \n \t\tif (!autostash)\n--- builtin/read-tree.c\n+++ /tmp/cocci-output-206336-40b38a-read-tree.c\n@@ -180,11 +180,11 @@ int cmd_read_tree(int argc, const char *\n \t */\n \n \tif (opts.reset || opts.merge || opts.prefix) {\n-\t\tif (read_cache_unmerged() && (opts.prefix || opts.merge))\n+\t\tif (read_index_unmerged(&the_index) && (opts.prefix || opts.merge))\n \t\t\tdie(\"You need to resolve your current index first\");\n \t\tstage = opts.merge = 1;\n \t}\n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \n \tfor (i = 0; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n@@ -220,7 +220,7 @@ int cmd_read_tree(int argc, const char *\n \t\t\tbreak;\n \t\tcase 2:\n \t\t\topts.fn = twoway_merge;\n-\t\t\topts.initial_checkout = is_cache_unborn();\n+\t\t\topts.initial_checkout = is_index_unborn(&the_index);\n \t\t\tbreak;\n \t\tcase 3:\n \t\tdefault:\n@@ -237,7 +237,7 @@ int cmd_read_tree(int argc, const char *\n \tif (opts.debug_unpack)\n \t\topts.fn = debug_merge;\n \n-\tcache_tree_free(&active_cache_tree);\n+\tcache_tree_free(&the_index.cache_tree);\n \tfor (i = 0; i < nr_trees; i++) {\n \t\tstruct tree *tree = trees[i];\n \t\tparse_tree(tree);\n--- builtin/reset.c\n+++ /tmp/cocci-output-206350-640828-reset.c\n@@ -71,7 +71,7 @@ static int reset_index(const struct obje\n \t\topts.reset = 1;\n \t}\n \n-\tread_cache_unmerged();\n+\tread_index_unmerged(&the_index);\n \n \tif (reset_type == KEEP) {\n \t\tstruct object_id head_oid;\n@@ -131,7 +131,7 @@ static void update_index_from_diff(struc\n \t\tstruct cache_entry *ce;\n \n \t\tif (is_missing && !intent_to_add) {\n-\t\t\tremove_file_from_cache(one->path);\n+\t\t\tremove_file_from_index(&the_index, one->path);\n \t\t\tcontinue;\n \t\t}\n \n@@ -144,7 +144,8 @@ static void update_index_from_diff(struc\n \t\t\tce->ce_flags |= CE_INTENT_TO_ADD;\n \t\t\tset_object_name_for_intent_to_add_entry(ce);\n \t\t}\n-\t\tadd_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n+\t\tadd_index_entry(&the_index, ce,\n+\t\t\t\tADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);\n \t}\n }\n \n@@ -187,7 +188,7 @@ static void set_reflog_message(struct st\n \n static void die_if_unmerged_cache(int reset_type)\n {\n-\tif (is_merge() || unmerged_cache())\n+\tif (is_merge() || unmerged_index(&the_index))\n \t\tdie(_(\"Cannot do a %s reset in the middle of a merge.\"),\n \t\t    _(reset_type_names[reset_type]));\n \n@@ -239,7 +240,7 @@ static void parse_args(struct pathspec *\n \t}\n \t*rev_ret = rev;\n \n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tparse_pathspec(pathspec, 0,\n--- builtin/rev-parse.c\n+++ /tmp/cocci-output-206356-b7ba64-rev-parse.c\n@@ -889,7 +889,7 @@ int cmd_rev_parse(int argc, const char *\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--shared-index-path\")) {\n-\t\t\t\tif (read_cache() < 0)\n+\t\t\t\tif (read_index(&the_index) < 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--- builtin/rm.c\n+++ /tmp/cocci-output-206362-a79cb3-rm.c\n@@ -32,8 +32,8 @@ static int get_ours_cache_pos(const char\n {\n \tint i = -pos - 1;\n \n-\twhile ((i < active_nr) && !strcmp(active_cache[i]->name, path)) {\n-\t\tif (ce_stage(active_cache[i]) == 2)\n+\twhile ((i < the_index.cache_nr) && !strcmp(the_index.cache[i]->name, path)) {\n+\t\tif (ce_stage(the_index.cache[i]) == 2)\n \t\t\treturn i;\n \t\ti++;\n \t}\n@@ -69,13 +69,13 @@ static void submodules_absorb_gitdir_if_\n \t\tint pos;\n \t\tconst struct cache_entry *ce;\n \n-\t\tpos = cache_name_pos(name, strlen(name));\n+\t\tpos = index_name_pos(&the_index, name, strlen(name));\n \t\tif (pos < 0) {\n \t\t\tpos = get_ours_cache_pos(name, pos);\n \t\t\tif (pos < 0)\n \t\t\t\tcontinue;\n \t\t}\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \n \t\tif (!S_ISGITLINK(ce->ce_mode) ||\n \t\t    !file_exists(ce->name) ||\n@@ -114,7 +114,7 @@ static int check_local_mod(struct object\n \t\tint local_changes = 0;\n \t\tint staged_changes = 0;\n \n-\t\tpos = cache_name_pos(name, strlen(name));\n+\t\tpos = index_name_pos(&the_index, name, strlen(name));\n \t\tif (pos < 0) {\n \t\t\t/*\n \t\t\t * Skip unmerged entries except for populated submodules\n@@ -124,11 +124,11 @@ static int check_local_mod(struct object\n \t\t\tif (pos < 0)\n \t\t\t\tcontinue;\n \n-\t\t\tif (!S_ISGITLINK(active_cache[pos]->ce_mode) ||\n+\t\t\tif (!S_ISGITLINK(the_index.cache[pos]->ce_mode) ||\n \t\t\t    is_empty_dir(name))\n \t\t\t\tcontinue;\n \t\t}\n-\t\tce = active_cache[pos];\n+\t\tce = the_index.cache[pos];\n \n \t\tif (lstat(ce->name, &st) < 0) {\n \t\t\tif (!is_missing_file_error(errno))\n@@ -165,7 +165,7 @@ static int check_local_mod(struct object\n \t\t * Is the index different from the file in the work tree?\n \t\t * If it's a submodule, is its work tree modified?\n \t\t */\n-\t\tif (ce_match_stat(ce, &st, 0) ||\n+\t\tif (ie_match_stat(&the_index, ce, &st, 0) ||\n \t\t    (S_ISGITLINK(ce->ce_mode) &&\n \t\t     bad_to_remove_submodule(ce->name,\n \t\t\t\tSUBMODULE_REMOVAL_DIE_ON_ERROR |\n@@ -267,7 +267,7 @@ int cmd_rm(int argc, const char **argv,\n \n \thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n \n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n \tparse_pathspec(&pathspec, 0,\n@@ -277,8 +277,8 @@ int cmd_rm(int argc, const char **argv,\n \n \tseen = xcalloc(pathspec.nr, 1);\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \t\tif (!ce_path_match(&the_index, ce, &pathspec, seen))\n \t\t\tcontinue;\n \t\tALLOC_GROW(list.entry, list.nr + 1, list.alloc);\n@@ -342,7 +342,7 @@ int cmd_rm(int argc, const char **argv,\n \t\tif (!quiet)\n \t\t\tprintf(\"rm '%s'\\n\", path);\n \n-\t\tif (remove_file_from_cache(path))\n+\t\tif (remove_file_from_index(&the_index, path))\n \t\t\tdie(_(\"git rm: unable to remove %s\"), path);\n \t}\n \n--- builtin/submodule--helper.c\n+++ /tmp/cocci-output-206373-deb7ed-submodule--helper.c\n@@ -325,11 +325,11 @@ static int module_list_compute(int argc,\n \tif (pathspec->nr)\n \t\tps_matched = xcalloc(pathspec->nr, 1);\n \n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < the_index.cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[i];\n \n \t\tif (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),\n \t\t\t\t    0, ps_matched, 1) ||\n@@ -338,8 +338,8 @@ static int module_list_compute(int argc,\n \n \t\tALLOC_GROW(list->entries, list->nr + 1, list->alloc);\n \t\tlist->entries[list->nr++] = ce;\n-\t\twhile (i + 1 < active_nr &&\n-\t\t       !strcmp(ce->name, active_cache[i + 1]->name))\n+\t\twhile (i + 1 < the_index.cache_nr &&\n+\t\t       !strcmp(ce->name, the_index.cache[i + 1]->name))\n \t\t\t/*\n \t\t\t * Skip entries with the same name in different stages\n \t\t\t * to make sure an entry is returned only once.\n--- builtin/update-index.c\n+++ /tmp/cocci-output-206382-a11b11-update-index.c\n@@ -229,16 +229,16 @@ done:\n static int mark_ce_flags(const char *path, int flag, int mark)\n {\n \tint namelen = strlen(path);\n-\tint pos = cache_name_pos(path, namelen);\n+\tint pos = index_name_pos(&the_index, path, namelen);\n \tif (0 <= pos) {\n-\t\tmark_fsmonitor_invalid(&the_index, active_cache[pos]);\n+\t\tmark_fsmonitor_invalid(&the_index, the_index.cache[pos]);\n \t\tif (mark)\n-\t\t\tactive_cache[pos]->ce_flags |= flag;\n+\t\t\tthe_index.cache[pos]->ce_flags |= flag;\n \t\telse\n-\t\t\tactive_cache[pos]->ce_flags &= ~flag;\n-\t\tactive_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;\n+\t\t\tthe_index.cache[pos]->ce_flags &= ~flag;\n+\t\tthe_index.cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;\n \t\tcache_tree_invalidate_path(&the_index, path);\n-\t\tactive_cache_changed |= CE_ENTRY_CHANGED;\n+\t\tthe_index.cache_changed |= CE_ENTRY_CHANGED;\n \t\treturn 0;\n \t}\n \treturn -1;\n@@ -248,7 +248,7 @@ static int remove_one_path(const char *p\n {\n \tif (!allow_remove)\n \t\treturn error(\"%s: does not exist and --remove not passed\", path);\n-\tif (remove_file_from_cache(path))\n+\tif (remove_file_from_index(&the_index, path))\n \t\treturn error(\"%s: cannot remove from the index\", path);\n \treturn 0;\n }\n@@ -273,7 +273,7 @@ static int add_one_path(const struct cac\n \tstruct cache_entry *ce;\n \n \t/* Was the old index entry already up-to-date? */\n-\tif (old && !ce_stage(old) && !ce_match_stat(old, st, 0))\n+\tif (old && !ce_stage(old) && !ie_match_stat(&the_index, old, st, 0))\n \t\treturn 0;\n \n \tsize = cache_entry_size(len);\n@@ -291,7 +291,7 @@ static int add_one_path(const struct cac\n \t}\n \toption = allow_add ? ADD_CACHE_OK_TO_ADD : 0;\n \toption |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;\n-\tif (add_cache_entry(ce, option)) {\n+\tif (add_index_entry(&the_index, ce, option)) {\n \t\tfree(ce);\n \t\treturn error(\"%s: cannot add to the index - missing --add option?\", path);\n \t}\n@@ -324,11 +324,11 @@ static int add_one_path(const struct cac\n static int process_directory(const char *path, int len, struct stat *st)\n {\n \tstruct object_id oid;\n-\tint pos = cache_name_pos(path, len);\n+\tint pos = index_name_pos(&the_index, path, len);\n \n \t/* Exact match: file or existing gitlink */\n \tif (pos >= 0) {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tif (S_ISGITLINK(ce->ce_mode)) {\n \n \t\t\t/* Do nothing to the index if there is no HEAD! */\n@@ -343,8 +343,8 @@ static int process_directory(const char\n \n \t/* Inexact match: is there perhaps a subdirectory match? */\n \tpos = -pos-1;\n-\twhile (pos < active_nr) {\n-\t\tconst struct cache_entry *ce = active_cache[pos++];\n+\twhile (pos < the_index.cache_nr) {\n+\t\tconst struct cache_entry *ce = the_index.cache[pos++];\n \n \t\tif (strncmp(ce->name, path, len))\n \t\t\tbreak;\n@@ -374,15 +374,15 @@ static int process_path(const char *path\n \tif (has_symlink_leading_path(path, len))\n \t\treturn error(\"'%s' is beyond a symbolic link\", path);\n \n-\tpos = cache_name_pos(path, len);\n-\tce = pos < 0 ? NULL : active_cache[pos];\n+\tpos = index_name_pos(&the_index, path, len);\n+\tce = pos < 0 ? NULL : the_index.cache[pos];\n \tif (ce && ce_skip_worktree(ce)) {\n \t\t/*\n \t\t * working directory version is assumed \"good\"\n \t\t * so updating it does not make sense.\n \t\t * On the other hand, removing it from index should work\n \t\t */\n-\t\tif (allow_remove && remove_file_from_cache(path))\n+\t\tif (allow_remove && remove_file_from_index(&the_index, path))\n \t\t\treturn error(\"%s: cannot remove from the index\", path);\n \t\treturn 0;\n \t}\n@@ -422,7 +422,7 @@ static int add_cacheinfo(unsigned int mo\n \t\tce->ce_flags |= CE_VALID;\n \toption = allow_add ? ADD_CACHE_OK_TO_ADD : 0;\n \toption |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;\n-\tif (add_cache_entry(ce, option))\n+\tif (add_index_entry(&the_index, ce, option))\n \t\treturn error(\"%s: cannot add to the index - missing --add option?\",\n \t\t\t     path);\n \treport(\"add '%s'\", path);\n@@ -434,11 +434,11 @@ static void chmod_path(char flip, const\n \tint pos;\n \tstruct cache_entry *ce;\n \n-\tpos = cache_name_pos(path, strlen(path));\n+\tpos = index_name_pos(&the_index, path, strlen(path));\n \tif (pos < 0)\n \t\tgoto fail;\n-\tce = active_cache[pos];\n-\tif (chmod_cache_entry(ce, flip) < 0)\n+\tce = the_index.cache[pos];\n+\tif (chmod_index_entry(&the_index, ce, flip) < 0)\n \t\tgoto fail;\n \n \treport(\"chmod %cx '%s'\", flip, path);\n@@ -481,7 +481,7 @@ static void update_one(const char *path)\n \t}\n \n \tif (force_remove) {\n-\t\tif (remove_file_from_cache(path))\n+\t\tif (remove_file_from_index(&the_index, path))\n \t\t\tdie(\"git update-index: unable to remove %s\", path);\n \t\treport(\"remove '%s'\", path);\n \t\treturn;\n@@ -563,7 +563,7 @@ static void read_index_info(int nul_term\n \n \t\tif (!mode) {\n \t\t\t/* mode == 0 means there is no such path -- remove */\n-\t\t\tif (remove_file_from_cache(path_name))\n+\t\t\tif (remove_file_from_index(&the_index, path_name))\n \t\t\t\tdie(\"git update-index: unable to remove %s\",\n \t\t\t\t    ptr);\n \t\t}\n@@ -632,12 +632,12 @@ static int unresolve_one(const char *pat\n \tstruct cache_entry *ce_2 = NULL, *ce_3 = NULL;\n \n \t/* See if there is such entry in the index. */\n-\tpos = cache_name_pos(path, namelen);\n+\tpos = index_name_pos(&the_index, path, namelen);\n \tif (0 <= pos) {\n \t\t/* already merged */\n-\t\tpos = unmerge_cache_entry_at(pos);\n-\t\tif (pos < active_nr) {\n-\t\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tpos = unmerge_index_entry_at(&the_index, pos);\n+\t\tif (pos < the_index.cache_nr) {\n+\t\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\t\tif (ce_stage(ce) &&\n \t\t\t    ce_namelen(ce) == namelen &&\n \t\t\t    !memcmp(ce->name, path, namelen))\n@@ -650,8 +650,8 @@ static int unresolve_one(const char *pat\n \t\t * want to do anything in the former case.\n \t\t */\n \t\tpos = -pos-1;\n-\t\tif (pos < active_nr) {\n-\t\t\tconst struct cache_entry *ce = active_cache[pos];\n+\t\tif (pos < the_index.cache_nr) {\n+\t\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\t\tif (ce_namelen(ce) == namelen &&\n \t\t\t    !memcmp(ce->name, path, namelen)) {\n \t\t\t\tfprintf(stderr,\n@@ -680,13 +680,13 @@ static int unresolve_one(const char *pat\n \t\tgoto free_return;\n \t}\n \n-\tremove_file_from_cache(path);\n-\tif (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) {\n+\tremove_file_from_index(&the_index, path);\n+\tif (add_index_entry(&the_index, ce_2, ADD_CACHE_OK_TO_ADD)) {\n \t\terror(\"%s: cannot add our version to the index.\", path);\n \t\tret = -1;\n \t\tgoto free_return;\n \t}\n-\tif (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD))\n+\tif (!add_index_entry(&the_index, ce_3, ADD_CACHE_OK_TO_ADD))\n \t\treturn 0;\n \terror(\"%s: cannot add their version to the index.\", path);\n \tret = -1;\n@@ -746,8 +746,8 @@ static int do_reupdate(int ac, const cha\n \t\t */\n \t\thas_head = 0;\n  redo:\n-\tfor (pos = 0; pos < active_nr; pos++) {\n-\t\tconst struct cache_entry *ce = active_cache[pos];\n+\tfor (pos = 0; pos < the_index.cache_nr; pos++) {\n+\t\tconst struct cache_entry *ce = the_index.cache[pos];\n \t\tstruct cache_entry *old = NULL;\n \t\tint save_nr;\n \t\tchar *path;\n@@ -766,12 +766,12 @@ static int do_reupdate(int ac, const cha\n \t\t * path anymore, in which case, under 'allow_remove',\n \t\t * or worse yet 'allow_replace', active_nr may decrease.\n \t\t */\n-\t\tsave_nr = active_nr;\n+\t\tsave_nr = the_index.cache_nr;\n \t\tpath = xstrdup(ce->name);\n \t\tupdate_one(path);\n \t\tfree(path);\n \t\tfree(old);\n-\t\tif (save_nr != active_nr)\n+\t\tif (save_nr != the_index.cache_nr)\n \t\t\tgoto redo;\n \t}\n \tclear_pathspec(&pathspec);\n@@ -786,8 +786,9 @@ struct refresh_params {\n static int refresh(struct refresh_params *o, unsigned int flag)\n {\n \tsetup_work_tree();\n-\tread_cache_preload(NULL);\n-\t*o->has_errors |= refresh_cache(o->flags | flag);\n+\tread_index_preload(&the_index, NULL);\n+\t*o->has_errors |= refresh_index(&the_index, o->flags | flag, NULL,\n+\t\t\t\t\tNULL, NULL);\n \treturn 0;\n }\n \n@@ -816,7 +817,7 @@ static int chmod_callback(const struct o\n static int resolve_undo_clear_callback(const struct option *opt,\n \t\t\t\tconst char *arg, int unset)\n {\n-\tresolve_undo_clear();\n+\tresolve_undo_clear_index(&the_index);\n \treturn 0;\n }\n \n@@ -900,7 +901,7 @@ static int unresolve_callback(struct par\n \t*has_errors = do_unresolve(ctx->argc, ctx->argv,\n \t\t\t\tprefix, prefix ? strlen(prefix) : 0);\n \tif (*has_errors)\n-\t\tactive_cache_changed = 0;\n+\t\tthe_index.cache_changed = 0;\n \n \tctx->argv += ctx->argc - 1;\n \tctx->argc = 1;\n@@ -918,7 +919,7 @@ static int reupdate_callback(struct pars\n \t*has_errors = do_reupdate(ctx->argc, ctx->argv,\n \t\t\t\tprefix, prefix ? strlen(prefix) : 0);\n \tif (*has_errors)\n-\t\tactive_cache_changed = 0;\n+\t\tthe_index.cache_changed = 0;\n \n \tctx->argv += ctx->argc - 1;\n \tctx->argc = 1;\n@@ -1052,7 +1053,7 @@ int cmd_update_index(int argc, const cha\n \tif (newfd < 0)\n \t\tlock_error = errno;\n \n-\tentries = read_cache();\n+\tentries = read_index(&the_index);\n \tif (entries < 0)\n \t\tdie(\"cache corrupted\");\n \n@@ -1107,7 +1108,7 @@ int cmd_update_index(int argc, const cha\n \t\t\t    INDEX_FORMAT_LB, INDEX_FORMAT_UB);\n \n \t\tif (the_index.version != preferred_index_format)\n-\t\t\tactive_cache_changed |= SOMETHING_CHANGED;\n+\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n \t\tthe_index.version = preferred_index_format;\n \t}\n \n@@ -1194,7 +1195,7 @@ int cmd_update_index(int argc, const cha\n \t\treport(_(\"fsmonitor disabled\"));\n \t}\n \n-\tif (active_cache_changed || force_write) {\n+\tif (the_index.cache_changed || force_write) {\n \t\tif (newfd < 0) {\n \t\t\tif (refresh_args.flags & REFRESH_QUIET)\n \t\t\t\texit(128);\n--- t/helper/test-dump-untracked-cache.c\n+++ /tmp/cocci-output-206411-64fa0f-test-dump-untracked-cache.c\n@@ -48,7 +48,7 @@ int cmd_main(int ac, const char **av)\n \tignore_untracked_cache_config = 1;\n \n \tsetup_git_directory();\n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(\"unable to read index file\");\n \tuc = the_index.untracked;\n \tif (!uc) {\n--- t/helper/test-dump-cache-tree.c\n+++ /tmp/cocci-output-206428-a636a2-test-dump-cache-tree.c\n@@ -60,10 +60,10 @@ int cmd__dump_cache_tree(int ac, const c\n \tstruct index_state istate;\n \tstruct cache_tree *another = cache_tree();\n \tsetup_git_directory();\n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(\"unable to read index file\");\n \tistate = the_index;\n \tistate.cache_tree = another;\n \tcache_tree_update(&istate, WRITE_TREE_DRY_RUN);\n-\treturn dump_cache_tree(active_cache_tree, another, \"\");\n+\treturn dump_cache_tree(the_index.cache_tree, another, \"\");\n }\n--- t/helper/test-lazy-init-name-hash.c\n+++ /tmp/cocci-output-206438-8b586f-test-lazy-init-name-hash.c\n@@ -32,7 +32,7 @@ static void dump_run(void)\n \tstruct dir_entry *dir;\n \tstruct cache_entry *ce;\n \n-\tread_cache();\n+\tread_index(&the_index);\n \tif (single) {\n \t\ttest_lazy_init_name_hash(&the_index, 0);\n \t} else {\n@@ -53,7 +53,7 @@ static void dump_run(void)\n \t\tce = hashmap_iter_next(&iter_cache);\n \t}\n \n-\tdiscard_cache();\n+\tdiscard_index(&the_index);\n }\n \n /*\n@@ -70,7 +70,7 @@ static uint64_t time_runs(int try_thread\n \n \tfor (i = 0; i < count; i++) {\n \t\tt0 = getnanotime();\n-\t\tread_cache();\n+\t\tread_index(&the_index);\n \t\tt1 = getnanotime();\n \t\tnr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded);\n \t\tt2 = getnanotime();\n@@ -93,7 +93,7 @@ static uint64_t time_runs(int try_thread\n \t\t\t\t   the_index.cache_nr);\n \t\tfflush(stdout);\n \n-\t\tdiscard_cache();\n+\t\tdiscard_index(&the_index);\n \t}\n \n \tavg = sum / count;\n@@ -117,9 +117,9 @@ static void analyze_run(void)\n \tint i;\n \tint nr;\n \n-\tread_cache();\n+\tread_index(&the_index);\n \tcache_nr_limit = the_index.cache_nr;\n-\tdiscard_cache();\n+\tdiscard_index(&the_index);\n \n \tnr = analyze;\n \twhile (1) {\n@@ -132,23 +132,23 @@ static void analyze_run(void)\n \t\t\tnr = cache_nr_limit;\n \n \t\tfor (i = 0; i < count; i++) {\n-\t\t\tread_cache();\n+\t\t\tread_index(&the_index);\n \t\t\tthe_index.cache_nr = nr; /* cheap truncate of index */\n \t\t\tt1s = getnanotime();\n \t\t\ttest_lazy_init_name_hash(&the_index, 0);\n \t\t\tt2s = getnanotime();\n \t\t\tsum_single += (t2s - t1s);\n \t\t\tthe_index.cache_nr = cache_nr_limit;\n-\t\t\tdiscard_cache();\n+\t\t\tdiscard_index(&the_index);\n \n-\t\t\tread_cache();\n+\t\t\tread_index(&the_index);\n \t\t\tthe_index.cache_nr = nr; /* cheap truncate of index */\n \t\t\tt1m = getnanotime();\n \t\t\tnr_threads_used = test_lazy_init_name_hash(&the_index, 1);\n \t\t\tt2m = getnanotime();\n \t\t\tsum_multi += (t2m - t1m);\n \t\t\tthe_index.cache_nr = cache_nr_limit;\n-\t\t\tdiscard_cache();\n+\t\t\tdiscard_index(&the_index);\n \n \t\t\tif (!nr_threads_used)\n \t\t\t\tprintf(\"    [size %8d] [single %f]   non-threaded code path used\\n\",\n--- t/helper/test-read-cache.c\n+++ /tmp/cocci-output-206449-76a1d5-test-read-cache.c\n@@ -8,8 +8,8 @@ int cmd__read_cache(int argc, const char\n \t\tcnt = strtol(argv[1], NULL, 0);\n \tsetup_git_directory();\n \tfor (i = 0; i < cnt; i++) {\n-\t\tread_cache();\n-\t\tdiscard_cache();\n+\t\tread_index(&the_index);\n+\t\tdiscard_index(&the_index);\n \t}\n \treturn 0;\n }\n--- t/helper/test-scrap-cache-tree.c\n+++ /tmp/cocci-output-206458-4e21e5-test-scrap-cache-tree.c\n@@ -10,9 +10,9 @@ int cmd__scrap_cache_tree(int ac, const\n \n \tsetup_git_directory();\n \thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n-\tif (read_cache() < 0)\n+\tif (read_index(&the_index) < 0)\n \t\tdie(\"unable to read index file\");\n-\tactive_cache_tree = NULL;\n+\tthe_index.cache_tree = NULL;\n \tif (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))\n \t\tdie(\"unable to write index file\");\n \treturn 0;\n--- t/helper/test-write-cache.c\n+++ /tmp/cocci-output-206472-8a0fe8-test-write-cache.c\n@@ -9,7 +9,7 @@ int cmd__write_cache(int argc, const cha\n \tif (argc == 2)\n \t\tcnt = strtol(argv[1], NULL, 0);\n \tsetup_git_directory();\n-\tread_cache();\n+\tread_index(&the_index);\n \tfor (i = 0; i < cnt; i++) {\n \t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n \t\tif (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))\n"},{"id":"350468","messageId":"2c01d5ef-7b92-bf1f-75d0-147910feec08@gmail.com","threadId":"48719","inReplyTo":"20180616054157.32433-1-pclouds@gmail.com","subject":"Re: [PATCH 00/15] Kill the_index part 1, expose it","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2018-06-19T11:48:04Z","receivedAt":"2018-06-19T11:48:09Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 6/16/2018 1:41 AM, Nguyễn Thái Ngọc Duy wrote:\n> This is the beginning of the end of the_index. The problem with\n> the_index is it lets library code anywhere access it freely. This is\n> not good because from high level you may not realize that the_index is\n> being used while you don't want to touch index at all, or you want to\n> use a different index instead.\n>\n> This is a long series, 86 patches [1], so I'm going to split and\n> submit it in 15-20 patches at a time. The first two parts are trivial\n> though and could be safely fast tracked if needed.\n>\n> This is the first part, which kills the use of index compat macros\n> outside builtin/ and expose the_index in all library code. Later on we\n> will ban the_index from one file each time until it's gone for good.\n>\n> \"struct index_state *\" will be passed from builtin/ through the call\n> chain to the function that needs it. In some cases, \"struct\n> repository *\" will be passed instead when the whole operation spans\n> more than just the index.  By the end, the_index becomes part of\n> \"index compat macros\" and cannot be used outside builtin/\n>\n> Part one is mechanical conversion with the help of coccinelle. The\n> only real patches are the first and the last one.\n>\n> [1] https://gitlab.com/pclouds/git/commits/really-kill-the-index\n\nThis is a good series, and a good goal!\n\nOutside of dropping [PATCH 01/15] until all the changes are applied, \nthis patch looks like a good, mechanical change.\n\nThere are a lot of cross-cutting changes happening right now, between \nthis series of series and Stefan's series of series. Hopefully after \n2.18 is cut, a lot of these can graduate to master quickly. Personally, \nI find it difficult to base a patch off of multiple in-progress branches \nand would rather work off of a \"known good\" point like the tip of master.\n\nThanks,\n-Stolee\n"},{"id":"350474","messageId":"CACsJy8BLGJHZMqoGbx20B+b8qb8cry0DNRmzrjNyEgxqo13NBg@mail.gmail.com","threadId":"48719","inReplyTo":"2c01d5ef-7b92-bf1f-75d0-147910feec08@gmail.com","subject":"Re: [PATCH 00/15] Kill the_index part 1, expose it","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-19T14:48:07Z","receivedAt":"2018-06-19T14:48:37Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Jun 19, 2018 at 1:48 PM Derrick Stolee <stolee@gmail.com> wrote:\n> Personally,\n> I find it difficult to base a patch off of multiple in-progress branches\n> and would rather work off of a \"known good\" point like the tip of master.\n\nYou should always base your patches on 'master' (or even 'maint' if\nit's bug fixes that have a chance of entering 'maint'). We all we face\nconflicts at some point (mostly when we rebase after something gets\nmerged to master; or things are merged on 'pu'). But git-rerere should\nkeep conflict resolution easy (most of the time). I also expect Junio\nto kick and scream when patch series conflict badly on 'pu' and he\nwill decide which one goes first and kick others out temporarily.\n-- \nDuy\n"},{"id":"350475","messageId":"CACsJy8AkUyU+yECMSoNUm=SSNn+zXN5QbWEvYjkcngp0PzJ9PA@mail.gmail.com","threadId":"48719","inReplyTo":"20180619114143.206568-1-dstolee@microsoft.com","subject":"Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-19T14:51:29Z","receivedAt":"2018-06-19T14:52:00Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Jun 19, 2018 at 1:41 PM Derrick Stolee <stolee@gmail.com> wrote:\n>\n> Duy,\n>\n> Here is the patch that was generated by `make coccicheck`.\n>\n> Thanks,\n> -Stolee\n>\n> -->8--\n>\n> --- builtin/add.c\n\nAh right. This is on purpose. I think I mentioned in the commit\nmessage that builtin/ is not touched. Do we run 'make coccicheck'\nautomatically somewhere? If true, I need to move this script elsewhere\nbecause it's meant to run manually. You run it when you intend to do\nmore manual fixups afterwards. For builtin/, I think I'll wait until\n'struct repository *' conversion is complete then maybe fix them one\nby one.\n\n> +++ /tmp/cocci-output-206193-4c91ec-add.c\n> @@ -38,13 +38,13 @@ static void chmod_pathspec(struct pathsp\n>  {\n>         int i;\n>\n> -       for (i = 0; i < active_nr; i++) {\n> -               struct cache_entry *ce = active_cache[i];\n> +       for (i = 0; i < the_index.cache_nr; i++) {\n> +               struct cache_entry *ce = the_index.cache[i];\n>\n>                 if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))\n>                         continue;\n>\n> -               if (chmod_cache_entry(ce, flip) < 0)\n> +               if (chmod_index_entry(&the_index, ce, flip) < 0)\n>                         fprintf(stderr, \"cannot chmod %cx '%s'\\n\", flip, ce->name);\n>         }\n>  }\n-- \nDuy\n"},{"id":"350478","messageId":"d5511564-ef51-7e6c-521d-b9ccc2af1773@gmail.com","threadId":"48719","inReplyTo":"CACsJy8AkUyU+yECMSoNUm=SSNn+zXN5QbWEvYjkcngp0PzJ9PA@mail.gmail.com","subject":"Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2018-06-19T15:21:09Z","receivedAt":"2018-06-19T15:21:15Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 6/19/2018 10:51 AM, Duy Nguyen wrote:\n> On Tue, Jun 19, 2018 at 1:41 PM Derrick Stolee <stolee@gmail.com> wrote:\n>> Duy,\n>>\n>> Here is the patch that was generated by `make coccicheck`.\n>>\n>> Thanks,\n>> -Stolee\n>>\n>> -->8--\n>>\n>> --- builtin/add.c\n> Ah right. This is on purpose. I think I mentioned in the commit\n> message that builtin/ is not touched. Do we run 'make coccicheck'\n> automatically somewhere? If true, I need to move this script elsewhere\n> because it's meant to run manually. You run it when you intend to do\n> more manual fixups afterwards. For builtin/, I think I'll wait until\n> 'struct repository *' conversion is complete then maybe fix them one\n> by one.\n\nI don't think it is part of the CI runs, but some community members run \nthis themselves on 'next' and 'master'.\n\nI'm CC'ing Szeder, as he has contributed a fix to my own Coccinelle \nscript [1].\n\n[1] \nhttps://public-inbox.org/git/20180430093153.13040-1-szeder.dev@gmail.com/\n     [PATCH] coccinelle: avoid wrong transformation suggestions from \ncommit.cocci\n"},{"id":"350524","messageId":"c030f0d3-9b24-9751-b600-50463b7721fb@gmail.com","threadId":"48719","inReplyTo":"20180618184111.GC73085@google.com","subject":"Re: [PATCH 00/15] Kill the_index part 1, expose it","fromName":"Ben Peart","fromEmail":"peartben@gmail.com","sentAt":"2018-06-19T19:00:20Z","receivedAt":"2018-06-19T19:00:29Z","isPatch":true,"sender":{"key":"benpeart@microsoft.com","avatar":"https://avatars.githubusercontent.com/u/15252029?v=4"},"body":"\n\nOn 6/18/2018 2:41 PM, Brandon Williams wrote:\n> On 06/17, Duy Nguyen wrote:\n>> On Sun, Jun 17, 2018 at 9:02 AM Elijah Newren <newren@gmail.com> wrote:\n>>>\n>>> On Fri, Jun 15, 2018 at 10:41 PM, Nguyễn Thái Ngọc Duy\n>>> <pclouds@gmail.com> wrote:\n>>>> This is the beginning of the end of the_index. The problem with\n>>>> the_index is it lets library code anywhere access it freely. This is\n>>>> not good because from high level you may not realize that the_index is\n>>>> being used while you don't want to touch index at all, or you want to\n>>>> use a different index instead.\n>>>>\n>>>> This is a long series, 86 patches [1], so I'm going to split and\n>>>> submit it in 15-20 patches at a time. The first two parts are trivial\n>>>> though and could be safely fast tracked if needed.\n>>>\n>>> You post this small little patch about unpack-trees.c, mentioning you\n>>> don't know if it's even correct, and bait me into reviewing it and\n>>> then spring on me that it's actually nearly 100 patches that need\n>>> review...   Very sneaky.  ;-)\n>>\n>> To be fair, it's all Brandon's fault. If he didn't kick the_index out\n>> of dir.c, it would not conflict with one of my out-of-tree patches in\n>> unpack-trees.c, catch my attention and make me go down this rabbit\n>> hole :D\n> \n> Haha well this is something I've wanted to do for over a year now, glad\n> you've decided to run with it :)\n> \n> I guess I've gotten pretty good at getting people to go down rabbit\n> holes.  First Stefan with the object store refactoring and now you with\n> the index stuff.  All because I wanted git to be more object oriented\n> and have less global state ;)\n> \n\nLet me join the chorus of voices excited to see someone finally taking \nthe plunge to do this!  I'm very happy about seeing this taken through \nto \"the end of the_index.\"\n"},{"id":"350864","messageId":"xmqqbmbypyis.fsf@gitster-ct.c.googlers.com","threadId":"48719","inReplyTo":"20180616054157.32433-3-pclouds@gmail.com","subject":"Re: [PATCH 02/15] apply.c: stop using index compat macros","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-06-25T17:27:23Z","receivedAt":"2018-06-25T17:27:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  apply.c | 34 +++++++++++++++++++---------------\n>  1 file changed, 19 insertions(+), 15 deletions(-)\n\nUntil all the codepaths that reach these callsites to index_*\nfunctions from cmd_main() are converted to pass \"struct index_state\n*\" throughout, a step like this patch does fundamentally changes\nnothing.  The only two issues worth addressing in this area still\nremain.  All the lines we see here still depend on the existence of\n\"the_index\" instance, and they can only operate on that single\n\"the_index\" instance and nothing else.\n\nIt is true that the dependency has been made more explicit, but it\nalready is explicit (to see them you just say \"no-the-index-macros\"\nand see what fails to compile).\n\nI see others are enthused with this series, but seeing the changes\nlike these I am not all that impressed.\n\nWould it become hard to review if we combine this step *and* the\nnext logical step (i.e. pass the \"struct index_state\" throughout the\ncallflow) into a single patch?  The functions in apply.c are fairly\nwell isolated and there won't be all that heavy interaction with the\noutside world if we convert this file (and it alone) without\ntouchning the other files.  If a division in that direction is\npossible, it may make a better orgainzation (i.e.  instead of doing\nwhole-tree superficial conversion that needs to be fixed up again\nlater, do a deep full conversion on selected files before going on\nto next set of files).\n\n"},{"id":"351410","messageId":"20180630083825.GA2436@duynguyen.home","threadId":"48719","inReplyTo":"xmqqbmbypyis.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 02/15] apply.c: stop using index compat macros","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-06-30T08:38:26Z","receivedAt":"2018-06-30T08:38:35Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Jun 25, 2018 at 10:27:23AM -0700, Junio C Hamano wrote:\n> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n> \n> > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> > ---\n> >  apply.c | 34 +++++++++++++++++++---------------\n> >  1 file changed, 19 insertions(+), 15 deletions(-)\n> \n> Until all the codepaths that reach these callsites to index_*\n> functions from cmd_main() are converted to pass \"struct index_state\n> *\" throughout, a step like this patch does fundamentally changes\n> nothing.  The only two issues worth addressing in this area still\n> remain.  All the lines we see here still depend on the existence of\n> \"the_index\" instance, and they can only operate on that single\n> \"the_index\" instance and nothing else.\n> \n> It is true that the dependency has been made more explicit, but it\n> already is explicit (to see them you just say \"no-the-index-macros\"\n> and see what fails to compile).\n> \n> I see others are enthused with this series, but seeing the changes\n> like these I am not all that impressed.\n\nI agree there is nothing to be impressed about these patches. These,\nstandalone, are worthless changes. I would not do this if I could not\ndelete all these the_index by the end. The changes are separated this\nway in order to reduce diff noise (indentation, function name changes)\nin later patches.\n\n> \n> Would it become hard to review if we combine this step *and* the\n> next logical step (i.e. pass the \"struct index_state\" throughout the\n> callflow) into a single patch? The functions in apply.c are fairly\n> well isolated and there won't be all that heavy interaction with the\n> outside world if we convert this file (and it alone) without\n> touchning the other files.\n\nA singe patch conversion would look like below. But for that to\nhappen, convert.c, rerere, ws.c and read-cache.c have to be converted\nfirst to not use the_index. A single patch to convert apply.c probably\npulls a lot more outside changes than just apply.c\n\n> If a division in that direction is possible, it may make a better\n> orgainzation (i.e.  instead of doing whole-tree superficial\n> conversion that needs to be fixed up again later, do a deep full\n> conversion on selected files before going on to next set of files).\n\nI think that's the direction in the following patches, where I try to\nkick the_index out of one file each time until they are gone.\n\nI'm ok with dropping these patches and incorporate them in the \"real\nconversion\" patches too. Let me know which way you want.\n\nAnyway the \"everything in apply.c\" patch would look like this, which\nis a combined patch of the following commits on my branch [1]\n\n18d1848077 read-cache.c: kill read_index()\ne8445d01a5 repository.c: replace hold_locked_index() with repo_hold_locked_index()\ncc970ac179 ws.c: remove implicit dependency on the_index\nb8a14120c4 rerere.c: remove implicit dependency on the_index\n6b68ac65dc ll-merge.c: remove implicit dependency on the_index\n5d990e1b71 apply.c: use apply_state->repo->index instead of the_index\ncb3f1ad8e8 apply.c: make init_apply_state() take a struct repository\na0bcf49024 apply.c: pass struct apply_state to more functions\n4265838aec apply.c: use the right index instead of the_index\n4fbbdbca80 read-cache.c: remove an implicit dependency on the_index\nef8bd1e81d convert.c: remove an implicit dependency on the_index\n\n[1] https://gitlab.com/pclouds/git/commits/really-kill-the-index\n\n-- 8< --\ndiff --git a/apply.c b/apply.c\nindex 57a7d3cafd..0ec5b1ec57 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -75,10 +75,12 @@ static int parse_ignorewhitespace_option(struct apply_state *state,\n }\n \n int init_apply_state(struct apply_state *state,\n+\t\t     struct repository *repo,\n \t\t     const char *prefix)\n {\n \tmemset(state, 0, sizeof(*state));\n \tstate->prefix = prefix;\n+\tstate->repo = repo;\n \tstate->apply = 1;\n \tstate->line_termination = '\\n';\n \tstate->p_value = 1;\n@@ -2126,10 +2128,12 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si\n \n \tif (!use_patch(state, patch))\n \t\tpatch->ws_rule = 0;\n+\telse if (patch->new_name)\n+\t\tpatch->ws_rule = whitespace_rule(state->repo->index,\n+\t\t\t\t\t\t patch->new_name);\n \telse\n-\t\tpatch->ws_rule = whitespace_rule(patch->new_name\n-\t\t\t\t\t\t ? patch->new_name\n-\t\t\t\t\t\t : patch->old_name);\n+\t\tpatch->ws_rule = whitespace_rule(state->repo->index,\n+\t\t\t\t\t\t patch->old_name);\n \n \tpatchsize = parse_single_patch(state,\n \t\t\t\t       buffer + offset + hdrsize,\n@@ -3371,14 +3375,16 @@ static struct patch *previous_patch(struct apply_state *state,\n \treturn previous;\n }\n \n-static int verify_index_match(const struct cache_entry *ce, struct stat *st)\n+static int verify_index_match(struct apply_state *state,\n+\t\t\t      const struct cache_entry *ce,\n+\t\t\t      struct stat *st)\n {\n \tif (S_ISGITLINK(ce->ce_mode)) {\n \t\tif (!S_ISDIR(st->st_mode))\n \t\t\treturn -1;\n \t\treturn 0;\n \t}\n-\treturn ie_match_stat(&the_index, ce, st,\n+\treturn ie_match_stat(state->repo->index, ce, st,\n \t\t\t     CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);\n }\n \n@@ -3460,7 +3466,8 @@ static int load_preimage(struct apply_state *state,\n \treturn 0;\n }\n \n-static int three_way_merge(struct image *image,\n+static int three_way_merge(struct apply_state *state,\n+\t\t\t   struct image *image,\n \t\t\t   char *path,\n \t\t\t   const struct object_id *base,\n \t\t\t   const struct object_id *ours,\n@@ -3476,7 +3483,9 @@ static int three_way_merge(struct image *image,\n \tstatus = ll_merge(&result, path,\n \t\t\t  &base_file, \"base\",\n \t\t\t  &our_file, \"ours\",\n-\t\t\t  &their_file, \"theirs\", NULL);\n+\t\t\t  &their_file, \"theirs\",\n+\t\t\t  state->repo->index,\n+\t\t\t  NULL);\n \tfree(base_file.ptr);\n \tfree(our_file.ptr);\n \tfree(their_file.ptr);\n@@ -3512,17 +3521,17 @@ static int load_current(struct apply_state *state,\n \tif (!patch->is_new)\n \t\tBUG(\"patch to %s is not a creation\", patch->old_name);\n \n-\tpos = index_name_pos(&the_index, name, strlen(name));\n+\tpos = index_name_pos(state->repo->index, name, strlen(name));\n \tif (pos < 0)\n \t\treturn error(_(\"%s: does not exist in index\"), name);\n-\tce = the_index.cache[pos];\n+\tce = state->repo->index->cache[pos];\n \tif (lstat(name, &st)) {\n \t\tif (errno != ENOENT)\n \t\t\treturn error_errno(\"%s\", name);\n-\t\tif (checkout_target(&the_index, ce, &st))\n+\t\tif (checkout_target(state->repo->index, ce, &st))\n \t\t\treturn -1;\n \t}\n-\tif (verify_index_match(ce, &st))\n+\tif (verify_index_match(state, ce, &st))\n \t\treturn error(_(\"%s: does not match index\"), name);\n \n \tstatus = load_patch_target(state, &buf, ce, &st, patch, name, mode);\n@@ -3588,7 +3597,7 @@ static int try_threeway(struct apply_state *state,\n \tclear_image(&tmp_image);\n \n \t/* in-core three-way merge between post and our using pre as base */\n-\tstatus = three_way_merge(image, patch->new_name,\n+\tstatus = three_way_merge(state, image, patch->new_name,\n \t\t\t\t &pre_oid, &our_oid, &post_oid);\n \tif (status < 0) {\n \t\tif (state->apply_verbosity > verbosity_silent)\n@@ -3681,19 +3690,19 @@ static int check_preimage(struct apply_state *state,\n \t}\n \n \tif (state->check_index && !previous) {\n-\t\tint pos = index_name_pos(&the_index, old_name,\n+\t\tint pos = index_name_pos(state->repo->index, old_name,\n \t\t\t\t\t strlen(old_name));\n \t\tif (pos < 0) {\n \t\t\tif (patch->is_new < 0)\n \t\t\t\tgoto is_new;\n \t\t\treturn error(_(\"%s: does not exist in index\"), old_name);\n \t\t}\n-\t\t*ce = the_index.cache[pos];\n+\t\t*ce = state->repo->index->cache[pos];\n \t\tif (stat_ret < 0) {\n-\t\t\tif (checkout_target(&the_index, *ce, st))\n+\t\t\tif (checkout_target(state->repo->index, *ce, st))\n \t\t\t\treturn -1;\n \t\t}\n-\t\tif (!state->cached && verify_index_match(*ce, st))\n+\t\tif (!state->cached && verify_index_match(state, *ce, st))\n \t\t\treturn error(_(\"%s: does not match index\"), old_name);\n \t\tif (state->cached)\n \t\t\tst_mode = (*ce)->ce_mode;\n@@ -3737,7 +3746,7 @@ static int check_to_create(struct apply_state *state,\n \tstruct stat nst;\n \n \tif (state->check_index &&\n-\t    index_name_pos(&the_index, new_name, strlen(new_name)) >= 0 &&\n+\t    index_name_pos(state->repo->index, new_name, strlen(new_name)) >= 0 &&\n \t    !ok_if_exists)\n \t\treturn EXISTS_IN_INDEX;\n \tif (state->cached)\n@@ -3826,7 +3835,7 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *na\n \t\tif (state->check_index) {\n \t\t\tstruct cache_entry *ce;\n \n-\t\t\tce = index_file_exists(&the_index, name->buf,\n+\t\t\tce = index_file_exists(state->repo->index, name->buf,\n \t\t\t\t\t       name->len, ignore_case);\n \t\t\tif (ce && S_ISLNK(ce->ce_mode))\n \t\t\t\treturn 1;\n@@ -4002,10 +4011,10 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)\n static int read_apply_cache(struct apply_state *state)\n {\n \tif (state->index_file)\n-\t\treturn read_index_from(&the_index, state->index_file,\n+\t\treturn read_index_from(state->repo->index, state->index_file,\n \t\t\t\t       get_git_dir());\n \telse\n-\t\treturn read_index(&the_index);\n+\t\treturn repo_read_index(state->repo);\n }\n \n /* This function tries to read the object name from the current index */\n@@ -4016,10 +4025,10 @@ static int get_current_oid(struct apply_state *state, const char *path,\n \n \tif (read_apply_cache(state) < 0)\n \t\treturn -1;\n-\tpos = index_name_pos(&the_index, path, strlen(path));\n+\tpos = index_name_pos(state->repo->index, path, strlen(path));\n \tif (pos < 0)\n \t\treturn -1;\n-\toidcpy(oid, &the_index.cache[pos]->oid);\n+\toidcpy(oid, &state->repo->index->cache[pos]->oid);\n \treturn 0;\n }\n \n@@ -4094,9 +4103,9 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)\n \t\t\treturn error(_(\"sha1 information is lacking or useless \"\n \t\t\t\t       \"(%s).\"), name);\n \n-\t\tce = make_cache_entry(patch->old_mode, oid.hash, name, 0, 0);\n+\t\tce = make_index_entry(&result, patch->old_mode, oid.hash, name, 0, 0);\n \t\tif (!ce)\n-\t\t\treturn error(_(\"make_cache_entry failed for path '%s'\"),\n+\t\t\treturn error(_(\"make_index_entry failed for path '%s'\"),\n \t\t\t\t     name);\n \t\tif (add_index_entry(&result, ce, ADD_CACHE_OK_TO_ADD)) {\n \t\t\tfree(ce);\n@@ -4247,7 +4256,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)\n static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)\n {\n \tif (state->update_index) {\n-\t\tif (remove_file_from_index(&the_index, patch->old_name) < 0)\n+\t\tif (remove_file_from_index(state->repo->index, patch->old_name) < 0)\n \t\t\treturn error(_(\"unable to remove %s from index\"), patch->old_name);\n \t}\n \tif (!state->cached) {\n@@ -4301,7 +4310,7 @@ static int add_index_file(struct apply_state *state,\n \t\t\t\t       \"for newly created file %s\"), path);\n \t\t}\n \t}\n-\tif (add_index_entry(&the_index, ce, ADD_CACHE_OK_TO_ADD) < 0) {\n+\tif (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {\n \t\tfree(ce);\n \t\treturn error(_(\"unable to add cache entry for %s\"), path);\n \t}\n@@ -4315,7 +4324,9 @@ static int add_index_file(struct apply_state *state,\n  *   0 if everything went well\n  *   1 if a recoverable error happened\n  */\n-static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)\n+static int try_create_file(struct apply_state *state, const char *path,\n+\t\t\t   unsigned int mode, const char *buf,\n+\t\t\t   unsigned long size)\n {\n \tint fd, res;\n \tstruct strbuf nbuf = STRBUF_INIT;\n@@ -4337,7 +4348,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,\n \tif (fd < 0)\n \t\treturn 1;\n \n-\tif (convert_to_working_tree(path, buf, size, &nbuf)) {\n+\tif (convert_to_working_tree(state->repo->index, path, buf, size, &nbuf)) {\n \t\tsize = nbuf.len;\n \t\tbuf  = nbuf.buf;\n \t}\n@@ -4373,7 +4384,7 @@ static int create_one_file(struct apply_state *state,\n \tif (state->cached)\n \t\treturn 0;\n \n-\tres = try_create_file(path, mode, buf, size);\n+\tres = try_create_file(state, path, mode, buf, size);\n \tif (res < 0)\n \t\treturn -1;\n \tif (!res)\n@@ -4382,7 +4393,7 @@ static int create_one_file(struct apply_state *state,\n \tif (errno == ENOENT) {\n \t\tif (safe_create_leading_directories(path))\n \t\t\treturn 0;\n-\t\tres = try_create_file(path, mode, buf, size);\n+\t\tres = try_create_file(state, path, mode, buf, size);\n \t\tif (res < 0)\n \t\t\treturn -1;\n \t\tif (!res)\n@@ -4404,7 +4415,7 @@ static int create_one_file(struct apply_state *state,\n \t\tfor (;;) {\n \t\t\tchar newpath[PATH_MAX];\n \t\t\tmksnpath(newpath, sizeof(newpath), \"%s~%u\", path, nr);\n-\t\t\tres = try_create_file(newpath, mode, buf, size);\n+\t\t\tres = try_create_file(state, newpath, mode, buf, size);\n \t\t\tif (res < 0)\n \t\t\t\treturn -1;\n \t\t\tif (!res) {\n@@ -4435,7 +4446,7 @@ static int add_conflicted_stages_file(struct apply_state *state,\n \tce_size = cache_entry_size(namelen);\n \tmode = patch->new_mode ? patch->new_mode : (S_IFREG | 0644);\n \n-\tremove_file_from_index(&the_index, patch->new_name);\n+\tremove_file_from_index(state->repo->index, patch->new_name);\n \tfor (stage = 1; stage < 4; stage++) {\n \t\tif (is_null_oid(&patch->threeway_stage[stage - 1]))\n \t\t\tcontinue;\n@@ -4445,7 +4456,7 @@ static int add_conflicted_stages_file(struct apply_state *state,\n \t\tce->ce_flags = create_ce_flags(stage);\n \t\tce->ce_namelen = namelen;\n \t\toidcpy(&ce->oid, &patch->threeway_stage[stage - 1]);\n-\t\tif (add_index_entry(&the_index, ce, ADD_CACHE_OK_TO_ADD) < 0) {\n+\t\tif (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {\n \t\t\tfree(ce);\n \t\t\treturn error(_(\"unable to add cache entry for %s\"),\n \t\t\t\t     patch->new_name);\n@@ -4619,7 +4630,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)\n \t\t}\n \t\tstring_list_clear(&cpath, 0);\n \n-\t\trerere(0);\n+\t\trerere(state->repo, 0);\n \t}\n \n \treturn errs;\n@@ -4697,7 +4708,8 @@ static int apply_patch(struct apply_state *state,\n \t\t\t\t\t\t  state->index_file,\n \t\t\t\t\t\t  LOCK_DIE_ON_ERROR);\n \t\telse\n-\t\t\thold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR);\n+\t\t\trepo_hold_locked_index(state->repo, &state->lock_file,\n+\t\t\t\t\t       LOCK_DIE_ON_ERROR);\n \t}\n \n \tif (state->check_index && read_apply_cache(state) < 0) {\n@@ -4893,7 +4905,7 @@ int apply_all_patches(struct apply_state *state,\n \t}\n \n \tif (state->update_index) {\n-\t\tres = write_locked_index(&the_index, &state->lock_file, COMMIT_LOCK);\n+\t\tres = write_locked_index(state->repo->index, &state->lock_file, COMMIT_LOCK);\n \t\tif (res) {\n \t\t\terror(_(\"Unable to write new index file\"));\n \t\t\tres = -128;\n-- 8< --\n"},{"id":"351636","messageId":"xmqqsh50qiiw.fsf@gitster-ct.c.googlers.com","threadId":"48719","inReplyTo":"20180630083825.GA2436@duynguyen.home","subject":"Re: [PATCH 02/15] apply.c: stop using index compat macros","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-07-03T18:30:15Z","receivedAt":"2018-07-03T18:30:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Duy Nguyen <pclouds@gmail.com> writes:\n\n> A singe patch conversion would look like below. But for that to\n> happen, convert.c, rerere, ws.c and read-cache.c have to be converted\n> first to not use the_index.\n\nYes, that was pretty much what I was driving at.  I do not have any\ntrouble seeing a patch that converts callees that are deep in the\ncallchain and are meant to serve helpers to make them capable of\nworking on arbitrary in-core index instance.  That's a welcome\nchange that allows us to reuse them in more context (namely, by\ncallers that want to work on istate that is not the_index\nthemselves).  Skipping the \"intermediate\" step like this patch would\nforce us to focus on converting these lower-layer dependencies.\n"},{"id":"351946","messageId":"CACsJy8DrGnK3eM1mL7eLUL1hBNct=8qNC2f=PmO+g+7rjV8idg@mail.gmail.com","threadId":"48719","inReplyTo":"xmqqsh50qiiw.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 02/15] apply.c: stop using index compat macros","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-07-09T14:35:17Z","receivedAt":"2018-07-09T14:35:47Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Jul 3, 2018 at 8:30 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Duy Nguyen <pclouds@gmail.com> writes:\n>\n> > A singe patch conversion would look like below. But for that to\n> > happen, convert.c, rerere, ws.c and read-cache.c have to be converted\n> > first to not use the_index.\n>\n> Yes, that was pretty much what I was driving at.  I do not have any\n> trouble seeing a patch that converts callees that are deep in the\n> callchain and are meant to serve helpers to make them capable of\n> working on arbitrary in-core index instance.  That's a welcome\n> change that allows us to reuse them in more context (namely, by\n> callers that want to work on istate that is not the_index\n> themselves).  Skipping the \"intermediate\" step like this patch would\n> force us to focus on converting these lower-layer dependencies.\n\nOK I'll drop part one and incorporate the changes in later patches.\n-- \nDuy\n"},{"id":"353336","messageId":"CAM0VKj=CuhY1VB6Hepe0an5pJvTufinewZrLkR2ofHc=HU962A@mail.gmail.com","threadId":"48719","inReplyTo":"d5511564-ef51-7e6c-521d-b9ccc2af1773@gmail.com","subject":"Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-07-23T12:56:14Z","receivedAt":"2018-07-23T12:56:29Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Jun 19, 2018 at 5:21 PM Derrick Stolee <stolee@gmail.com> wrote:\n>\n> On 6/19/2018 10:51 AM, Duy Nguyen wrote:\n\n> > Do we run 'make coccicheck'\n> > automatically somewhere? If true, I need to move this script elsewhere\n> > because it's meant to run manually. You run it when you intend to do\n> > more manual fixups afterwards. For builtin/, I think I'll wait until\n> > 'struct repository *' conversion is complete then maybe fix them one\n> > by one.\n>\n> I don't think it is part of the CI runs, but some community members run\n> this themselves on 'next' and 'master'.\n\nTravis CI does run 'make coccicheck' already, that's the\n\"StaticAnalysis\" build job.\n\nAlas, it's not particularly useful as it is, because Coccinelle's and\nin turn 'make coccicheck's exit code only indicates that Coccinelle\nmanaged to finish its analysis without any errors (e.g. no unknown\n--options, no missing files, no syntax errors in the semantic patches,\netc.), but it doesn't indicate whether it found any undesired code\npatterns to transform or not.\n\nI have been sitting on two patches implementing two different\napproaches to improve this situation for several months now (sorry :)\nI think I'll just pick the shorter-simpler of the two, and submit it\nshortly.\n"}]}