{"thread":{"id":"50159","subject":"Re: [PATCH 02/10] repository.c: replace hold_locked_index() with repo_hold_locked_index()","startedAt":"2019-01-05T05:52:20Z","lastAt":"2019-01-12T02:15:02Z","messageCount":25,"participants":["Martin Ågren","Nguyễn Thái Ngọc Duy","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":10},"messages":[{"id":"366191","messageId":"20190105055153.3256-1-pclouds@gmail.com","threadId":"50159","inReplyTo":null,"subject":"[PATCH 00/10] Remove the_index, the final part","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:43Z","receivedAt":"2019-01-05T05:52:20Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This completely removes the_index outside builtin/. The macro\nNO_THE_INDEX_COMPATIBILITY_MACROS is replaced with\nUSE_THE_INDEX_COMPATIBILITY_MACROS, which means by default you don't\nhave access to the_index any more. And USE_THE_... should only be\ndefined in builtin/\n\nThere's one easy conflict in builtin/rebase.c when merging this to 'pu'.\nbuiltin/stash.c also needs to define USE_THE_... to build, but I think\nthat could be part of the builtin stash topic when it's rerolled.\n\nNguyễn Thái Ngọc Duy (10):\n  notes-utils.c: remove the_repository references\n  repository.c: replace hold_locked_index() with repo_hold_locked_index()\n  checkout: avoid the_index when possible\n  read-cache.c: kill read_index()\n  read-cache.c: replace update_index_if_able with repo_&\n  sha1-name.c: remove implicit dependency on the_index\n  merge-recursive.c: remove implicit dependency on the_index\n  merge-recursive.c: remove implicit dependency on the_repository\n  read-cache.c: remove the_* from index_has_changes()\n  cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch\n\n apply.c                              |   5 +-\n attr.c                               |   1 -\n blame.c                              |   4 +-\n builtin/add.c                        |   1 +\n builtin/am.c                         |  13 +-\n builtin/blame.c                      |   3 +-\n builtin/cat-file.c                   |   7 +-\n builtin/check-attr.c                 |   1 +\n builtin/check-ignore.c               |   1 +\n builtin/checkout-index.c             |   1 +\n builtin/checkout.c                   |   5 +-\n builtin/clean.c                      |   1 +\n builtin/clone.c                      |   1 +\n builtin/commit.c                     |   7 +-\n builtin/describe.c                   |   3 +-\n builtin/diff-files.c                 |   1 +\n builtin/diff-index.c                 |   1 +\n builtin/diff-tree.c                  |   3 +-\n builtin/diff.c                       |   3 +-\n builtin/difftool.c                   |   1 +\n builtin/fsck.c                       |   1 +\n builtin/grep.c                       |   4 +-\n builtin/hash-object.c                |   3 +-\n builtin/log.c                        |   4 +-\n builtin/ls-files.c                   |   1 -\n builtin/merge-index.c                |   1 +\n builtin/merge-ours.c                 |   1 +\n builtin/merge-recursive.c            |   2 +-\n builtin/merge-tree.c                 |   4 +-\n builtin/merge.c                      |   3 +-\n builtin/mv.c                         |   1 +\n builtin/notes.c                      |  21 +--\n builtin/pack-objects.c               |   2 +-\n builtin/pull.c                       |   1 +\n builtin/read-tree.c                  |   1 +\n builtin/rebase--interactive.c        |   1 +\n builtin/rebase.c                     |  14 +-\n builtin/replace.c                    |   2 +-\n builtin/reset.c                      |   1 +\n builtin/rev-parse.c                  |   4 +-\n builtin/rm.c                         |   1 +\n builtin/submodule--helper.c          |   1 +\n builtin/update-index.c               |   1 +\n builtin/write-tree.c                 |   1 +\n cache-tree.h                         |   2 +-\n cache.h                              |  35 ++---\n convert.c                            |   1 -\n dir.c                                |   1 -\n git.c                                |   4 +-\n list-objects-filter-options.c        |   2 +-\n merge-recursive.c                    | 191 +++++++++++++++------------\n merge-recursive.h                    |   6 +-\n merge.c                              |   4 +-\n name-hash.c                          |   1 -\n notes-merge.c                        |   4 +-\n notes-utils.c                        |  17 ++-\n notes-utils.h                        |  11 +-\n pathspec.c                           |   1 -\n preload-index.c                      |  11 +-\n read-cache.c                         |  44 +++---\n repository.c                         |   9 ++\n repository.h                         |  16 +++\n rerere.c                             |   8 +-\n revision.c                           |  12 +-\n sequencer.c                          |  41 +++---\n sequencer.h                          |   3 +-\n sha1-name.c                          |  56 ++++----\n submodule.c                          |   1 -\n t/helper/test-dump-fsmonitor.c       |   4 +-\n t/helper/test-dump-untracked-cache.c |   1 +\n t/helper/test-tool.h                 |   1 +\n tree.c                               |   1 -\n unpack-trees.c                       |   1 -\n wt-status.c                          |   4 +-\n 74 files changed, 359 insertions(+), 273 deletions(-)\n\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366182","messageId":"20190105055153.3256-2-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH 01/10] notes-utils.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:44Z","receivedAt":"2019-01-05T05:52:25Z","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 builtin/am.c     |  2 +-\n builtin/commit.c |  2 +-\n builtin/notes.c  | 21 +++++++++++++--------\n notes-merge.c    |  4 ++--\n notes-utils.c    | 17 ++++++++++-------\n notes-utils.h    | 11 ++++++++---\n sequencer.c      |  7 ++++---\n sequencer.h      |  3 ++-\n 8 files changed, 41 insertions(+), 26 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 95370313b6..d32044545d 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -527,7 +527,7 @@ static int copy_notes_for_rebase(const struct am_state *state)\n \t}\n \n finish:\n-\tfinish_copy_notes_for_rewrite(c, msg);\n+\tfinish_copy_notes_for_rewrite(the_repository, c, msg);\n \tfclose(fp);\n \tstrbuf_release(&sb);\n \treturn ret;\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 004b816635..e29fb5e3eb 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1674,7 +1674,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \trun_command_v_opt(argv_gc_auto, RUN_GIT_CMD);\n \trun_commit_hook(use_editor, get_index_file(), \"post-commit\", NULL);\n \tif (amend && !no_post_rewrite) {\n-\t\tcommit_post_rewrite(current_head, &oid);\n+\t\tcommit_post_rewrite(the_repository, current_head, &oid);\n \t}\n \tif (!quiet) {\n \t\tunsigned int flags = 0;\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 4996a670f7..02e97f55c5 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -330,10 +330,10 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)\n \t}\n \n \tif (!rewrite_cmd) {\n-\t\tcommit_notes(t, msg);\n+\t\tcommit_notes(the_repository, t, msg);\n \t\tfree_notes(t);\n \t} else {\n-\t\tfinish_copy_notes_for_rewrite(c, msg);\n+\t\tfinish_copy_notes_for_rewrite(the_repository, c, msg);\n \t}\n \tstrbuf_release(&buf);\n \treturn ret;\n@@ -469,12 +469,14 @@ static int add(int argc, const char **argv, const char *prefix)\n \t\twrite_note_data(&d, &new_note);\n \t\tif (add_note(t, &object, &new_note, combine_notes_overwrite))\n \t\t\tBUG(\"combine_notes_overwrite failed\");\n-\t\tcommit_notes(t, \"Notes added by 'git notes add'\");\n+\t\tcommit_notes(the_repository, t,\n+\t\t\t     \"Notes added by 'git notes add'\");\n \t} else {\n \t\tfprintf(stderr, _(\"Removing note for object %s\\n\"),\n \t\t\toid_to_hex(&object));\n \t\tremove_note(t, object.hash);\n-\t\tcommit_notes(t, \"Notes removed by 'git notes add'\");\n+\t\tcommit_notes(the_repository, t,\n+\t\t\t     \"Notes removed by 'git notes add'\");\n \t}\n \n \tfree_note_data(&d);\n@@ -552,7 +554,8 @@ static int copy(int argc, const char **argv, const char *prefix)\n \n \tif (add_note(t, &object, from_note, combine_notes_overwrite))\n \t\tBUG(\"combine_notes_overwrite failed\");\n-\tcommit_notes(t, \"Notes added by 'git notes copy'\");\n+\tcommit_notes(the_repository, t,\n+\t\t     \"Notes added by 'git notes copy'\");\n out:\n \tfree_notes(t);\n \treturn retval;\n@@ -636,7 +639,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)\n \t\tremove_note(t, object.hash);\n \t\tlogmsg = xstrfmt(\"Notes removed by 'git notes %s'\", argv[0]);\n \t}\n-\tcommit_notes(t, logmsg);\n+\tcommit_notes(the_repository, t, logmsg);\n \n \tfree(logmsg);\n \tfree_note_data(&d);\n@@ -937,7 +940,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)\n \t\tstrbuf_release(&sb);\n \t}\n \tif (!retval)\n-\t\tcommit_notes(t, \"Notes removed by 'git notes remove'\");\n+\t\tcommit_notes(the_repository, t,\n+\t\t\t     \"Notes removed by 'git notes remove'\");\n \tfree_notes(t);\n \treturn retval;\n }\n@@ -965,7 +969,8 @@ static int prune(int argc, const char **argv, const char *prefix)\n \tprune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |\n \t\t(show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );\n \tif (!show_only)\n-\t\tcommit_notes(t, \"Notes removed by 'git notes prune'\");\n+\t\tcommit_notes(the_repository, t,\n+\t\t\t     \"Notes removed by 'git notes prune'\");\n \tfree_notes(t);\n \treturn 0;\n }\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 72688d301b..280aa8e6c1 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -649,7 +649,7 @@ int notes_merge(struct notes_merge_options *o,\n \t\tstruct commit_list *parents = NULL;\n \t\tcommit_list_insert(remote, &parents); /* LIFO order */\n \t\tcommit_list_insert(local, &parents);\n-\t\tcreate_notes_commit(local_tree, parents, o->commit_msg.buf,\n+\t\tcreate_notes_commit(o->repo, local_tree, parents, o->commit_msg.buf,\n \t\t\t\t    o->commit_msg.len, result_oid);\n \t}\n \n@@ -724,7 +724,7 @@ int notes_merge_commit(struct notes_merge_options *o,\n \t\tstrbuf_setlen(&path, baselen);\n \t}\n \n-\tcreate_notes_commit(partial_tree, partial_commit->parents, msg,\n+\tcreate_notes_commit(o->repo, partial_tree, partial_commit->parents, msg,\n \t\t\t    strlen(msg), result_oid);\n \tunuse_commit_buffer(partial_commit, buffer);\n \tif (o->verbosity >= 4)\ndiff --git a/notes-utils.c b/notes-utils.c\nindex 14ea03178e..a819410698 100644\n--- a/notes-utils.c\n+++ b/notes-utils.c\n@@ -5,7 +5,9 @@\n #include \"notes-utils.h\"\n #include \"repository.h\"\n \n-void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n+void create_notes_commit(struct repository *r,\n+\t\t\t struct notes_tree *t,\n+\t\t\t struct commit_list *parents,\n \t\t\t const char *msg, size_t msg_len,\n \t\t\t struct object_id *result_oid)\n {\n@@ -20,8 +22,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n \t\t/* Deduce parent commit from t->ref */\n \t\tstruct object_id parent_oid;\n \t\tif (!read_ref(t->ref, &parent_oid)) {\n-\t\t\tstruct commit *parent = lookup_commit(the_repository,\n-\t\t\t\t\t\t\t      &parent_oid);\n+\t\t\tstruct commit *parent = lookup_commit(r, &parent_oid);\n \t\t\tif (parse_commit(parent))\n \t\t\t\tdie(\"Failed to find/parse commit %s\", t->ref);\n \t\t\tcommit_list_insert(parent, &parents);\n@@ -34,7 +35,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n \t\tdie(\"Failed to commit notes tree to database\");\n }\n \n-void commit_notes(struct notes_tree *t, const char *msg)\n+void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct object_id commit_oid;\n@@ -50,7 +51,7 @@ void commit_notes(struct notes_tree *t, const char *msg)\n \tstrbuf_addstr(&buf, msg);\n \tstrbuf_complete_line(&buf);\n \n-\tcreate_notes_commit(t, NULL, buf.buf, buf.len, &commit_oid);\n+\tcreate_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);\n \tstrbuf_insert(&buf, 0, \"notes: \", 7); /* commit message starts at index 7 */\n \tupdate_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,\n \t\t   UPDATE_REFS_DIE_ON_ERR);\n@@ -171,11 +172,13 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,\n \treturn ret;\n }\n \n-void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg)\n+void finish_copy_notes_for_rewrite(struct repository *r,\n+\t\t\t\t   struct notes_rewrite_cfg *c,\n+\t\t\t\t   const char *msg)\n {\n \tint i;\n \tfor (i = 0; c->trees[i]; i++) {\n-\t\tcommit_notes(c->trees[i], msg);\n+\t\tcommit_notes(r, c->trees[i], msg);\n \t\tfree_notes(c->trees[i]);\n \t}\n \tfree(c->trees);\ndiff --git a/notes-utils.h b/notes-utils.h\nindex 5408306528..d9b3c09eaf 100644\n--- a/notes-utils.h\n+++ b/notes-utils.h\n@@ -5,6 +5,7 @@\n \n struct commit_list;\n struct object_id;\n+struct repository;\n \n /*\n  * Create new notes commit from the given notes tree\n@@ -17,11 +18,13 @@ struct object_id;\n  *\n  * The resulting commit SHA1 is stored in result_sha1.\n  */\n-void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n+void create_notes_commit(struct repository *r,\n+\t\t\t struct notes_tree *t,\n+\t\t\t struct commit_list *parents,\n \t\t\t const char *msg, size_t msg_len,\n \t\t\t struct object_id *result_oid);\n \n-void commit_notes(struct notes_tree *t, const char *msg);\n+void commit_notes(struct repository *r, struct notes_tree *t, const char *msg);\n \n enum notes_merge_strategy {\n \t\tNOTES_MERGE_RESOLVE_MANUAL = 0,\n@@ -45,6 +48,8 @@ int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);\n struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);\n int copy_note_for_rewrite(struct notes_rewrite_cfg *c,\n \t\t\t  const struct object_id *from_obj, const struct object_id *to_obj);\n-void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg);\n+void finish_copy_notes_for_rewrite(struct repository *r,\n+\t\t\t\t   struct notes_rewrite_cfg *c,\n+\t\t\t\t   const char *msg);\n \n #endif\ndiff --git a/sequencer.c b/sequencer.c\nindex b68bca0bef..1a92a5d678 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1115,7 +1115,8 @@ static int run_rewrite_hook(const struct object_id *oldoid,\n \treturn finish_command(&proc);\n }\n \n-void commit_post_rewrite(const struct commit *old_head,\n+void commit_post_rewrite(struct repository *r,\n+\t\t\t const struct commit *old_head,\n \t\t\t const struct object_id *new_head)\n {\n \tstruct notes_rewrite_cfg *cfg;\n@@ -1124,7 +1125,7 @@ void commit_post_rewrite(const struct commit *old_head,\n \tif (cfg) {\n \t\t/* we are amending, so old_head is not NULL */\n \t\tcopy_note_for_rewrite(cfg, &old_head->object.oid, new_head);\n-\t\tfinish_copy_notes_for_rewrite(cfg, \"Notes added by 'git commit --amend'\");\n+\t\tfinish_copy_notes_for_rewrite(r, cfg, \"Notes added by 'git commit --amend'\");\n \t}\n \trun_rewrite_hook(&old_head->object.oid, new_head);\n }\n@@ -1405,7 +1406,7 @@ static int try_to_commit(struct repository *r,\n \t}\n \n \tif (flags & AMEND_MSG)\n-\t\tcommit_post_rewrite(current_head, oid);\n+\t\tcommit_post_rewrite(r, current_head, oid);\n \n out:\n \tfree_commit_extra_headers(extra);\ndiff --git a/sequencer.h b/sequencer.h\nindex 9d83f0f3e9..2caecd550b 100644\n--- a/sequencer.h\n+++ b/sequencer.h\n@@ -124,7 +124,8 @@ int update_head_with_reflog(const struct commit *old_head,\n \t\t\t    const struct object_id *new_head,\n \t\t\t    const char *action, const struct strbuf *msg,\n \t\t\t    struct strbuf *err);\n-void commit_post_rewrite(const struct commit *current_head,\n+void commit_post_rewrite(struct repository *r,\n+\t\t\t const struct commit *current_head,\n \t\t\t const struct object_id *new_head);\n \n int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366192","messageId":"20190105055153.3256-3-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH 02/10] repository.c: replace hold_locked_index() with repo_hold_locked_index()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:45Z","receivedAt":"2019-01-05T05:52:29Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"hold_locked_index() assumes the index path at $GIT_DIR/index. This is\nnot good for places that take an arbitrary index_state instead of\nthe_index, which is basically everywhere except builtin/.\n\nReplace it with repo_hold_locked_index(). hold_locked_index() remains\nas a wrapper around repo_hold_locked_index() to reduce changes in builtin/\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n apply.c           |  3 ++-\n builtin/clone.c   |  1 +\n cache.h           |  2 +-\n merge-recursive.c |  2 +-\n merge.c           |  2 +-\n read-cache.c      |  5 -----\n repository.c      |  8 ++++++++\n repository.h      |  4 ++++\n rerere.c          |  2 +-\n sequencer.c       | 10 +++++-----\n wt-status.c       |  2 +-\n 11 files changed, 25 insertions(+), 16 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 01793d6126..08cde3c4bf 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4712,7 +4712,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) {\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 7c7f98c72c..ddb3230d21 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -8,6 +8,7 @@\n  * Clone a repository into a different directory that does not yet exist.\n  */\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/cache.h b/cache.h\nindex ca36b44ee0..634c9ce325 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -433,6 +433,7 @@ void validate_cache_entries(const struct index_state *istate);\n #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)\n #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)\n #define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))\n+#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n \n #define TYPE_BITS 3\n@@ -833,7 +834,6 @@ extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cach\n  */\n extern void update_index_if_able(struct index_state *, struct lock_file *);\n \n-extern int hold_locked_index(struct lock_file *, int);\n extern void set_alternate_index_output(const char *);\n \n extern int verify_index_checksum;\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex ecf8db0b71..8dba939d8f 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3643,7 +3643,7 @@ int merge_recursive_generic(struct merge_options *o,\n \t\t}\n \t}\n \n-\thold_locked_index(&lock, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);\n \tclean = merge_recursive(o, head_commit, next_commit, ca,\n \t\t\t\tresult);\n \tif (clean < 0) {\ndiff --git a/merge.c b/merge.c\nindex 91008f7602..dbbc9d9f80 100644\n--- a/merge.c\n+++ b/merge.c\n@@ -58,7 +58,7 @@ int checkout_fast_forward(struct repository *r,\n \n \trefresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);\n \n-\tif (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0)\n+\tif (repo_hold_locked_index(r, &lock_file, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n \n \tmemset(&trees, 0, sizeof(trees));\ndiff --git a/read-cache.c b/read-cache.c\nindex 48c1797a4a..1030e11051 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1733,11 +1733,6 @@ static int read_index_extension(struct index_state *istate,\n \treturn 0;\n }\n \n-int hold_locked_index(struct lock_file *lk, int lock_flags)\n-{\n-\treturn hold_lock_file_for_update(lk, get_index_file(), lock_flags);\n-}\n-\n int read_index(struct index_state *istate)\n {\n \treturn read_index_from(istate, get_index_file(), get_git_dir());\ndiff --git a/repository.c b/repository.c\nindex 7b02e1dffa..fd965c127c 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -3,6 +3,7 @@\n #include \"object-store.h\"\n #include \"config.h\"\n #include \"object.h\"\n+#include \"lockfile.h\"\n #include \"submodule-config.h\"\n \n /* The main repository */\n@@ -263,3 +264,10 @@ int repo_read_index(struct repository *repo)\n \n \treturn read_index_from(repo->index, repo->index_file, repo->gitdir);\n }\n+\n+int repo_hold_locked_index(struct repository *repo,\n+\t\t\t   struct lock_file *lf,\n+\t\t\t   int flags)\n+{\n+\treturn hold_lock_file_for_update(lf, repo->index_file, flags);\n+}\ndiff --git a/repository.h b/repository.h\nindex 9f16c42c1e..968330218f 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -6,6 +6,7 @@\n struct config_set;\n struct git_hash_algo;\n struct index_state;\n+struct lock_file;\n struct raw_object_store;\n struct submodule_cache;\n \n@@ -130,5 +131,8 @@ void repo_clear(struct repository *repo);\n  * populated then the number of entries will simply be returned.\n  */\n int repo_read_index(struct repository *repo);\n+int repo_hold_locked_index(struct repository *repo,\n+\t\t\t   struct lock_file *lf,\n+\t\t\t   int flags);\n \n #endif /* REPOSITORY_H */\ndiff --git a/rerere.c b/rerere.c\nindex 13624038e6..fb0fdb2392 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -705,7 +705,7 @@ static void update_paths(struct repository *r, struct string_list *update)\n \tstruct lock_file index_lock = LOCK_INIT;\n \tint i;\n \n-\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(r, &index_lock, LOCK_DIE_ON_ERROR);\n \n \tfor (i = 0; i < update->nr; i++) {\n \t\tstruct string_list_item *item = &update->items[i];\ndiff --git a/sequencer.c b/sequencer.c\nindex 1a92a5d678..668c232b05 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -540,7 +540,7 @@ static int do_recursive_merge(struct repository *r,\n \tchar **xopt;\n \tstruct lock_file index_lock = LOCK_INIT;\n \n-\tif (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)\n+\tif (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n \n \tread_index(r->index);\n@@ -1992,8 +1992,8 @@ static int read_and_refresh_cache(struct repository *r,\n \t\t\t\t  struct replay_opts *opts)\n {\n \tstruct lock_file index_lock = LOCK_INIT;\n-\tint index_fd = hold_locked_index(&index_lock, 0);\n-\tif (read_index(r->index) < 0) {\n+\tint index_fd = repo_hold_locked_index(r, &index_lock, 0);\n+\tif (repo_read_index(r) < 0) {\n \t\trollback_lock_file(&index_lock);\n \t\treturn error(_(\"git %s: failed to read the index\"),\n \t\t\t_(action_name(opts)));\n@@ -2978,7 +2978,7 @@ static int do_reset(struct repository *r,\n \tstruct unpack_trees_options unpack_tree_opts;\n \tint ret = 0;\n \n-\tif (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0)\n+\tif (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n \n \tif (len == 10 && !strncmp(\"[new root]\", name, len)) {\n@@ -3096,7 +3096,7 @@ static int do_merge(struct repository *r,\n \tstatic struct lock_file lock;\n \tconst char *p;\n \n-\tif (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {\n+\tif (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) {\n \t\tret = -1;\n \t\tgoto leave_merge;\n \t}\ndiff --git a/wt-status.c b/wt-status.c\nindex 0fe3bcd4cd..becf78b04f 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -2375,7 +2375,7 @@ int require_clean_work_tree(struct repository *r,\n \tstruct lock_file lock_file = LOCK_INIT;\n \tint err = 0, fd;\n \n-\tfd = hold_locked_index(&lock_file, 0);\n+\tfd = repo_hold_locked_index(r, &lock_file, 0);\n \trefresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);\n \tif (0 <= fd)\n \t\tupdate_index_if_able(r->index, &lock_file);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366185","messageId":"20190105055153.3256-4-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH 03/10] checkout: avoid the_index when possible","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:46Z","receivedAt":"2019-01-05T05:52:33Z","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 builtin/checkout.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 08b0ac48f3..1b672a9fd9 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -284,7 +284,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t\treturn run_add_interactive(revision, \"--patch=checkout\",\n \t\t\t\t\t   &opts->pathspec);\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \tif (read_cache_preload(&opts->pathspec) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366193","messageId":"20190105055153.3256-5-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH 04/10] read-cache.c: kill read_index()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:47Z","receivedAt":"2019-01-05T05:52:39Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"read_index() shares the same problem as hold_locked_index(): it\nassumes $GIT_DIR/index. Move all call sites to repo_read_index()\ninstead. read_index_preload() and read_index_unmerged() are also\nkilled as a consequence.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n apply.c             |  2 +-\n blame.c             |  4 ++--\n builtin/am.c        |  2 +-\n builtin/commit.c    |  2 +-\n builtin/diff-tree.c |  2 +-\n builtin/rebase.c    |  8 ++++----\n cache.h             | 11 +++--------\n merge-recursive.c   |  2 +-\n merge.c             |  2 +-\n preload-index.c     | 11 ++++++-----\n read-cache.c        | 11 ++++-------\n repository.h        |  6 ++++++\n rerere.c            |  6 +++---\n revision.c          |  4 ++--\n sequencer.c         | 20 ++++++++++----------\n sha1-name.c         |  6 +++---\n 16 files changed, 49 insertions(+), 50 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 08cde3c4bf..e040c0b957 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4019,7 +4019,7 @@ static int read_apply_cache(struct apply_state *state)\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(state->repo->index);\n+\t\treturn repo_read_index(state->repo);\n }\n \n /* This function tries to read the object name from the current index */\ndiff --git a/blame.c b/blame.c\nindex 43861437f7..da57233cbb 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -188,7 +188,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,\n \tunsigned mode;\n \tstruct strbuf msg = STRBUF_INIT;\n \n-\tread_index(r->index);\n+\trepo_read_index(r);\n \ttime(&now);\n \tcommit = alloc_commit_node(r);\n \tcommit->object.parsed = 1;\n@@ -270,7 +270,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,\n \t * want to run \"diff-index --cached\".\n \t */\n \tdiscard_index(r->index);\n-\tread_index(r->index);\n+\trepo_read_index(r);\n \n \tlen = strlen(path);\n \tif (!mode) {\ndiff --git a/builtin/am.c b/builtin/am.c\nindex d32044545d..901dc55078 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2278,7 +2278,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n \t/* Ensure a valid committer ident can be constructed */\n \tgit_committer_info(IDENT_STRICT);\n \n-\tif (read_index_preload(&the_index, NULL, 0) < 0)\n+\tif (repo_read_index_preload(the_repository, NULL, 0) < 0)\n \t\tdie(_(\"failed to read the index\"));\n \n \tif (in_progress) {\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex e29fb5e3eb..19eb6cff86 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1367,7 +1367,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \tif (status_format != STATUS_FORMAT_PORCELAIN &&\n \t    status_format != STATUS_FORMAT_PORCELAIN_V2)\n \t\tprogress_flag = REFRESH_PROGRESS;\n-\tread_index(&the_index);\n+\trepo_read_index(the_repository);\n \trefresh_index(&the_index,\n \t\t      REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,\n \t\t      &s.pathspec, NULL, NULL);\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex ef996126d7..42bc1eb41d 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -165,7 +165,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)\n \n \t\tif (opt->diffopt.detect_rename) {\n \t\t\tif (!the_index.cache)\n-\t\t\t\tread_index(&the_index);\n+\t\t\t\trepo_read_index(the_repository);\n \t\t\topt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;\n \t\t}\n \t\twhile (fgets(line, sizeof(line), stdin)) {\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 00de70365e..ce5f5b5a17 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -576,7 +576,7 @@ static int reset_head(struct object_id *oid, const char *action,\n \tif (!detach_head)\n \t\tunpack_tree_opts.reset = 1;\n \n-\tif (read_index_unmerged(the_repository->index) < 0) {\n+\tif (repo_read_index_unmerged(the_repository) < 0) {\n \t\tret = error(_(\"could not read index\"));\n \t\tgoto leave_reset_head;\n \t}\n@@ -1015,7 +1015,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"Cannot read HEAD\"));\n \n \t\tfd = hold_locked_index(&lock_file, 0);\n-\t\tif (read_index(the_repository->index) < 0)\n+\t\tif (repo_read_index(the_repository) < 0)\n \t\t\tdie(_(\"could not read index\"));\n \t\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,\n \t\t\t      NULL);\n@@ -1368,7 +1368,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\tget_fork_point(options.upstream_name, head);\n \t}\n \n-\tif (read_index(the_repository->index) < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"could not read index\"));\n \n \tif (options.autostash) {\n@@ -1423,7 +1423,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\tputchar('\\n');\n \n \t\t\tif (discard_index(the_repository->index) < 0 ||\n-\t\t\t\tread_index(the_repository->index) < 0)\n+\t\t\t\trepo_read_index(the_repository) < 0)\n \t\t\t\tdie(_(\"could not read index\"));\n \t\t}\n \t}\ndiff --git a/cache.h b/cache.h\nindex 634c9ce325..3715808f52 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -408,11 +408,11 @@ void validate_cache_entries(const struct index_state *istate);\n #define active_cache_changed (the_index.cache_changed)\n #define active_cache_tree (the_index.cache_tree)\n \n-#define read_cache() read_index(&the_index)\n+#define read_cache() repo_read_index(the_repository)\n #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))\n-#define read_cache_preload(pathspec) read_index_preload(&the_index, (pathspec), 0)\n+#define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)\n #define is_cache_unborn() is_index_unborn(&the_index)\n-#define read_cache_unmerged() read_index_unmerged(&the_index)\n+#define read_cache_unmerged() repo_read_index_unmerged(the_repository)\n #define discard_cache() discard_index(&the_index)\n #define unmerged_cache() unmerged_index(&the_index)\n #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))\n@@ -661,19 +661,14 @@ extern int daemonize(void);\n \n /* Initialize and use the cache information */\n struct lock_file;\n-extern int read_index(struct index_state *);\n extern void preload_index(struct index_state *index,\n \t\t\t  const struct pathspec *pathspec,\n \t\t\t  unsigned int refresh_flags);\n-extern int read_index_preload(struct index_state *,\n-\t\t\t      const struct pathspec *pathspec,\n-\t\t\t      unsigned int refresh_flags);\n extern int do_read_index(struct index_state *istate, const char *path,\n \t\t\t int must_exist); /* for testting only! */\n extern int read_index_from(struct index_state *, const char *path,\n \t\t\t   const char *gitdir);\n extern int is_index_unborn(struct index_state *);\n-extern int read_index_unmerged(struct index_state *);\n \n /* For use with `write_locked_index()`. */\n #define COMMIT_LOCK\t\t(1 << 0)\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 8dba939d8f..5fbd4253c1 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3576,7 +3576,7 @@ int merge_recursive(struct merge_options *o,\n \n \tdiscard_cache();\n \tif (!o->call_depth)\n-\t\tread_cache();\n+\t\trepo_read_index(the_repository);\n \n \to->ancestor = \"merged common ancestors\";\n \tclean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),\ndiff --git a/merge.c b/merge.c\nindex dbbc9d9f80..7c1d756c3f 100644\n--- a/merge.c\n+++ b/merge.c\n@@ -37,7 +37,7 @@ int try_merge_command(struct repository *r,\n \targv_array_clear(&args);\n \n \tdiscard_index(r->index);\n-\tif (read_index(r->index) < 0)\n+\tif (repo_read_index(r) < 0)\n \t\tdie(_(\"failed to read the cache\"));\n \tresolve_undo_clear_index(r->index);\n \ndiff --git a/preload-index.c b/preload-index.c\nindex c7dc3f2b9f..e73600ee78 100644\n--- a/preload-index.c\n+++ b/preload-index.c\n@@ -8,6 +8,7 @@\n #include \"config.h\"\n #include \"progress.h\"\n #include \"thread-utils.h\"\n+#include \"repository.h\"\n \n /*\n  * Mostly randomly chosen maximum thread counts: we\n@@ -146,12 +147,12 @@ void preload_index(struct index_state *index,\n \ttrace_performance_leave(\"preload index\");\n }\n \n-int read_index_preload(struct index_state *index,\n-\t\t       const struct pathspec *pathspec,\n-\t\t       unsigned int refresh_flags)\n+int repo_read_index_preload(struct repository *repo,\n+\t\t\t    const struct pathspec *pathspec,\n+\t\t\t    unsigned int refresh_flags)\n {\n-\tint retval = read_index(index);\n+\tint retval = repo_read_index(repo);\n \n-\tpreload_index(index, pathspec, refresh_flags);\n+\tpreload_index(repo->index, pathspec, refresh_flags);\n \treturn retval;\n }\ndiff --git a/read-cache.c b/read-cache.c\nindex 1030e11051..afbf976107 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1733,11 +1733,6 @@ static int read_index_extension(struct index_state *istate,\n \treturn 0;\n }\n \n-int read_index(struct index_state *istate)\n-{\n-\treturn read_index_from(istate, get_index_file(), get_git_dir());\n-}\n-\n static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,\n \t\t\t\t\t    unsigned int version,\n \t\t\t\t\t    struct ondisk_cache_entry *ondisk,\n@@ -3218,12 +3213,14 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,\n  * state can call this and check its return value, instead of calling\n  * read_cache().\n  */\n-int read_index_unmerged(struct index_state *istate)\n+int repo_read_index_unmerged(struct repository *repo)\n {\n+\tstruct index_state *istate;\n \tint i;\n \tint unmerged = 0;\n \n-\tread_index(istate);\n+\trepo_read_index(repo);\n+\tistate = repo->index;\n \tfor (i = 0; i < istate->cache_nr; i++) {\n \t\tstruct cache_entry *ce = istate->cache[i];\n \t\tstruct cache_entry *new_ce;\ndiff --git a/repository.h b/repository.h\nindex 968330218f..cc3879add4 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -7,6 +7,7 @@ struct config_set;\n struct git_hash_algo;\n struct index_state;\n struct lock_file;\n+struct pathspec;\n struct raw_object_store;\n struct submodule_cache;\n \n@@ -135,4 +136,9 @@ int repo_hold_locked_index(struct repository *repo,\n \t\t\t   struct lock_file *lf,\n \t\t\t   int flags);\n \n+int repo_read_index_preload(struct repository *,\n+\t\t\t    const struct pathspec *pathspec,\n+\t\t\t    unsigned refresh_flags);\n+int repo_read_index_unmerged(struct repository *);\n+\n #endif /* REPOSITORY_H */\ndiff --git a/rerere.c b/rerere.c\nindex fb0fdb2392..17abb47321 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -561,7 +561,7 @@ static int find_conflict(struct repository *r, struct string_list *conflict)\n {\n \tint i;\n \n-\tif (read_index(r->index) < 0)\n+\tif (repo_read_index(r) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n \tfor (i = 0; i < r->index->cache_nr;) {\n@@ -595,7 +595,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr)\n \n \tif (setup_rerere(r, merge_rr, RERERE_READONLY))\n \t\treturn 0;\n-\tif (read_index(r->index) < 0)\n+\tif (repo_read_index(r) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n \tfor (i = 0; i < r->index->cache_nr;) {\n@@ -1107,7 +1107,7 @@ int rerere_forget(struct repository *r, 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_index(r->index) < 0)\n+\tif (repo_read_index(r) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n \tfd = setup_rerere(r, &merge_rr, RERERE_NOAUTOUPDATE);\ndiff --git a/revision.c b/revision.c\nindex 13e0519c02..c51ea6a052 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1384,7 +1384,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)\n {\n \tstruct worktree **worktrees, **p;\n \n-\tread_index(revs->repo->index);\n+\trepo_read_index(revs->repo);\n \tdo_add_index_objects_to_pending(revs, revs->repo->index, flags);\n \n \tif (revs->single_worktree)\n@@ -1530,7 +1530,7 @@ static void prepare_show_merge(struct rev_info *revs)\n \thead->object.flags |= SYMMETRIC_LEFT;\n \n \tif (!istate->cache_nr)\n-\t\tread_index(istate);\n+\t\trepo_read_index(revs->repo);\n \tfor (i = 0; i < istate->cache_nr; i++) {\n \t\tconst struct cache_entry *ce = istate->cache[i];\n \t\tif (!ce_stage(ce))\ndiff --git a/sequencer.c b/sequencer.c\nindex 668c232b05..c2c9cc7e2b 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -446,9 +446,9 @@ static struct tree *empty_tree(struct repository *r)\n \treturn lookup_tree(r, the_hash_algo->empty_tree);\n }\n \n-static int error_dirty_index(struct index_state *istate, struct replay_opts *opts)\n+static int error_dirty_index(struct repository *repo, struct replay_opts *opts)\n {\n-\tif (read_index_unmerged(istate))\n+\tif (repo_read_index_unmerged(repo))\n \t\treturn error_resolve_conflict(_(action_name(opts)));\n \n \terror(_(\"your local changes would be overwritten by %s.\"),\n@@ -483,7 +483,7 @@ static int fast_forward_to(struct repository *r,\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct strbuf err = STRBUF_INIT;\n \n-\tread_index(r->index);\n+\trepo_read_index(r);\n \tif (checkout_fast_forward(r, from, to, 1))\n \t\treturn -1; /* the callee should have complained already */\n \n@@ -543,7 +543,7 @@ static int do_recursive_merge(struct repository *r,\n \tif (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n \n-\tread_index(r->index);\n+\trepo_read_index(r);\n \n \tinit_merge_options(&o);\n \to.ancestor = base ? base_label : \"(empty tree)\";\n@@ -1766,7 +1766,7 @@ static int do_pick_commit(struct repository *r,\n \t\t\toidcpy(&head, the_hash_algo->empty_tree);\n \t\tif (index_differs_from(r, unborn ? empty_tree_oid_hex() : \"HEAD\",\n \t\t\t\t       NULL, 0))\n-\t\t\treturn error_dirty_index(r->index, opts);\n+\t\t\treturn error_dirty_index(r, opts);\n \t}\n \tdiscard_index(r->index);\n \n@@ -2854,7 +2854,7 @@ static int do_exec(struct repository *r, 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_index(r->index) < 0 || read_index(r->index) < 0)\n+\tif (discard_index(r->index) < 0 || repo_read_index(r) < 0)\n \t\treturn error(_(\"could not read index\"));\n \n \tdirty = require_clean_work_tree(r, \"rebase\", NULL, 1, 1);\n@@ -3023,7 +3023,7 @@ static int do_reset(struct repository *r,\n \tunpack_tree_opts.merge = 1;\n \tunpack_tree_opts.update = 1;\n \n-\tif (read_index_unmerged(r->index)) {\n+\tif (repo_read_index_unmerged(r)) {\n \t\trollback_lock_file(&lock);\n \t\tstrbuf_release(&ref_name);\n \t\treturn error_resolve_conflict(_(action_name(opts)));\n@@ -3277,7 +3277,7 @@ static int do_merge(struct repository *r,\n \n \t\t/* force re-reading of the cache */\n \t\tif (!ret && (discard_index(r->index) < 0 ||\n-\t\t\t     read_index(r->index) < 0))\n+\t\t\t     repo_read_index(r) < 0))\n \t\t\tret = error(_(\"could not read index\"));\n \t\tgoto leave_merge;\n \t}\n@@ -3299,7 +3299,7 @@ static int do_merge(struct repository *r,\n \t\tcommit_list_insert(j->item, &reversed);\n \tfree_commit_list(bases);\n \n-\tread_index(r->index);\n+\trepo_read_index(r);\n \tinit_merge_options(&o);\n \to.branch1 = \"HEAD\";\n \to.branch2 = ref_name.buf;\n@@ -3972,7 +3972,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)\n \t\t\t\tgoto release_todo_list;\n \t\t}\n \t\tif (index_differs_from(r, \"HEAD\", NULL, 0)) {\n-\t\t\tres = error_dirty_index(r->index, opts);\n+\t\t\tres = error_dirty_index(r, opts);\n \t\t\tgoto release_todo_list;\n \t\t}\n \t\ttodo_list.current++;\ndiff --git a/sha1-name.c b/sha1-name.c\nindex b24502811b..a0fc1008ec 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1723,9 +1723,9 @@ 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\trepo_read_index(the_repository);\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-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366181","messageId":"20190105055153.3256-6-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH 05/10] read-cache.c: replace update_index_if_able with repo_&","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:48Z","receivedAt":"2019-01-05T05:52:43Z","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 builtin/commit.c   |  2 +-\n builtin/describe.c |  2 +-\n builtin/diff.c     |  2 +-\n builtin/rebase.c   |  5 ++---\n cache.h            |  6 ------\n read-cache.c       | 14 ++++++++------\n repository.h       |  6 ++++++\n wt-status.c        |  2 +-\n 8 files changed, 20 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 19eb6cff86..d3f1234bf0 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1396,7 +1396,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \twt_status_collect(&s);\n \n \tif (0 <= fd)\n-\t\tupdate_index_if_able(&the_index, &index_lock);\n+\t\trepo_update_index_if_able(the_repository, &index_lock);\n \n \tif (s.relative_paths)\n \t\ts.prefix = prefix;\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex cc118448ee..bc97e50650 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -634,7 +634,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\t\t      NULL, NULL, NULL);\n \t\t\tfd = hold_locked_index(&index_lock, 0);\n \t\t\tif (0 <= fd)\n-\t\t\t\tupdate_index_if_able(&the_index, &index_lock);\n+\t\t\t\trepo_update_index_if_able(the_repository, &index_lock);\n \n \t\t\trepo_init_revisions(the_repository, &revs, prefix);\n \t\t\targv_array_pushv(&args, diff_index_args);\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex f0393bba23..ec78920ee2 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -212,7 +212,7 @@ static void refresh_index_quietly(void)\n \tdiscard_cache();\n \tread_cache();\n \trefresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);\n-\tupdate_index_if_able(&the_index, &lock_file);\n+\trepo_update_index_if_able(the_repository, &lock_file);\n }\n \n static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv)\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex ce5f5b5a17..7124e66d00 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1020,8 +1020,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,\n \t\t\t      NULL);\n \t\tif (0 <= fd)\n-\t\t\tupdate_index_if_able(the_repository->index,\n-\t\t\t\t\t     &lock_file);\n+\t\t\trepo_update_index_if_able(the_repository, &lock_file);\n \t\trollback_lock_file(&lock_file);\n \n \t\tif (has_unstaged_changes(the_repository, 1)) {\n@@ -1378,7 +1377,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\tfd = hold_locked_index(&lock_file, 0);\n \t\trefresh_cache(REFRESH_QUIET);\n \t\tif (0 <= fd)\n-\t\t\tupdate_index_if_able(&the_index, &lock_file);\n+\t\t\trepo_update_index_if_able(the_repository, &lock_file);\n \t\trollback_lock_file(&lock_file);\n \n \t\tif (has_unstaged_changes(the_repository, 1) ||\ndiff --git a/cache.h b/cache.h\nindex 3715808f52..702c5bfbb3 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -823,12 +823,6 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);\n extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);\n extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);\n \n-/*\n- * Opportunistically update the index but do not complain if we can't.\n- * The lockfile is always committed or rolled back.\n- */\n-extern void update_index_if_able(struct index_state *, struct lock_file *);\n-\n extern void set_alternate_index_output(const char *);\n \n extern int verify_index_checksum;\ndiff --git a/read-cache.c b/read-cache.c\nindex afbf976107..61cc0571da 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2654,9 +2654,9 @@ static int verify_index_from(const struct index_state *istate, const char *path)\n \treturn 0;\n }\n \n-static int verify_index(const struct index_state *istate)\n+static int repo_verify_index(struct repository *repo)\n {\n-\treturn verify_index_from(istate, get_index_file());\n+\treturn verify_index_from(repo->index, repo->index_file);\n }\n \n static int has_racy_timestamp(struct index_state *istate)\n@@ -2672,11 +2672,13 @@ static int has_racy_timestamp(struct index_state *istate)\n \treturn 0;\n }\n \n-void update_index_if_able(struct index_state *istate, struct lock_file *lockfile)\n+void repo_update_index_if_able(struct repository *repo,\n+\t\t\t       struct lock_file *lockfile)\n {\n-\tif ((istate->cache_changed || has_racy_timestamp(istate)) &&\n-\t    verify_index(istate))\n-\t\twrite_locked_index(istate, lockfile, COMMIT_LOCK);\n+\tif ((repo->index->cache_changed ||\n+\t     has_racy_timestamp(repo->index)) &&\n+\t    repo_verify_index(repo))\n+\t\twrite_locked_index(repo->index, lockfile, COMMIT_LOCK);\n \telse\n \t\trollback_lock_file(lockfile);\n }\ndiff --git a/repository.h b/repository.h\nindex cc3879add4..6fe1c089db 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -140,5 +140,11 @@ int repo_read_index_preload(struct repository *,\n \t\t\t    const struct pathspec *pathspec,\n \t\t\t    unsigned refresh_flags);\n int repo_read_index_unmerged(struct repository *);\n+/*\n+ * Opportunistically update the index but do not complain if we can't.\n+ * The lockfile is always committed or rolled back.\n+ */\n+void repo_update_index_if_able(struct repository *, struct lock_file *);\n+\n \n #endif /* REPOSITORY_H */\ndiff --git a/wt-status.c b/wt-status.c\nindex becf78b04f..1f564b12d2 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -2378,7 +2378,7 @@ int require_clean_work_tree(struct repository *r,\n \tfd = repo_hold_locked_index(r, &lock_file, 0);\n \trefresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);\n \tif (0 <= fd)\n-\t\tupdate_index_if_able(r->index, &lock_file);\n+\t\trepo_update_index_if_able(r, &lock_file);\n \trollback_lock_file(&lock_file);\n \n \tif (has_unstaged_changes(r, ignore_submodules)) {\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366187","messageId":"20190105055153.3256-7-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH 06/10] sha1-name.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:49Z","receivedAt":"2019-01-05T05:52:47Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This kills the_index dependency in get_oid_with_context() but for\nget_oid() and friends, they still assume the_repository (which also\nmeans the_index).\n\nUnfortunately the widespread use of get_oid() will make it hard to\nmake the conversion now. We probably will add repo_get_oid() at some\npoint and limit the use of get_oid() in builtin/ instead of forcing\nall get_oid() call sites to carry struct repository.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/cat-file.c            |  6 ++--\n builtin/grep.c                |  3 +-\n builtin/log.c                 |  3 +-\n builtin/rev-parse.c           |  3 +-\n cache.h                       |  4 ++-\n list-objects-filter-options.c |  2 +-\n revision.c                    |  8 +++---\n sha1-name.c                   | 54 +++++++++++++++++++++--------------\n 8 files changed, 50 insertions(+), 33 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 2ca56fd086..7622c502f0 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -73,7 +73,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \tif (unknown_type)\n \t\tflags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;\n \n-\tif (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,\n+\tif (get_oid_with_context(the_repository, obj_name,\n+\t\t\t\t GET_OID_RECORD_PATH,\n \t\t\t\t &oid, &obj_context))\n \t\tdie(\"Not a valid object name %s\", obj_name);\n \n@@ -382,7 +383,8 @@ static void batch_one_object(const char *obj_name,\n \tint flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;\n \tenum follow_symlinks_result result;\n \n-\tresult = get_oid_with_context(obj_name, flags, &data->oid, &ctx);\n+\tresult = get_oid_with_context(the_repository, obj_name,\n+\t\t\t\t      flags, &data->oid, &ctx);\n \tif (result != FOUND) {\n \t\tswitch (result) {\n \t\tcase MISSING_OBJECT:\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex bad9c0a3d5..3d695ad8fe 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -1014,7 +1014,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\tbreak;\n \t\t}\n \n-\t\tif (get_oid_with_context(arg, GET_OID_RECORD_PATH,\n+\t\tif (get_oid_with_context(the_repository, arg,\n+\t\t\t\t\t GET_OID_RECORD_PATH,\n \t\t\t\t\t &oid, &oc)) {\n \t\t\tif (seen_dashdash)\n \t\t\t\tdie(_(\"unable to resolve revision: %s\"), arg);\ndiff --git a/builtin/log.c b/builtin/log.c\nindex e8e51068bd..dbfb4e31ad 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -508,7 +508,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c\n \t    !rev->diffopt.flags.allow_textconv)\n \t\treturn stream_blob_to_fd(1, oid, NULL, 0);\n \n-\tif (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,\n+\tif (get_oid_with_context(the_repository, obj_name,\n+\t\t\t\t GET_OID_RECORD_PATH,\n \t\t\t\t &oidc, &obj_context))\n \t\tdie(_(\"Not a valid object name %s\"), obj_name);\n \tif (!obj_context.path ||\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 10d4dab894..910a71ed8b 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -933,7 +933,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\tname++;\n \t\t\ttype = REVERSED;\n \t\t}\n-\t\tif (!get_oid_with_context(name, flags, &oid, &unused)) {\n+\t\tif (!get_oid_with_context(the_repository, name,\n+\t\t\t\t\t  flags, &oid, &unused)) {\n \t\t\tif (verify)\n \t\t\t\trevs_count++;\n \t\t\telse\ndiff --git a/cache.h b/cache.h\nindex 702c5bfbb3..fdcd69bfb0 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1328,7 +1328,9 @@ extern int get_oid_tree(const char *str, struct object_id *oid);\n extern int get_oid_treeish(const char *str, struct object_id *oid);\n extern int get_oid_blob(const char *str, struct object_id *oid);\n extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);\n-extern int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc);\n+extern int get_oid_with_context(struct repository *repo, const char *str,\n+\t\t\t\tunsigned flags, struct object_id *oid,\n+\t\t\t\tstruct object_context *oc);\n \n \n typedef int each_abbrev_fn(const struct object_id *oid, void *);\ndiff --git a/list-objects-filter-options.c b/list-objects-filter-options.c\nindex e8da2e8581..8443184e22 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -71,7 +71,7 @@ static int gently_parse_list_objects_filter(\n \t\t * command, but DO NOT complain if we don't have the blob or\n \t\t * ref locally.\n \t\t */\n-\t\tif (!get_oid_with_context(v0, GET_OID_BLOB,\n+\t\tif (!get_oid_with_context(the_repository, v0, GET_OID_BLOB,\n \t\t\t\t\t  &sparse_oid, &oc))\n \t\t\tfilter_options->sparse_oid_value = oiddup(&sparse_oid);\n \t\tfilter_options->choice = LOFC_SPARSE_OID;\ndiff --git a/revision.c b/revision.c\nindex c51ea6a052..4a723efe9a 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1589,8 +1589,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,\n \tif (!*b_name)\n \t\tb_name = \"HEAD\";\n \n-\tif (get_oid_with_context(a_name, oc_flags, &a_oid, a_oc) ||\n-\t    get_oid_with_context(b_name, oc_flags, &b_oid, b_oc))\n+\tif (get_oid_with_context(revs->repo, a_name, oc_flags, &a_oid, a_oc) ||\n+\t    get_oid_with_context(revs->repo, b_name, oc_flags, &b_oid, b_oc))\n \t\treturn -1;\n \n \tif (!cant_be_filename) {\n@@ -1724,7 +1724,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi\n \tif (revarg_opt & REVARG_COMMITTISH)\n \t\tget_sha1_flags |= GET_OID_COMMITTISH;\n \n-\tif (get_oid_with_context(arg, get_sha1_flags, &oid, &oc))\n+\tif (get_oid_with_context(revs->repo, arg, get_sha1_flags, &oid, &oc))\n \t\treturn revs->ignore_missing ? 0 : -1;\n \tif (!cant_be_filename)\n \t\tverify_non_filename(revs->prefix, arg);\n@@ -2453,7 +2453,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s\n \t\tstruct object_id oid;\n \t\tstruct object *object;\n \t\tstruct object_context oc;\n-\t\tif (get_oid_with_context(revs->def, 0, &oid, &oc))\n+\t\tif (get_oid_with_context(revs->repo, revs->def, 0, &oid, &oc))\n \t\t\tdiagnose_missing_default(revs->def);\n \t\tobject = get_reference(revs, revs->def, &oid, 0);\n \t\tadd_pending_object_with_mode(revs, object, revs->def, oc.mode);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex a0fc1008ec..d8cab7b5a6 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1513,7 +1513,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)\n int get_oid(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, 0, oid, &unused);\n+\treturn get_oid_with_context(the_repository, name, 0, oid, &unused);\n }\n \n \n@@ -1530,35 +1530,40 @@ int get_oid(const char *name, struct object_id *oid)\n int get_oid_committish(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, GET_OID_COMMITTISH,\n+\treturn get_oid_with_context(the_repository,\n+\t\t\t\t    name, GET_OID_COMMITTISH,\n \t\t\t\t    oid, &unused);\n }\n \n int get_oid_treeish(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, GET_OID_TREEISH,\n+\treturn get_oid_with_context(the_repository,\n+\t\t\t\t    name, GET_OID_TREEISH,\n \t\t\t\t    oid, &unused);\n }\n \n int get_oid_commit(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, GET_OID_COMMIT,\n+\treturn get_oid_with_context(the_repository,\n+\t\t\t\t    name, GET_OID_COMMIT,\n \t\t\t\t    oid, &unused);\n }\n \n int get_oid_tree(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, GET_OID_TREE,\n+\treturn get_oid_with_context(the_repository,\n+\t\t\t\t    name, GET_OID_TREE,\n \t\t\t\t    oid, &unused);\n }\n \n int get_oid_blob(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, GET_OID_BLOB,\n+\treturn get_oid_with_context(the_repository,\n+\t\t\t\t    name, GET_OID_BLOB,\n \t\t\t\t    oid, &unused);\n }\n \n@@ -1597,7 +1602,8 @@ static void diagnose_invalid_oid_path(const char *prefix,\n }\n \n /* Must be called only when :stage:filename doesn't exist. */\n-static void diagnose_invalid_index_path(int stage,\n+static void diagnose_invalid_index_path(struct index_state *istate,\n+\t\t\t\t\tint stage,\n \t\t\t\t\tconst char *prefix,\n \t\t\t\t\tconst char *filename)\n {\n@@ -1610,11 +1616,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(istate, 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 < istate->cache_nr) {\n+\t\tce = istate->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@@ -1626,11 +1632,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(istate, 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 < istate->cache_nr) {\n+\t\tce = istate->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@@ -1664,7 +1670,8 @@ static char *resolve_relative_path(const char *rel)\n \t\t\t   rel);\n }\n \n-static int get_oid_with_context_1(const char *name,\n+static int get_oid_with_context_1(struct repository *repo,\n+\t\t\t\t  const char *name,\n \t\t\t\t  unsigned flags,\n \t\t\t\t  const char *prefix,\n \t\t\t\t  struct object_id *oid,\n@@ -1723,13 +1730,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 (!the_index.cache)\n+\t\tif (!repo->index->cache)\n \t\t\trepo_read_index(the_repository);\n-\t\tpos = index_name_pos(&the_index, cp, namelen);\n+\t\tpos = index_name_pos(repo->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 < repo->index->cache_nr) {\n+\t\t\tce = repo->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@@ -1742,7 +1749,7 @@ static int get_oid_with_context_1(const char *name,\n \t\t\tpos++;\n \t\t}\n \t\tif (only_to_die && name[1] && name[1] != '/')\n-\t\t\tdiagnose_invalid_index_path(stage, prefix, cp);\n+\t\t\tdiagnose_invalid_index_path(repo->index, stage, prefix, cp);\n \t\tfree(new_path);\n \t\treturn -1;\n \t}\n@@ -1807,12 +1814,15 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)\n {\n \tstruct object_context oc;\n \tstruct object_id oid;\n-\tget_oid_with_context_1(name, GET_OID_ONLY_TO_DIE, prefix, &oid, &oc);\n+\tget_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,\n+\t\t\t       prefix, &oid, &oc);\n }\n \n-int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc)\n+int get_oid_with_context(struct repository *repo, const char *str,\n+\t\t\t unsigned flags, struct object_id *oid,\n+\t\t\t struct object_context *oc)\n {\n \tif (flags & GET_OID_FOLLOW_SYMLINKS && flags & GET_OID_ONLY_TO_DIE)\n \t\tBUG(\"incompatible flags for get_sha1_with_context\");\n-\treturn get_oid_with_context_1(str, flags, NULL, oid, oc);\n+\treturn get_oid_with_context_1(repo, str, flags, NULL, oid, oc);\n }\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366184","messageId":"20190105055153.3256-8-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH 07/10] merge-recursive.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:50Z","receivedAt":"2019-01-05T05:52: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 builtin/am.c              |   2 +-\n builtin/checkout.c        |   2 +-\n builtin/merge-recursive.c |   2 +-\n builtin/merge.c           |   2 +-\n merge-recursive.c         | 148 ++++++++++++++++++++------------------\n merge-recursive.h         |   6 +-\n sequencer.c               |   4 +-\n 7 files changed, 91 insertions(+), 75 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 901dc55078..611712dc95 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1545,7 +1545,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \t * changes.\n \t */\n \n-\tinit_merge_options(&o);\n+\tinit_merge_options(&o, the_repository);\n \n \to.branch1 = \"HEAD\";\n \ttheir_tree_name = xstrfmt(\"%.*s\", linelen(state->msg), state->msg);\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 1b672a9fd9..a95ba2c6dc 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -670,7 +670,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \t\t\t * a pain; plumb in an option to set\n \t\t\t * o.renormalize?\n \t\t\t */\n-\t\t\tinit_merge_options(&o);\n+\t\t\tinit_merge_options(&o, the_repository);\n \t\t\to.verbosity = 0;\n \t\t\twork = write_tree_from_memory(&o);\n \ndiff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c\nindex 9b2f707c29..4864f7b22f 100644\n--- a/builtin/merge-recursive.c\n+++ b/builtin/merge-recursive.c\n@@ -28,7 +28,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)\n \tstruct merge_options o;\n \tstruct commit *result;\n \n-\tinit_merge_options(&o);\n+\tinit_merge_options(&o, the_repository);\n \tif (argv[0] && ends_with(argv[0], \"-subtree\"))\n \t\to.subtree_shift = \"\";\n \ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex dc0b7cc521..bc1aecfe70 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -702,7 +702,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,\n \t\t\treturn 2;\n \t\t}\n \n-\t\tinit_merge_options(&o);\n+\t\tinit_merge_options(&o, the_repository);\n \t\tif (!strcmp(strategy, \"subtree\"))\n \t\t\to.subtree_shift = \"\";\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 5fbd4253c1..28f44c73ec 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -343,22 +343,24 @@ static int add_cacheinfo(struct merge_options *o,\n \t\t\t unsigned int mode, const struct object_id *oid,\n \t\t\t const char *path, int stage, int refresh, int options)\n {\n+\tstruct index_state *istate = o->repo->index;\n \tstruct cache_entry *ce;\n \tint ret;\n \n-\tce = make_cache_entry(&the_index, mode, oid ? oid : &null_oid, path, stage, 0);\n+\tce = make_cache_entry(istate, mode, oid ? oid : &null_oid, path, stage, 0);\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(istate, ce, options);\n \tif (refresh) {\n \t\tstruct cache_entry *nce;\n \n-\t\tnce = refresh_cache_entry(&the_index, ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);\n+\t\tnce = refresh_cache_entry(istate, ce,\n+\t\t\t\t\t  CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);\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(istate, nce, options);\n \t}\n \treturn ret;\n }\n@@ -386,7 +388,7 @@ static int unpack_trees_start(struct merge_options *o,\n \to->unpack_opts.merge = 1;\n \to->unpack_opts.head_idx = 2;\n \to->unpack_opts.fn = threeway_merge;\n-\to->unpack_opts.src_index = &the_index;\n+\to->unpack_opts.src_index = o->repo->index;\n \to->unpack_opts.dst_index = &tmp_index;\n \to->unpack_opts.aggressive = !merge_detect_rename(o);\n \tsetup_unpack_trees_porcelain(&o->unpack_opts, \"merge\");\n@@ -396,16 +398,16 @@ 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(&o->repo->index->cache_tree);\n \n \t/*\n-\t * Update the_index to match the new results, AFTER saving a copy\n+\t * Update o->repo->index to match the new results, AFTER saving a copy\n \t * in o->orig_index.  Update src_index to point to the saved copy.\n \t * (verify_uptodate() checks src_index, and the original index is\n \t * the one that had the necessary modification timestamps.)\n \t */\n-\to->orig_index = the_index;\n-\tthe_index = tmp_index;\n+\to->orig_index = *o->repo->index;\n+\t*o->repo->index = tmp_index;\n \to->unpack_opts.src_index = &o->orig_index;\n \n \treturn rc;\n@@ -420,12 +422,13 @@ static void unpack_trees_finish(struct merge_options *o)\n struct tree *write_tree_from_memory(struct merge_options *o)\n {\n \tstruct tree *result = NULL;\n+\tstruct index_state *istate = o->repo->index;\n \n-\tif (unmerged_cache()) {\n+\tif (unmerged_index(istate)) {\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 < istate->cache_nr; i++) {\n+\t\t\tconst struct cache_entry *ce = istate->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@@ -433,16 +436,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 (!istate->cache_tree)\n+\t\tistate->cache_tree = cache_tree();\n \n-\tif (!cache_tree_fully_valid(active_cache_tree) &&\n-\t    cache_tree_update(&the_index, 0) < 0) {\n+\tif (!cache_tree_fully_valid(istate->cache_tree) &&\n+\t    cache_tree_update(istate, 0) < 0) {\n \t\terr(o, _(\"error building trees\"));\n \t\treturn NULL;\n \t}\n \n-\tresult = lookup_tree(the_repository, &active_cache_tree->oid);\n+\tresult = lookup_tree(the_repository, &istate->cache_tree->oid);\n \n \treturn result;\n }\n@@ -512,17 +515,17 @@ static struct stage_data *insert_stage_data(const char *path,\n  * Create a dictionary mapping file names to stage_data objects. The\n  * dictionary contains one entry for every path with a non-zero stage entry.\n  */\n-static struct string_list *get_unmerged(void)\n+static struct string_list *get_unmerged(struct index_state *istate)\n {\n \tstruct string_list *unmerged = xcalloc(1, sizeof(struct string_list));\n \tint i;\n \n \tunmerged->strdup_strings = 1;\n \n-\tfor (i = 0; i < active_nr; i++) {\n+\tfor (i = 0; i < istate->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 = istate->cache[i];\n \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \n@@ -682,7 +685,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(opt->repo->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@@ -717,13 +720,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(o->repo->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(o->repo->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@@ -773,7 +777,8 @@ static char *unique_path(struct merge_options *o, const char *path, const char *\n  * check the working directory.  If empty_ok is non-zero, also return\n  * 0 in the case where the working-tree dir exists but is empty.\n  */\n-static int dir_in_way(const char *path, int check_working_copy, int empty_ok)\n+static int dir_in_way(struct index_state *istate, const char *path,\n+\t\t      int check_working_copy, int empty_ok)\n {\n \tint pos;\n \tstruct strbuf dirpath = STRBUF_INIT;\n@@ -782,12 +787,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(istate, 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 < istate->cache_nr &&\n+\t    !strncmp(dirpath.buf, istate->cache[pos]->name, dirpath.len)) {\n \t\tstrbuf_release(&dirpath);\n \t\treturn 1;\n \t}\n@@ -830,8 +835,10 @@ static int was_tracked(struct merge_options *o, const char *path)\n \treturn 0;\n }\n \n-static int would_lose_untracked(const char *path)\n+static int would_lose_untracked(struct merge_options *o, const char *path)\n {\n+\tstruct index_state *istate = o->repo->index;\n+\n \t/*\n \t * This may look like it can be simplified to:\n \t *   return !was_tracked(o, path) && file_exists(path)\n@@ -849,19 +856,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(istate, 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 < istate->cache_nr &&\n+\t       !strcmp(path, istate->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(istate->cache[pos])) {\n \t\tcase 0:\n \t\tcase 2:\n \t\t\treturn 0;\n@@ -921,7 +928,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)\n \t * Do not unlink a file in the work tree if we are not\n \t * tracking it.\n \t */\n-\tif (would_lose_untracked(path))\n+\tif (would_lose_untracked(o, path))\n \t\treturn err(o, _(\"refusing to lose untracked file at '%s'\"),\n \t\t\t   path);\n \n@@ -971,7 +978,7 @@ static int update_file_flags(struct merge_options *o,\n \t\t}\n \t\tif (S_ISREG(mode)) {\n \t\t\tstruct strbuf strbuf = STRBUF_INIT;\n-\t\t\tif (convert_to_working_tree(&the_index, path, buf, size, &strbuf)) {\n+\t\t\tif (convert_to_working_tree(o->repo->index, path, buf, size, &strbuf)) {\n \t\t\t\tfree(buf);\n \t\t\t\tsize = strbuf.len;\n \t\t\t\tbuf = strbuf_detach(&strbuf, NULL);\n@@ -1091,7 +1098,7 @@ static int merge_3way(struct merge_options *o,\n \n \tmerge_status = ll_merge(result_buf, a->path, &orig, base_name,\n \t\t\t\t&src1, name1, &src2, name2,\n-\t\t\t\t&the_index, &ll_opts);\n+\t\t\t\to->repo->index, &ll_opts);\n \n \tfree(base_name);\n \tfree(name1);\n@@ -1102,7 +1109,8 @@ static int merge_3way(struct merge_options *o,\n \treturn merge_status;\n }\n \n-static int find_first_merges(struct object_array *result, const char *path,\n+static int find_first_merges(struct repository *repo,\n+\t\t\t     struct object_array *result, const char *path,\n \t\t\t     struct commit *a, struct commit *b)\n {\n \tint i, j;\n@@ -1122,7 +1130,7 @@ static int find_first_merges(struct object_array *result, const char *path,\n \t/* get all revisions that merge commit a */\n \txsnprintf(merged_revision, sizeof(merged_revision), \"^%s\",\n \t\t  oid_to_hex(&a->object.oid));\n-\trepo_init_revisions(the_repository, &revs, NULL);\n+\trepo_init_revisions(repo, &revs, NULL);\n \trev_opts.submodule = path;\n \t/* FIXME: can't handle linked worktrees in submodules yet */\n \trevs.single_worktree = path != NULL;\n@@ -1252,7 +1260,8 @@ static int merge_submodule(struct merge_options *o,\n \t\treturn 0;\n \n \t/* find commit which merges them */\n-\tparent_count = find_first_merges(&merges, path, commit_a, commit_b);\n+\tparent_count = find_first_merges(o->repo, &merges, path,\n+\t\t\t\t\t commit_a, commit_b);\n \tswitch (parent_count) {\n \tcase 0:\n \t\toutput(o, 1, _(\"Failed to merge submodule %s (merge following commits not found)\"), path);\n@@ -1400,7 +1409,7 @@ static int handle_rename_via_dir(struct merge_options *o,\n \t */\n \tconst struct diff_filespec *dest = pair->two;\n \n-\tif (!o->call_depth && would_lose_untracked(dest->path)) {\n+\tif (!o->call_depth && would_lose_untracked(o, dest->path)) {\n \t\tchar *alt_path = unique_path(o, dest->path, rename_branch);\n \n \t\toutput(o, 1, _(\"Error: Refusing to lose untracked file at %s; \"\n@@ -1438,8 +1447,8 @@ static int handle_change_delete(struct merge_options *o,\n \tconst char *update_path = path;\n \tint ret = 0;\n \n-\tif (dir_in_way(path, !o->call_depth, 0) ||\n-\t    (!o->call_depth && would_lose_untracked(path))) {\n+\tif (dir_in_way(o->repo->index, path, !o->call_depth, 0) ||\n+\t    (!o->call_depth && would_lose_untracked(o, path))) {\n \t\tupdate_path = alt_path = unique_path(o, path, change_branch);\n \t}\n \n@@ -1449,7 +1458,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(o->repo->index, path);\n \t\tif (!ret)\n \t\t\tret = update_file(o, 0, o_oid, o_mode, update_path);\n \t} else {\n@@ -1525,7 +1534,7 @@ static int handle_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(o->repo->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@@ -1606,10 +1615,10 @@ static int handle_file_collision(struct merge_options *o,\n \t/* Remove rename sources if rename/add or rename/rename(2to1) */\n \tif (prev_path1)\n \t\tremove_file(o, 1, prev_path1,\n-\t\t\t    o->call_depth || would_lose_untracked(prev_path1));\n+\t\t\t    o->call_depth || would_lose_untracked(o, prev_path1));\n \tif (prev_path2)\n \t\tremove_file(o, 1, prev_path2,\n-\t\t\t    o->call_depth || would_lose_untracked(prev_path2));\n+\t\t\t    o->call_depth || would_lose_untracked(o, prev_path2));\n \n \t/*\n \t * Remove the collision path, if it wouldn't cause dirty contents\n@@ -1620,7 +1629,7 @@ static int handle_file_collision(struct merge_options *o,\n \t\toutput(o, 1, _(\"Refusing to lose dirty file at %s\"),\n \t\t       collide_path);\n \t\tupdate_path = alt_path = unique_path(o, collide_path, \"merged\");\n-\t} else if (would_lose_untracked(collide_path)) {\n+\t} else if (would_lose_untracked(o, collide_path)) {\n \t\t/*\n \t\t * Only way we get here is if both renames were from\n \t\t * a directory rename AND user had an untracked file\n@@ -1716,12 +1725,12 @@ static char *find_path_for_conflict(struct merge_options *o,\n \t\t\t\t    const char *branch2)\n {\n \tchar *new_path = NULL;\n-\tif (dir_in_way(path, !o->call_depth, 0)) {\n+\tif (dir_in_way(o->repo->index, path, !o->call_depth, 0)) {\n \t\tnew_path = unique_path(o, path, branch1);\n \t\toutput(o, 1, _(\"%s is a directory in %s adding \"\n \t\t\t       \"as %s instead\"),\n \t\t       path, branch2, new_path);\n-\t} else if (would_lose_untracked(path)) {\n+\t} else if (would_lose_untracked(o, path)) {\n \t\tnew_path = unique_path(o, path, branch1);\n \t\toutput(o, 1, _(\"Refusing to lose untracked file\"\n \t\t\t       \" at %s; adding as %s instead\"),\n@@ -1782,14 +1791,14 @@ static int handle_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(o->repo->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(o->repo->index, b->path);\n \t} else {\n \t\t/*\n \t\t * For each destination path, we need to see if there is a\n@@ -1886,7 +1895,7 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *o,\n \tstruct diff_queue_struct *ret;\n \tstruct diff_options opts;\n \n-\trepo_diff_setup(the_repository, &opts);\n+\trepo_diff_setup(o->repo, &opts);\n \topts.flags.recursive = 1;\n \topts.flags.rename_empty = 0;\n \topts.detect_rename = merge_detect_rename(o);\n@@ -3041,8 +3050,8 @@ static int blob_unchanged(struct merge_options *opt,\n \t * performed.  Comparison can be skipped if both files are\n \t * unchanged since their sha1s have already been compared.\n \t */\n-\tif (renormalize_buffer(&the_index, path, o.buf, o.len, &o) |\n-\t    renormalize_buffer(&the_index, path, a.buf, a.len, &a))\n+\tif (renormalize_buffer(opt->repo->index, path, o.buf, o.len, &o) |\n+\t    renormalize_buffer(opt->repo->index, path, a.buf, a.len, &a))\n \t\tret = (o.len == a.len && !memcmp(o.buf, a.buf, o.len));\n \n error_return:\n@@ -3123,7 +3132,7 @@ static int handle_content_merge(struct merge_options *o,\n \t\ta.path = (char *)path1;\n \t\tb.path = (char *)path2;\n \n-\t\tif (dir_in_way(path, !o->call_depth,\n+\t\tif (dir_in_way(o->repo->index, path, !o->call_depth,\n \t\t\t       S_ISGITLINK(pair1->two->mode)))\n \t\t\tdf_conflict_remains = 1;\n \t}\n@@ -3157,8 +3166,8 @@ static int handle_content_merge(struct merge_options *o,\n \t\tpos = index_name_pos(&o->orig_index, path, strlen(path));\n \t\tce = o->orig_index.cache[pos];\n \t\tif (ce_skip_worktree(ce)) {\n-\t\t\tpos = index_name_pos(&the_index, path, strlen(path));\n-\t\t\tce = the_index.cache[pos];\n+\t\t\tpos = index_name_pos(o->repo->index, path, strlen(path));\n+\t\t\tce = o->repo->index->cache[pos];\n \t\t\tce->ce_flags |= CE_SKIP_WORKTREE;\n \t\t}\n \t\treturn mfi.clean;\n@@ -3177,7 +3186,7 @@ static int handle_content_merge(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(o->repo->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@@ -3337,7 +3346,7 @@ static int process_entry(struct merge_options *o,\n \t\t\toid = b_oid;\n \t\t\tconf = _(\"directory/file\");\n \t\t}\n-\t\tif (dir_in_way(path,\n+\t\tif (dir_in_way(o->repo->index, path,\n \t\t\t       !o->call_depth && !S_ISGITLINK(a_mode),\n \t\t\t       0)) {\n \t\t\tchar *new_path = unique_path(o, path, add_branch);\n@@ -3348,7 +3357,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(o->repo->index, path);\n \t\t\tfree(new_path);\n \t\t} else {\n \t\t\toutput(o, 2, _(\"Adding %s\"), path);\n@@ -3396,10 +3405,11 @@ int merge_trees(struct merge_options *o,\n \t\tstruct tree *common,\n \t\tstruct tree **result)\n {\n+\tstruct index_state *istate = o->repo->index;\n \tint code, clean;\n \tstruct strbuf sb = STRBUF_INIT;\n \n-\tif (!o->call_depth && index_has_changes(&the_index, head, &sb)) {\n+\tif (!o->call_depth && index_has_changes(istate, head, &sb)) {\n \t\terr(o, _(\"Your local changes to the following files would be overwritten by merge:\\n  %s\"),\n \t\t    sb.buf);\n \t\treturn -1;\n@@ -3427,7 +3437,7 @@ int merge_trees(struct merge_options *o,\n \t\treturn -1;\n \t}\n \n-\tif (unmerged_cache()) {\n+\tif (unmerged_index(istate)) {\n \t\tstruct string_list *entries;\n \t\tstruct rename_info re_info;\n \t\tint i;\n@@ -3442,7 +3452,7 @@ int merge_trees(struct merge_options *o,\n \t\tget_files_dirs(o, head);\n \t\tget_files_dirs(o, merge);\n \n-\t\tentries = get_unmerged();\n+\t\tentries = get_unmerged(o->repo->index);\n \t\tclean = detect_and_process_renames(o, common, head, merge,\n \t\t\t\t\t\t   entries, &re_info);\n \t\trecord_df_conflict_files(o, entries);\n@@ -3558,7 +3568,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(o->repo->index);\n \t\tsaved_b1 = o->branch1;\n \t\tsaved_b2 = o->branch2;\n \t\to->branch1 = \"Temporary merge branch 1\";\n@@ -3574,9 +3584,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(o->repo->index);\n \tif (!o->call_depth)\n-\t\trepo_read_index(the_repository);\n+\t\trepo_read_index(o->repo);\n \n \to->ancestor = \"merged common ancestors\";\n \tclean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),\n@@ -3643,7 +3653,7 @@ int merge_recursive_generic(struct merge_options *o,\n \t\t}\n \t}\n \n-\trepo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(o->repo, &lock, LOCK_DIE_ON_ERROR);\n \tclean = merge_recursive(o, head_commit, next_commit, ca,\n \t\t\t\tresult);\n \tif (clean < 0) {\n@@ -3651,7 +3661,7 @@ int merge_recursive_generic(struct merge_options *o,\n \t\treturn clean;\n \t}\n \n-\tif (write_locked_index(&the_index, &lock,\n+\tif (write_locked_index(o->repo->index, &lock,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\treturn err(o, _(\"Unable to write index.\"));\n \n@@ -3675,10 +3685,12 @@ static void merge_recursive_config(struct merge_options *o)\n \tgit_config(git_xmerge_config, NULL);\n }\n \n-void init_merge_options(struct merge_options *o)\n+void init_merge_options(struct merge_options *o,\n+\t\t\tstruct repository *repo)\n {\n \tconst char *merge_verbosity;\n \tmemset(o, 0, sizeof(struct merge_options));\n+\to->repo = repo;\n \to->verbosity = 2;\n \to->buffer_output = 1;\n \to->diff_rename_limit = -1;\ndiff --git a/merge-recursive.h b/merge-recursive.h\nindex e6a0828eca..c2b7bb65c6 100644\n--- a/merge-recursive.h\n+++ b/merge-recursive.h\n@@ -6,6 +6,8 @@\n \n struct commit;\n \n+struct repository;\n+\n struct merge_options {\n \tconst char *ancestor;\n \tconst char *branch1;\n@@ -34,6 +36,7 @@ struct merge_options {\n \tstruct string_list df_conflict_file_set;\n \tstruct unpack_trees_options unpack_opts;\n \tstruct index_state orig_index;\n+\tstruct repository *repo;\n };\n \n /*\n@@ -92,7 +95,8 @@ int merge_recursive_generic(struct merge_options *o,\n \t\t\t    const struct object_id **ca,\n \t\t\t    struct commit **result);\n \n-void init_merge_options(struct merge_options *o);\n+void init_merge_options(struct merge_options *o,\n+\t\t\tstruct repository *repo);\n struct tree *write_tree_from_memory(struct merge_options *o);\n \n int parse_merge_opt(struct merge_options *out, const char *s);\ndiff --git a/sequencer.c b/sequencer.c\nindex c2c9cc7e2b..cede6ea095 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -545,7 +545,7 @@ static int do_recursive_merge(struct repository *r,\n \n \trepo_read_index(r);\n \n-\tinit_merge_options(&o);\n+\tinit_merge_options(&o, r);\n \to.ancestor = base ? base_label : \"(empty tree)\";\n \to.branch1 = \"HEAD\";\n \to.branch2 = next ? next_label : \"(empty tree)\";\n@@ -3300,7 +3300,7 @@ static int do_merge(struct repository *r,\n \tfree_commit_list(bases);\n \n \trepo_read_index(r);\n-\tinit_merge_options(&o);\n+\tinit_merge_options(&o, r);\n \to.branch1 = \"HEAD\";\n \to.branch2 = ref_name.buf;\n \to.buffer_output = 2;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366188","messageId":"20190105055153.3256-9-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH 08/10] merge-recursive.c: remove implicit dependency on the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:51Z","receivedAt":"2019-01-05T05:52:55Z","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 | 45 ++++++++++++++++++++++++---------------------\n 1 file changed, 24 insertions(+), 21 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 28f44c73ec..a596d95739 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -146,7 +146,8 @@ static int err(struct merge_options *o, const char *err, ...)\n \treturn -1;\n }\n \n-static struct tree *shift_tree_object(struct tree *one, struct tree *two,\n+static struct tree *shift_tree_object(struct repository *repo,\n+\t\t\t\t      struct tree *one, struct tree *two,\n \t\t\t\t      const char *subtree_shift)\n {\n \tstruct object_id shifted;\n@@ -159,12 +160,14 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,\n \t}\n \tif (oideq(&two->object.oid, &shifted))\n \t\treturn two;\n-\treturn lookup_tree(the_repository, &shifted);\n+\treturn lookup_tree(repo, &shifted);\n }\n \n-static struct commit *make_virtual_commit(struct tree *tree, const char *comment)\n+static struct commit *make_virtual_commit(struct repository *repo,\n+\t\t\t\t\t  struct tree *tree,\n+\t\t\t\t\t  const char *comment)\n {\n-\tstruct commit *commit = alloc_commit_node(the_repository);\n+\tstruct commit *commit = alloc_commit_node(repo);\n \n \tset_merge_remote_desc(commit, comment, (struct object *)commit);\n \tcommit->maybe_tree = tree;\n@@ -445,7 +448,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)\n \t\treturn NULL;\n \t}\n \n-\tresult = lookup_tree(the_repository, &istate->cache_tree->oid);\n+\tresult = lookup_tree(o->repo, &istate->cache_tree->oid);\n \n \treturn result;\n }\n@@ -1208,9 +1211,9 @@ static int merge_submodule(struct merge_options *o,\n \t\treturn 0;\n \t}\n \n-\tif (!(commit_base = lookup_commit_reference(the_repository, base)) ||\n-\t    !(commit_a = lookup_commit_reference(the_repository, a)) ||\n-\t    !(commit_b = lookup_commit_reference(the_repository, b))) {\n+\tif (!(commit_base = lookup_commit_reference(o->repo, base)) ||\n+\t    !(commit_a = lookup_commit_reference(o->repo, a)) ||\n+\t    !(commit_b = lookup_commit_reference(o->repo, b))) {\n \t\toutput(o, 1, _(\"Failed to merge submodule %s (commits not present)\"), path);\n \t\treturn 0;\n \t}\n@@ -3416,8 +3419,8 @@ int merge_trees(struct merge_options *o,\n \t}\n \n \tif (o->subtree_shift) {\n-\t\tmerge = shift_tree_object(head, merge, o->subtree_shift);\n-\t\tcommon = shift_tree_object(head, common, o->subtree_shift);\n+\t\tmerge = shift_tree_object(o->repo, head, merge, o->subtree_shift);\n+\t\tcommon = shift_tree_object(o->repo, head, common, o->subtree_shift);\n \t}\n \n \tif (oid_eq(&common->object.oid, &merge->object.oid)) {\n@@ -3553,8 +3556,8 @@ int merge_recursive(struct merge_options *o,\n \t\t/* if there is no common ancestor, use an empty tree */\n \t\tstruct tree *tree;\n \n-\t\ttree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree);\n-\t\tmerged_common_ancestors = make_virtual_commit(tree, \"ancestor\");\n+\t\ttree = lookup_tree(o->repo, o->repo->hash_algo->empty_tree);\n+\t\tmerged_common_ancestors = make_virtual_commit(o->repo, tree, \"ancestor\");\n \t}\n \n \tfor (iter = ca; iter; iter = iter->next) {\n@@ -3598,7 +3601,7 @@ int merge_recursive(struct merge_options *o,\n \t}\n \n \tif (o->call_depth) {\n-\t\t*result = make_virtual_commit(mrtree, \"merged tree\");\n+\t\t*result = make_virtual_commit(o->repo, mrtree, \"merged tree\");\n \t\tcommit_list_insert(h1, &(*result)->parents);\n \t\tcommit_list_insert(h2, &(*result)->parents->next);\n \t}\n@@ -3611,17 +3614,17 @@ int merge_recursive(struct merge_options *o,\n \treturn clean;\n }\n \n-static struct commit *get_ref(const struct object_id *oid, const char *name)\n+static struct commit *get_ref(struct repository *repo, const struct object_id *oid,\n+\t\t\t      const char *name)\n {\n \tstruct object *object;\n \n-\tobject = deref_tag(the_repository, parse_object(the_repository, oid),\n-\t\t\t   name,\n-\t\t\t   strlen(name));\n+\tobject = deref_tag(repo, parse_object(repo, oid),\n+\t\t\t   name, strlen(name));\n \tif (!object)\n \t\treturn NULL;\n \tif (object->type == OBJ_TREE)\n-\t\treturn make_virtual_commit((struct tree*)object, name);\n+\t\treturn make_virtual_commit(repo, (struct tree*)object, name);\n \tif (object->type != OBJ_COMMIT)\n \t\treturn NULL;\n \tif (parse_commit((struct commit *)object))\n@@ -3638,15 +3641,15 @@ int merge_recursive_generic(struct merge_options *o,\n {\n \tint clean;\n \tstruct lock_file lock = LOCK_INIT;\n-\tstruct commit *head_commit = get_ref(head, o->branch1);\n-\tstruct commit *next_commit = get_ref(merge, o->branch2);\n+\tstruct commit *head_commit = get_ref(o->repo, head, o->branch1);\n+\tstruct commit *next_commit = get_ref(o->repo, merge, o->branch2);\n \tstruct commit_list *ca = NULL;\n \n \tif (base_list) {\n \t\tint i;\n \t\tfor (i = 0; i < num_base_list; ++i) {\n \t\t\tstruct commit *base;\n-\t\t\tif (!(base = get_ref(base_list[i], oid_to_hex(base_list[i]))))\n+\t\t\tif (!(base = get_ref(o->repo, base_list[i], oid_to_hex(base_list[i]))))\n \t\t\t\treturn err(o, _(\"Could not parse object '%s'\"),\n \t\t\t\t\t   oid_to_hex(base_list[i]));\n \t\t\tcommit_list_insert(base, &ca);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366183","messageId":"20190105055153.3256-10-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH 09/10] read-cache.c: remove the_* from index_has_changes()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:52Z","receivedAt":"2019-01-05T05:53:01Z","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 builtin/am.c      |  6 +++---\n cache.h           |  6 +++---\n merge-recursive.c |  2 +-\n read-cache.c      | 12 +++++-------\n 4 files changed, 12 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 611712dc95..a9ffc92eaa 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1719,7 +1719,7 @@ static void am_run(struct am_state *state, int resume)\n \n \trefresh_and_write_cache();\n \n-\tif (index_has_changes(&the_index, NULL, &sb)) {\n+\tif (repo_index_has_changes(the_repository, NULL, &sb)) {\n \t\twrite_state_bool(state, \"dirtyindex\", 1);\n \t\tdie(_(\"Dirty index: cannot apply patches (dirty: %s)\"), sb.buf);\n \t}\n@@ -1777,7 +1777,7 @@ static void am_run(struct am_state *state, int resume)\n \t\t\t * the result may have produced the same tree as ours.\n \t\t\t */\n \t\t\tif (!apply_status &&\n-\t\t\t    !index_has_changes(&the_index, NULL, NULL)) {\n+\t\t\t    !repo_index_has_changes(the_repository, NULL, NULL)) {\n \t\t\t\tsay(state, stdout, _(\"No changes -- Patch already applied.\"));\n \t\t\t\tgoto next;\n \t\t\t}\n@@ -1831,7 +1831,7 @@ static void am_resolve(struct am_state *state)\n \n \tsay(state, stdout, _(\"Applying: %.*s\"), linelen(state->msg), state->msg);\n \n-\tif (!index_has_changes(&the_index, NULL, NULL)) {\n+\tif (!repo_index_has_changes(the_repository, NULL, NULL)) {\n \t\tprintf_ln(_(\"No changes - did you forget to use 'git add'?\\n\"\n \t\t\t\"If there is nothing left to stage, chances are that something else\\n\"\n \t\t\t\"already introduced the same changes; you might want to skip this patch.\"));\ndiff --git a/cache.h b/cache.h\nindex fdcd69bfb0..326e73f391 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -706,9 +706,9 @@ extern int unmerged_index(const struct index_state *);\n  * provided, the space-separated list of files that differ will be appended\n  * to it.\n  */\n-extern int index_has_changes(struct index_state *istate,\n-\t\t\t     struct tree *tree,\n-\t\t\t     struct strbuf *sb);\n+extern int repo_index_has_changes(struct repository *repo,\n+\t\t\t\t  struct tree *tree,\n+\t\t\t\t  struct strbuf *sb);\n \n extern int verify_path(const char *path, unsigned mode);\n extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change);\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex a596d95739..df00896b25 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3412,7 +3412,7 @@ int merge_trees(struct merge_options *o,\n \tint code, clean;\n \tstruct strbuf sb = STRBUF_INIT;\n \n-\tif (!o->call_depth && index_has_changes(istate, head, &sb)) {\n+\tif (!o->call_depth && repo_index_has_changes(o->repo, head, &sb)) {\n \t\terr(o, _(\"Your local changes to the following files would be overwritten by merge:\\n  %s\"),\n \t\t    sb.buf);\n \t\treturn -1;\ndiff --git a/read-cache.c b/read-cache.c\nindex 61cc0571da..2549477ed2 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2365,22 +2365,20 @@ int unmerged_index(const struct index_state *istate)\n \treturn 0;\n }\n \n-int index_has_changes(struct index_state *istate,\n-\t\t      struct tree *tree,\n-\t\t      struct strbuf *sb)\n+int repo_index_has_changes(struct repository *repo,\n+\t\t\t   struct tree *tree,\n+\t\t\t   struct strbuf *sb)\n {\n+\tstruct index_state *istate = repo->index;\n \tstruct object_id cmp;\n \tint i;\n \n-\tif (istate != &the_index) {\n-\t\tBUG(\"index_has_changes cannot yet accept istate != &the_index; do_diff_cache needs updating first.\");\n-\t}\n \tif (tree)\n \t\tcmp = tree->object.oid;\n \tif (tree || !get_oid_tree(\"HEAD\", &cmp)) {\n \t\tstruct diff_options opt;\n \n-\t\trepo_diff_setup(the_repository, &opt);\n+\t\trepo_diff_setup(repo, &opt);\n \t\topt.flags.exit_with_status = 1;\n \t\tif (!sb)\n \t\t\topt.flags.quick = 1;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366180","messageId":"20190105055153.3256-11-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH 10/10] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-05T05:51:53Z","receivedAt":"2019-01-05T05:53:05Z","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/blame.c                      | 3 ++-\n builtin/cat-file.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/difftool.c                   | 1 +\n builtin/fsck.c                       | 1 +\n builtin/grep.c                       | 1 +\n builtin/hash-object.c                | 3 ++-\n builtin/log.c                        | 1 +\n builtin/ls-files.c                   | 1 -\n builtin/merge-index.c                | 1 +\n builtin/merge-ours.c                 | 1 +\n builtin/merge-tree.c                 | 4 +++-\n builtin/merge.c                      | 1 +\n builtin/mv.c                         | 1 +\n builtin/pack-objects.c               | 2 +-\n builtin/pull.c                       | 1 +\n builtin/read-tree.c                  | 1 +\n builtin/rebase--interactive.c        | 1 +\n builtin/rebase.c                     | 1 +\n builtin/replace.c                    | 2 +-\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 builtin/write-tree.c                 | 1 +\n cache-tree.h                         | 2 +-\n cache.h                              | 6 +++---\n convert.c                            | 1 -\n dir.c                                | 1 -\n git.c                                | 4 ++--\n name-hash.c                          | 1 -\n pathspec.c                           | 1 -\n read-cache.c                         | 2 --\n repository.c                         | 1 +\n submodule.c                          | 1 -\n t/helper/test-dump-fsmonitor.c       | 4 ++--\n t/helper/test-dump-untracked-cache.c | 1 +\n t/helper/test-tool.h                 | 1 +\n tree.c                               | 1 -\n unpack-trees.c                       | 1 -\n 54 files changed, 52 insertions(+), 24 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex b63fe0fc0e..e4e4574857 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 f65c172299..81df0d34de 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 a9ffc92eaa..ad913ef20e 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/blame.c b/builtin/blame.c\nindex 6d798f9939..0074ed311c 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -1007,7 +1007,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\tlong bottom, top;\n \t\tif (parse_range_arg(range_list.items[range_i].string,\n \t\t\t\t    nth_line_cb, &sb, lno, anchor,\n-\t\t\t\t    &bottom, &top, sb.path, &the_index))\n+\t\t\t\t    &bottom, &top, sb.path,\n+\t\t\t\t    the_repository->index))\n \t\t\tusage(blame_usage);\n \t\tif ((!lno && (top || bottom)) || lno < bottom)\n \t\t\tdie(Q_(\"file %s has only %lu line\",\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 7622c502f0..a5ca47c697 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.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 \"builtin.h\"\ndiff --git a/builtin/check-attr.c b/builtin/check-attr.c\nindex 30a2f84274..dd83397786 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 eb74774cbc..345591bc4b 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 a95ba2c6dc..0446cac05e 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 bbcdeb2d9e..aaba4af3c2 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 d3f1234bf0..2f4af02a27 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 bc97e50650..02ec56417a 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 48cfcb935d..86ae474fbf 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 fcccd1f10d..93ec642423 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 42bc1eb41d..a90681bcba 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 ec78920ee2..74351a5757 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/difftool.c b/builtin/difftool.c\nindex 544b0e8639..eeb9e370b9 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -11,6 +11,7 @@\n  *\n  * Copyright (C) 2016 Johannes Schindelin\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex bf5ddff43f..46f6ea9baa 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/grep.c b/builtin/grep.c\nindex 3d695ad8fe..308b89536e 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.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 \"repository.h\"\n #include \"config.h\"\ndiff --git a/builtin/hash-object.c b/builtin/hash-object.c\nindex d6f06ea32f..e055c11103 100644\n--- a/builtin/hash-object.c\n+++ b/builtin/hash-object.c\n@@ -40,7 +40,8 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,\n \tif (fstat(fd, &st) < 0 ||\n \t    (literally\n \t     ? hash_literally(&oid, fd, type, flags)\n-\t     : index_fd(&the_index, &oid, fd, &st, type_from_string(type), path, flags)))\n+\t     : index_fd(the_repository->index, &oid, fd, &st,\n+\t\t\ttype_from_string(type), path, flags)))\n \t\tdie((flags & HASH_WRITE_OBJECT)\n \t\t    ? \"Unable to add %s to database\"\n \t\t    : \"Unable to hash %s\", path);\ndiff --git a/builtin/log.c b/builtin/log.c\nindex dbfb4e31ad..195ff0b471 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -4,6 +4,7 @@\n  * (C) Copyright 2006 Linus Torvalds\n  *\t\t 2006 Junio Hamano\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"refs.h\"\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex c70a9c7158..7cc7ec22c9 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 0b07263415..4594507420 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-tree.c b/builtin/merge-tree.c\nindex 70f6fc9167..53719e0b9d 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"tree-walk.h\"\n #include \"xdiff-interface.h\"\n@@ -76,7 +77,8 @@ static void *result(struct merge_list *entry, unsigned long *size)\n \ttheir = NULL;\n \tif (entry)\n \t\ttheir = entry->blob;\n-\treturn merge_blobs(&the_index, path, base, our, their, size);\n+\treturn merge_blobs(the_repository->index, path,\n+\t\t\t   base, our, their, size);\n }\n \n static void *origin(struct merge_list *entry, unsigned long *size)\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex bc1aecfe70..e47d77baee 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/pack-objects.c b/builtin/pack-objects.c\nindex 24bba8147f..d9d3b90b23 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -970,7 +970,7 @@ static int no_try_delta(const char *path)\n \n \tif (!check)\n \t\tcheck = attr_check_initl(\"delta\", NULL);\n-\tgit_check_attr(&the_index, path, check);\n+\tgit_check_attr(the_repository->index, path, check);\n \tif (ATTR_FALSE(check->items[0].value))\n \t\treturn 1;\n \treturn 0;\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 74808b9455..701d1473dc 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 ac255ad2c2..9083dcfa28 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/rebase--interactive.c b/builtin/rebase--interactive.c\nindex dd2a55ab1d..6895322d61 100644\n--- a/builtin/rebase--interactive.c\n+++ b/builtin/rebase--interactive.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/rebase.c b/builtin/rebase.c\nindex 7124e66d00..b667837276 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -4,6 +4,7 @@\n  * Copyright (c) 2018 Pratik Karki\n  */\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"run-command.h\"\n #include \"exec-cmd.h\"\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex affcdfb416..5b80b7f211 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -295,7 +295,7 @@ static int import_object(struct object_id *oid, enum object_type type,\n \t\t\tclose(fd);\n \t\t\treturn -1;\n \t\t}\n-\t\tif (index_fd(&the_index, oid, fd, &st, type, NULL, flags) < 0)\n+\t\tif (index_fd(the_repository->index, oid, fd, &st, type, NULL, flags) < 0)\n \t\t\treturn error(_(\"unable to write object to database\"));\n \t\t/* index_fd close()s fd for us */\n \t}\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 59898c972e..4d18a461fa 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 910a71ed8b..f8bbe6d47e 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 17086d3d97..db85b33982 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 b45514be31..9c832fc606 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 e19da77edc..02ace602b9 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/builtin/write-tree.c b/builtin/write-tree.c\nindex cdcbf8264e..3d46d22ee5 100644\n--- a/builtin/write-tree.c\n+++ b/builtin/write-tree.c\n@@ -3,6 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\ndiff --git a/cache-tree.h b/cache-tree.h\nindex 326209198b..757bbc48bc 100644\n--- a/cache-tree.h\n+++ b/cache-tree.h\n@@ -51,7 +51,7 @@ void prime_cache_tree(struct repository *, struct index_state *, struct tree *);\n \n int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);\n \n-#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS\n+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)\n {\n \treturn write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);\ndiff --git a/cache.h b/cache.h\nindex 326e73f391..962eb127d3 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -338,8 +338,6 @@ struct index_state {\n \tstruct mem_pool *ce_mem_pool;\n };\n \n-extern struct index_state the_index;\n-\n /* Name hashing */\n extern int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);\n extern void add_name_hash(struct index_state *istate, struct cache_entry *ce);\n@@ -401,7 +399,9 @@ struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_s\n  */\n void validate_cache_entries(const struct index_state *istate);\n \n-#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS\n+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n+extern struct index_state the_index;\n+\n #define active_cache (the_index.cache)\n #define active_nr (the_index.cache_nr)\n #define active_alloc (the_index.cache_alloc)\ndiff --git a/convert.c b/convert.c\nindex e0848226d2..df8c6a0bf8 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 \"object-store.h\"\ndiff --git a/dir.c b/dir.c\nindex ab6477d777..80e07441f7 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/git.c b/git.c\nindex 4d53a3d50d..0c2b269797 100644\n--- a/git.c\n+++ b/git.c\n@@ -417,9 +417,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n \n \ttrace_argv_printf(argv, \"trace: built-in: git\");\n \n-\tvalidate_cache_entries(&the_index);\n+\tvalidate_cache_entries(the_repository->index);\n \tstatus = p->fn(argc, argv, prefix);\n-\tvalidate_cache_entries(&the_index);\n+\tvalidate_cache_entries(the_repository->index);\n \n \tif (status)\n \t\treturn status;\ndiff --git a/name-hash.c b/name-hash.c\nindex 623ca6923a..b4861bc7b0 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 #include \"thread-utils.h\"\n \ndiff --git a/pathspec.c b/pathspec.c\nindex 6f005996fd..f1505cfd0a 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 2549477ed2..b3865d6884 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 \"diff.h\"\n@@ -95,7 +94,6 @@ static struct mem_pool *find_mem_pool(struct index_state *istate)\n \treturn *pool_ptr;\n }\n \n-struct index_state the_index;\n static const char *alternate_index_output;\n \n static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)\ndiff --git a/repository.c b/repository.c\nindex fd965c127c..81dc4f0a23 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -9,6 +9,7 @@\n /* The main repository */\n static struct repository the_repo;\n struct repository *the_repository;\n+struct index_state the_index;\n \n void initialize_the_repository(void)\n {\ndiff --git a/submodule.c b/submodule.c\nindex 6415cc5580..4208a50260 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-fsmonitor.c b/t/helper/test-dump-fsmonitor.c\nindex 08e3684aff..2786f47088 100644\n--- a/t/helper/test-dump-fsmonitor.c\n+++ b/t/helper/test-dump-fsmonitor.c\n@@ -3,11 +3,11 @@\n \n int cmd__dump_fsmonitor(int ac, const char **av)\n {\n-\tstruct index_state *istate = &the_index;\n+\tstruct index_state *istate = the_repository->index;\n \tint i;\n \n \tsetup_git_directory();\n-\tif (do_read_index(istate, get_index_file(), 0) < 0)\n+\tif (do_read_index(istate, the_repository->index_file, 0) < 0)\n \t\tdie(\"unable to read index file\");\n \tif (!istate->fsmonitor_last_update) {\n \t\tprintf(\"no fsmonitor\\n\");\ndiff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c\nindex 52870ebbb3..cf0f2c7228 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 \"test-tool.h\"\n #include \"cache.h\"\n #include \"dir.h\"\ndiff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\nindex 042f12464b..f4fb3b9861 100644\n--- a/t/helper/test-tool.h\n+++ b/t/helper/test-tool.h\n@@ -1,6 +1,7 @@\n #ifndef TEST_TOOL_H\n #define TEST_TOOL_H\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"git-compat-util.h\"\n \n int cmd__chmtime(int argc, const char **argv);\ndiff --git a/tree.c b/tree.c\nindex 215d3fdc7c..181a3778f3 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 6d53cbfc86..40f554814d 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.20.0.482.g66447595a7\n\n"},{"id":"366175","messageId":"CAN0heSoRSgZVZ=NE6eof4dusEhfdz-eSiht06rGKb=GELvm86Q@mail.gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-3-pclouds@gmail.com","subject":"Re: [PATCH 02/10] repository.c: replace hold_locked_index() with repo_hold_locked_index()","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2019-01-05T14:33:49Z","receivedAt":"2019-01-05T14:34:04Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"On Sat, 5 Jan 2019 at 07:07, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n>\n> hold_locked_index() assumes the index path at $GIT_DIR/index. This is\n> not good for places that take an arbitrary index_state instead of\n> the_index, which is basically everywhere except builtin/.\n>\n> Replace it with repo_hold_locked_index(). hold_locked_index() remains\n> as a wrapper around repo_hold_locked_index() to reduce changes in builtin/\n\n> diff --git a/builtin/clone.c b/builtin/clone.c\n> index 7c7f98c72c..ddb3230d21 100644\n> --- a/builtin/clone.c\n> +++ b/builtin/clone.c\n> @@ -8,6 +8,7 @@\n>   * Clone a repository into a different directory that does not yet exist.\n>   */\n>\n> +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n\nI think this should be in patch 10/10.\n\n> diff --git a/cache.h b/cache.h\n> index ca36b44ee0..634c9ce325 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -433,6 +433,7 @@ void validate_cache_entries(const struct index_state *istate);\n>  #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)\n>  #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)\n>  #define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))\n> +#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n>  #endif\n>\n>  #define TYPE_BITS 3\n> @@ -833,7 +834,6 @@ extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cach\n>   */\n>  extern void update_index_if_able(struct index_state *, struct lock_file *);\n>\n> -extern int hold_locked_index(struct lock_file *, int);\n\nThe reason this moves is it gets protected with \"#ifndef\nNO_THE_INDEX_COMPATIBILITY_MACROS\". Ok.\n\n> -int hold_locked_index(struct lock_file *lk, int lock_flags)\n> -{\n> -       return hold_lock_file_for_update(lk, get_index_file(), lock_flags);\n> -}\n\n> +int repo_hold_locked_index(struct repository *repo,\n> +                          struct lock_file *lf,\n> +                          int flags)\n> +{\n> +       return hold_lock_file_for_update(lf, repo->index_file, flags);\n> +}\n\n`get_index_file()` BUGs if `the_repository->index_file` is NULL, but\nother than that, this looks like a faithful conversion. Do we want to\nkeep that check here?\n\n\nMartin\n"},{"id":"366254","messageId":"CACsJy8DLFOyh3pvPPhkAVMFMT=wnfOBWuDN9dUr6sUNaNe=3TA@mail.gmail.com","threadId":"50159","inReplyTo":"CAN0heSoRSgZVZ=NE6eof4dusEhfdz-eSiht06rGKb=GELvm86Q@mail.gmail.com","subject":"Re: [PATCH 02/10] repository.c: replace hold_locked_index() with repo_hold_locked_index()","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-07T12:55:50Z","receivedAt":"2019-01-07T13:19:49Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, Jan 5, 2019 at 9:34 PM Martin Ågren <martin.agren@gmail.com> wrote:\n>\n> On Sat, 5 Jan 2019 at 07:07, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n> >\n> > hold_locked_index() assumes the index path at $GIT_DIR/index. This is\n> > not good for places that take an arbitrary index_state instead of\n> > the_index, which is basically everywhere except builtin/.\n> >\n> > Replace it with repo_hold_locked_index(). hold_locked_index() remains\n> > as a wrapper around repo_hold_locked_index() to reduce changes in builtin/\n>\n> > diff --git a/builtin/clone.c b/builtin/clone.c\n> > index 7c7f98c72c..ddb3230d21 100644\n> > --- a/builtin/clone.c\n> > +++ b/builtin/clone.c\n> > @@ -8,6 +8,7 @@\n> >   * Clone a repository into a different directory that does not yet exist.\n> >   */\n> >\n> > +#define USE_THE_INDEX_COMPATIBILITY_MACROS\n>\n> I think this should be in patch 10/10.\n\nEck. There has been a lot of fixups in this series. I guess I fixed up\nthe wrong commit.\n\n> > -int hold_locked_index(struct lock_file *lk, int lock_flags)\n> > -{\n> > -       return hold_lock_file_for_update(lk, get_index_file(), lock_flags);\n> > -}\n>\n> > +int repo_hold_locked_index(struct repository *repo,\n> > +                          struct lock_file *lf,\n> > +                          int flags)\n> > +{\n> > +       return hold_lock_file_for_update(lf, repo->index_file, flags);\n> > +}\n>\n> `get_index_file()` BUGs if `the_repository->index_file` is NULL, but\n> other than that, this looks like a faithful conversion. Do we want to\n> keep that check here?\n\nBetter than segfault :)\n-- \nDuy\n"},{"id":"366596","messageId":"20190112021332.11066-1-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190105055153.3256-1-pclouds@gmail.com","subject":"[PATCH v2 00/11] Remove the_index, the final part","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:21Z","receivedAt":"2019-01-12T02:14:08Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"v2 fixes Martin's comment in 2/10 and also includes a new patch about\ngrep_opt->repo that was sent and reviewed during rc time [1]. It's kind\nof the same topic so I include it here instead of resending it\nseparately.\n\n[1] https://public-inbox.org/git/20181118163851.32178-1-pclouds@gmail.com/\n\nRange-diff:\n\n -:  ---------- >  1:  2e43d9479e grep: use grep_opt->repo instead of explict repo argument\n 1:  5e2b073fcc =  2:  f6eeeba0e7 notes-utils.c: remove the_repository references\n 2:  7055e1e351 !  3:  1fca26dc83 repository.c: replace hold_locked_index() with repo_hold_locked_index()\n    @@ -23,18 +23,6 @@\n      \n      \tif (state->check_index && read_apply_cache(state) < 0) {\n     \n    - diff --git a/builtin/clone.c b/builtin/clone.c\n    - --- a/builtin/clone.c\n    - +++ b/builtin/clone.c\n    -@@\n    -  * Clone a repository into a different directory that does not yet exist.\n    -  */\n    - \n    -+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    - #include \"builtin.h\"\n    - #include \"config.h\"\n    - #include \"lockfile.h\"\n    -\n      diff --git a/cache.h b/cache.h\n      --- a/cache.h\n      +++ b/cache.h\n    @@ -117,6 +105,8 @@\n     +\t\t\t   struct lock_file *lf,\n     +\t\t\t   int flags)\n     +{\n    ++\tif (!repo->index_file)\n    ++\t\tBUG(\"the repo hasn't been setup\");\n     +\treturn hold_lock_file_for_update(lf, repo->index_file, flags);\n     +}\n     \n 3:  86d6231d9e =  4:  4f63b505d7 checkout: avoid the_index when possible\n 4:  50b7828c17 =  5:  be722abc06 read-cache.c: kill read_index()\n 5:  6cf6d66b97 =  6:  a86921c6b6 read-cache.c: replace update_index_if_able with repo_&\n 6:  a5b19aac6d =  7:  637289c4ff sha1-name.c: remove implicit dependency on the_index\n 7:  f9660a561e =  8:  f7fc854a43 merge-recursive.c: remove implicit dependency on the_index\n 8:  be609ede73 =  9:  c1b37119a7 merge-recursive.c: remove implicit dependency on the_repository\n 9:  639062ad41 = 10:  315f3f37d6 read-cache.c: remove the_* from index_has_changes()\n10:  b41cebabad ! 11:  c271d734aa cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch\n    @@ -119,6 +119,18 @@\n      #include \"cache.h\"\n      #include \"config.h\"\n     \n    + diff --git a/builtin/clone.c b/builtin/clone.c\n    + --- a/builtin/clone.c\n    + +++ b/builtin/clone.c\n    +@@\n    +  * Clone a repository into a different directory that does not yet exist.\n    +  */\n    + \n    ++#define USE_THE_INDEX_COMPATIBILITY_MACROS\n    + #include \"builtin.h\"\n    + #include \"config.h\"\n    + #include \"lockfile.h\"\n    +\n      diff --git a/builtin/commit.c b/builtin/commit.c\n      --- a/builtin/commit.c\n      +++ b/builtin/commit.c\n\nNguyễn Thái Ngọc Duy (11):\n  grep: use grep_opt->repo instead of explict repo argument\n  notes-utils.c: remove the_repository references\n  repository.c: replace hold_locked_index() with\n    repo_hold_locked_index()\n  checkout: avoid the_index when possible\n  read-cache.c: kill read_index()\n  read-cache.c: replace update_index_if_able with repo_&\n  sha1-name.c: remove implicit dependency on the_index\n  merge-recursive.c: remove implicit dependency on the_index\n  merge-recursive.c: remove implicit dependency on the_repository\n  read-cache.c: remove the_* from index_has_changes()\n  cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch\n\n apply.c                              |   5 +-\n attr.c                               |   1 -\n blame.c                              |   4 +-\n builtin/add.c                        |   1 +\n builtin/am.c                         |  13 +-\n builtin/blame.c                      |   3 +-\n builtin/cat-file.c                   |   7 +-\n builtin/check-attr.c                 |   1 +\n builtin/check-ignore.c               |   1 +\n builtin/checkout-index.c             |   1 +\n builtin/checkout.c                   |   5 +-\n builtin/clean.c                      |   1 +\n builtin/clone.c                      |   1 +\n builtin/commit.c                     |   7 +-\n builtin/describe.c                   |   3 +-\n builtin/diff-files.c                 |   1 +\n builtin/diff-index.c                 |   1 +\n builtin/diff-tree.c                  |   3 +-\n builtin/diff.c                       |   3 +-\n builtin/difftool.c                   |   1 +\n builtin/fsck.c                       |   1 +\n builtin/grep.c                       |  45 ++++---\n builtin/hash-object.c                |   3 +-\n builtin/log.c                        |   4 +-\n builtin/ls-files.c                   |   1 -\n builtin/merge-index.c                |   1 +\n builtin/merge-ours.c                 |   1 +\n builtin/merge-recursive.c            |   2 +-\n builtin/merge-tree.c                 |   4 +-\n builtin/merge.c                      |   3 +-\n builtin/mv.c                         |   1 +\n builtin/notes.c                      |  21 +--\n builtin/pack-objects.c               |   2 +-\n builtin/pull.c                       |   1 +\n builtin/read-tree.c                  |   1 +\n builtin/rebase--interactive.c        |   1 +\n builtin/rebase.c                     |  14 +-\n builtin/replace.c                    |   2 +-\n builtin/reset.c                      |   1 +\n builtin/rev-parse.c                  |   4 +-\n builtin/rm.c                         |   1 +\n builtin/submodule--helper.c          |   1 +\n builtin/update-index.c               |   1 +\n builtin/write-tree.c                 |   1 +\n cache-tree.h                         |   2 +-\n cache.h                              |  35 ++---\n convert.c                            |   1 -\n dir.c                                |   1 -\n git.c                                |   4 +-\n list-objects-filter-options.c        |   2 +-\n merge-recursive.c                    | 191 +++++++++++++++------------\n merge-recursive.h                    |   6 +-\n merge.c                              |   4 +-\n name-hash.c                          |   1 -\n notes-merge.c                        |   4 +-\n notes-utils.c                        |  17 ++-\n notes-utils.h                        |  11 +-\n pathspec.c                           |   1 -\n preload-index.c                      |  11 +-\n read-cache.c                         |  44 +++---\n repository.c                         |  11 ++\n repository.h                         |  16 +++\n rerere.c                             |   8 +-\n revision.c                           |  12 +-\n sequencer.c                          |  41 +++---\n sequencer.h                          |   3 +-\n sha1-name.c                          |  56 ++++----\n submodule.c                          |   1 -\n t/helper/test-dump-fsmonitor.c       |   4 +-\n t/helper/test-dump-untracked-cache.c |   1 +\n t/helper/test-tool.h                 |   1 +\n tree.c                               |   1 -\n unpack-trees.c                       |   1 -\n wt-status.c                          |   4 +-\n 74 files changed, 385 insertions(+), 290 deletions(-)\n\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366597","messageId":"20190112021332.11066-2-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 01/11] grep: use grep_opt->repo instead of explict repo argument","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:22Z","receivedAt":"2019-01-12T02:14:13Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This command is probably the first one that operates on a repository\nother than the_repository, in f9ee2fcdfa (grep: recurse in-process\nusing 'struct repository' - 2017-08-02). An explicit 'struct\nrepository *' was added in that commit to pass around the repository\nthat we're supposed to grep from.\n\nSince 38bbc2ea39 (grep.c: remove implicit dependency on the_index -\n2018-09-21). 'struct grep_opt *' carries in itself a repository\nparameter for grepping. We should now be able to reuse grep_opt to\nhold the submodule repo instead of a separate argument, which is just\nroom for mistakes.\n\nWhile at there, use the right reference instead of the_repository and\nthe_index in this code. I was a bit careless in my attempt to kick\nthe_repository / the_index out of library code. It's normally safe to\njust stick the_repository / the_index in bultin/ code, but it's not\nthe case for grep.\n\nReviewed-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/grep.c | 41 ++++++++++++++++++++++++-----------------\n 1 file changed, 24 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex bad9c0a3d5..0cc671f7d6 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -393,18 +393,20 @@ static void run_pager(struct grep_opt *opt, const char *prefix)\n \t\texit(status);\n }\n \n-static int grep_cache(struct grep_opt *opt, struct repository *repo,\n+static int grep_cache(struct grep_opt *opt,\n \t\t      const struct pathspec *pathspec, int cached);\n static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\t     struct tree_desc *tree, struct strbuf *base, int tn_len,\n-\t\t     int check_attr, struct repository *repo);\n+\t\t     int check_attr);\n \n-static int grep_submodule(struct grep_opt *opt, struct repository *superproject,\n+static int grep_submodule(struct grep_opt *opt,\n \t\t\t  const struct pathspec *pathspec,\n \t\t\t  const struct object_id *oid,\n \t\t\t  const char *filename, const char *path)\n {\n+\tstruct repository *superproject = opt->repo;\n \tstruct repository submodule;\n+\tstruct grep_opt subopt;\n \tint hit;\n \n \t/*\n@@ -440,6 +442,9 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,\n \tadd_to_alternates_memory(submodule.objects->odb->path);\n \tgrep_read_unlock();\n \n+\tmemcpy(&subopt, opt, sizeof(subopt));\n+\tsubopt.repo = &submodule;\n+\n \tif (oid) {\n \t\tstruct object *object;\n \t\tstruct tree_desc tree;\n@@ -461,21 +466,22 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,\n \t\tstrbuf_addch(&base, '/');\n \n \t\tinit_tree_desc(&tree, data, size);\n-\t\thit = grep_tree(opt, pathspec, &tree, &base, base.len,\n-\t\t\t\tobject->type == OBJ_COMMIT, &submodule);\n+\t\thit = grep_tree(&subopt, pathspec, &tree, &base, base.len,\n+\t\t\t\tobject->type == OBJ_COMMIT);\n \t\tstrbuf_release(&base);\n \t\tfree(data);\n \t} else {\n-\t\thit = grep_cache(opt, &submodule, pathspec, 1);\n+\t\thit = grep_cache(&subopt, pathspec, 1);\n \t}\n \n \trepo_clear(&submodule);\n \treturn hit;\n }\n \n-static int grep_cache(struct grep_opt *opt, struct repository *repo,\n+static int grep_cache(struct grep_opt *opt,\n \t\t      const struct pathspec *pathspec, int cached)\n {\n+\tstruct repository *repo = opt->repo;\n \tint hit = 0;\n \tint nr;\n \tstruct strbuf name = STRBUF_INIT;\n@@ -513,7 +519,7 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,\n \t\t\t}\n \t\t} else if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&\n \t\t\t   submodule_path_match(repo->index, pathspec, name.buf, NULL)) {\n-\t\t\thit |= grep_submodule(opt, repo, pathspec, NULL, ce->name, ce->name);\n+\t\t\thit |= grep_submodule(opt, pathspec, NULL, ce->name, ce->name);\n \t\t} else {\n \t\t\tcontinue;\n \t\t}\n@@ -535,8 +541,9 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,\n \n static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\t     struct tree_desc *tree, struct strbuf *base, int tn_len,\n-\t\t     int check_attr, struct repository *repo)\n+\t\t     int check_attr)\n {\n+\tstruct repository *repo = opt->repo;\n \tint hit = 0;\n \tenum interesting match = entry_not_interesting;\n \tstruct name_entry entry;\n@@ -582,10 +589,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\t\tstrbuf_addch(base, '/');\n \t\t\tinit_tree_desc(&sub, data, size);\n \t\t\thit |= grep_tree(opt, pathspec, &sub, base, tn_len,\n-\t\t\t\t\t check_attr, repo);\n+\t\t\t\t\t check_attr);\n \t\t\tfree(data);\n \t\t} else if (recurse_submodules && S_ISGITLINK(entry.mode)) {\n-\t\t\thit |= grep_submodule(opt, repo, pathspec, entry.oid,\n+\t\t\thit |= grep_submodule(opt, pathspec, entry.oid,\n \t\t\t\t\t      base->buf, base->buf + tn_len);\n \t\t}\n \n@@ -627,7 +634,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\t}\n \t\tinit_tree_desc(&tree, data, size);\n \t\thit = grep_tree(opt, pathspec, &tree, &base, base.len,\n-\t\t\t\tobj->type == OBJ_COMMIT, the_repository);\n+\t\t\t\tobj->type == OBJ_COMMIT);\n \t\tstrbuf_release(&base);\n \t\tfree(data);\n \t\treturn hit;\n@@ -644,12 +651,12 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,\n \n \tfor (i = 0; i < nr; i++) {\n \t\tstruct object *real_obj;\n-\t\treal_obj = deref_tag(the_repository, list->objects[i].item,\n+\t\treal_obj = deref_tag(opt->repo, list->objects[i].item,\n \t\t\t\t     NULL, 0);\n \n \t\t/* load the gitmodules file for this rev */\n \t\tif (recurse_submodules) {\n-\t\t\tsubmodule_free(the_repository);\n+\t\t\tsubmodule_free(opt->repo);\n \t\t\tgitmodules_config_oid(&real_obj->oid);\n \t\t}\n \t\tif (grep_object(opt, pathspec, real_obj, list->objects[i].name,\n@@ -674,9 +681,9 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,\n \tif (exc_std)\n \t\tsetup_standard_excludes(&dir);\n \n-\tfill_directory(&dir, &the_index, pathspec);\n+\tfill_directory(&dir, opt->repo->index, pathspec);\n \tfor (i = 0; i < dir.nr; i++) {\n-\t\tif (!dir_path_match(&the_index, dir.entries[i], pathspec, 0, NULL))\n+\t\tif (!dir_path_match(opt->repo->index, dir.entries[i], pathspec, 0, NULL))\n \t\t\tcontinue;\n \t\thit |= grep_file(opt, dir.entries[i]->name);\n \t\tif (hit && opt->status_only)\n@@ -1117,7 +1124,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\tif (!cached)\n \t\t\tsetup_work_tree();\n \n-\t\thit = grep_cache(&opt, the_repository, &pathspec, cached);\n+\t\thit = grep_cache(&opt, &pathspec, cached);\n \t} else {\n \t\tif (cached)\n \t\t\tdie(_(\"both --cached and trees are given\"));\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366598","messageId":"20190112021332.11066-3-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 02/11] notes-utils.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:23Z","receivedAt":"2019-01-12T02:14:17Z","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 builtin/am.c     |  2 +-\n builtin/commit.c |  2 +-\n builtin/notes.c  | 21 +++++++++++++--------\n notes-merge.c    |  4 ++--\n notes-utils.c    | 17 ++++++++++-------\n notes-utils.h    | 11 ++++++++---\n sequencer.c      |  7 ++++---\n sequencer.h      |  3 ++-\n 8 files changed, 41 insertions(+), 26 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 95370313b6..d32044545d 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -527,7 +527,7 @@ static int copy_notes_for_rebase(const struct am_state *state)\n \t}\n \n finish:\n-\tfinish_copy_notes_for_rewrite(c, msg);\n+\tfinish_copy_notes_for_rewrite(the_repository, c, msg);\n \tfclose(fp);\n \tstrbuf_release(&sb);\n \treturn ret;\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 004b816635..e29fb5e3eb 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1674,7 +1674,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \trun_command_v_opt(argv_gc_auto, RUN_GIT_CMD);\n \trun_commit_hook(use_editor, get_index_file(), \"post-commit\", NULL);\n \tif (amend && !no_post_rewrite) {\n-\t\tcommit_post_rewrite(current_head, &oid);\n+\t\tcommit_post_rewrite(the_repository, current_head, &oid);\n \t}\n \tif (!quiet) {\n \t\tunsigned int flags = 0;\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 4996a670f7..02e97f55c5 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -330,10 +330,10 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)\n \t}\n \n \tif (!rewrite_cmd) {\n-\t\tcommit_notes(t, msg);\n+\t\tcommit_notes(the_repository, t, msg);\n \t\tfree_notes(t);\n \t} else {\n-\t\tfinish_copy_notes_for_rewrite(c, msg);\n+\t\tfinish_copy_notes_for_rewrite(the_repository, c, msg);\n \t}\n \tstrbuf_release(&buf);\n \treturn ret;\n@@ -469,12 +469,14 @@ static int add(int argc, const char **argv, const char *prefix)\n \t\twrite_note_data(&d, &new_note);\n \t\tif (add_note(t, &object, &new_note, combine_notes_overwrite))\n \t\t\tBUG(\"combine_notes_overwrite failed\");\n-\t\tcommit_notes(t, \"Notes added by 'git notes add'\");\n+\t\tcommit_notes(the_repository, t,\n+\t\t\t     \"Notes added by 'git notes add'\");\n \t} else {\n \t\tfprintf(stderr, _(\"Removing note for object %s\\n\"),\n \t\t\toid_to_hex(&object));\n \t\tremove_note(t, object.hash);\n-\t\tcommit_notes(t, \"Notes removed by 'git notes add'\");\n+\t\tcommit_notes(the_repository, t,\n+\t\t\t     \"Notes removed by 'git notes add'\");\n \t}\n \n \tfree_note_data(&d);\n@@ -552,7 +554,8 @@ static int copy(int argc, const char **argv, const char *prefix)\n \n \tif (add_note(t, &object, from_note, combine_notes_overwrite))\n \t\tBUG(\"combine_notes_overwrite failed\");\n-\tcommit_notes(t, \"Notes added by 'git notes copy'\");\n+\tcommit_notes(the_repository, t,\n+\t\t     \"Notes added by 'git notes copy'\");\n out:\n \tfree_notes(t);\n \treturn retval;\n@@ -636,7 +639,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)\n \t\tremove_note(t, object.hash);\n \t\tlogmsg = xstrfmt(\"Notes removed by 'git notes %s'\", argv[0]);\n \t}\n-\tcommit_notes(t, logmsg);\n+\tcommit_notes(the_repository, t, logmsg);\n \n \tfree(logmsg);\n \tfree_note_data(&d);\n@@ -937,7 +940,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)\n \t\tstrbuf_release(&sb);\n \t}\n \tif (!retval)\n-\t\tcommit_notes(t, \"Notes removed by 'git notes remove'\");\n+\t\tcommit_notes(the_repository, t,\n+\t\t\t     \"Notes removed by 'git notes remove'\");\n \tfree_notes(t);\n \treturn retval;\n }\n@@ -965,7 +969,8 @@ static int prune(int argc, const char **argv, const char *prefix)\n \tprune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |\n \t\t(show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );\n \tif (!show_only)\n-\t\tcommit_notes(t, \"Notes removed by 'git notes prune'\");\n+\t\tcommit_notes(the_repository, t,\n+\t\t\t     \"Notes removed by 'git notes prune'\");\n \tfree_notes(t);\n \treturn 0;\n }\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 72688d301b..280aa8e6c1 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -649,7 +649,7 @@ int notes_merge(struct notes_merge_options *o,\n \t\tstruct commit_list *parents = NULL;\n \t\tcommit_list_insert(remote, &parents); /* LIFO order */\n \t\tcommit_list_insert(local, &parents);\n-\t\tcreate_notes_commit(local_tree, parents, o->commit_msg.buf,\n+\t\tcreate_notes_commit(o->repo, local_tree, parents, o->commit_msg.buf,\n \t\t\t\t    o->commit_msg.len, result_oid);\n \t}\n \n@@ -724,7 +724,7 @@ int notes_merge_commit(struct notes_merge_options *o,\n \t\tstrbuf_setlen(&path, baselen);\n \t}\n \n-\tcreate_notes_commit(partial_tree, partial_commit->parents, msg,\n+\tcreate_notes_commit(o->repo, partial_tree, partial_commit->parents, msg,\n \t\t\t    strlen(msg), result_oid);\n \tunuse_commit_buffer(partial_commit, buffer);\n \tif (o->verbosity >= 4)\ndiff --git a/notes-utils.c b/notes-utils.c\nindex 14ea03178e..a819410698 100644\n--- a/notes-utils.c\n+++ b/notes-utils.c\n@@ -5,7 +5,9 @@\n #include \"notes-utils.h\"\n #include \"repository.h\"\n \n-void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n+void create_notes_commit(struct repository *r,\n+\t\t\t struct notes_tree *t,\n+\t\t\t struct commit_list *parents,\n \t\t\t const char *msg, size_t msg_len,\n \t\t\t struct object_id *result_oid)\n {\n@@ -20,8 +22,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n \t\t/* Deduce parent commit from t->ref */\n \t\tstruct object_id parent_oid;\n \t\tif (!read_ref(t->ref, &parent_oid)) {\n-\t\t\tstruct commit *parent = lookup_commit(the_repository,\n-\t\t\t\t\t\t\t      &parent_oid);\n+\t\t\tstruct commit *parent = lookup_commit(r, &parent_oid);\n \t\t\tif (parse_commit(parent))\n \t\t\t\tdie(\"Failed to find/parse commit %s\", t->ref);\n \t\t\tcommit_list_insert(parent, &parents);\n@@ -34,7 +35,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n \t\tdie(\"Failed to commit notes tree to database\");\n }\n \n-void commit_notes(struct notes_tree *t, const char *msg)\n+void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct object_id commit_oid;\n@@ -50,7 +51,7 @@ void commit_notes(struct notes_tree *t, const char *msg)\n \tstrbuf_addstr(&buf, msg);\n \tstrbuf_complete_line(&buf);\n \n-\tcreate_notes_commit(t, NULL, buf.buf, buf.len, &commit_oid);\n+\tcreate_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);\n \tstrbuf_insert(&buf, 0, \"notes: \", 7); /* commit message starts at index 7 */\n \tupdate_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,\n \t\t   UPDATE_REFS_DIE_ON_ERR);\n@@ -171,11 +172,13 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,\n \treturn ret;\n }\n \n-void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg)\n+void finish_copy_notes_for_rewrite(struct repository *r,\n+\t\t\t\t   struct notes_rewrite_cfg *c,\n+\t\t\t\t   const char *msg)\n {\n \tint i;\n \tfor (i = 0; c->trees[i]; i++) {\n-\t\tcommit_notes(c->trees[i], msg);\n+\t\tcommit_notes(r, c->trees[i], msg);\n \t\tfree_notes(c->trees[i]);\n \t}\n \tfree(c->trees);\ndiff --git a/notes-utils.h b/notes-utils.h\nindex 5408306528..d9b3c09eaf 100644\n--- a/notes-utils.h\n+++ b/notes-utils.h\n@@ -5,6 +5,7 @@\n \n struct commit_list;\n struct object_id;\n+struct repository;\n \n /*\n  * Create new notes commit from the given notes tree\n@@ -17,11 +18,13 @@ struct object_id;\n  *\n  * The resulting commit SHA1 is stored in result_sha1.\n  */\n-void create_notes_commit(struct notes_tree *t, struct commit_list *parents,\n+void create_notes_commit(struct repository *r,\n+\t\t\t struct notes_tree *t,\n+\t\t\t struct commit_list *parents,\n \t\t\t const char *msg, size_t msg_len,\n \t\t\t struct object_id *result_oid);\n \n-void commit_notes(struct notes_tree *t, const char *msg);\n+void commit_notes(struct repository *r, struct notes_tree *t, const char *msg);\n \n enum notes_merge_strategy {\n \t\tNOTES_MERGE_RESOLVE_MANUAL = 0,\n@@ -45,6 +48,8 @@ int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);\n struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);\n int copy_note_for_rewrite(struct notes_rewrite_cfg *c,\n \t\t\t  const struct object_id *from_obj, const struct object_id *to_obj);\n-void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg);\n+void finish_copy_notes_for_rewrite(struct repository *r,\n+\t\t\t\t   struct notes_rewrite_cfg *c,\n+\t\t\t\t   const char *msg);\n \n #endif\ndiff --git a/sequencer.c b/sequencer.c\nindex b68bca0bef..1a92a5d678 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1115,7 +1115,8 @@ static int run_rewrite_hook(const struct object_id *oldoid,\n \treturn finish_command(&proc);\n }\n \n-void commit_post_rewrite(const struct commit *old_head,\n+void commit_post_rewrite(struct repository *r,\n+\t\t\t const struct commit *old_head,\n \t\t\t const struct object_id *new_head)\n {\n \tstruct notes_rewrite_cfg *cfg;\n@@ -1124,7 +1125,7 @@ void commit_post_rewrite(const struct commit *old_head,\n \tif (cfg) {\n \t\t/* we are amending, so old_head is not NULL */\n \t\tcopy_note_for_rewrite(cfg, &old_head->object.oid, new_head);\n-\t\tfinish_copy_notes_for_rewrite(cfg, \"Notes added by 'git commit --amend'\");\n+\t\tfinish_copy_notes_for_rewrite(r, cfg, \"Notes added by 'git commit --amend'\");\n \t}\n \trun_rewrite_hook(&old_head->object.oid, new_head);\n }\n@@ -1405,7 +1406,7 @@ static int try_to_commit(struct repository *r,\n \t}\n \n \tif (flags & AMEND_MSG)\n-\t\tcommit_post_rewrite(current_head, oid);\n+\t\tcommit_post_rewrite(r, current_head, oid);\n \n out:\n \tfree_commit_extra_headers(extra);\ndiff --git a/sequencer.h b/sequencer.h\nindex 9d83f0f3e9..2caecd550b 100644\n--- a/sequencer.h\n+++ b/sequencer.h\n@@ -124,7 +124,8 @@ int update_head_with_reflog(const struct commit *old_head,\n \t\t\t    const struct object_id *new_head,\n \t\t\t    const char *action, const struct strbuf *msg,\n \t\t\t    struct strbuf *err);\n-void commit_post_rewrite(const struct commit *current_head,\n+void commit_post_rewrite(struct repository *r,\n+\t\t\t const struct commit *current_head,\n \t\t\t const struct object_id *new_head);\n \n int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366599","messageId":"20190112021332.11066-4-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 03/11] repository.c: replace hold_locked_index() with repo_hold_locked_index()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:24Z","receivedAt":"2019-01-12T02:14:22Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"hold_locked_index() assumes the index path at $GIT_DIR/index. This is\nnot good for places that take an arbitrary index_state instead of\nthe_index, which is basically everywhere except builtin/.\n\nReplace it with repo_hold_locked_index(). hold_locked_index() remains\nas a wrapper around repo_hold_locked_index() to reduce changes in builtin/\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n apply.c           |  3 ++-\n cache.h           |  2 +-\n merge-recursive.c |  2 +-\n merge.c           |  2 +-\n read-cache.c      |  5 -----\n repository.c      | 10 ++++++++++\n repository.h      |  4 ++++\n rerere.c          |  2 +-\n sequencer.c       | 10 +++++-----\n wt-status.c       |  2 +-\n 10 files changed, 26 insertions(+), 16 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 01793d6126..08cde3c4bf 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4712,7 +4712,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) {\ndiff --git a/cache.h b/cache.h\nindex ca36b44ee0..634c9ce325 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -433,6 +433,7 @@ void validate_cache_entries(const struct index_state *istate);\n #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)\n #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)\n #define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))\n+#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))\n #endif\n \n #define TYPE_BITS 3\n@@ -833,7 +834,6 @@ extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cach\n  */\n extern void update_index_if_able(struct index_state *, struct lock_file *);\n \n-extern int hold_locked_index(struct lock_file *, int);\n extern void set_alternate_index_output(const char *);\n \n extern int verify_index_checksum;\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex ecf8db0b71..8dba939d8f 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3643,7 +3643,7 @@ int merge_recursive_generic(struct merge_options *o,\n \t\t}\n \t}\n \n-\thold_locked_index(&lock, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);\n \tclean = merge_recursive(o, head_commit, next_commit, ca,\n \t\t\t\tresult);\n \tif (clean < 0) {\ndiff --git a/merge.c b/merge.c\nindex 91008f7602..dbbc9d9f80 100644\n--- a/merge.c\n+++ b/merge.c\n@@ -58,7 +58,7 @@ int checkout_fast_forward(struct repository *r,\n \n \trefresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);\n \n-\tif (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0)\n+\tif (repo_hold_locked_index(r, &lock_file, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n \n \tmemset(&trees, 0, sizeof(trees));\ndiff --git a/read-cache.c b/read-cache.c\nindex 48c1797a4a..1030e11051 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1733,11 +1733,6 @@ static int read_index_extension(struct index_state *istate,\n \treturn 0;\n }\n \n-int hold_locked_index(struct lock_file *lk, int lock_flags)\n-{\n-\treturn hold_lock_file_for_update(lk, get_index_file(), lock_flags);\n-}\n-\n int read_index(struct index_state *istate)\n {\n \treturn read_index_from(istate, get_index_file(), get_git_dir());\ndiff --git a/repository.c b/repository.c\nindex 7b02e1dffa..9411c4baee 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -3,6 +3,7 @@\n #include \"object-store.h\"\n #include \"config.h\"\n #include \"object.h\"\n+#include \"lockfile.h\"\n #include \"submodule-config.h\"\n \n /* The main repository */\n@@ -263,3 +264,12 @@ int repo_read_index(struct repository *repo)\n \n \treturn read_index_from(repo->index, repo->index_file, repo->gitdir);\n }\n+\n+int repo_hold_locked_index(struct repository *repo,\n+\t\t\t   struct lock_file *lf,\n+\t\t\t   int flags)\n+{\n+\tif (!repo->index_file)\n+\t\tBUG(\"the repo hasn't been setup\");\n+\treturn hold_lock_file_for_update(lf, repo->index_file, flags);\n+}\ndiff --git a/repository.h b/repository.h\nindex 9f16c42c1e..968330218f 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -6,6 +6,7 @@\n struct config_set;\n struct git_hash_algo;\n struct index_state;\n+struct lock_file;\n struct raw_object_store;\n struct submodule_cache;\n \n@@ -130,5 +131,8 @@ void repo_clear(struct repository *repo);\n  * populated then the number of entries will simply be returned.\n  */\n int repo_read_index(struct repository *repo);\n+int repo_hold_locked_index(struct repository *repo,\n+\t\t\t   struct lock_file *lf,\n+\t\t\t   int flags);\n \n #endif /* REPOSITORY_H */\ndiff --git a/rerere.c b/rerere.c\nindex 13624038e6..fb0fdb2392 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -705,7 +705,7 @@ static void update_paths(struct repository *r, struct string_list *update)\n \tstruct lock_file index_lock = LOCK_INIT;\n \tint i;\n \n-\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(r, &index_lock, LOCK_DIE_ON_ERROR);\n \n \tfor (i = 0; i < update->nr; i++) {\n \t\tstruct string_list_item *item = &update->items[i];\ndiff --git a/sequencer.c b/sequencer.c\nindex 1a92a5d678..668c232b05 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -540,7 +540,7 @@ static int do_recursive_merge(struct repository *r,\n \tchar **xopt;\n \tstruct lock_file index_lock = LOCK_INIT;\n \n-\tif (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)\n+\tif (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n \n \tread_index(r->index);\n@@ -1992,8 +1992,8 @@ static int read_and_refresh_cache(struct repository *r,\n \t\t\t\t  struct replay_opts *opts)\n {\n \tstruct lock_file index_lock = LOCK_INIT;\n-\tint index_fd = hold_locked_index(&index_lock, 0);\n-\tif (read_index(r->index) < 0) {\n+\tint index_fd = repo_hold_locked_index(r, &index_lock, 0);\n+\tif (repo_read_index(r) < 0) {\n \t\trollback_lock_file(&index_lock);\n \t\treturn error(_(\"git %s: failed to read the index\"),\n \t\t\t_(action_name(opts)));\n@@ -2978,7 +2978,7 @@ static int do_reset(struct repository *r,\n \tstruct unpack_trees_options unpack_tree_opts;\n \tint ret = 0;\n \n-\tif (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0)\n+\tif (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n \n \tif (len == 10 && !strncmp(\"[new root]\", name, len)) {\n@@ -3096,7 +3096,7 @@ static int do_merge(struct repository *r,\n \tstatic struct lock_file lock;\n \tconst char *p;\n \n-\tif (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {\n+\tif (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) {\n \t\tret = -1;\n \t\tgoto leave_merge;\n \t}\ndiff --git a/wt-status.c b/wt-status.c\nindex 0fe3bcd4cd..becf78b04f 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -2375,7 +2375,7 @@ int require_clean_work_tree(struct repository *r,\n \tstruct lock_file lock_file = LOCK_INIT;\n \tint err = 0, fd;\n \n-\tfd = hold_locked_index(&lock_file, 0);\n+\tfd = repo_hold_locked_index(r, &lock_file, 0);\n \trefresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);\n \tif (0 <= fd)\n \t\tupdate_index_if_able(r->index, &lock_file);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366600","messageId":"20190112021332.11066-5-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 04/11] checkout: avoid the_index when possible","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:25Z","receivedAt":"2019-01-12T02:14:26Z","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 builtin/checkout.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 08b0ac48f3..1b672a9fd9 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -284,7 +284,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t\treturn run_add_interactive(revision, \"--patch=checkout\",\n \t\t\t\t\t   &opts->pathspec);\n \n-\thold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);\n \tif (read_cache_preload(&opts->pathspec) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366601","messageId":"20190112021332.11066-6-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 05/11] read-cache.c: kill read_index()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:26Z","receivedAt":"2019-01-12T02:14:32Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"read_index() shares the same problem as hold_locked_index(): it\nassumes $GIT_DIR/index. Move all call sites to repo_read_index()\ninstead. read_index_preload() and read_index_unmerged() are also\nkilled as a consequence.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n apply.c             |  2 +-\n blame.c             |  4 ++--\n builtin/am.c        |  2 +-\n builtin/commit.c    |  2 +-\n builtin/diff-tree.c |  2 +-\n builtin/rebase.c    |  8 ++++----\n cache.h             | 11 +++--------\n merge-recursive.c   |  2 +-\n merge.c             |  2 +-\n preload-index.c     | 11 ++++++-----\n read-cache.c        | 11 ++++-------\n repository.h        |  6 ++++++\n rerere.c            |  6 +++---\n revision.c          |  4 ++--\n sequencer.c         | 20 ++++++++++----------\n sha1-name.c         |  6 +++---\n 16 files changed, 49 insertions(+), 50 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 08cde3c4bf..e040c0b957 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4019,7 +4019,7 @@ static int read_apply_cache(struct apply_state *state)\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(state->repo->index);\n+\t\treturn repo_read_index(state->repo);\n }\n \n /* This function tries to read the object name from the current index */\ndiff --git a/blame.c b/blame.c\nindex 43861437f7..da57233cbb 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -188,7 +188,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,\n \tunsigned mode;\n \tstruct strbuf msg = STRBUF_INIT;\n \n-\tread_index(r->index);\n+\trepo_read_index(r);\n \ttime(&now);\n \tcommit = alloc_commit_node(r);\n \tcommit->object.parsed = 1;\n@@ -270,7 +270,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,\n \t * want to run \"diff-index --cached\".\n \t */\n \tdiscard_index(r->index);\n-\tread_index(r->index);\n+\trepo_read_index(r);\n \n \tlen = strlen(path);\n \tif (!mode) {\ndiff --git a/builtin/am.c b/builtin/am.c\nindex d32044545d..901dc55078 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2278,7 +2278,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n \t/* Ensure a valid committer ident can be constructed */\n \tgit_committer_info(IDENT_STRICT);\n \n-\tif (read_index_preload(&the_index, NULL, 0) < 0)\n+\tif (repo_read_index_preload(the_repository, NULL, 0) < 0)\n \t\tdie(_(\"failed to read the index\"));\n \n \tif (in_progress) {\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex e29fb5e3eb..19eb6cff86 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1367,7 +1367,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \tif (status_format != STATUS_FORMAT_PORCELAIN &&\n \t    status_format != STATUS_FORMAT_PORCELAIN_V2)\n \t\tprogress_flag = REFRESH_PROGRESS;\n-\tread_index(&the_index);\n+\trepo_read_index(the_repository);\n \trefresh_index(&the_index,\n \t\t      REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,\n \t\t      &s.pathspec, NULL, NULL);\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex ef996126d7..42bc1eb41d 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -165,7 +165,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)\n \n \t\tif (opt->diffopt.detect_rename) {\n \t\t\tif (!the_index.cache)\n-\t\t\t\tread_index(&the_index);\n+\t\t\t\trepo_read_index(the_repository);\n \t\t\topt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;\n \t\t}\n \t\twhile (fgets(line, sizeof(line), stdin)) {\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 00de70365e..ce5f5b5a17 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -576,7 +576,7 @@ static int reset_head(struct object_id *oid, const char *action,\n \tif (!detach_head)\n \t\tunpack_tree_opts.reset = 1;\n \n-\tif (read_index_unmerged(the_repository->index) < 0) {\n+\tif (repo_read_index_unmerged(the_repository) < 0) {\n \t\tret = error(_(\"could not read index\"));\n \t\tgoto leave_reset_head;\n \t}\n@@ -1015,7 +1015,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"Cannot read HEAD\"));\n \n \t\tfd = hold_locked_index(&lock_file, 0);\n-\t\tif (read_index(the_repository->index) < 0)\n+\t\tif (repo_read_index(the_repository) < 0)\n \t\t\tdie(_(\"could not read index\"));\n \t\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,\n \t\t\t      NULL);\n@@ -1368,7 +1368,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\tget_fork_point(options.upstream_name, head);\n \t}\n \n-\tif (read_index(the_repository->index) < 0)\n+\tif (repo_read_index(the_repository) < 0)\n \t\tdie(_(\"could not read index\"));\n \n \tif (options.autostash) {\n@@ -1423,7 +1423,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\tputchar('\\n');\n \n \t\t\tif (discard_index(the_repository->index) < 0 ||\n-\t\t\t\tread_index(the_repository->index) < 0)\n+\t\t\t\trepo_read_index(the_repository) < 0)\n \t\t\t\tdie(_(\"could not read index\"));\n \t\t}\n \t}\ndiff --git a/cache.h b/cache.h\nindex 634c9ce325..3715808f52 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -408,11 +408,11 @@ void validate_cache_entries(const struct index_state *istate);\n #define active_cache_changed (the_index.cache_changed)\n #define active_cache_tree (the_index.cache_tree)\n \n-#define read_cache() read_index(&the_index)\n+#define read_cache() repo_read_index(the_repository)\n #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))\n-#define read_cache_preload(pathspec) read_index_preload(&the_index, (pathspec), 0)\n+#define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)\n #define is_cache_unborn() is_index_unborn(&the_index)\n-#define read_cache_unmerged() read_index_unmerged(&the_index)\n+#define read_cache_unmerged() repo_read_index_unmerged(the_repository)\n #define discard_cache() discard_index(&the_index)\n #define unmerged_cache() unmerged_index(&the_index)\n #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))\n@@ -661,19 +661,14 @@ extern int daemonize(void);\n \n /* Initialize and use the cache information */\n struct lock_file;\n-extern int read_index(struct index_state *);\n extern void preload_index(struct index_state *index,\n \t\t\t  const struct pathspec *pathspec,\n \t\t\t  unsigned int refresh_flags);\n-extern int read_index_preload(struct index_state *,\n-\t\t\t      const struct pathspec *pathspec,\n-\t\t\t      unsigned int refresh_flags);\n extern int do_read_index(struct index_state *istate, const char *path,\n \t\t\t int must_exist); /* for testting only! */\n extern int read_index_from(struct index_state *, const char *path,\n \t\t\t   const char *gitdir);\n extern int is_index_unborn(struct index_state *);\n-extern int read_index_unmerged(struct index_state *);\n \n /* For use with `write_locked_index()`. */\n #define COMMIT_LOCK\t\t(1 << 0)\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 8dba939d8f..5fbd4253c1 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3576,7 +3576,7 @@ int merge_recursive(struct merge_options *o,\n \n \tdiscard_cache();\n \tif (!o->call_depth)\n-\t\tread_cache();\n+\t\trepo_read_index(the_repository);\n \n \to->ancestor = \"merged common ancestors\";\n \tclean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),\ndiff --git a/merge.c b/merge.c\nindex dbbc9d9f80..7c1d756c3f 100644\n--- a/merge.c\n+++ b/merge.c\n@@ -37,7 +37,7 @@ int try_merge_command(struct repository *r,\n \targv_array_clear(&args);\n \n \tdiscard_index(r->index);\n-\tif (read_index(r->index) < 0)\n+\tif (repo_read_index(r) < 0)\n \t\tdie(_(\"failed to read the cache\"));\n \tresolve_undo_clear_index(r->index);\n \ndiff --git a/preload-index.c b/preload-index.c\nindex c7dc3f2b9f..e73600ee78 100644\n--- a/preload-index.c\n+++ b/preload-index.c\n@@ -8,6 +8,7 @@\n #include \"config.h\"\n #include \"progress.h\"\n #include \"thread-utils.h\"\n+#include \"repository.h\"\n \n /*\n  * Mostly randomly chosen maximum thread counts: we\n@@ -146,12 +147,12 @@ void preload_index(struct index_state *index,\n \ttrace_performance_leave(\"preload index\");\n }\n \n-int read_index_preload(struct index_state *index,\n-\t\t       const struct pathspec *pathspec,\n-\t\t       unsigned int refresh_flags)\n+int repo_read_index_preload(struct repository *repo,\n+\t\t\t    const struct pathspec *pathspec,\n+\t\t\t    unsigned int refresh_flags)\n {\n-\tint retval = read_index(index);\n+\tint retval = repo_read_index(repo);\n \n-\tpreload_index(index, pathspec, refresh_flags);\n+\tpreload_index(repo->index, pathspec, refresh_flags);\n \treturn retval;\n }\ndiff --git a/read-cache.c b/read-cache.c\nindex 1030e11051..afbf976107 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1733,11 +1733,6 @@ static int read_index_extension(struct index_state *istate,\n \treturn 0;\n }\n \n-int read_index(struct index_state *istate)\n-{\n-\treturn read_index_from(istate, get_index_file(), get_git_dir());\n-}\n-\n static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,\n \t\t\t\t\t    unsigned int version,\n \t\t\t\t\t    struct ondisk_cache_entry *ondisk,\n@@ -3218,12 +3213,14 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,\n  * state can call this and check its return value, instead of calling\n  * read_cache().\n  */\n-int read_index_unmerged(struct index_state *istate)\n+int repo_read_index_unmerged(struct repository *repo)\n {\n+\tstruct index_state *istate;\n \tint i;\n \tint unmerged = 0;\n \n-\tread_index(istate);\n+\trepo_read_index(repo);\n+\tistate = repo->index;\n \tfor (i = 0; i < istate->cache_nr; i++) {\n \t\tstruct cache_entry *ce = istate->cache[i];\n \t\tstruct cache_entry *new_ce;\ndiff --git a/repository.h b/repository.h\nindex 968330218f..cc3879add4 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -7,6 +7,7 @@ struct config_set;\n struct git_hash_algo;\n struct index_state;\n struct lock_file;\n+struct pathspec;\n struct raw_object_store;\n struct submodule_cache;\n \n@@ -135,4 +136,9 @@ int repo_hold_locked_index(struct repository *repo,\n \t\t\t   struct lock_file *lf,\n \t\t\t   int flags);\n \n+int repo_read_index_preload(struct repository *,\n+\t\t\t    const struct pathspec *pathspec,\n+\t\t\t    unsigned refresh_flags);\n+int repo_read_index_unmerged(struct repository *);\n+\n #endif /* REPOSITORY_H */\ndiff --git a/rerere.c b/rerere.c\nindex fb0fdb2392..17abb47321 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -561,7 +561,7 @@ static int find_conflict(struct repository *r, struct string_list *conflict)\n {\n \tint i;\n \n-\tif (read_index(r->index) < 0)\n+\tif (repo_read_index(r) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n \tfor (i = 0; i < r->index->cache_nr;) {\n@@ -595,7 +595,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr)\n \n \tif (setup_rerere(r, merge_rr, RERERE_READONLY))\n \t\treturn 0;\n-\tif (read_index(r->index) < 0)\n+\tif (repo_read_index(r) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n \tfor (i = 0; i < r->index->cache_nr;) {\n@@ -1107,7 +1107,7 @@ int rerere_forget(struct repository *r, 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_index(r->index) < 0)\n+\tif (repo_read_index(r) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n \tfd = setup_rerere(r, &merge_rr, RERERE_NOAUTOUPDATE);\ndiff --git a/revision.c b/revision.c\nindex 13e0519c02..c51ea6a052 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1384,7 +1384,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)\n {\n \tstruct worktree **worktrees, **p;\n \n-\tread_index(revs->repo->index);\n+\trepo_read_index(revs->repo);\n \tdo_add_index_objects_to_pending(revs, revs->repo->index, flags);\n \n \tif (revs->single_worktree)\n@@ -1530,7 +1530,7 @@ static void prepare_show_merge(struct rev_info *revs)\n \thead->object.flags |= SYMMETRIC_LEFT;\n \n \tif (!istate->cache_nr)\n-\t\tread_index(istate);\n+\t\trepo_read_index(revs->repo);\n \tfor (i = 0; i < istate->cache_nr; i++) {\n \t\tconst struct cache_entry *ce = istate->cache[i];\n \t\tif (!ce_stage(ce))\ndiff --git a/sequencer.c b/sequencer.c\nindex 668c232b05..c2c9cc7e2b 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -446,9 +446,9 @@ static struct tree *empty_tree(struct repository *r)\n \treturn lookup_tree(r, the_hash_algo->empty_tree);\n }\n \n-static int error_dirty_index(struct index_state *istate, struct replay_opts *opts)\n+static int error_dirty_index(struct repository *repo, struct replay_opts *opts)\n {\n-\tif (read_index_unmerged(istate))\n+\tif (repo_read_index_unmerged(repo))\n \t\treturn error_resolve_conflict(_(action_name(opts)));\n \n \terror(_(\"your local changes would be overwritten by %s.\"),\n@@ -483,7 +483,7 @@ static int fast_forward_to(struct repository *r,\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct strbuf err = STRBUF_INIT;\n \n-\tread_index(r->index);\n+\trepo_read_index(r);\n \tif (checkout_fast_forward(r, from, to, 1))\n \t\treturn -1; /* the callee should have complained already */\n \n@@ -543,7 +543,7 @@ static int do_recursive_merge(struct repository *r,\n \tif (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n \n-\tread_index(r->index);\n+\trepo_read_index(r);\n \n \tinit_merge_options(&o);\n \to.ancestor = base ? base_label : \"(empty tree)\";\n@@ -1766,7 +1766,7 @@ static int do_pick_commit(struct repository *r,\n \t\t\toidcpy(&head, the_hash_algo->empty_tree);\n \t\tif (index_differs_from(r, unborn ? empty_tree_oid_hex() : \"HEAD\",\n \t\t\t\t       NULL, 0))\n-\t\t\treturn error_dirty_index(r->index, opts);\n+\t\t\treturn error_dirty_index(r, opts);\n \t}\n \tdiscard_index(r->index);\n \n@@ -2854,7 +2854,7 @@ static int do_exec(struct repository *r, 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_index(r->index) < 0 || read_index(r->index) < 0)\n+\tif (discard_index(r->index) < 0 || repo_read_index(r) < 0)\n \t\treturn error(_(\"could not read index\"));\n \n \tdirty = require_clean_work_tree(r, \"rebase\", NULL, 1, 1);\n@@ -3023,7 +3023,7 @@ static int do_reset(struct repository *r,\n \tunpack_tree_opts.merge = 1;\n \tunpack_tree_opts.update = 1;\n \n-\tif (read_index_unmerged(r->index)) {\n+\tif (repo_read_index_unmerged(r)) {\n \t\trollback_lock_file(&lock);\n \t\tstrbuf_release(&ref_name);\n \t\treturn error_resolve_conflict(_(action_name(opts)));\n@@ -3277,7 +3277,7 @@ static int do_merge(struct repository *r,\n \n \t\t/* force re-reading of the cache */\n \t\tif (!ret && (discard_index(r->index) < 0 ||\n-\t\t\t     read_index(r->index) < 0))\n+\t\t\t     repo_read_index(r) < 0))\n \t\t\tret = error(_(\"could not read index\"));\n \t\tgoto leave_merge;\n \t}\n@@ -3299,7 +3299,7 @@ static int do_merge(struct repository *r,\n \t\tcommit_list_insert(j->item, &reversed);\n \tfree_commit_list(bases);\n \n-\tread_index(r->index);\n+\trepo_read_index(r);\n \tinit_merge_options(&o);\n \to.branch1 = \"HEAD\";\n \to.branch2 = ref_name.buf;\n@@ -3972,7 +3972,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)\n \t\t\t\tgoto release_todo_list;\n \t\t}\n \t\tif (index_differs_from(r, \"HEAD\", NULL, 0)) {\n-\t\t\tres = error_dirty_index(r->index, opts);\n+\t\t\tres = error_dirty_index(r, opts);\n \t\t\tgoto release_todo_list;\n \t\t}\n \t\ttodo_list.current++;\ndiff --git a/sha1-name.c b/sha1-name.c\nindex b24502811b..a0fc1008ec 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1723,9 +1723,9 @@ 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\trepo_read_index(the_repository);\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-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366602","messageId":"20190112021332.11066-7-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 06/11] read-cache.c: replace update_index_if_able with repo_&","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:27Z","receivedAt":"2019-01-12T02:14:36Z","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 builtin/commit.c   |  2 +-\n builtin/describe.c |  2 +-\n builtin/diff.c     |  2 +-\n builtin/rebase.c   |  5 ++---\n cache.h            |  6 ------\n read-cache.c       | 14 ++++++++------\n repository.h       |  6 ++++++\n wt-status.c        |  2 +-\n 8 files changed, 20 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 19eb6cff86..d3f1234bf0 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1396,7 +1396,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \twt_status_collect(&s);\n \n \tif (0 <= fd)\n-\t\tupdate_index_if_able(&the_index, &index_lock);\n+\t\trepo_update_index_if_able(the_repository, &index_lock);\n \n \tif (s.relative_paths)\n \t\ts.prefix = prefix;\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex cc118448ee..bc97e50650 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -634,7 +634,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\t\t      NULL, NULL, NULL);\n \t\t\tfd = hold_locked_index(&index_lock, 0);\n \t\t\tif (0 <= fd)\n-\t\t\t\tupdate_index_if_able(&the_index, &index_lock);\n+\t\t\t\trepo_update_index_if_able(the_repository, &index_lock);\n \n \t\t\trepo_init_revisions(the_repository, &revs, prefix);\n \t\t\targv_array_pushv(&args, diff_index_args);\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex f0393bba23..ec78920ee2 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -212,7 +212,7 @@ static void refresh_index_quietly(void)\n \tdiscard_cache();\n \tread_cache();\n \trefresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);\n-\tupdate_index_if_able(&the_index, &lock_file);\n+\trepo_update_index_if_able(the_repository, &lock_file);\n }\n \n static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv)\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex ce5f5b5a17..7124e66d00 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1020,8 +1020,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\trefresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,\n \t\t\t      NULL);\n \t\tif (0 <= fd)\n-\t\t\tupdate_index_if_able(the_repository->index,\n-\t\t\t\t\t     &lock_file);\n+\t\t\trepo_update_index_if_able(the_repository, &lock_file);\n \t\trollback_lock_file(&lock_file);\n \n \t\tif (has_unstaged_changes(the_repository, 1)) {\n@@ -1378,7 +1377,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\tfd = hold_locked_index(&lock_file, 0);\n \t\trefresh_cache(REFRESH_QUIET);\n \t\tif (0 <= fd)\n-\t\t\tupdate_index_if_able(&the_index, &lock_file);\n+\t\t\trepo_update_index_if_able(the_repository, &lock_file);\n \t\trollback_lock_file(&lock_file);\n \n \t\tif (has_unstaged_changes(the_repository, 1) ||\ndiff --git a/cache.h b/cache.h\nindex 3715808f52..702c5bfbb3 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -823,12 +823,6 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);\n extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);\n extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);\n \n-/*\n- * Opportunistically update the index but do not complain if we can't.\n- * The lockfile is always committed or rolled back.\n- */\n-extern void update_index_if_able(struct index_state *, struct lock_file *);\n-\n extern void set_alternate_index_output(const char *);\n \n extern int verify_index_checksum;\ndiff --git a/read-cache.c b/read-cache.c\nindex afbf976107..61cc0571da 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2654,9 +2654,9 @@ static int verify_index_from(const struct index_state *istate, const char *path)\n \treturn 0;\n }\n \n-static int verify_index(const struct index_state *istate)\n+static int repo_verify_index(struct repository *repo)\n {\n-\treturn verify_index_from(istate, get_index_file());\n+\treturn verify_index_from(repo->index, repo->index_file);\n }\n \n static int has_racy_timestamp(struct index_state *istate)\n@@ -2672,11 +2672,13 @@ static int has_racy_timestamp(struct index_state *istate)\n \treturn 0;\n }\n \n-void update_index_if_able(struct index_state *istate, struct lock_file *lockfile)\n+void repo_update_index_if_able(struct repository *repo,\n+\t\t\t       struct lock_file *lockfile)\n {\n-\tif ((istate->cache_changed || has_racy_timestamp(istate)) &&\n-\t    verify_index(istate))\n-\t\twrite_locked_index(istate, lockfile, COMMIT_LOCK);\n+\tif ((repo->index->cache_changed ||\n+\t     has_racy_timestamp(repo->index)) &&\n+\t    repo_verify_index(repo))\n+\t\twrite_locked_index(repo->index, lockfile, COMMIT_LOCK);\n \telse\n \t\trollback_lock_file(lockfile);\n }\ndiff --git a/repository.h b/repository.h\nindex cc3879add4..6fe1c089db 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -140,5 +140,11 @@ int repo_read_index_preload(struct repository *,\n \t\t\t    const struct pathspec *pathspec,\n \t\t\t    unsigned refresh_flags);\n int repo_read_index_unmerged(struct repository *);\n+/*\n+ * Opportunistically update the index but do not complain if we can't.\n+ * The lockfile is always committed or rolled back.\n+ */\n+void repo_update_index_if_able(struct repository *, struct lock_file *);\n+\n \n #endif /* REPOSITORY_H */\ndiff --git a/wt-status.c b/wt-status.c\nindex becf78b04f..1f564b12d2 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -2378,7 +2378,7 @@ int require_clean_work_tree(struct repository *r,\n \tfd = repo_hold_locked_index(r, &lock_file, 0);\n \trefresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);\n \tif (0 <= fd)\n-\t\tupdate_index_if_able(r->index, &lock_file);\n+\t\trepo_update_index_if_able(r, &lock_file);\n \trollback_lock_file(&lock_file);\n \n \tif (has_unstaged_changes(r, ignore_submodules)) {\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366603","messageId":"20190112021332.11066-8-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 07/11] sha1-name.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:28Z","receivedAt":"2019-01-12T02:14:42Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This kills the_index dependency in get_oid_with_context() but for\nget_oid() and friends, they still assume the_repository (which also\nmeans the_index).\n\nUnfortunately the widespread use of get_oid() will make it hard to\nmake the conversion now. We probably will add repo_get_oid() at some\npoint and limit the use of get_oid() in builtin/ instead of forcing\nall get_oid() call sites to carry struct repository.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/cat-file.c            |  6 ++--\n builtin/grep.c                |  3 +-\n builtin/log.c                 |  3 +-\n builtin/rev-parse.c           |  3 +-\n cache.h                       |  4 ++-\n list-objects-filter-options.c |  2 +-\n revision.c                    |  8 +++---\n sha1-name.c                   | 54 +++++++++++++++++++++--------------\n 8 files changed, 50 insertions(+), 33 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 2ca56fd086..7622c502f0 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -73,7 +73,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \tif (unknown_type)\n \t\tflags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;\n \n-\tif (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,\n+\tif (get_oid_with_context(the_repository, obj_name,\n+\t\t\t\t GET_OID_RECORD_PATH,\n \t\t\t\t &oid, &obj_context))\n \t\tdie(\"Not a valid object name %s\", obj_name);\n \n@@ -382,7 +383,8 @@ static void batch_one_object(const char *obj_name,\n \tint flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;\n \tenum follow_symlinks_result result;\n \n-\tresult = get_oid_with_context(obj_name, flags, &data->oid, &ctx);\n+\tresult = get_oid_with_context(the_repository, obj_name,\n+\t\t\t\t      flags, &data->oid, &ctx);\n \tif (result != FOUND) {\n \t\tswitch (result) {\n \t\tcase MISSING_OBJECT:\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 0cc671f7d6..fc7a9a9283 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -1021,7 +1021,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\tbreak;\n \t\t}\n \n-\t\tif (get_oid_with_context(arg, GET_OID_RECORD_PATH,\n+\t\tif (get_oid_with_context(the_repository, arg,\n+\t\t\t\t\t GET_OID_RECORD_PATH,\n \t\t\t\t\t &oid, &oc)) {\n \t\t\tif (seen_dashdash)\n \t\t\t\tdie(_(\"unable to resolve revision: %s\"), arg);\ndiff --git a/builtin/log.c b/builtin/log.c\nindex e8e51068bd..dbfb4e31ad 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -508,7 +508,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c\n \t    !rev->diffopt.flags.allow_textconv)\n \t\treturn stream_blob_to_fd(1, oid, NULL, 0);\n \n-\tif (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,\n+\tif (get_oid_with_context(the_repository, obj_name,\n+\t\t\t\t GET_OID_RECORD_PATH,\n \t\t\t\t &oidc, &obj_context))\n \t\tdie(_(\"Not a valid object name %s\"), obj_name);\n \tif (!obj_context.path ||\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 10d4dab894..910a71ed8b 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -933,7 +933,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\tname++;\n \t\t\ttype = REVERSED;\n \t\t}\n-\t\tif (!get_oid_with_context(name, flags, &oid, &unused)) {\n+\t\tif (!get_oid_with_context(the_repository, name,\n+\t\t\t\t\t  flags, &oid, &unused)) {\n \t\t\tif (verify)\n \t\t\t\trevs_count++;\n \t\t\telse\ndiff --git a/cache.h b/cache.h\nindex 702c5bfbb3..fdcd69bfb0 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1328,7 +1328,9 @@ extern int get_oid_tree(const char *str, struct object_id *oid);\n extern int get_oid_treeish(const char *str, struct object_id *oid);\n extern int get_oid_blob(const char *str, struct object_id *oid);\n extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);\n-extern int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc);\n+extern int get_oid_with_context(struct repository *repo, const char *str,\n+\t\t\t\tunsigned flags, struct object_id *oid,\n+\t\t\t\tstruct object_context *oc);\n \n \n typedef int each_abbrev_fn(const struct object_id *oid, void *);\ndiff --git a/list-objects-filter-options.c b/list-objects-filter-options.c\nindex e8da2e8581..8443184e22 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -71,7 +71,7 @@ static int gently_parse_list_objects_filter(\n \t\t * command, but DO NOT complain if we don't have the blob or\n \t\t * ref locally.\n \t\t */\n-\t\tif (!get_oid_with_context(v0, GET_OID_BLOB,\n+\t\tif (!get_oid_with_context(the_repository, v0, GET_OID_BLOB,\n \t\t\t\t\t  &sparse_oid, &oc))\n \t\t\tfilter_options->sparse_oid_value = oiddup(&sparse_oid);\n \t\tfilter_options->choice = LOFC_SPARSE_OID;\ndiff --git a/revision.c b/revision.c\nindex c51ea6a052..4a723efe9a 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1589,8 +1589,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,\n \tif (!*b_name)\n \t\tb_name = \"HEAD\";\n \n-\tif (get_oid_with_context(a_name, oc_flags, &a_oid, a_oc) ||\n-\t    get_oid_with_context(b_name, oc_flags, &b_oid, b_oc))\n+\tif (get_oid_with_context(revs->repo, a_name, oc_flags, &a_oid, a_oc) ||\n+\t    get_oid_with_context(revs->repo, b_name, oc_flags, &b_oid, b_oc))\n \t\treturn -1;\n \n \tif (!cant_be_filename) {\n@@ -1724,7 +1724,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi\n \tif (revarg_opt & REVARG_COMMITTISH)\n \t\tget_sha1_flags |= GET_OID_COMMITTISH;\n \n-\tif (get_oid_with_context(arg, get_sha1_flags, &oid, &oc))\n+\tif (get_oid_with_context(revs->repo, arg, get_sha1_flags, &oid, &oc))\n \t\treturn revs->ignore_missing ? 0 : -1;\n \tif (!cant_be_filename)\n \t\tverify_non_filename(revs->prefix, arg);\n@@ -2453,7 +2453,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s\n \t\tstruct object_id oid;\n \t\tstruct object *object;\n \t\tstruct object_context oc;\n-\t\tif (get_oid_with_context(revs->def, 0, &oid, &oc))\n+\t\tif (get_oid_with_context(revs->repo, revs->def, 0, &oid, &oc))\n \t\t\tdiagnose_missing_default(revs->def);\n \t\tobject = get_reference(revs, revs->def, &oid, 0);\n \t\tadd_pending_object_with_mode(revs, object, revs->def, oc.mode);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex a0fc1008ec..d8cab7b5a6 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1513,7 +1513,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)\n int get_oid(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, 0, oid, &unused);\n+\treturn get_oid_with_context(the_repository, name, 0, oid, &unused);\n }\n \n \n@@ -1530,35 +1530,40 @@ int get_oid(const char *name, struct object_id *oid)\n int get_oid_committish(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, GET_OID_COMMITTISH,\n+\treturn get_oid_with_context(the_repository,\n+\t\t\t\t    name, GET_OID_COMMITTISH,\n \t\t\t\t    oid, &unused);\n }\n \n int get_oid_treeish(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, GET_OID_TREEISH,\n+\treturn get_oid_with_context(the_repository,\n+\t\t\t\t    name, GET_OID_TREEISH,\n \t\t\t\t    oid, &unused);\n }\n \n int get_oid_commit(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, GET_OID_COMMIT,\n+\treturn get_oid_with_context(the_repository,\n+\t\t\t\t    name, GET_OID_COMMIT,\n \t\t\t\t    oid, &unused);\n }\n \n int get_oid_tree(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, GET_OID_TREE,\n+\treturn get_oid_with_context(the_repository,\n+\t\t\t\t    name, GET_OID_TREE,\n \t\t\t\t    oid, &unused);\n }\n \n int get_oid_blob(const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(name, GET_OID_BLOB,\n+\treturn get_oid_with_context(the_repository,\n+\t\t\t\t    name, GET_OID_BLOB,\n \t\t\t\t    oid, &unused);\n }\n \n@@ -1597,7 +1602,8 @@ static void diagnose_invalid_oid_path(const char *prefix,\n }\n \n /* Must be called only when :stage:filename doesn't exist. */\n-static void diagnose_invalid_index_path(int stage,\n+static void diagnose_invalid_index_path(struct index_state *istate,\n+\t\t\t\t\tint stage,\n \t\t\t\t\tconst char *prefix,\n \t\t\t\t\tconst char *filename)\n {\n@@ -1610,11 +1616,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(istate, 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 < istate->cache_nr) {\n+\t\tce = istate->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@@ -1626,11 +1632,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(istate, 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 < istate->cache_nr) {\n+\t\tce = istate->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@@ -1664,7 +1670,8 @@ static char *resolve_relative_path(const char *rel)\n \t\t\t   rel);\n }\n \n-static int get_oid_with_context_1(const char *name,\n+static int get_oid_with_context_1(struct repository *repo,\n+\t\t\t\t  const char *name,\n \t\t\t\t  unsigned flags,\n \t\t\t\t  const char *prefix,\n \t\t\t\t  struct object_id *oid,\n@@ -1723,13 +1730,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 (!the_index.cache)\n+\t\tif (!repo->index->cache)\n \t\t\trepo_read_index(the_repository);\n-\t\tpos = index_name_pos(&the_index, cp, namelen);\n+\t\tpos = index_name_pos(repo->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 < repo->index->cache_nr) {\n+\t\t\tce = repo->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@@ -1742,7 +1749,7 @@ static int get_oid_with_context_1(const char *name,\n \t\t\tpos++;\n \t\t}\n \t\tif (only_to_die && name[1] && name[1] != '/')\n-\t\t\tdiagnose_invalid_index_path(stage, prefix, cp);\n+\t\t\tdiagnose_invalid_index_path(repo->index, stage, prefix, cp);\n \t\tfree(new_path);\n \t\treturn -1;\n \t}\n@@ -1807,12 +1814,15 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)\n {\n \tstruct object_context oc;\n \tstruct object_id oid;\n-\tget_oid_with_context_1(name, GET_OID_ONLY_TO_DIE, prefix, &oid, &oc);\n+\tget_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,\n+\t\t\t       prefix, &oid, &oc);\n }\n \n-int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc)\n+int get_oid_with_context(struct repository *repo, const char *str,\n+\t\t\t unsigned flags, struct object_id *oid,\n+\t\t\t struct object_context *oc)\n {\n \tif (flags & GET_OID_FOLLOW_SYMLINKS && flags & GET_OID_ONLY_TO_DIE)\n \t\tBUG(\"incompatible flags for get_sha1_with_context\");\n-\treturn get_oid_with_context_1(str, flags, NULL, oid, oc);\n+\treturn get_oid_with_context_1(repo, str, flags, NULL, oid, oc);\n }\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366604","messageId":"20190112021332.11066-9-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 08/11] merge-recursive.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:29Z","receivedAt":"2019-01-12T02:14:47Z","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 builtin/am.c              |   2 +-\n builtin/checkout.c        |   2 +-\n builtin/merge-recursive.c |   2 +-\n builtin/merge.c           |   2 +-\n merge-recursive.c         | 148 ++++++++++++++++++++------------------\n merge-recursive.h         |   6 +-\n sequencer.c               |   4 +-\n 7 files changed, 91 insertions(+), 75 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 901dc55078..611712dc95 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1545,7 +1545,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \t * changes.\n \t */\n \n-\tinit_merge_options(&o);\n+\tinit_merge_options(&o, the_repository);\n \n \to.branch1 = \"HEAD\";\n \ttheir_tree_name = xstrfmt(\"%.*s\", linelen(state->msg), state->msg);\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 1b672a9fd9..a95ba2c6dc 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -670,7 +670,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \t\t\t * a pain; plumb in an option to set\n \t\t\t * o.renormalize?\n \t\t\t */\n-\t\t\tinit_merge_options(&o);\n+\t\t\tinit_merge_options(&o, the_repository);\n \t\t\to.verbosity = 0;\n \t\t\twork = write_tree_from_memory(&o);\n \ndiff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c\nindex 9b2f707c29..4864f7b22f 100644\n--- a/builtin/merge-recursive.c\n+++ b/builtin/merge-recursive.c\n@@ -28,7 +28,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)\n \tstruct merge_options o;\n \tstruct commit *result;\n \n-\tinit_merge_options(&o);\n+\tinit_merge_options(&o, the_repository);\n \tif (argv[0] && ends_with(argv[0], \"-subtree\"))\n \t\to.subtree_shift = \"\";\n \ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex dc0b7cc521..bc1aecfe70 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -702,7 +702,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,\n \t\t\treturn 2;\n \t\t}\n \n-\t\tinit_merge_options(&o);\n+\t\tinit_merge_options(&o, the_repository);\n \t\tif (!strcmp(strategy, \"subtree\"))\n \t\t\to.subtree_shift = \"\";\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 5fbd4253c1..28f44c73ec 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -343,22 +343,24 @@ static int add_cacheinfo(struct merge_options *o,\n \t\t\t unsigned int mode, const struct object_id *oid,\n \t\t\t const char *path, int stage, int refresh, int options)\n {\n+\tstruct index_state *istate = o->repo->index;\n \tstruct cache_entry *ce;\n \tint ret;\n \n-\tce = make_cache_entry(&the_index, mode, oid ? oid : &null_oid, path, stage, 0);\n+\tce = make_cache_entry(istate, mode, oid ? oid : &null_oid, path, stage, 0);\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(istate, ce, options);\n \tif (refresh) {\n \t\tstruct cache_entry *nce;\n \n-\t\tnce = refresh_cache_entry(&the_index, ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);\n+\t\tnce = refresh_cache_entry(istate, ce,\n+\t\t\t\t\t  CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);\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(istate, nce, options);\n \t}\n \treturn ret;\n }\n@@ -386,7 +388,7 @@ static int unpack_trees_start(struct merge_options *o,\n \to->unpack_opts.merge = 1;\n \to->unpack_opts.head_idx = 2;\n \to->unpack_opts.fn = threeway_merge;\n-\to->unpack_opts.src_index = &the_index;\n+\to->unpack_opts.src_index = o->repo->index;\n \to->unpack_opts.dst_index = &tmp_index;\n \to->unpack_opts.aggressive = !merge_detect_rename(o);\n \tsetup_unpack_trees_porcelain(&o->unpack_opts, \"merge\");\n@@ -396,16 +398,16 @@ 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(&o->repo->index->cache_tree);\n \n \t/*\n-\t * Update the_index to match the new results, AFTER saving a copy\n+\t * Update o->repo->index to match the new results, AFTER saving a copy\n \t * in o->orig_index.  Update src_index to point to the saved copy.\n \t * (verify_uptodate() checks src_index, and the original index is\n \t * the one that had the necessary modification timestamps.)\n \t */\n-\to->orig_index = the_index;\n-\tthe_index = tmp_index;\n+\to->orig_index = *o->repo->index;\n+\t*o->repo->index = tmp_index;\n \to->unpack_opts.src_index = &o->orig_index;\n \n \treturn rc;\n@@ -420,12 +422,13 @@ static void unpack_trees_finish(struct merge_options *o)\n struct tree *write_tree_from_memory(struct merge_options *o)\n {\n \tstruct tree *result = NULL;\n+\tstruct index_state *istate = o->repo->index;\n \n-\tif (unmerged_cache()) {\n+\tif (unmerged_index(istate)) {\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 < istate->cache_nr; i++) {\n+\t\t\tconst struct cache_entry *ce = istate->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@@ -433,16 +436,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 (!istate->cache_tree)\n+\t\tistate->cache_tree = cache_tree();\n \n-\tif (!cache_tree_fully_valid(active_cache_tree) &&\n-\t    cache_tree_update(&the_index, 0) < 0) {\n+\tif (!cache_tree_fully_valid(istate->cache_tree) &&\n+\t    cache_tree_update(istate, 0) < 0) {\n \t\terr(o, _(\"error building trees\"));\n \t\treturn NULL;\n \t}\n \n-\tresult = lookup_tree(the_repository, &active_cache_tree->oid);\n+\tresult = lookup_tree(the_repository, &istate->cache_tree->oid);\n \n \treturn result;\n }\n@@ -512,17 +515,17 @@ static struct stage_data *insert_stage_data(const char *path,\n  * Create a dictionary mapping file names to stage_data objects. The\n  * dictionary contains one entry for every path with a non-zero stage entry.\n  */\n-static struct string_list *get_unmerged(void)\n+static struct string_list *get_unmerged(struct index_state *istate)\n {\n \tstruct string_list *unmerged = xcalloc(1, sizeof(struct string_list));\n \tint i;\n \n \tunmerged->strdup_strings = 1;\n \n-\tfor (i = 0; i < active_nr; i++) {\n+\tfor (i = 0; i < istate->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 = istate->cache[i];\n \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \n@@ -682,7 +685,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(opt->repo->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@@ -717,13 +720,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(o->repo->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(o->repo->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@@ -773,7 +777,8 @@ static char *unique_path(struct merge_options *o, const char *path, const char *\n  * check the working directory.  If empty_ok is non-zero, also return\n  * 0 in the case where the working-tree dir exists but is empty.\n  */\n-static int dir_in_way(const char *path, int check_working_copy, int empty_ok)\n+static int dir_in_way(struct index_state *istate, const char *path,\n+\t\t      int check_working_copy, int empty_ok)\n {\n \tint pos;\n \tstruct strbuf dirpath = STRBUF_INIT;\n@@ -782,12 +787,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(istate, 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 < istate->cache_nr &&\n+\t    !strncmp(dirpath.buf, istate->cache[pos]->name, dirpath.len)) {\n \t\tstrbuf_release(&dirpath);\n \t\treturn 1;\n \t}\n@@ -830,8 +835,10 @@ static int was_tracked(struct merge_options *o, const char *path)\n \treturn 0;\n }\n \n-static int would_lose_untracked(const char *path)\n+static int would_lose_untracked(struct merge_options *o, const char *path)\n {\n+\tstruct index_state *istate = o->repo->index;\n+\n \t/*\n \t * This may look like it can be simplified to:\n \t *   return !was_tracked(o, path) && file_exists(path)\n@@ -849,19 +856,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(istate, 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 < istate->cache_nr &&\n+\t       !strcmp(path, istate->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(istate->cache[pos])) {\n \t\tcase 0:\n \t\tcase 2:\n \t\t\treturn 0;\n@@ -921,7 +928,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)\n \t * Do not unlink a file in the work tree if we are not\n \t * tracking it.\n \t */\n-\tif (would_lose_untracked(path))\n+\tif (would_lose_untracked(o, path))\n \t\treturn err(o, _(\"refusing to lose untracked file at '%s'\"),\n \t\t\t   path);\n \n@@ -971,7 +978,7 @@ static int update_file_flags(struct merge_options *o,\n \t\t}\n \t\tif (S_ISREG(mode)) {\n \t\t\tstruct strbuf strbuf = STRBUF_INIT;\n-\t\t\tif (convert_to_working_tree(&the_index, path, buf, size, &strbuf)) {\n+\t\t\tif (convert_to_working_tree(o->repo->index, path, buf, size, &strbuf)) {\n \t\t\t\tfree(buf);\n \t\t\t\tsize = strbuf.len;\n \t\t\t\tbuf = strbuf_detach(&strbuf, NULL);\n@@ -1091,7 +1098,7 @@ static int merge_3way(struct merge_options *o,\n \n \tmerge_status = ll_merge(result_buf, a->path, &orig, base_name,\n \t\t\t\t&src1, name1, &src2, name2,\n-\t\t\t\t&the_index, &ll_opts);\n+\t\t\t\to->repo->index, &ll_opts);\n \n \tfree(base_name);\n \tfree(name1);\n@@ -1102,7 +1109,8 @@ static int merge_3way(struct merge_options *o,\n \treturn merge_status;\n }\n \n-static int find_first_merges(struct object_array *result, const char *path,\n+static int find_first_merges(struct repository *repo,\n+\t\t\t     struct object_array *result, const char *path,\n \t\t\t     struct commit *a, struct commit *b)\n {\n \tint i, j;\n@@ -1122,7 +1130,7 @@ static int find_first_merges(struct object_array *result, const char *path,\n \t/* get all revisions that merge commit a */\n \txsnprintf(merged_revision, sizeof(merged_revision), \"^%s\",\n \t\t  oid_to_hex(&a->object.oid));\n-\trepo_init_revisions(the_repository, &revs, NULL);\n+\trepo_init_revisions(repo, &revs, NULL);\n \trev_opts.submodule = path;\n \t/* FIXME: can't handle linked worktrees in submodules yet */\n \trevs.single_worktree = path != NULL;\n@@ -1252,7 +1260,8 @@ static int merge_submodule(struct merge_options *o,\n \t\treturn 0;\n \n \t/* find commit which merges them */\n-\tparent_count = find_first_merges(&merges, path, commit_a, commit_b);\n+\tparent_count = find_first_merges(o->repo, &merges, path,\n+\t\t\t\t\t commit_a, commit_b);\n \tswitch (parent_count) {\n \tcase 0:\n \t\toutput(o, 1, _(\"Failed to merge submodule %s (merge following commits not found)\"), path);\n@@ -1400,7 +1409,7 @@ static int handle_rename_via_dir(struct merge_options *o,\n \t */\n \tconst struct diff_filespec *dest = pair->two;\n \n-\tif (!o->call_depth && would_lose_untracked(dest->path)) {\n+\tif (!o->call_depth && would_lose_untracked(o, dest->path)) {\n \t\tchar *alt_path = unique_path(o, dest->path, rename_branch);\n \n \t\toutput(o, 1, _(\"Error: Refusing to lose untracked file at %s; \"\n@@ -1438,8 +1447,8 @@ static int handle_change_delete(struct merge_options *o,\n \tconst char *update_path = path;\n \tint ret = 0;\n \n-\tif (dir_in_way(path, !o->call_depth, 0) ||\n-\t    (!o->call_depth && would_lose_untracked(path))) {\n+\tif (dir_in_way(o->repo->index, path, !o->call_depth, 0) ||\n+\t    (!o->call_depth && would_lose_untracked(o, path))) {\n \t\tupdate_path = alt_path = unique_path(o, path, change_branch);\n \t}\n \n@@ -1449,7 +1458,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(o->repo->index, path);\n \t\tif (!ret)\n \t\t\tret = update_file(o, 0, o_oid, o_mode, update_path);\n \t} else {\n@@ -1525,7 +1534,7 @@ static int handle_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(o->repo->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@@ -1606,10 +1615,10 @@ static int handle_file_collision(struct merge_options *o,\n \t/* Remove rename sources if rename/add or rename/rename(2to1) */\n \tif (prev_path1)\n \t\tremove_file(o, 1, prev_path1,\n-\t\t\t    o->call_depth || would_lose_untracked(prev_path1));\n+\t\t\t    o->call_depth || would_lose_untracked(o, prev_path1));\n \tif (prev_path2)\n \t\tremove_file(o, 1, prev_path2,\n-\t\t\t    o->call_depth || would_lose_untracked(prev_path2));\n+\t\t\t    o->call_depth || would_lose_untracked(o, prev_path2));\n \n \t/*\n \t * Remove the collision path, if it wouldn't cause dirty contents\n@@ -1620,7 +1629,7 @@ static int handle_file_collision(struct merge_options *o,\n \t\toutput(o, 1, _(\"Refusing to lose dirty file at %s\"),\n \t\t       collide_path);\n \t\tupdate_path = alt_path = unique_path(o, collide_path, \"merged\");\n-\t} else if (would_lose_untracked(collide_path)) {\n+\t} else if (would_lose_untracked(o, collide_path)) {\n \t\t/*\n \t\t * Only way we get here is if both renames were from\n \t\t * a directory rename AND user had an untracked file\n@@ -1716,12 +1725,12 @@ static char *find_path_for_conflict(struct merge_options *o,\n \t\t\t\t    const char *branch2)\n {\n \tchar *new_path = NULL;\n-\tif (dir_in_way(path, !o->call_depth, 0)) {\n+\tif (dir_in_way(o->repo->index, path, !o->call_depth, 0)) {\n \t\tnew_path = unique_path(o, path, branch1);\n \t\toutput(o, 1, _(\"%s is a directory in %s adding \"\n \t\t\t       \"as %s instead\"),\n \t\t       path, branch2, new_path);\n-\t} else if (would_lose_untracked(path)) {\n+\t} else if (would_lose_untracked(o, path)) {\n \t\tnew_path = unique_path(o, path, branch1);\n \t\toutput(o, 1, _(\"Refusing to lose untracked file\"\n \t\t\t       \" at %s; adding as %s instead\"),\n@@ -1782,14 +1791,14 @@ static int handle_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(o->repo->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(o->repo->index, b->path);\n \t} else {\n \t\t/*\n \t\t * For each destination path, we need to see if there is a\n@@ -1886,7 +1895,7 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *o,\n \tstruct diff_queue_struct *ret;\n \tstruct diff_options opts;\n \n-\trepo_diff_setup(the_repository, &opts);\n+\trepo_diff_setup(o->repo, &opts);\n \topts.flags.recursive = 1;\n \topts.flags.rename_empty = 0;\n \topts.detect_rename = merge_detect_rename(o);\n@@ -3041,8 +3050,8 @@ static int blob_unchanged(struct merge_options *opt,\n \t * performed.  Comparison can be skipped if both files are\n \t * unchanged since their sha1s have already been compared.\n \t */\n-\tif (renormalize_buffer(&the_index, path, o.buf, o.len, &o) |\n-\t    renormalize_buffer(&the_index, path, a.buf, a.len, &a))\n+\tif (renormalize_buffer(opt->repo->index, path, o.buf, o.len, &o) |\n+\t    renormalize_buffer(opt->repo->index, path, a.buf, a.len, &a))\n \t\tret = (o.len == a.len && !memcmp(o.buf, a.buf, o.len));\n \n error_return:\n@@ -3123,7 +3132,7 @@ static int handle_content_merge(struct merge_options *o,\n \t\ta.path = (char *)path1;\n \t\tb.path = (char *)path2;\n \n-\t\tif (dir_in_way(path, !o->call_depth,\n+\t\tif (dir_in_way(o->repo->index, path, !o->call_depth,\n \t\t\t       S_ISGITLINK(pair1->two->mode)))\n \t\t\tdf_conflict_remains = 1;\n \t}\n@@ -3157,8 +3166,8 @@ static int handle_content_merge(struct merge_options *o,\n \t\tpos = index_name_pos(&o->orig_index, path, strlen(path));\n \t\tce = o->orig_index.cache[pos];\n \t\tif (ce_skip_worktree(ce)) {\n-\t\t\tpos = index_name_pos(&the_index, path, strlen(path));\n-\t\t\tce = the_index.cache[pos];\n+\t\t\tpos = index_name_pos(o->repo->index, path, strlen(path));\n+\t\t\tce = o->repo->index->cache[pos];\n \t\t\tce->ce_flags |= CE_SKIP_WORKTREE;\n \t\t}\n \t\treturn mfi.clean;\n@@ -3177,7 +3186,7 @@ static int handle_content_merge(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(o->repo->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@@ -3337,7 +3346,7 @@ static int process_entry(struct merge_options *o,\n \t\t\toid = b_oid;\n \t\t\tconf = _(\"directory/file\");\n \t\t}\n-\t\tif (dir_in_way(path,\n+\t\tif (dir_in_way(o->repo->index, path,\n \t\t\t       !o->call_depth && !S_ISGITLINK(a_mode),\n \t\t\t       0)) {\n \t\t\tchar *new_path = unique_path(o, path, add_branch);\n@@ -3348,7 +3357,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(o->repo->index, path);\n \t\t\tfree(new_path);\n \t\t} else {\n \t\t\toutput(o, 2, _(\"Adding %s\"), path);\n@@ -3396,10 +3405,11 @@ int merge_trees(struct merge_options *o,\n \t\tstruct tree *common,\n \t\tstruct tree **result)\n {\n+\tstruct index_state *istate = o->repo->index;\n \tint code, clean;\n \tstruct strbuf sb = STRBUF_INIT;\n \n-\tif (!o->call_depth && index_has_changes(&the_index, head, &sb)) {\n+\tif (!o->call_depth && index_has_changes(istate, head, &sb)) {\n \t\terr(o, _(\"Your local changes to the following files would be overwritten by merge:\\n  %s\"),\n \t\t    sb.buf);\n \t\treturn -1;\n@@ -3427,7 +3437,7 @@ int merge_trees(struct merge_options *o,\n \t\treturn -1;\n \t}\n \n-\tif (unmerged_cache()) {\n+\tif (unmerged_index(istate)) {\n \t\tstruct string_list *entries;\n \t\tstruct rename_info re_info;\n \t\tint i;\n@@ -3442,7 +3452,7 @@ int merge_trees(struct merge_options *o,\n \t\tget_files_dirs(o, head);\n \t\tget_files_dirs(o, merge);\n \n-\t\tentries = get_unmerged();\n+\t\tentries = get_unmerged(o->repo->index);\n \t\tclean = detect_and_process_renames(o, common, head, merge,\n \t\t\t\t\t\t   entries, &re_info);\n \t\trecord_df_conflict_files(o, entries);\n@@ -3558,7 +3568,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(o->repo->index);\n \t\tsaved_b1 = o->branch1;\n \t\tsaved_b2 = o->branch2;\n \t\to->branch1 = \"Temporary merge branch 1\";\n@@ -3574,9 +3584,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(o->repo->index);\n \tif (!o->call_depth)\n-\t\trepo_read_index(the_repository);\n+\t\trepo_read_index(o->repo);\n \n \to->ancestor = \"merged common ancestors\";\n \tclean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),\n@@ -3643,7 +3653,7 @@ int merge_recursive_generic(struct merge_options *o,\n \t\t}\n \t}\n \n-\trepo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);\n+\trepo_hold_locked_index(o->repo, &lock, LOCK_DIE_ON_ERROR);\n \tclean = merge_recursive(o, head_commit, next_commit, ca,\n \t\t\t\tresult);\n \tif (clean < 0) {\n@@ -3651,7 +3661,7 @@ int merge_recursive_generic(struct merge_options *o,\n \t\treturn clean;\n \t}\n \n-\tif (write_locked_index(&the_index, &lock,\n+\tif (write_locked_index(o->repo->index, &lock,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\treturn err(o, _(\"Unable to write index.\"));\n \n@@ -3675,10 +3685,12 @@ static void merge_recursive_config(struct merge_options *o)\n \tgit_config(git_xmerge_config, NULL);\n }\n \n-void init_merge_options(struct merge_options *o)\n+void init_merge_options(struct merge_options *o,\n+\t\t\tstruct repository *repo)\n {\n \tconst char *merge_verbosity;\n \tmemset(o, 0, sizeof(struct merge_options));\n+\to->repo = repo;\n \to->verbosity = 2;\n \to->buffer_output = 1;\n \to->diff_rename_limit = -1;\ndiff --git a/merge-recursive.h b/merge-recursive.h\nindex e6a0828eca..c2b7bb65c6 100644\n--- a/merge-recursive.h\n+++ b/merge-recursive.h\n@@ -6,6 +6,8 @@\n \n struct commit;\n \n+struct repository;\n+\n struct merge_options {\n \tconst char *ancestor;\n \tconst char *branch1;\n@@ -34,6 +36,7 @@ struct merge_options {\n \tstruct string_list df_conflict_file_set;\n \tstruct unpack_trees_options unpack_opts;\n \tstruct index_state orig_index;\n+\tstruct repository *repo;\n };\n \n /*\n@@ -92,7 +95,8 @@ int merge_recursive_generic(struct merge_options *o,\n \t\t\t    const struct object_id **ca,\n \t\t\t    struct commit **result);\n \n-void init_merge_options(struct merge_options *o);\n+void init_merge_options(struct merge_options *o,\n+\t\t\tstruct repository *repo);\n struct tree *write_tree_from_memory(struct merge_options *o);\n \n int parse_merge_opt(struct merge_options *out, const char *s);\ndiff --git a/sequencer.c b/sequencer.c\nindex c2c9cc7e2b..cede6ea095 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -545,7 +545,7 @@ static int do_recursive_merge(struct repository *r,\n \n \trepo_read_index(r);\n \n-\tinit_merge_options(&o);\n+\tinit_merge_options(&o, r);\n \to.ancestor = base ? base_label : \"(empty tree)\";\n \to.branch1 = \"HEAD\";\n \to.branch2 = next ? next_label : \"(empty tree)\";\n@@ -3300,7 +3300,7 @@ static int do_merge(struct repository *r,\n \tfree_commit_list(bases);\n \n \trepo_read_index(r);\n-\tinit_merge_options(&o);\n+\tinit_merge_options(&o, r);\n \to.branch1 = \"HEAD\";\n \to.branch2 = ref_name.buf;\n \to.buffer_output = 2;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366605","messageId":"20190112021332.11066-10-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 09/11] merge-recursive.c: remove implicit dependency on the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:30Z","receivedAt":"2019-01-12T02:14: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 merge-recursive.c | 45 ++++++++++++++++++++++++---------------------\n 1 file changed, 24 insertions(+), 21 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 28f44c73ec..a596d95739 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -146,7 +146,8 @@ static int err(struct merge_options *o, const char *err, ...)\n \treturn -1;\n }\n \n-static struct tree *shift_tree_object(struct tree *one, struct tree *two,\n+static struct tree *shift_tree_object(struct repository *repo,\n+\t\t\t\t      struct tree *one, struct tree *two,\n \t\t\t\t      const char *subtree_shift)\n {\n \tstruct object_id shifted;\n@@ -159,12 +160,14 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,\n \t}\n \tif (oideq(&two->object.oid, &shifted))\n \t\treturn two;\n-\treturn lookup_tree(the_repository, &shifted);\n+\treturn lookup_tree(repo, &shifted);\n }\n \n-static struct commit *make_virtual_commit(struct tree *tree, const char *comment)\n+static struct commit *make_virtual_commit(struct repository *repo,\n+\t\t\t\t\t  struct tree *tree,\n+\t\t\t\t\t  const char *comment)\n {\n-\tstruct commit *commit = alloc_commit_node(the_repository);\n+\tstruct commit *commit = alloc_commit_node(repo);\n \n \tset_merge_remote_desc(commit, comment, (struct object *)commit);\n \tcommit->maybe_tree = tree;\n@@ -445,7 +448,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)\n \t\treturn NULL;\n \t}\n \n-\tresult = lookup_tree(the_repository, &istate->cache_tree->oid);\n+\tresult = lookup_tree(o->repo, &istate->cache_tree->oid);\n \n \treturn result;\n }\n@@ -1208,9 +1211,9 @@ static int merge_submodule(struct merge_options *o,\n \t\treturn 0;\n \t}\n \n-\tif (!(commit_base = lookup_commit_reference(the_repository, base)) ||\n-\t    !(commit_a = lookup_commit_reference(the_repository, a)) ||\n-\t    !(commit_b = lookup_commit_reference(the_repository, b))) {\n+\tif (!(commit_base = lookup_commit_reference(o->repo, base)) ||\n+\t    !(commit_a = lookup_commit_reference(o->repo, a)) ||\n+\t    !(commit_b = lookup_commit_reference(o->repo, b))) {\n \t\toutput(o, 1, _(\"Failed to merge submodule %s (commits not present)\"), path);\n \t\treturn 0;\n \t}\n@@ -3416,8 +3419,8 @@ int merge_trees(struct merge_options *o,\n \t}\n \n \tif (o->subtree_shift) {\n-\t\tmerge = shift_tree_object(head, merge, o->subtree_shift);\n-\t\tcommon = shift_tree_object(head, common, o->subtree_shift);\n+\t\tmerge = shift_tree_object(o->repo, head, merge, o->subtree_shift);\n+\t\tcommon = shift_tree_object(o->repo, head, common, o->subtree_shift);\n \t}\n \n \tif (oid_eq(&common->object.oid, &merge->object.oid)) {\n@@ -3553,8 +3556,8 @@ int merge_recursive(struct merge_options *o,\n \t\t/* if there is no common ancestor, use an empty tree */\n \t\tstruct tree *tree;\n \n-\t\ttree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree);\n-\t\tmerged_common_ancestors = make_virtual_commit(tree, \"ancestor\");\n+\t\ttree = lookup_tree(o->repo, o->repo->hash_algo->empty_tree);\n+\t\tmerged_common_ancestors = make_virtual_commit(o->repo, tree, \"ancestor\");\n \t}\n \n \tfor (iter = ca; iter; iter = iter->next) {\n@@ -3598,7 +3601,7 @@ int merge_recursive(struct merge_options *o,\n \t}\n \n \tif (o->call_depth) {\n-\t\t*result = make_virtual_commit(mrtree, \"merged tree\");\n+\t\t*result = make_virtual_commit(o->repo, mrtree, \"merged tree\");\n \t\tcommit_list_insert(h1, &(*result)->parents);\n \t\tcommit_list_insert(h2, &(*result)->parents->next);\n \t}\n@@ -3611,17 +3614,17 @@ int merge_recursive(struct merge_options *o,\n \treturn clean;\n }\n \n-static struct commit *get_ref(const struct object_id *oid, const char *name)\n+static struct commit *get_ref(struct repository *repo, const struct object_id *oid,\n+\t\t\t      const char *name)\n {\n \tstruct object *object;\n \n-\tobject = deref_tag(the_repository, parse_object(the_repository, oid),\n-\t\t\t   name,\n-\t\t\t   strlen(name));\n+\tobject = deref_tag(repo, parse_object(repo, oid),\n+\t\t\t   name, strlen(name));\n \tif (!object)\n \t\treturn NULL;\n \tif (object->type == OBJ_TREE)\n-\t\treturn make_virtual_commit((struct tree*)object, name);\n+\t\treturn make_virtual_commit(repo, (struct tree*)object, name);\n \tif (object->type != OBJ_COMMIT)\n \t\treturn NULL;\n \tif (parse_commit((struct commit *)object))\n@@ -3638,15 +3641,15 @@ int merge_recursive_generic(struct merge_options *o,\n {\n \tint clean;\n \tstruct lock_file lock = LOCK_INIT;\n-\tstruct commit *head_commit = get_ref(head, o->branch1);\n-\tstruct commit *next_commit = get_ref(merge, o->branch2);\n+\tstruct commit *head_commit = get_ref(o->repo, head, o->branch1);\n+\tstruct commit *next_commit = get_ref(o->repo, merge, o->branch2);\n \tstruct commit_list *ca = NULL;\n \n \tif (base_list) {\n \t\tint i;\n \t\tfor (i = 0; i < num_base_list; ++i) {\n \t\t\tstruct commit *base;\n-\t\t\tif (!(base = get_ref(base_list[i], oid_to_hex(base_list[i]))))\n+\t\t\tif (!(base = get_ref(o->repo, base_list[i], oid_to_hex(base_list[i]))))\n \t\t\t\treturn err(o, _(\"Could not parse object '%s'\"),\n \t\t\t\t\t   oid_to_hex(base_list[i]));\n \t\t\tcommit_list_insert(base, &ca);\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366606","messageId":"20190112021332.11066-11-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 10/11] read-cache.c: remove the_* from index_has_changes()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:31Z","receivedAt":"2019-01-12T02:14:56Z","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 builtin/am.c      |  6 +++---\n cache.h           |  6 +++---\n merge-recursive.c |  2 +-\n read-cache.c      | 12 +++++-------\n 4 files changed, 12 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 611712dc95..a9ffc92eaa 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1719,7 +1719,7 @@ static void am_run(struct am_state *state, int resume)\n \n \trefresh_and_write_cache();\n \n-\tif (index_has_changes(&the_index, NULL, &sb)) {\n+\tif (repo_index_has_changes(the_repository, NULL, &sb)) {\n \t\twrite_state_bool(state, \"dirtyindex\", 1);\n \t\tdie(_(\"Dirty index: cannot apply patches (dirty: %s)\"), sb.buf);\n \t}\n@@ -1777,7 +1777,7 @@ static void am_run(struct am_state *state, int resume)\n \t\t\t * the result may have produced the same tree as ours.\n \t\t\t */\n \t\t\tif (!apply_status &&\n-\t\t\t    !index_has_changes(&the_index, NULL, NULL)) {\n+\t\t\t    !repo_index_has_changes(the_repository, NULL, NULL)) {\n \t\t\t\tsay(state, stdout, _(\"No changes -- Patch already applied.\"));\n \t\t\t\tgoto next;\n \t\t\t}\n@@ -1831,7 +1831,7 @@ static void am_resolve(struct am_state *state)\n \n \tsay(state, stdout, _(\"Applying: %.*s\"), linelen(state->msg), state->msg);\n \n-\tif (!index_has_changes(&the_index, NULL, NULL)) {\n+\tif (!repo_index_has_changes(the_repository, NULL, NULL)) {\n \t\tprintf_ln(_(\"No changes - did you forget to use 'git add'?\\n\"\n \t\t\t\"If there is nothing left to stage, chances are that something else\\n\"\n \t\t\t\"already introduced the same changes; you might want to skip this patch.\"));\ndiff --git a/cache.h b/cache.h\nindex fdcd69bfb0..326e73f391 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -706,9 +706,9 @@ extern int unmerged_index(const struct index_state *);\n  * provided, the space-separated list of files that differ will be appended\n  * to it.\n  */\n-extern int index_has_changes(struct index_state *istate,\n-\t\t\t     struct tree *tree,\n-\t\t\t     struct strbuf *sb);\n+extern int repo_index_has_changes(struct repository *repo,\n+\t\t\t\t  struct tree *tree,\n+\t\t\t\t  struct strbuf *sb);\n \n extern int verify_path(const char *path, unsigned mode);\n extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change);\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex a596d95739..df00896b25 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3412,7 +3412,7 @@ int merge_trees(struct merge_options *o,\n \tint code, clean;\n \tstruct strbuf sb = STRBUF_INIT;\n \n-\tif (!o->call_depth && index_has_changes(istate, head, &sb)) {\n+\tif (!o->call_depth && repo_index_has_changes(o->repo, head, &sb)) {\n \t\terr(o, _(\"Your local changes to the following files would be overwritten by merge:\\n  %s\"),\n \t\t    sb.buf);\n \t\treturn -1;\ndiff --git a/read-cache.c b/read-cache.c\nindex 61cc0571da..2549477ed2 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2365,22 +2365,20 @@ int unmerged_index(const struct index_state *istate)\n \treturn 0;\n }\n \n-int index_has_changes(struct index_state *istate,\n-\t\t      struct tree *tree,\n-\t\t      struct strbuf *sb)\n+int repo_index_has_changes(struct repository *repo,\n+\t\t\t   struct tree *tree,\n+\t\t\t   struct strbuf *sb)\n {\n+\tstruct index_state *istate = repo->index;\n \tstruct object_id cmp;\n \tint i;\n \n-\tif (istate != &the_index) {\n-\t\tBUG(\"index_has_changes cannot yet accept istate != &the_index; do_diff_cache needs updating first.\");\n-\t}\n \tif (tree)\n \t\tcmp = tree->object.oid;\n \tif (tree || !get_oid_tree(\"HEAD\", &cmp)) {\n \t\tstruct diff_options opt;\n \n-\t\trepo_diff_setup(the_repository, &opt);\n+\t\trepo_diff_setup(repo, &opt);\n \t\topt.flags.exit_with_status = 1;\n \t\tif (!sb)\n \t\t\topt.flags.quick = 1;\n-- \n2.20.0.482.g66447595a7\n\n"},{"id":"366607","messageId":"20190112021332.11066-12-pclouds@gmail.com","threadId":"50159","inReplyTo":"20190112021332.11066-1-pclouds@gmail.com","subject":"[PATCH v2 11/11] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-12T02:13:32Z","receivedAt":"2019-01-12T02:15:02Z","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/blame.c                      | 3 ++-\n builtin/cat-file.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/clone.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/difftool.c                   | 1 +\n builtin/fsck.c                       | 1 +\n builtin/grep.c                       | 1 +\n builtin/hash-object.c                | 3 ++-\n builtin/log.c                        | 1 +\n builtin/ls-files.c                   | 1 -\n builtin/merge-index.c                | 1 +\n builtin/merge-ours.c                 | 1 +\n builtin/merge-tree.c                 | 4 +++-\n builtin/merge.c                      | 1 +\n builtin/mv.c                         | 1 +\n builtin/pack-objects.c               | 2 +-\n builtin/pull.c                       | 1 +\n builtin/read-tree.c                  | 1 +\n builtin/rebase--interactive.c        | 1 +\n builtin/rebase.c                     | 1 +\n builtin/replace.c                    | 2 +-\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 builtin/write-tree.c                 | 1 +\n cache-tree.h                         | 2 +-\n cache.h                              | 6 +++---\n convert.c                            | 1 -\n dir.c                                | 1 -\n git.c                                | 4 ++--\n name-hash.c                          | 1 -\n pathspec.c                           | 1 -\n read-cache.c                         | 2 --\n repository.c                         | 1 +\n submodule.c                          | 1 -\n t/helper/test-dump-fsmonitor.c       | 4 ++--\n t/helper/test-dump-untracked-cache.c | 1 +\n t/helper/test-tool.h                 | 1 +\n tree.c                               | 1 -\n unpack-trees.c                       | 1 -\n 55 files changed, 53 insertions(+), 24 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex b63fe0fc0e..e4e4574857 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 f65c172299..81df0d34de 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 a9ffc92eaa..ad913ef20e 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/blame.c b/builtin/blame.c\nindex 6d798f9939..0074ed311c 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -1007,7 +1007,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\tlong bottom, top;\n \t\tif (parse_range_arg(range_list.items[range_i].string,\n \t\t\t\t    nth_line_cb, &sb, lno, anchor,\n-\t\t\t\t    &bottom, &top, sb.path, &the_index))\n+\t\t\t\t    &bottom, &top, sb.path,\n+\t\t\t\t    the_repository->index))\n \t\t\tusage(blame_usage);\n \t\tif ((!lno && (top || bottom)) || lno < bottom)\n \t\t\tdie(Q_(\"file %s has only %lu line\",\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 7622c502f0..a5ca47c697 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.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 \"builtin.h\"\ndiff --git a/builtin/check-attr.c b/builtin/check-attr.c\nindex 30a2f84274..dd83397786 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 eb74774cbc..345591bc4b 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 a95ba2c6dc..0446cac05e 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 bbcdeb2d9e..aaba4af3c2 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/clone.c b/builtin/clone.c\nindex 7c7f98c72c..ddb3230d21 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -8,6 +8,7 @@\n  * Clone a repository into a different directory that does not yet exist.\n  */\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex d3f1234bf0..2f4af02a27 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 bc97e50650..02ec56417a 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 48cfcb935d..86ae474fbf 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 fcccd1f10d..93ec642423 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 42bc1eb41d..a90681bcba 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 ec78920ee2..74351a5757 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/difftool.c b/builtin/difftool.c\nindex 544b0e8639..eeb9e370b9 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -11,6 +11,7 @@\n  *\n  * Copyright (C) 2016 Johannes Schindelin\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex bf5ddff43f..46f6ea9baa 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/grep.c b/builtin/grep.c\nindex fc7a9a9283..39a8e9d4a3 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.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 \"repository.h\"\n #include \"config.h\"\ndiff --git a/builtin/hash-object.c b/builtin/hash-object.c\nindex d6f06ea32f..e055c11103 100644\n--- a/builtin/hash-object.c\n+++ b/builtin/hash-object.c\n@@ -40,7 +40,8 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,\n \tif (fstat(fd, &st) < 0 ||\n \t    (literally\n \t     ? hash_literally(&oid, fd, type, flags)\n-\t     : index_fd(&the_index, &oid, fd, &st, type_from_string(type), path, flags)))\n+\t     : index_fd(the_repository->index, &oid, fd, &st,\n+\t\t\ttype_from_string(type), path, flags)))\n \t\tdie((flags & HASH_WRITE_OBJECT)\n \t\t    ? \"Unable to add %s to database\"\n \t\t    : \"Unable to hash %s\", path);\ndiff --git a/builtin/log.c b/builtin/log.c\nindex dbfb4e31ad..195ff0b471 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -4,6 +4,7 @@\n  * (C) Copyright 2006 Linus Torvalds\n  *\t\t 2006 Junio Hamano\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"config.h\"\n #include \"refs.h\"\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex c70a9c7158..7cc7ec22c9 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 0b07263415..4594507420 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-tree.c b/builtin/merge-tree.c\nindex 70f6fc9167..53719e0b9d 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"tree-walk.h\"\n #include \"xdiff-interface.h\"\n@@ -76,7 +77,8 @@ static void *result(struct merge_list *entry, unsigned long *size)\n \ttheir = NULL;\n \tif (entry)\n \t\ttheir = entry->blob;\n-\treturn merge_blobs(&the_index, path, base, our, their, size);\n+\treturn merge_blobs(the_repository->index, path,\n+\t\t\t   base, our, their, size);\n }\n \n static void *origin(struct merge_list *entry, unsigned long *size)\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex bc1aecfe70..e47d77baee 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/pack-objects.c b/builtin/pack-objects.c\nindex 24bba8147f..d9d3b90b23 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -970,7 +970,7 @@ static int no_try_delta(const char *path)\n \n \tif (!check)\n \t\tcheck = attr_check_initl(\"delta\", NULL);\n-\tgit_check_attr(&the_index, path, check);\n+\tgit_check_attr(the_repository->index, path, check);\n \tif (ATTR_FALSE(check->items[0].value))\n \t\treturn 1;\n \treturn 0;\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 74808b9455..701d1473dc 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 ac255ad2c2..9083dcfa28 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/rebase--interactive.c b/builtin/rebase--interactive.c\nindex dd2a55ab1d..6895322d61 100644\n--- a/builtin/rebase--interactive.c\n+++ b/builtin/rebase--interactive.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/rebase.c b/builtin/rebase.c\nindex 7124e66d00..b667837276 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -4,6 +4,7 @@\n  * Copyright (c) 2018 Pratik Karki\n  */\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"run-command.h\"\n #include \"exec-cmd.h\"\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex affcdfb416..5b80b7f211 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -295,7 +295,7 @@ static int import_object(struct object_id *oid, enum object_type type,\n \t\t\tclose(fd);\n \t\t\treturn -1;\n \t\t}\n-\t\tif (index_fd(&the_index, oid, fd, &st, type, NULL, flags) < 0)\n+\t\tif (index_fd(the_repository->index, oid, fd, &st, type, NULL, flags) < 0)\n \t\t\treturn error(_(\"unable to write object to database\"));\n \t\t/* index_fd close()s fd for us */\n \t}\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 59898c972e..4d18a461fa 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 910a71ed8b..f8bbe6d47e 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 17086d3d97..db85b33982 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 b45514be31..9c832fc606 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 e19da77edc..02ace602b9 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/builtin/write-tree.c b/builtin/write-tree.c\nindex cdcbf8264e..3d46d22ee5 100644\n--- a/builtin/write-tree.c\n+++ b/builtin/write-tree.c\n@@ -3,6 +3,7 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"config.h\"\ndiff --git a/cache-tree.h b/cache-tree.h\nindex 326209198b..757bbc48bc 100644\n--- a/cache-tree.h\n+++ b/cache-tree.h\n@@ -51,7 +51,7 @@ void prime_cache_tree(struct repository *, struct index_state *, struct tree *);\n \n int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);\n \n-#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS\n+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)\n {\n \treturn write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);\ndiff --git a/cache.h b/cache.h\nindex 326e73f391..962eb127d3 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -338,8 +338,6 @@ struct index_state {\n \tstruct mem_pool *ce_mem_pool;\n };\n \n-extern struct index_state the_index;\n-\n /* Name hashing */\n extern int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);\n extern void add_name_hash(struct index_state *istate, struct cache_entry *ce);\n@@ -401,7 +399,9 @@ struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_s\n  */\n void validate_cache_entries(const struct index_state *istate);\n \n-#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS\n+#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS\n+extern struct index_state the_index;\n+\n #define active_cache (the_index.cache)\n #define active_nr (the_index.cache_nr)\n #define active_alloc (the_index.cache_alloc)\ndiff --git a/convert.c b/convert.c\nindex e0848226d2..df8c6a0bf8 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 \"object-store.h\"\ndiff --git a/dir.c b/dir.c\nindex ab6477d777..80e07441f7 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/git.c b/git.c\nindex 4d53a3d50d..0c2b269797 100644\n--- a/git.c\n+++ b/git.c\n@@ -417,9 +417,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n \n \ttrace_argv_printf(argv, \"trace: built-in: git\");\n \n-\tvalidate_cache_entries(&the_index);\n+\tvalidate_cache_entries(the_repository->index);\n \tstatus = p->fn(argc, argv, prefix);\n-\tvalidate_cache_entries(&the_index);\n+\tvalidate_cache_entries(the_repository->index);\n \n \tif (status)\n \t\treturn status;\ndiff --git a/name-hash.c b/name-hash.c\nindex 623ca6923a..b4861bc7b0 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 #include \"thread-utils.h\"\n \ndiff --git a/pathspec.c b/pathspec.c\nindex 6f005996fd..f1505cfd0a 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 2549477ed2..b3865d6884 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 \"diff.h\"\n@@ -95,7 +94,6 @@ static struct mem_pool *find_mem_pool(struct index_state *istate)\n \treturn *pool_ptr;\n }\n \n-struct index_state the_index;\n static const char *alternate_index_output;\n \n static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)\ndiff --git a/repository.c b/repository.c\nindex 9411c4baee..a92550ade2 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -9,6 +9,7 @@\n /* The main repository */\n static struct repository the_repo;\n struct repository *the_repository;\n+struct index_state the_index;\n \n void initialize_the_repository(void)\n {\ndiff --git a/submodule.c b/submodule.c\nindex 6415cc5580..4208a50260 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-fsmonitor.c b/t/helper/test-dump-fsmonitor.c\nindex 08e3684aff..2786f47088 100644\n--- a/t/helper/test-dump-fsmonitor.c\n+++ b/t/helper/test-dump-fsmonitor.c\n@@ -3,11 +3,11 @@\n \n int cmd__dump_fsmonitor(int ac, const char **av)\n {\n-\tstruct index_state *istate = &the_index;\n+\tstruct index_state *istate = the_repository->index;\n \tint i;\n \n \tsetup_git_directory();\n-\tif (do_read_index(istate, get_index_file(), 0) < 0)\n+\tif (do_read_index(istate, the_repository->index_file, 0) < 0)\n \t\tdie(\"unable to read index file\");\n \tif (!istate->fsmonitor_last_update) {\n \t\tprintf(\"no fsmonitor\\n\");\ndiff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c\nindex 52870ebbb3..cf0f2c7228 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 \"test-tool.h\"\n #include \"cache.h\"\n #include \"dir.h\"\ndiff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\nindex 042f12464b..f4fb3b9861 100644\n--- a/t/helper/test-tool.h\n+++ b/t/helper/test-tool.h\n@@ -1,6 +1,7 @@\n #ifndef TEST_TOOL_H\n #define TEST_TOOL_H\n \n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"git-compat-util.h\"\n \n int cmd__chmtime(int argc, const char **argv);\ndiff --git a/tree.c b/tree.c\nindex 215d3fdc7c..181a3778f3 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 6d53cbfc86..40f554814d 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.20.0.482.g66447595a7\n\n"}]}