{"thread":{"id":"49616","subject":"[PATCH/WIP 00/19] Kill the_index, final part","startedAt":"2018-10-19T14:52:45Z","lastAt":"2018-10-29T16:43:10Z","messageCount":22,"participants":["Nguyễn Thái Ngọc Duy","Stefan Beller","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":19},"messages":[{"id":"360917","messageId":"20181019145237.16079-1-pclouds@gmail.com","threadId":"49616","inReplyTo":null,"subject":"[PATCH/WIP 00/19] Kill the_index, final part","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:18Z","receivedAt":"2018-10-19T14:52:45Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Stefan I see you start removing more references of the_repository in\nanother series (haven't really looked at it yet) so this is just heads\nup so we could coordinate if needed. Still WIP, not really ready for\nreview yet.\n\nThis series removes use of the_index outside builtin/ and t/helper/.\nThe only the_index reference left is in repository.c. The macro\nNO_THE_REPOSITORY_COMPATIBILITY_MACROS is now flipped to\nUSE_THE_INDEX_COMPATIBILITY_MACROS. \"the_index\" is forbidden by\ndefault.\n\nAfter this I think we can start pushing the_repository outside library\ncode. Then perhaps clean them up in builtin code too and you can\nfinally get rid of it. But I don't think that'll happen in a year's\ntime.\n\nNguyễn Thái Ngọc Duy (19):\n  wt-status.c: remove implicit dependency on the_index\n  wt-status.c: remove implicit dependency the_repository\n  list-objects-filter.c: remove implicit dependency on the_index\n  list-objects.c: remove implicit dependency on the_index\n  sequencer.c: remove implicit dependency on the_index\n  sequencer.c: remove implicit dependency on the_repository\n  notes-merge.c: remove implicit dependency on the_index\n  notes-merge.c: remove implicit dependency the_repository\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  transport.c: remove implicit dependency on the_index\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  Flip NO_THE_REPOSITORY_COMPATIBILITY_MACROS\n\n apply.c                              |   5 +-\n attr.c                               |   1 -\n blame.c                              |   4 +-\n builtin/add.c                        |   1 +\n builtin/am.c                         |  11 +-\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                     |  10 +-\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                 |   3 +-\n builtin/merge.c                      |   5 +-\n builtin/mv.c                         |   1 +\n builtin/notes.c                      |   2 +-\n builtin/pack-objects.c               |   2 +-\n builtin/pull.c                       |   4 +-\n builtin/push.c                       |   3 +-\n builtin/read-tree.c                  |   1 +\n builtin/rebase--helper.c             |  15 +-\n builtin/replace.c                    |   2 +-\n builtin/reset.c                      |   1 +\n builtin/rev-parse.c                  |   4 +-\n builtin/revert.c                     |   6 +-\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 diff.h                               |   2 +-\n dir.c                                |   1 -\n git.c                                |   4 +-\n list-objects-filter-options.c        |   2 +-\n list-objects-filter.c                |   7 +-\n list-objects-filter.h                |   1 +\n list-objects.c                       |   3 +\n merge-recursive.c                    | 194 ++++++------\n merge-recursive.h                    |   6 +-\n merge.c                              |   4 +-\n name-hash.c                          |   1 -\n notes-merge.c                        |  16 +-\n notes-merge.h                        |   6 +-\n pathspec.c                           |   1 -\n preload-index.c                      |  11 +-\n read-cache.c                         |  44 ++-\n ref-filter.c                         |   2 +-\n repository.c                         |   9 +\n repository.h                         |  16 +\n rerere.c                             |   8 +-\n rerere.h                             |   2 +-\n revision.c                           |  12 +-\n revision.h                           |   2 +-\n sequencer.c                          | 435 +++++++++++++++------------\n sequencer.h                          |  27 +-\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 transport.c                          |   7 +-\n transport.h                          |   3 +-\n tree.c                               |   1 -\n unpack-trees.c                       |   1 -\n wt-status.c                          |  97 +++---\n wt-status.h                          |  21 +-\n 84 files changed, 673 insertions(+), 508 deletions(-)\n\n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360918","messageId":"20181019145237.16079-2-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 01/19] wt-status.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:19Z","receivedAt":"2018-10-19T14:52: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/commit.c |  2 +-\n builtin/pull.c   |  3 +-\n sequencer.c      |  6 ++--\n wt-status.c      | 77 +++++++++++++++++++++++++++---------------------\n wt-status.h      | 17 +++++++----\n 5 files changed, 62 insertions(+), 43 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 074bd9a551..379d8c5cdf 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -185,7 +185,7 @@ static void determine_whence(struct wt_status *s)\n \n static void status_init_config(struct wt_status *s, config_fn_t fn)\n {\n-\twt_status_prepare(s);\n+\twt_status_prepare(s, the_repository);\n \tinit_diff_ui_defaults();\n \tgit_config(fn, s);\n \tdetermine_whence(s);\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 798ecf7faf..9b0fce07ca 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -888,7 +888,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"Updating an unborn branch with changes added to the index.\"));\n \n \t\tif (!autostash)\n-\t\t\trequire_clean_work_tree(N_(\"pull with rebase\"),\n+\t\t\trequire_clean_work_tree(the_repository,\n+\t\t\t\tN_(\"pull with rebase\"),\n \t\t\t\t_(\"please commit or stash them.\"), 1, 0);\n \n \t\tif (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))\ndiff --git a/sequencer.c b/sequencer.c\nindex 0c164d5f98..90435593a4 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -2712,7 +2712,7 @@ static int do_exec(const char *command_line)\n \tif (discard_cache() < 0 || read_cache() < 0)\n \t\treturn error(_(\"could not read index\"));\n \n-\tdirty = require_clean_work_tree(\"rebase\", NULL, 1, 1);\n+\tdirty = require_clean_work_tree(the_repository, \"rebase\", NULL, 1, 1);\n \n \tif (status) {\n \t\twarning(_(\"execution failed: %s\\n%s\"\n@@ -3583,10 +3583,10 @@ static int commit_staged_changes(struct replay_opts *opts,\n \tunsigned int flags = ALLOW_EMPTY | EDIT_MSG;\n \tunsigned int final_fixup = 0, is_clean;\n \n-\tif (has_unstaged_changes(1))\n+\tif (has_unstaged_changes(the_repository, 1))\n \t\treturn error(_(\"cannot rebase: You have unstaged changes.\"));\n \n-\tis_clean = !has_uncommitted_changes(0);\n+\tis_clean = !has_uncommitted_changes(the_repository, 0);\n \n \tif (file_exists(rebase_path_amend())) {\n \t\tstruct strbuf rev = STRBUF_INIT;\ndiff --git a/wt-status.c b/wt-status.c\nindex 187568a112..0378bc2a48 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -119,9 +119,11 @@ static void status_printf_more(struct wt_status *s, const char *color,\n \tva_end(ap);\n }\n \n-void wt_status_prepare(struct wt_status *s)\n+void wt_status_prepare(struct wt_status *s,\n+\t\t       struct repository *repo)\n {\n \tmemset(s, 0, sizeof(*s));\n+\ts->repo = repo;\n \tmemcpy(s->color_palette, default_wt_status_colors,\n \t       sizeof(default_wt_status_colors));\n \ts->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;\n@@ -494,19 +496,19 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,\n \t}\n }\n \n-static int unmerged_mask(const char *path)\n+static int unmerged_mask(struct index_state *istate, const char *path)\n {\n \tint pos, mask;\n \tconst struct cache_entry *ce;\n \n-\tpos = cache_name_pos(path, strlen(path));\n+\tpos = index_name_pos(istate, path, strlen(path));\n \tif (0 <= pos)\n \t\treturn 0;\n \n \tmask = 0;\n \tpos = -pos-1;\n-\twhile (pos < active_nr) {\n-\t\tce = active_cache[pos++];\n+\twhile (pos < istate->cache_nr) {\n+\t\tce = istate->cache[pos++];\n \t\tif (strcmp(ce->name, path) || !ce_stage(ce))\n \t\t\tbreak;\n \t\tmask |= (1 << (ce_stage(ce) - 1));\n@@ -566,7 +568,8 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,\n \t\t\ts->committable = 1;\n \t\t\tbreak;\n \t\tcase DIFF_STATUS_UNMERGED:\n-\t\t\td->stagemask = unmerged_mask(p->two->path);\n+\t\t\td->stagemask = unmerged_mask(s->repo->index,\n+\t\t\t\t\t\t     p->two->path);\n \t\t\t/*\n \t\t\t * Don't bother setting {mode,oid}_{head,index} since the print\n \t\t\t * code will output the stage values directly and not use the\n@@ -585,7 +588,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)\n {\n \tstruct rev_info rev;\n \n-\trepo_init_revisions(the_repository, &rev, NULL);\n+\trepo_init_revisions(s->repo, &rev, NULL);\n \tsetup_revisions(0, NULL, &rev, NULL);\n \trev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;\n \trev.diffopt.flags.dirty_submodules = 1;\n@@ -610,7 +613,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)\n \tstruct rev_info rev;\n \tstruct setup_revision_opt opt;\n \n-\trepo_init_revisions(the_repository, &rev, NULL);\n+\trepo_init_revisions(s->repo, &rev, NULL);\n \tmemset(&opt, 0, sizeof(opt));\n \topt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;\n \tsetup_revisions(0, NULL, &rev, &opt);\n@@ -643,14 +646,15 @@ static void wt_status_collect_changes_index(struct wt_status *s)\n \n static void wt_status_collect_changes_initial(struct wt_status *s)\n {\n+\tstruct index_state *istate = s->repo->index;\n \tint i;\n \n-\tfor (i = 0; i < active_nr; i++) {\n+\tfor (i = 0; i < istate->cache_nr; i++) {\n \t\tstruct string_list_item *it;\n \t\tstruct wt_status_change_data *d;\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\t\tconst struct cache_entry *ce = istate->cache[i];\n \n-\t\tif (!ce_path_match(&the_index, ce, &s->pathspec, NULL))\n+\t\tif (!ce_path_match(istate, ce, &s->pathspec, NULL))\n \t\t\tcontinue;\n \t\tif (ce_intent_to_add(ce))\n \t\t\tcontinue;\n@@ -684,6 +688,7 @@ static void wt_status_collect_untracked(struct wt_status *s)\n \tint i;\n \tstruct dir_struct dir;\n \tuint64_t t_begin = getnanotime();\n+\tstruct index_state *istate = s->repo->index;\n \n \tif (!s->show_untracked_files)\n \t\treturn;\n@@ -698,25 +703,25 @@ static void wt_status_collect_untracked(struct wt_status *s)\n \t\tif (s->show_ignored_mode == SHOW_MATCHING_IGNORED)\n \t\t\tdir.flags |= DIR_SHOW_IGNORED_TOO_MODE_MATCHING;\n \t} else {\n-\t\tdir.untracked = the_index.untracked;\n+\t\tdir.untracked = istate->untracked;\n \t}\n \n \tsetup_standard_excludes(&dir);\n \n-\tfill_directory(&dir, &the_index, &s->pathspec);\n+\tfill_directory(&dir, istate, &s->pathspec);\n \n \tfor (i = 0; i < dir.nr; i++) {\n \t\tstruct dir_entry *ent = dir.entries[i];\n-\t\tif (cache_name_is_other(ent->name, ent->len) &&\n-\t\t    dir_path_match(&the_index, ent, &s->pathspec, 0, NULL))\n+\t\tif (index_name_is_other(istate, ent->name, ent->len) &&\n+\t\t    dir_path_match(istate, ent, &s->pathspec, 0, NULL))\n \t\t\tstring_list_insert(&s->untracked, ent->name);\n \t\tfree(ent);\n \t}\n \n \tfor (i = 0; i < dir.ignored_nr; i++) {\n \t\tstruct dir_entry *ent = dir.ignored[i];\n-\t\tif (cache_name_is_other(ent->name, ent->len) &&\n-\t\t    dir_path_match(&the_index, ent, &s->pathspec, 0, NULL))\n+\t\tif (index_name_is_other(istate, ent->name, ent->len) &&\n+\t\t    dir_path_match(istate, ent, &s->pathspec, 0, NULL))\n \t\t\tstring_list_insert(&s->ignored, ent->name);\n \t\tfree(ent);\n \t}\n@@ -1009,7 +1014,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)\n \tint dirty_submodules;\n \tconst char *c = color(WT_STATUS_HEADER, s);\n \n-\trepo_init_revisions(the_repository, &rev, NULL);\n+\trepo_init_revisions(s->repo, &rev, NULL);\n \trev.diffopt.flags.allow_textconv = 1;\n \trev.diffopt.ita_invisible_in_index = 1;\n \n@@ -1326,7 +1331,7 @@ static void show_rebase_in_progress(struct wt_status *s,\n \t\t\t\t_(\"  (use \\\"git rebase --abort\\\" to check out the original branch)\"));\n \t\t}\n \t} else if (s->state.rebase_in_progress ||\n-\t\t   !stat(git_path_merge_msg(the_repository), &st)) {\n+\t\t   !stat(git_path_merge_msg(s->repo), &st)) {\n \t\tprint_rebase_state(s, color);\n \t\tif (s->hints)\n \t\t\tstatus_printf_ln(s, color,\n@@ -2135,6 +2140,7 @@ static void wt_porcelain_v2_print_unmerged_entry(\n \tstruct wt_status *s)\n {\n \tstruct wt_status_change_data *d = it->util;\n+\tstruct index_state *istate = s->repo->index;\n \tconst struct cache_entry *ce;\n \tstruct strbuf buf_index = STRBUF_INIT;\n \tconst char *path_index = NULL;\n@@ -2173,11 +2179,11 @@ static void wt_porcelain_v2_print_unmerged_entry(\n \t */\n \tmemset(stages, 0, sizeof(stages));\n \tsum = 0;\n-\tpos = cache_name_pos(it->string, strlen(it->string));\n+\tpos = index_name_pos(istate, it->string, strlen(it->string));\n \tassert(pos < 0);\n \tpos = -pos-1;\n-\twhile (pos < active_nr) {\n-\t\tce = active_cache[pos++];\n+\twhile (pos < istate->cache_nr) {\n+\t\tce = istate->cache[pos++];\n \t\tstage = ce_stage(ce);\n \t\tif (strcmp(ce->name, it->string) || !stage)\n \t\t\tbreak;\n@@ -2302,12 +2308,12 @@ void wt_status_print(struct wt_status *s)\n /**\n  * Returns 1 if there are unstaged changes, 0 otherwise.\n  */\n-int has_unstaged_changes(int ignore_submodules)\n+int has_unstaged_changes(struct repository *r, int ignore_submodules)\n {\n \tstruct rev_info rev_info;\n \tint result;\n \n-\trepo_init_revisions(the_repository, &rev_info, NULL);\n+\trepo_init_revisions(r, &rev_info, NULL);\n \tif (ignore_submodules) {\n \t\trev_info.diffopt.flags.ignore_submodules = 1;\n \t\trev_info.diffopt.flags.override_submodule_config = 1;\n@@ -2321,15 +2327,16 @@ int has_unstaged_changes(int ignore_submodules)\n /**\n  * Returns 1 if there are uncommitted changes, 0 otherwise.\n  */\n-int has_uncommitted_changes(int ignore_submodules)\n+int has_uncommitted_changes(struct repository *r,\n+\t\t\t    int ignore_submodules)\n {\n \tstruct rev_info rev_info;\n \tint result;\n \n-\tif (is_cache_unborn())\n+\tif (is_index_unborn(r->index))\n \t\treturn 0;\n \n-\trepo_init_revisions(the_repository, &rev_info, NULL);\n+\trepo_init_revisions(r, &rev_info, NULL);\n \tif (ignore_submodules)\n \t\trev_info.diffopt.flags.ignore_submodules = 1;\n \trev_info.diffopt.flags.quick = 1;\n@@ -2340,7 +2347,7 @@ int has_uncommitted_changes(int ignore_submodules)\n \t\t * We have no head (or it's corrupt); use the empty tree,\n \t\t * which will complain if the index is non-empty.\n \t\t */\n-\t\tstruct tree *tree = lookup_tree(the_repository, the_hash_algo->empty_tree);\n+\t\tstruct tree *tree = lookup_tree(r, the_hash_algo->empty_tree);\n \t\tadd_pending_object(&rev_info, &tree->object, \"\");\n \t}\n \n@@ -2353,24 +2360,28 @@ int has_uncommitted_changes(int ignore_submodules)\n  * If the work tree has unstaged or uncommitted changes, dies with the\n  * appropriate message.\n  */\n-int require_clean_work_tree(const char *action, const char *hint, int ignore_submodules, int gently)\n+int require_clean_work_tree(struct repository *r,\n+\t\t\t    const char *action,\n+\t\t\t    const char *hint,\n+\t\t\t    int ignore_submodules,\n+\t\t\t    int gently)\n {\n \tstruct lock_file lock_file = LOCK_INIT;\n \tint err = 0, fd;\n \n \tfd = hold_locked_index(&lock_file, 0);\n-\trefresh_cache(REFRESH_QUIET);\n+\trefresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);\n \tif (0 <= fd)\n-\t\tupdate_index_if_able(&the_index, &lock_file);\n+\t\tupdate_index_if_able(r->index, &lock_file);\n \trollback_lock_file(&lock_file);\n \n-\tif (has_unstaged_changes(ignore_submodules)) {\n+\tif (has_unstaged_changes(r, ignore_submodules)) {\n \t\t/* TRANSLATORS: the action is e.g. \"pull with rebase\" */\n \t\terror(_(\"cannot %s: You have unstaged changes.\"), _(action));\n \t\terr = 1;\n \t}\n \n-\tif (has_uncommitted_changes(ignore_submodules)) {\n+\tif (has_uncommitted_changes(r, ignore_submodules)) {\n \t\tif (err)\n \t\t\terror(_(\"additionally, your index contains uncommitted changes.\"));\n \t\telse\ndiff --git a/wt-status.h b/wt-status.h\nindex 1fcf93afbf..84653595e3 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -7,6 +7,7 @@\n #include \"pathspec.h\"\n #include \"remote.h\"\n \n+struct repository;\n struct worktree;\n \n enum color_wt_status {\n@@ -83,6 +84,7 @@ struct wt_status_state {\n };\n \n struct wt_status {\n+\tstruct repository *repo;\n \tint is_initial;\n \tchar *branch;\n \tconst char *reference;\n@@ -128,7 +130,7 @@ struct wt_status {\n \n size_t wt_status_locate_end(const char *s, size_t len);\n void wt_status_add_cut_line(FILE *fp);\n-void wt_status_prepare(struct wt_status *s);\n+void wt_status_prepare(struct wt_status *s, struct repository *repo);\n void wt_status_print(struct wt_status *s);\n void wt_status_collect(struct wt_status *s);\n void wt_status_collect_free_buffers(struct wt_status *s);\n@@ -144,9 +146,14 @@ __attribute__((format (printf, 3, 4)))\n void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);\n \n /* The following functions expect that the caller took care of reading the index. */\n-int has_unstaged_changes(int ignore_submodules);\n-int has_uncommitted_changes(int ignore_submodules);\n-int require_clean_work_tree(const char *action, const char *hint,\n-\tint ignore_submodules, int gently);\n+int has_unstaged_changes(struct repository *repo,\n+\t\t\t int ignore_submodules);\n+int has_uncommitted_changes(struct repository *repo,\n+\t\t\t    int ignore_submodules);\n+int require_clean_work_tree(struct repository *repo,\n+\t\t\t    const char *action,\n+\t\t\t    const char *hint,\n+\t\t\t    int ignore_submodules,\n+\t\t\t    int gently);\n \n #endif /* STATUS_H */\n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360919","messageId":"20181019145237.16079-3-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 02/19] wt-status.c: remove implicit dependency the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:20Z","receivedAt":"2018-10-19T14:52:48Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n ref-filter.c |  2 +-\n wt-status.c  | 18 ++++++++++--------\n wt-status.h  |  4 +++-\n 3 files changed, 14 insertions(+), 10 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 2a05619211..d6d3923eb2 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1412,7 +1412,7 @@ char *get_head_description(void)\n \tstruct strbuf desc = STRBUF_INIT;\n \tstruct wt_status_state state;\n \tmemset(&state, 0, sizeof(state));\n-\twt_status_get_state(&state, 1);\n+\twt_status_get_state(the_repository, &state, 1);\n \tif (state.rebase_in_progress ||\n \t    state.rebase_interactive_in_progress) {\n \t\tif (state.branch)\ndiff --git a/wt-status.c b/wt-status.c\nindex 0378bc2a48..3632276236 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -756,7 +756,7 @@ void wt_status_collect(struct wt_status *s)\n \t\twt_status_collect_changes_index(s);\n \twt_status_collect_untracked(s);\n \n-\twt_status_get_state(&s->state, s->branch && !strcmp(s->branch, \"HEAD\"));\n+\twt_status_get_state(s->repo, &s->state, s->branch && !strcmp(s->branch, \"HEAD\"));\n \tif (s->state.merge_in_progress && !has_unmerged(s))\n \t\ts->committable = 1;\n }\n@@ -1483,7 +1483,8 @@ static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,\n \treturn 1;\n }\n \n-static void wt_status_get_detached_from(struct wt_status_state *state)\n+static void wt_status_get_detached_from(struct repository *r,\n+\t\t\t\t\tstruct wt_status_state *state)\n {\n \tstruct grab_1st_switch_cbdata cb;\n \tstruct commit *commit;\n@@ -1500,7 +1501,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)\n \t    /* sha1 is a commit? match without further lookup */\n \t    (oideq(&cb.noid, &oid) ||\n \t     /* perhaps sha1 is a tag, try to dereference to a commit */\n-\t     ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&\n+\t     ((commit = lookup_commit_reference_gently(r, &oid, 1)) != NULL &&\n \t      oideq(&cb.noid, &commit->object.oid)))) {\n \t\tconst char *from = ref;\n \t\tif (!skip_prefix(from, \"refs/tags/\", &from))\n@@ -1557,30 +1558,31 @@ int wt_status_check_bisect(const struct worktree *wt,\n \treturn 0;\n }\n \n-void wt_status_get_state(struct wt_status_state *state,\n+void wt_status_get_state(struct repository *r,\n+\t\t\t struct wt_status_state *state,\n \t\t\t int get_detached_from)\n {\n \tstruct stat st;\n \tstruct object_id oid;\n \n-\tif (!stat(git_path_merge_head(the_repository), &st)) {\n+\tif (!stat(git_path_merge_head(r), &st)) {\n \t\tstate->merge_in_progress = 1;\n \t} else if (wt_status_check_rebase(NULL, state)) {\n \t\t;\t\t/* all set */\n-\t} else if (!stat(git_path_cherry_pick_head(the_repository), &st) &&\n+\t} else if (!stat(git_path_cherry_pick_head(r), &st) &&\n \t\t\t!get_oid(\"CHERRY_PICK_HEAD\", &oid)) {\n \t\tstate->cherry_pick_in_progress = 1;\n \t\toidcpy(&state->cherry_pick_head_oid, &oid);\n \t}\n \twt_status_check_bisect(NULL, state);\n-\tif (!stat(git_path_revert_head(the_repository), &st) &&\n+\tif (!stat(git_path_revert_head(r), &st) &&\n \t    !get_oid(\"REVERT_HEAD\", &oid)) {\n \t\tstate->revert_in_progress = 1;\n \t\toidcpy(&state->revert_head_oid, &oid);\n \t}\n \n \tif (get_detached_from)\n-\t\twt_status_get_detached_from(state);\n+\t\twt_status_get_detached_from(r, state);\n }\n \n static void wt_longstatus_print_state(struct wt_status *s)\ndiff --git a/wt-status.h b/wt-status.h\nindex 84653595e3..9dde7091f6 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -134,7 +134,9 @@ void wt_status_prepare(struct wt_status *s, struct repository *repo);\n void wt_status_print(struct wt_status *s);\n void wt_status_collect(struct wt_status *s);\n void wt_status_collect_free_buffers(struct wt_status *s);\n-void wt_status_get_state(struct wt_status_state *state, int get_detached_from);\n+void wt_status_get_state(struct repository *repo,\n+\t\t\t struct wt_status_state *state,\n+\t\t\t int get_detached_from);\n int wt_status_check_rebase(const struct worktree *wt,\n \t\t\t   struct wt_status_state *state);\n int wt_status_check_bisect(const struct worktree *wt,\n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360920","messageId":"20181019145237.16079-4-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 03/19] list-objects-filter.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:21Z","receivedAt":"2018-10-19T14:52:49Z","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 list-objects-filter.c | 7 +++++--\n list-objects-filter.h | 1 +\n list-objects.c        | 3 +++\n 3 files changed, 9 insertions(+), 2 deletions(-)\n\ndiff --git a/list-objects-filter.c b/list-objects-filter.c\nindex a0ba78b20c..8825e2a5ab 100644\n--- a/list-objects-filter.c\n+++ b/list-objects-filter.c\n@@ -38,6 +38,7 @@ static enum list_objects_filter_result filter_blobs_none(\n \tstruct object *obj,\n \tconst char *pathname,\n \tconst char *filename,\n+\tstruct index_state *istate,\n \tvoid *filter_data_)\n {\n \tstruct filter_blobs_none_data *filter_data = filter_data_;\n@@ -94,6 +95,7 @@ static enum list_objects_filter_result filter_blobs_limit(\n \tstruct object *obj,\n \tconst char *pathname,\n \tconst char *filename,\n+\tstruct index_state *istate,\n \tvoid *filter_data_)\n {\n \tstruct filter_blobs_limit_data *filter_data = filter_data_;\n@@ -200,6 +202,7 @@ static enum list_objects_filter_result filter_sparse(\n \tstruct object *obj,\n \tconst char *pathname,\n \tconst char *filename,\n+\tstruct index_state *istate,\n \tvoid *filter_data_)\n {\n \tstruct filter_sparse_data *filter_data = filter_data_;\n@@ -216,7 +219,7 @@ static enum list_objects_filter_result filter_sparse(\n \t\tdtype = DT_DIR;\n \t\tval = is_excluded_from_list(pathname, strlen(pathname),\n \t\t\t\t\t    filename, &dtype, &filter_data->el,\n-\t\t\t\t\t    &the_index);\n+\t\t\t\t\t    istate);\n \t\tif (val < 0)\n \t\t\tval = filter_data->array_frame[filter_data->nr].defval;\n \n@@ -279,7 +282,7 @@ static enum list_objects_filter_result filter_sparse(\n \t\tdtype = DT_REG;\n \t\tval = is_excluded_from_list(pathname, strlen(pathname),\n \t\t\t\t\t    filename, &dtype, &filter_data->el,\n-\t\t\t\t\t    &the_index);\n+\t\t\t\t\t    istate);\n \t\tif (val < 0)\n \t\t\tval = frame->defval;\n \t\tif (val > 0) {\ndiff --git a/list-objects-filter.h b/list-objects-filter.h\nindex a6f6b4990b..dfa29595d1 100644\n--- a/list-objects-filter.h\n+++ b/list-objects-filter.h\n@@ -58,6 +58,7 @@ typedef enum list_objects_filter_result (*filter_object_fn)(\n \tstruct object *obj,\n \tconst char *pathname,\n \tconst char *filename,\n+\tstruct index_state *istate,\n \tvoid *filter_data);\n \n typedef void (*filter_free_fn)(void *filter_data);\ndiff --git a/list-objects.c b/list-objects.c\nindex 0c2989d5ca..f9d36dabf2 100644\n--- a/list-objects.c\n+++ b/list-objects.c\n@@ -51,6 +51,7 @@ static void process_blob(struct rev_info *revs,\n \tif (!(obj->flags & USER_GIVEN) && filter_fn)\n \t\tr = filter_fn(LOFS_BLOB, obj,\n \t\t\t      path->buf, &path->buf[pathlen],\n+\t\t\t      &the_index,\n \t\t\t      filter_data);\n \tif (r & LOFR_MARK_SEEN)\n \t\tobj->flags |= SEEN;\n@@ -136,6 +137,7 @@ static void process_tree(struct rev_info *revs,\n \tif (!(obj->flags & USER_GIVEN) && filter_fn)\n \t\tr = filter_fn(LOFS_BEGIN_TREE, obj,\n \t\t\t      base->buf, &base->buf[baselen],\n+\t\t\t      &the_index,\n \t\t\t      filter_data);\n \tif (r & LOFR_MARK_SEEN)\n \t\tobj->flags |= SEEN;\n@@ -175,6 +177,7 @@ static void process_tree(struct rev_info *revs,\n \tif (!(obj->flags & USER_GIVEN) && filter_fn) {\n \t\tr = filter_fn(LOFS_END_TREE, obj,\n \t\t\t      base->buf, &base->buf[baselen],\n+\t\t\t      &the_index,\n \t\t\t      filter_data);\n \t\tif (r & LOFR_MARK_SEEN)\n \t\t\tobj->flags |= SEEN;\n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360921","messageId":"20181019145237.16079-5-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 04/19] list-objects.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:22Z","receivedAt":"2018-10-19T14:52:51Z","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 list-objects.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/list-objects.c b/list-objects.c\nindex f9d36dabf2..c3a1a9b004 100644\n--- a/list-objects.c\n+++ b/list-objects.c\n@@ -51,7 +51,7 @@ static void process_blob(struct rev_info *revs,\n \tif (!(obj->flags & USER_GIVEN) && filter_fn)\n \t\tr = filter_fn(LOFS_BLOB, obj,\n \t\t\t      path->buf, &path->buf[pathlen],\n-\t\t\t      &the_index,\n+\t\t\t      revs->repo->index,\n \t\t\t      filter_data);\n \tif (r & LOFR_MARK_SEEN)\n \t\tobj->flags |= SEEN;\n@@ -137,7 +137,7 @@ static void process_tree(struct rev_info *revs,\n \tif (!(obj->flags & USER_GIVEN) && filter_fn)\n \t\tr = filter_fn(LOFS_BEGIN_TREE, obj,\n \t\t\t      base->buf, &base->buf[baselen],\n-\t\t\t      &the_index,\n+\t\t\t      revs->repo->index,\n \t\t\t      filter_data);\n \tif (r & LOFR_MARK_SEEN)\n \t\tobj->flags |= SEEN;\n@@ -177,7 +177,7 @@ static void process_tree(struct rev_info *revs,\n \tif (!(obj->flags & USER_GIVEN) && filter_fn) {\n \t\tr = filter_fn(LOFS_END_TREE, obj,\n \t\t\t      base->buf, &base->buf[baselen],\n-\t\t\t      &the_index,\n+\t\t\t      revs->repo->index,\n \t\t\t      filter_data);\n \t\tif (r & LOFR_MARK_SEEN)\n \t\t\tobj->flags |= SEEN;\n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360922","messageId":"20181019145237.16079-7-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 06/19] sequencer.c: remove implicit dependency on the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:24Z","receivedAt":"2018-10-19T14:52:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Note that the_hash_algo stays, even if we can easily replace it with\nrepo->hash_algo. My reason is I still believe tying hash_algo to a\nstruct repository is a wrong move. But if I'm wrong, we can always go\nfor another round of conversion.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/rebase--helper.c |  10 ++--\n builtin/revert.c         |   2 +-\n sequencer.c              | 108 +++++++++++++++++++++------------------\n sequencer.h              |  12 ++---\n 4 files changed, 70 insertions(+), 62 deletions(-)\n\ndiff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c\nindex b66cd8cd41..605fcaa89c 100644\n--- a/builtin/rebase--helper.c\n+++ b/builtin/rebase--helper.c\n@@ -76,14 +76,14 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)\n \t\treturn !!sequencer_make_script(the_repository, stdout,\n \t\t\t\t\t       argc, argv, flags);\n \tif ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)\n-\t\treturn !!transform_todos(flags);\n+\t\treturn !!transform_todos(the_repository, flags);\n \tif (command == CHECK_TODO_LIST && argc == 1)\n-\t\treturn !!check_todo_list();\n+\t\treturn !!check_todo_list(the_repository);\n \tif (command == SKIP_UNNECESSARY_PICKS && argc == 1)\n-\t\treturn !!skip_unnecessary_picks();\n+\t\treturn !!skip_unnecessary_picks(the_repository);\n \tif (command == REARRANGE_SQUASH && argc == 1)\n-\t\treturn !!rearrange_squash();\n+\t\treturn !!rearrange_squash(the_repository);\n \tif (command == ADD_EXEC && argc == 2)\n-\t\treturn !!sequencer_add_exec_commands(argv[1]);\n+\t\treturn !!sequencer_add_exec_commands(the_repository, argv[1]);\n \tusage_with_options(builtin_rebase_helper_usage, options);\n }\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex cd9f068195..1fa75b2773 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -201,7 +201,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)\n \tif (cmd == 'c')\n \t\treturn sequencer_continue(the_repository, opts);\n \tif (cmd == 'a')\n-\t\treturn sequencer_rollback(opts);\n+\t\treturn sequencer_rollback(the_repository, opts);\n \treturn sequencer_pick_revisions(the_repository, opts);\n }\n \ndiff --git a/sequencer.c b/sequencer.c\nindex 6b79359114..2c2ea2b45d 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -351,7 +351,8 @@ static void free_message(struct commit *commit, struct commit_message *msg)\n \tunuse_commit_buffer(commit, msg->message);\n }\n \n-static void print_advice(int show_hint, struct replay_opts *opts)\n+static void print_advice(struct repository *r, int show_hint,\n+\t\t\t struct replay_opts *opts)\n {\n \tchar *msg = getenv(\"GIT_CHERRY_PICK_HELP\");\n \n@@ -362,7 +363,7 @@ static void print_advice(int show_hint, struct replay_opts *opts)\n \t\t * (typically rebase --interactive) wants to take care\n \t\t * of the commit itself so remove CHERRY_PICK_HEAD\n \t\t */\n-\t\tunlink(git_path_cherry_pick_head(the_repository));\n+\t\tunlink(git_path_cherry_pick_head(r));\n \t\treturn;\n \t}\n \n@@ -435,9 +436,9 @@ static int read_oneliner(struct strbuf *buf,\n \treturn 1;\n }\n \n-static struct tree *empty_tree(void)\n+static struct tree *empty_tree(struct repository *r)\n {\n-\treturn lookup_tree(the_repository, the_repository->hash_algo->empty_tree);\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@@ -548,8 +549,8 @@ static int do_recursive_merge(struct repository *r,\n \to.show_rename_progress = 1;\n \n \thead_tree = parse_tree_indirect(head);\n-\tnext_tree = next ? get_commit_tree(next) : empty_tree();\n-\tbase_tree = base ? get_commit_tree(base) : empty_tree();\n+\tnext_tree = next ? get_commit_tree(next) : empty_tree(r);\n+\tbase_tree = base ? get_commit_tree(base) : empty_tree(r);\n \n \tfor (xopt = opts->xopts; xopt != opts->xopts + opts->xopts_nr; xopt++)\n \t\tparse_merge_opt(&o, *xopt);\n@@ -595,15 +596,16 @@ static struct object_id *get_cache_tree_oid(struct index_state *istate)\n \treturn &istate->cache_tree->oid;\n }\n \n-static int is_index_unchanged(struct index_state *istate)\n+static int is_index_unchanged(struct repository *r)\n {\n \tstruct object_id head_oid, *cache_tree_oid;\n \tstruct commit *head_commit;\n+\tstruct index_state *istate = r->index;\n \n \tif (!resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING, &head_oid, NULL))\n \t\treturn error(_(\"could not resolve HEAD commit\"));\n \n-\thead_commit = lookup_commit(the_repository, &head_oid);\n+\thead_commit = lookup_commit(r, &head_oid);\n \n \t/*\n \t * If head_commit is NULL, check_commit, called from\n@@ -1221,7 +1223,7 @@ void print_commit_summary(struct repository *r,\n \tstrbuf_release(&format);\n }\n \n-static int parse_head(struct commit **head)\n+static int parse_head(struct repository *r, struct commit **head)\n {\n \tstruct commit *current_head;\n \tstruct object_id oid;\n@@ -1229,7 +1231,7 @@ static int parse_head(struct commit **head)\n \tif (get_oid(\"HEAD\", &oid)) {\n \t\tcurrent_head = NULL;\n \t} else {\n-\t\tcurrent_head = lookup_commit_reference(the_repository, &oid);\n+\t\tcurrent_head = lookup_commit_reference(r, &oid);\n \t\tif (!current_head)\n \t\t\treturn error(_(\"could not parse HEAD\"));\n \t\tif (!oideq(&oid, &current_head->object.oid)) {\n@@ -1269,7 +1271,7 @@ static int try_to_commit(struct repository *r,\n \tenum commit_msg_cleanup_mode cleanup;\n \tint res = 0;\n \n-\tif (parse_head(&current_head))\n+\tif (parse_head(r, &current_head))\n \t\treturn -1;\n \n \tif (flags & AMEND_MSG) {\n@@ -1436,7 +1438,7 @@ static int allow_empty(struct repository *r,\n \tif (!opts->allow_empty)\n \t\treturn 0; /* let \"git commit\" barf as necessary */\n \n-\tindex_unchanged = is_index_unchanged(r->index);\n+\tindex_unchanged = is_index_unchanged(r);\n \tif (index_unchanged < 0)\n \t\treturn index_unchanged;\n \tif (!index_unchanged)\n@@ -1538,8 +1540,10 @@ static int is_pick_or_similar(enum todo_command command)\n \t}\n }\n \n-static int update_squash_messages(enum todo_command command,\n-\t\tstruct commit *commit, struct replay_opts *opts)\n+static int update_squash_messages(struct repository *r,\n+\t\t\t\t  enum todo_command command,\n+\t\t\t\t  struct commit *commit,\n+\t\t\t\t  struct replay_opts *opts)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tint res;\n@@ -1568,7 +1572,7 @@ static int update_squash_messages(enum todo_command command,\n \n \t\tif (get_oid(\"HEAD\", &head))\n \t\t\treturn error(_(\"need a HEAD to fixup\"));\n-\t\tif (!(head_commit = lookup_commit_reference(the_repository, &head)))\n+\t\tif (!(head_commit = lookup_commit_reference(r, &head)))\n \t\t\treturn error(_(\"could not read HEAD\"));\n \t\tif (!(head_message = get_commit_buffer(head_commit, NULL)))\n \t\t\treturn error(_(\"could not read HEAD's commit message\"));\n@@ -1807,7 +1811,7 @@ static int do_pick_commit(struct repository *r,\n \tif (command == TODO_REWORD)\n \t\tflags |= EDIT_MSG | VERIFY_MSG;\n \telse if (is_fixup(command)) {\n-\t\tif (update_squash_messages(command, commit, opts))\n+\t\tif (update_squash_messages(r, command, commit, opts))\n \t\t\treturn -1;\n \t\tflags |= AMEND_MSG;\n \t\tif (!final_fixup)\n@@ -1877,7 +1881,7 @@ static int do_pick_commit(struct repository *r,\n \t\t      ? _(\"could not revert %s... %s\")\n \t\t      : _(\"could not apply %s... %s\"),\n \t\t      short_commit_name(commit), msg.subject);\n-\t\tprint_advice(res == 1, opts);\n+\t\tprint_advice(r, res == 1, opts);\n \t\trepo_rerere(r, opts->allow_rerere_auto);\n \t\tgoto leave;\n \t}\n@@ -1984,7 +1988,8 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list)\n \treturn todo_list->items + todo_list->nr++;\n }\n \n-static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)\n+static int parse_insn_line(struct repository *r, struct todo_item *item,\n+\t\t\t   const char *bol, char *eol)\n {\n \tstruct object_id commit_oid;\n \tchar *end_of_object_name;\n@@ -2068,11 +2073,12 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)\n \tif (status < 0)\n \t\treturn -1;\n \n-\titem->commit = lookup_commit_reference(the_repository, &commit_oid);\n+\titem->commit = lookup_commit_reference(r, &commit_oid);\n \treturn !item->commit;\n }\n \n-static int parse_insn_buffer(char *buf, struct todo_list *todo_list)\n+static int parse_insn_buffer(struct repository *r, char *buf,\n+\t\t\t     struct todo_list *todo_list)\n {\n \tstruct todo_item *item;\n \tchar *p = buf, *next_p;\n@@ -2088,7 +2094,7 @@ static int parse_insn_buffer(char *buf, struct todo_list *todo_list)\n \n \t\titem = append_new_todo(todo_list);\n \t\titem->offset_in_buf = p - todo_list->buf.buf;\n-\t\tif (parse_insn_line(item, p, eol)) {\n+\t\tif (parse_insn_line(r, item, p, eol)) {\n \t\t\tres = error(_(\"invalid line %d: %.*s\"),\n \t\t\t\ti, (int)(eol - p), p);\n \t\t\titem->command = TODO_NOOP;\n@@ -2149,8 +2155,9 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path)\n \treturn len;\n }\n \n-static int read_populate_todo(struct todo_list *todo_list,\n-\t\t\tstruct replay_opts *opts)\n+static int read_populate_todo(struct repository *r,\n+\t\t\t      struct todo_list *todo_list,\n+\t\t\t      struct replay_opts *opts)\n {\n \tstruct stat st;\n \tconst char *todo_file = get_todo_path(opts);\n@@ -2165,7 +2172,7 @@ static int read_populate_todo(struct todo_list *todo_list,\n \t\treturn error(_(\"could not stat '%s'\"), todo_file);\n \tfill_stat_data(&todo_list->stat, &st);\n \n-\tres = parse_insn_buffer(todo_list->buf.buf, todo_list);\n+\tres = parse_insn_buffer(r, todo_list->buf.buf, todo_list);\n \tif (res) {\n \t\tif (is_rebase_i(opts))\n \t\t\treturn error(_(\"please fix this using \"\n@@ -2196,7 +2203,7 @@ static int read_populate_todo(struct todo_list *todo_list,\n \t\tFILE *f = fopen_or_warn(rebase_path_msgtotal(), \"w\");\n \n \t\tif (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&\n-\t\t\t\t!parse_insn_buffer(done.buf.buf, &done))\n+\t\t    !parse_insn_buffer(r, done.buf.buf, &done))\n \t\t\ttodo_list->done_nr = count_commands(&done);\n \t\telse\n \t\t\ttodo_list->done_nr = 0;\n@@ -2459,12 +2466,12 @@ static int reset_for_rollback(const struct object_id *oid)\n \treturn run_command_v_opt(argv, RUN_GIT_CMD);\n }\n \n-static int rollback_single_pick(void)\n+static int rollback_single_pick(struct repository *r)\n {\n \tstruct object_id head_oid;\n \n-\tif (!file_exists(git_path_cherry_pick_head(the_repository)) &&\n-\t    !file_exists(git_path_revert_head(the_repository)))\n+\tif (!file_exists(git_path_cherry_pick_head(r)) &&\n+\t    !file_exists(git_path_revert_head(r)))\n \t\treturn error(_(\"no cherry-pick or revert in progress\"));\n \tif (read_ref_full(\"HEAD\", 0, &head_oid, NULL))\n \t\treturn error(_(\"cannot resolve HEAD\"));\n@@ -2473,7 +2480,7 @@ static int rollback_single_pick(void)\n \treturn reset_for_rollback(&head_oid);\n }\n \n-int sequencer_rollback(struct replay_opts *opts)\n+int sequencer_rollback(struct repository *r, struct replay_opts *opts)\n {\n \tFILE *f;\n \tstruct object_id oid;\n@@ -2487,7 +2494,7 @@ int sequencer_rollback(struct replay_opts *opts)\n \t\t * If CHERRY_PICK_HEAD or REVERT_HEAD indicates\n \t\t * a single-cherry-pick in progress, abort that.\n \t\t */\n-\t\treturn rollback_single_pick();\n+\t\treturn rollback_single_pick(r);\n \t}\n \tif (!f)\n \t\treturn error_errno(_(\"cannot open '%s'\"), git_path_head_file());\n@@ -3441,7 +3448,7 @@ static int pick_commits(struct repository *r,\n \t\t\t\t\t\t  get_todo_path(opts));\n \t\t\telse if (match_stat_data(&todo_list->stat, &st)) {\n \t\t\t\ttodo_list_release(todo_list);\n-\t\t\t\tif (read_populate_todo(todo_list, opts))\n+\t\t\t\tif (read_populate_todo(r, todo_list, opts))\n \t\t\t\t\tres = -1; /* message was printed */\n \t\t\t\t/* `current` will be incremented below */\n \t\t\t\ttodo_list->current = -1;\n@@ -3601,12 +3608,12 @@ static int pick_commits(struct repository *r,\n \treturn sequencer_remove_state(opts);\n }\n \n-static int continue_single_pick(void)\n+static int continue_single_pick(struct repository *r)\n {\n \tconst char *argv[] = { \"commit\", NULL };\n \n-\tif (!file_exists(git_path_cherry_pick_head(the_repository)) &&\n-\t    !file_exists(git_path_revert_head(the_repository)))\n+\tif (!file_exists(git_path_cherry_pick_head(r)) &&\n+\t    !file_exists(git_path_revert_head(r)))\n \t\treturn error(_(\"no cherry-pick or revert in progress\"));\n \treturn run_command_v_opt(argv, RUN_GIT_CMD);\n }\n@@ -3705,7 +3712,7 @@ static int commit_staged_changes(struct repository *r,\n \t\t\t\tstruct commit *commit;\n \t\t\t\tconst char *path = rebase_path_squash_msg();\n \n-\t\t\t\tif (parse_head(&commit) ||\n+\t\t\t\tif (parse_head(r, &commit) ||\n \t\t\t\t    !(p = get_commit_buffer(commit, NULL)) ||\n \t\t\t\t    write_message(p, strlen(p), path, 0)) {\n \t\t\t\t\tunuse_commit_buffer(commit, p);\n@@ -3760,20 +3767,20 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)\n \tif (read_populate_opts(opts))\n \t\treturn -1;\n \tif (is_rebase_i(opts)) {\n-\t\tif ((res = read_populate_todo(&todo_list, opts)))\n+\t\tif ((res = read_populate_todo(r, &todo_list, opts)))\n \t\t\tgoto release_todo_list;\n \t\tif (commit_staged_changes(r, opts, &todo_list))\n \t\t\treturn -1;\n \t} else if (!file_exists(get_todo_path(opts)))\n-\t\treturn continue_single_pick();\n-\telse if ((res = read_populate_todo(&todo_list, opts)))\n+\t\treturn continue_single_pick(r);\n+\telse if ((res = read_populate_todo(r, &todo_list, opts)))\n \t\tgoto release_todo_list;\n \n \tif (!is_rebase_i(opts)) {\n \t\t/* Verify that the conflict has been resolved */\n \t\tif (file_exists(git_path_cherry_pick_head(r)) ||\n \t\t    file_exists(git_path_revert_head(r))) {\n-\t\t\tres = continue_single_pick();\n+\t\t\tres = continue_single_pick(r);\n \t\t\tif (res)\n \t\t\t\tgoto release_todo_list;\n \t\t}\n@@ -4346,7 +4353,8 @@ int sequencer_make_script(struct repository *r, FILE *out,\n  * Add commands after pick and (series of) squash/fixup commands\n  * in the todo list.\n  */\n-int sequencer_add_exec_commands(const char *commands)\n+int sequencer_add_exec_commands(struct repository *r,\n+\t\t\t\tconst char *commands)\n {\n \tconst char *todo_file = rebase_path_todo();\n \tstruct todo_list todo_list = TODO_LIST_INIT;\n@@ -4357,7 +4365,7 @@ int sequencer_add_exec_commands(const char *commands)\n \tif (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)\n \t\treturn error(_(\"could not read '%s'.\"), todo_file);\n \n-\tif (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {\n+\tif (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {\n \t\ttodo_list_release(&todo_list);\n \t\treturn error(_(\"unusable todo list: '%s'\"), todo_file);\n \t}\n@@ -4402,7 +4410,7 @@ int sequencer_add_exec_commands(const char *commands)\n \treturn i;\n }\n \n-int transform_todos(unsigned flags)\n+int transform_todos(struct repository *r, unsigned flags)\n {\n \tconst char *todo_file = rebase_path_todo();\n \tstruct todo_list todo_list = TODO_LIST_INIT;\n@@ -4413,7 +4421,7 @@ int transform_todos(unsigned flags)\n \tif (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)\n \t\treturn error(_(\"could not read '%s'.\"), todo_file);\n \n-\tif (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {\n+\tif (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {\n \t\ttodo_list_release(&todo_list);\n \t\treturn error(_(\"unusable todo list: '%s'\"), todo_file);\n \t}\n@@ -4486,7 +4494,7 @@ define_commit_slab(commit_seen, unsigned char);\n  * Check if there is an unrecognized command or a\n  * bad SHA-1 in a command.\n  */\n-int check_todo_list(void)\n+int check_todo_list(struct repository *r)\n {\n \tenum check_level check_level = get_missing_commit_check_level();\n \tstruct strbuf todo_file = STRBUF_INIT;\n@@ -4503,7 +4511,7 @@ int check_todo_list(void)\n \t\tgoto leave_check;\n \t}\n \tadvise_to_edit_todo = res =\n-\t\tparse_insn_buffer(todo_list.buf.buf, &todo_list);\n+\t\tparse_insn_buffer(r, todo_list.buf.buf, &todo_list);\n \n \tif (res || check_level == CHECK_IGNORE)\n \t\tgoto leave_check;\n@@ -4522,7 +4530,7 @@ int check_todo_list(void)\n \t\tgoto leave_check;\n \t}\n \tstrbuf_release(&todo_file);\n-\tres = !!parse_insn_buffer(todo_list.buf.buf, &todo_list);\n+\tres = !!parse_insn_buffer(r, todo_list.buf.buf, &todo_list);\n \n \t/* Find commits in git-rebase-todo.backup yet unseen */\n \tfor (i = todo_list.nr - 1; i >= 0; i--) {\n@@ -4586,7 +4594,7 @@ static int rewrite_file(const char *path, const char *buf, size_t len)\n }\n \n /* skip picking commits whose parents are unchanged */\n-int skip_unnecessary_picks(void)\n+int skip_unnecessary_picks(struct repository *r)\n {\n \tconst char *todo_file = rebase_path_todo();\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -4604,7 +4612,7 @@ int skip_unnecessary_picks(void)\n \n \tif (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)\n \t\treturn -1;\n-\tif (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) {\n+\tif (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {\n \t\ttodo_list_release(&todo_list);\n \t\treturn -1;\n \t}\n@@ -4690,7 +4698,7 @@ define_commit_slab(commit_todo_item, struct todo_item *);\n  * message will have to be retrieved from the commit (as the oneline in the\n  * script cannot be trusted) in order to normalize the autosquash arrangement.\n  */\n-int rearrange_squash(void)\n+int rearrange_squash(struct repository *r)\n {\n \tconst char *todo_file = rebase_path_todo();\n \tstruct todo_list todo_list = TODO_LIST_INIT;\n@@ -4701,7 +4709,7 @@ int rearrange_squash(void)\n \n \tif (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)\n \t\treturn -1;\n-\tif (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) {\n+\tif (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {\n \t\ttodo_list_release(&todo_list);\n \t\treturn -1;\n \t}\ndiff --git a/sequencer.h b/sequencer.h\nindex ad151e95c7..1232157da2 100644\n--- a/sequencer.h\n+++ b/sequencer.h\n@@ -68,7 +68,7 @@ void sequencer_init_config(struct replay_opts *opts);\n int sequencer_pick_revisions(struct repository *repo,\n \t\t\t     struct replay_opts *opts);\n int sequencer_continue(struct repository *repo, struct replay_opts *opts);\n-int sequencer_rollback(struct replay_opts *opts);\n+int sequencer_rollback(struct repository *repo, struct replay_opts *opts);\n int sequencer_remove_state(struct replay_opts *opts);\n \n #define TODO_LIST_KEEP_EMPTY (1U << 0)\n@@ -85,11 +85,11 @@ int sequencer_make_script(struct repository *repo, FILE *out,\n \t\t\t  int argc, const char **argv,\n \t\t\t  unsigned flags);\n \n-int sequencer_add_exec_commands(const char *command);\n-int transform_todos(unsigned flags);\n-int check_todo_list(void);\n-int skip_unnecessary_picks(void);\n-int rearrange_squash(void);\n+int sequencer_add_exec_commands(struct repository *repo, const char *command);\n+int transform_todos(struct repository *repo, unsigned flags);\n+int check_todo_list(struct repository *repo);\n+int skip_unnecessary_picks(struct repository *repo);\n+int rearrange_squash(struct repository *repo);\n \n extern const char sign_off_header[];\n \n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360923","messageId":"20181019145237.16079-6-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 05/19] sequencer.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:23Z","receivedAt":"2018-10-19T14:52:55Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Since we're going to pass 'struct repository *' around most of the\ntime instead of 'struct index_state *' because most sequencer.c\noperations need more than just the index, the_repository is replaced\nas well in the functions that now take 'struct repository\n*'. the_repository is still present in this file, but total clean up\nwill be done later. It's not the main focus of this patch.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/commit.c         |   3 +-\n builtin/merge.c          |   2 +-\n builtin/rebase--helper.c |   5 +-\n builtin/revert.c         |   4 +-\n sequencer.c              | 319 ++++++++++++++++++++++-----------------\n sequencer.h              |  15 +-\n 6 files changed, 197 insertions(+), 151 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 379d8c5cdf..f7bbba944d 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1679,7 +1679,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\t\tflags |= SUMMARY_INITIAL_COMMIT;\n \t\tif (author_date_is_interesting())\n \t\t\tflags |= SUMMARY_SHOW_AUTHOR_DATE;\n-\t\tprint_commit_summary(prefix, &oid, flags);\n+\t\tprint_commit_summary(the_repository, prefix,\n+\t\t\t\t     &oid, flags);\n \t}\n \n \tUNLEAK(err);\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 4aa6071598..db22119c93 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -896,7 +896,7 @@ static int suggest_conflicts(void)\n \tfilename = git_path_merge_msg(the_repository);\n \tfp = xfopen(filename, \"a\");\n \n-\tappend_conflicts_hint(&msgbuf);\n+\tappend_conflicts_hint(&the_index, &msgbuf);\n \tfputs(msgbuf.buf, fp);\n \tstrbuf_release(&msgbuf);\n \tfclose(fp);\ndiff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c\nindex f7c2a5fdc8..b66cd8cd41 100644\n--- a/builtin/rebase--helper.c\n+++ b/builtin/rebase--helper.c\n@@ -69,11 +69,12 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)\n \t\t\t  \"--rebase-merges\"));\n \n \tif (command == CONTINUE && argc == 1)\n-\t\treturn !!sequencer_continue(&opts);\n+\t\treturn !!sequencer_continue(the_repository, &opts);\n \tif (command == ABORT && argc == 1)\n \t\treturn !!sequencer_remove_state(&opts);\n \tif (command == MAKE_SCRIPT && argc > 1)\n-\t\treturn !!sequencer_make_script(stdout, argc, argv, flags);\n+\t\treturn !!sequencer_make_script(the_repository, stdout,\n+\t\t\t\t\t       argc, argv, flags);\n \tif ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)\n \t\treturn !!transform_todos(flags);\n \tif (command == CHECK_TODO_LIST && argc == 1)\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex c93393c89b..cd9f068195 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -199,10 +199,10 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)\n \t\treturn ret;\n \t}\n \tif (cmd == 'c')\n-\t\treturn sequencer_continue(opts);\n+\t\treturn sequencer_continue(the_repository, opts);\n \tif (cmd == 'a')\n \t\treturn sequencer_rollback(opts);\n-\treturn sequencer_pick_revisions(opts);\n+\treturn sequencer_pick_revisions(the_repository, opts);\n }\n \n int cmd_revert(int argc, const char **argv, const char *prefix)\ndiff --git a/sequencer.c b/sequencer.c\nindex 90435593a4..6b79359114 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -440,9 +440,9 @@ static struct tree *empty_tree(void)\n \treturn lookup_tree(the_repository, the_repository->hash_algo->empty_tree);\n }\n \n-static int error_dirty_index(struct replay_opts *opts)\n+static int error_dirty_index(struct index_state *istate, struct replay_opts *opts)\n {\n-\tif (read_cache_unmerged())\n+\tif (read_index_unmerged(istate))\n \t\treturn error_resolve_conflict(_(action_name(opts)));\n \n \terror(_(\"your local changes would be overwritten by %s.\"),\n@@ -467,15 +467,18 @@ static void update_abort_safety_file(void)\n \t\twrite_file(git_path_abort_safety_file(), \"%s\", \"\");\n }\n \n-static int fast_forward_to(const struct object_id *to, const struct object_id *from,\n-\t\t\tint unborn, struct replay_opts *opts)\n+static int fast_forward_to(struct repository *r,\n+\t\t\t   const struct object_id *to,\n+\t\t\t   const struct object_id *from,\n+\t\t\t   int unborn,\n+\t\t\t   struct replay_opts *opts)\n {\n \tstruct ref_transaction *transaction;\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct strbuf err = STRBUF_INIT;\n \n-\tread_index(&the_index);\n-\tif (checkout_fast_forward(the_repository, from, to, 1))\n+\tread_index(r->index);\n+\tif (checkout_fast_forward(r, from, to, 1))\n \t\treturn -1; /* the callee should have complained already */\n \n \tstrbuf_addf(&sb, _(\"%s: fast-forward\"), _(action_name(opts)));\n@@ -501,24 +504,26 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f\n \treturn 0;\n }\n \n-void append_conflicts_hint(struct strbuf *msgbuf)\n+void append_conflicts_hint(struct index_state *istate,\n+\t\t\t   struct strbuf *msgbuf)\n {\n \tint i;\n \n \tstrbuf_addch(msgbuf, '\\n');\n \tstrbuf_commented_addf(msgbuf, \"Conflicts:\\n\");\n-\tfor (i = 0; i < active_nr;) {\n-\t\tconst struct cache_entry *ce = active_cache[i++];\n+\tfor (i = 0; i < istate->cache_nr;) {\n+\t\tconst struct cache_entry *ce = istate->cache[i++];\n \t\tif (ce_stage(ce)) {\n \t\t\tstrbuf_commented_addf(msgbuf, \"\\t%s\\n\", ce->name);\n-\t\t\twhile (i < active_nr && !strcmp(ce->name,\n-\t\t\t\t\t\t\tactive_cache[i]->name))\n+\t\t\twhile (i < istate->cache_nr &&\n+\t\t\t       !strcmp(ce->name, istate->cache[i]->name))\n \t\t\t\ti++;\n \t\t}\n \t}\n }\n \n-static int do_recursive_merge(struct commit *base, struct commit *next,\n+static int do_recursive_merge(struct repository *r,\n+\t\t\t      struct commit *base, struct commit *next,\n \t\t\t      const char *base_label, const char *next_label,\n \t\t\t      struct object_id *head, struct strbuf *msgbuf,\n \t\t\t      struct replay_opts *opts)\n@@ -532,7 +537,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,\n \tif (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)\n \t\treturn -1;\n \n-\tread_cache();\n+\tread_index(r->index);\n \n \tinit_merge_options(&o);\n \to.ancestor = base ? base_label : \"(empty tree)\";\n@@ -561,7 +566,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,\n \t\treturn clean;\n \t}\n \n-\tif (write_locked_index(&the_index, &index_lock,\n+\tif (write_locked_index(r->index, &index_lock,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n \t\t/*\n \t\t * TRANSLATORS: %s will be \"revert\", \"cherry-pick\" or\n@@ -571,26 +576,26 @@ static int do_recursive_merge(struct commit *base, struct commit *next,\n \t\t\t_(action_name(opts)));\n \n \tif (!clean)\n-\t\tappend_conflicts_hint(msgbuf);\n+\t\tappend_conflicts_hint(r->index, msgbuf);\n \n \treturn !clean;\n }\n \n-static struct object_id *get_cache_tree_oid(void)\n+static struct object_id *get_cache_tree_oid(struct index_state *istate)\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\tif (cache_tree_update(&the_index, 0)) {\n+\tif (!cache_tree_fully_valid(istate->cache_tree))\n+\t\tif (cache_tree_update(istate, 0)) {\n \t\t\terror(_(\"unable to update cache tree\"));\n \t\t\treturn NULL;\n \t\t}\n \n-\treturn &active_cache_tree->oid;\n+\treturn &istate->cache_tree->oid;\n }\n \n-static int is_index_unchanged(void)\n+static int is_index_unchanged(struct index_state *istate)\n {\n \tstruct object_id head_oid, *cache_tree_oid;\n \tstruct commit *head_commit;\n@@ -611,7 +616,7 @@ static int is_index_unchanged(void)\n \tif (parse_commit(head_commit))\n \t\treturn -1;\n \n-\tif (!(cache_tree_oid = get_cache_tree_oid()))\n+\tif (!(cache_tree_oid = get_cache_tree_oid(istate)))\n \t\treturn -1;\n \n \treturn oideq(cache_tree_oid, get_commit_tree_oid(head_commit));\n@@ -816,7 +821,9 @@ N_(\"you have staged changes in your working tree\\n\"\n  * interactive rebase: in that case, we will want to retain the\n  * author metadata.\n  */\n-static int run_git_commit(const char *defmsg, struct replay_opts *opts,\n+static int run_git_commit(struct repository *r,\n+\t\t\t  const char *defmsg,\n+\t\t\t  struct replay_opts *opts,\n \t\t\t  unsigned int flags)\n {\n \tstruct child_process cmd = CHILD_PROCESS_INIT;\n@@ -839,7 +846,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,\n \t\tif (!defmsg)\n \t\t\tBUG(\"root commit without message\");\n \n-\t\tif (!(cache_tree_oid = get_cache_tree_oid()))\n+\t\tif (!(cache_tree_oid = get_cache_tree_oid(r->index)))\n \t\t\tres = -1;\n \n \t\tif (!res)\n@@ -1066,7 +1073,9 @@ void commit_post_rewrite(const struct commit *old_head,\n \trun_rewrite_hook(&old_head->object.oid, new_head);\n }\n \n-static int run_prepare_commit_msg_hook(struct strbuf *msg, const char *commit)\n+static int run_prepare_commit_msg_hook(struct repository *r,\n+\t\t\t\t       struct strbuf *msg,\n+\t\t\t\t       const char *commit)\n {\n \tstruct argv_array hook_env = ARGV_ARRAY_INIT;\n \tint ret;\n@@ -1076,7 +1085,7 @@ static int run_prepare_commit_msg_hook(struct strbuf *msg, const char *commit)\n \tif (write_message(msg->buf, msg->len, name, 0))\n \t\treturn -1;\n \n-\targv_array_pushf(&hook_env, \"GIT_INDEX_FILE=%s\", get_index_file());\n+\targv_array_pushf(&hook_env, \"GIT_INDEX_FILE=%s\", r->index_file);\n \targv_array_push(&hook_env, \"GIT_EDITOR=:\");\n \tif (commit)\n \t\tret = run_hook_le(hook_env.argv, \"prepare-commit-msg\", name,\n@@ -1132,7 +1141,9 @@ static const char *implicit_ident_advice(void)\n \n }\n \n-void print_commit_summary(const char *prefix, const struct object_id *oid,\n+void print_commit_summary(struct repository *r,\n+\t\t\t  const char *prefix,\n+\t\t\t  const struct object_id *oid,\n \t\t\t  unsigned int flags)\n {\n \tstruct rev_info rev;\n@@ -1143,7 +1154,7 @@ void print_commit_summary(const char *prefix, const struct object_id *oid,\n \tstruct strbuf author_ident = STRBUF_INIT;\n \tstruct strbuf committer_ident = STRBUF_INIT;\n \n-\tcommit = lookup_commit(the_repository, oid);\n+\tcommit = lookup_commit(r, oid);\n \tif (!commit)\n \t\tdie(_(\"couldn't look up newly created commit\"));\n \tif (parse_commit(commit))\n@@ -1176,7 +1187,7 @@ void print_commit_summary(const char *prefix, const struct object_id *oid,\n \tstrbuf_release(&author_ident);\n \tstrbuf_release(&committer_ident);\n \n-\trepo_init_revisions(the_repository, &rev, prefix);\n+\trepo_init_revisions(r, &rev, prefix);\n \tsetup_revisions(0, NULL, &rev, NULL);\n \n \trev.diff = 1;\n@@ -1242,7 +1253,8 @@ static int parse_head(struct commit **head)\n  *   0 - success\n  *   1 - run 'git commit'\n  */\n-static int try_to_commit(struct strbuf *msg, const char *author,\n+static int try_to_commit(struct repository *r,\n+\t\t\t struct strbuf *msg, const char *author,\n \t\t\t struct replay_opts *opts, unsigned int flags,\n \t\t\t struct object_id *oid)\n {\n@@ -1286,7 +1298,7 @@ static int try_to_commit(struct strbuf *msg, const char *author,\n \t\tcommit_list_insert(current_head, &parents);\n \t}\n \n-\tif (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL)) {\n+\tif (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {\n \t\tres = error(_(\"git write-tree failed to write a tree\"));\n \t\tgoto out;\n \t}\n@@ -1299,7 +1311,7 @@ static int try_to_commit(struct strbuf *msg, const char *author,\n \t}\n \n \tif (find_hook(\"prepare-commit-msg\")) {\n-\t\tres = run_prepare_commit_msg_hook(msg, hook_commit);\n+\t\tres = run_prepare_commit_msg_hook(r, msg, hook_commit);\n \t\tif (res)\n \t\t\tgoto out;\n \t\tif (strbuf_read_file(&commit_msg, git_path_commit_editmsg(),\n@@ -1348,7 +1360,8 @@ static int try_to_commit(struct strbuf *msg, const char *author,\n \treturn res;\n }\n \n-static int do_commit(const char *msg_file, const char *author,\n+static int do_commit(struct repository *r,\n+\t\t     const char *msg_file, const char *author,\n \t\t     struct replay_opts *opts, unsigned int flags)\n {\n \tint res = 1;\n@@ -1363,20 +1376,20 @@ static int do_commit(const char *msg_file, const char *author,\n \t\t\t\t\t     \"from '%s'\"),\n \t\t\t\t\t   msg_file);\n \n-\t\tres = try_to_commit(msg_file ? &sb : NULL, author, opts, flags,\n-\t\t\t\t    &oid);\n+\t\tres = try_to_commit(r, msg_file ? &sb : NULL,\n+\t\t\t\t    author, opts, flags, &oid);\n \t\tstrbuf_release(&sb);\n \t\tif (!res) {\n-\t\t\tunlink(git_path_cherry_pick_head(the_repository));\n-\t\t\tunlink(git_path_merge_msg(the_repository));\n+\t\t\tunlink(git_path_cherry_pick_head(r));\n+\t\t\tunlink(git_path_merge_msg(r));\n \t\t\tif (!is_rebase_i(opts))\n-\t\t\t\tprint_commit_summary(NULL, &oid,\n+\t\t\t\tprint_commit_summary(r, NULL, &oid,\n \t\t\t\t\t\tSUMMARY_SHOW_AUTHOR_DATE);\n \t\t\treturn res;\n \t\t}\n \t}\n \tif (res == 1)\n-\t\treturn run_git_commit(msg_file, opts, flags);\n+\t\treturn run_git_commit(r, msg_file, opts, flags);\n \n \treturn res;\n }\n@@ -1404,7 +1417,9 @@ static int is_original_commit_empty(struct commit *commit)\n /*\n  * Do we run \"git commit\" with \"--allow-empty\"?\n  */\n-static int allow_empty(struct replay_opts *opts, struct commit *commit)\n+static int allow_empty(struct repository *r,\n+\t\t       struct replay_opts *opts,\n+\t\t       struct commit *commit)\n {\n \tint index_unchanged, empty_commit;\n \n@@ -1421,7 +1436,7 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit)\n \tif (!opts->allow_empty)\n \t\treturn 0; /* let \"git commit\" barf as necessary */\n \n-\tindex_unchanged = is_index_unchanged();\n+\tindex_unchanged = is_index_unchanged(r->index);\n \tif (index_unchanged < 0)\n \t\treturn index_unchanged;\n \tif (!index_unchanged)\n@@ -1652,11 +1667,14 @@ static void record_in_rewritten(struct object_id *oid,\n \t\tflush_rewritten_pending();\n }\n \n-static int do_pick_commit(enum todo_command command, struct commit *commit,\n-\t\tstruct replay_opts *opts, int final_fixup)\n+static int do_pick_commit(struct repository *r,\n+\t\t\t  enum todo_command command,\n+\t\t\t  struct commit *commit,\n+\t\t\t  struct replay_opts *opts,\n+\t\t\t  int final_fixup)\n {\n \tunsigned int flags = opts->edit ? EDIT_MSG : 0;\n-\tconst char *msg_file = opts->edit ? NULL : git_path_merge_msg(the_repository);\n+\tconst char *msg_file = opts->edit ? NULL : git_path_merge_msg(r);\n \tstruct object_id head;\n \tstruct commit *base, *next, *parent;\n \tconst char *base_label, *next_label;\n@@ -1672,7 +1690,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\t * that represents the \"current\" state for merge-recursive\n \t\t * to work on.\n \t\t */\n-\t\tif (write_index_as_tree(&head, &the_index, get_index_file(), 0, NULL))\n+\t\tif (write_index_as_tree(&head, r->index, r->index_file, 0, NULL))\n \t\t\treturn error(_(\"your index file is unmerged.\"));\n \t} else {\n \t\tunborn = get_oid(\"HEAD\", &head);\n@@ -1687,9 +1705,9 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\t\toidcpy(&head, the_hash_algo->empty_tree);\n \t\tif (index_differs_from(unborn ? empty_tree_oid_hex() : \"HEAD\",\n \t\t\t\t       NULL, 0))\n-\t\t\treturn error_dirty_index(opts);\n+\t\t\treturn error_dirty_index(r->index, opts);\n \t}\n-\tdiscard_cache();\n+\tdiscard_index(r->index);\n \n \tif (!commit->parents)\n \t\tparent = NULL;\n@@ -1725,7 +1743,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t     (!parent && unborn))) {\n \t\tif (is_rebase_i(opts))\n \t\t\twrite_author_script(msg.message);\n-\t\tres = fast_forward_to(&commit->object.oid, &head, unborn,\n+\t\tres = fast_forward_to(r, &commit->object.oid, &head, unborn,\n \t\t\topts);\n \t\tif (res || command != TODO_REWORD)\n \t\t\tgoto leave;\n@@ -1798,12 +1816,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\t\tflags |= CLEANUP_MSG;\n \t\t\tmsg_file = rebase_path_fixup_msg();\n \t\t} else {\n-\t\t\tconst char *dest = git_path_squash_msg(the_repository);\n+\t\t\tconst char *dest = git_path_squash_msg(r);\n \t\t\tunlink(dest);\n \t\t\tif (copy_file(dest, rebase_path_squash_msg(), 0666))\n \t\t\t\treturn error(_(\"could not rename '%s' to '%s'\"),\n \t\t\t\t\t     rebase_path_squash_msg(), dest);\n-\t\t\tunlink(git_path_merge_msg(the_repository));\n+\t\t\tunlink(git_path_merge_msg(r));\n \t\t\tmsg_file = dest;\n \t\t\tflags |= EDIT_MSG;\n \t\t}\n@@ -1815,23 +1833,23 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \tif (is_rebase_i(opts) && write_author_script(msg.message) < 0)\n \t\tres = -1;\n \telse if (!opts->strategy || !strcmp(opts->strategy, \"recursive\") || command == TODO_REVERT) {\n-\t\tres = do_recursive_merge(base, next, base_label, next_label,\n+\t\tres = do_recursive_merge(r, base, next, base_label, next_label,\n \t\t\t\t\t &head, &msgbuf, opts);\n \t\tif (res < 0)\n \t\t\tgoto leave;\n \n \t\tres |= write_message(msgbuf.buf, msgbuf.len,\n-\t\t\t\t     git_path_merge_msg(the_repository), 0);\n+\t\t\t\t     git_path_merge_msg(r), 0);\n \t} else {\n \t\tstruct commit_list *common = NULL;\n \t\tstruct commit_list *remotes = NULL;\n \n \t\tres = write_message(msgbuf.buf, msgbuf.len,\n-\t\t\t\t    git_path_merge_msg(the_repository), 0);\n+\t\t\t\t    git_path_merge_msg(r), 0);\n \n \t\tcommit_list_insert(base, &common);\n \t\tcommit_list_insert(next, &remotes);\n-\t\tres |= try_merge_command(the_repository, opts->strategy,\n+\t\tres |= try_merge_command(r, opts->strategy,\n \t\t\t\t\t opts->xopts_nr, (const char **)opts->xopts,\n \t\t\t\t\tcommon, oid_to_hex(&head), remotes);\n \t\tfree_commit_list(common);\n@@ -1860,11 +1878,11 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\t      : _(\"could not apply %s... %s\"),\n \t\t      short_commit_name(commit), msg.subject);\n \t\tprint_advice(res == 1, opts);\n-\t\trepo_rerere(the_repository, opts->allow_rerere_auto);\n+\t\trepo_rerere(r, opts->allow_rerere_auto);\n \t\tgoto leave;\n \t}\n \n-\tallow = allow_empty(opts, commit);\n+\tallow = allow_empty(r, opts, commit);\n \tif (allow < 0) {\n \t\tres = allow;\n \t\tgoto leave;\n@@ -1873,7 +1891,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \tif (!opts->no_commit) {\n fast_forward_edit:\n \t\tif (author || command == TODO_REVERT || (flags & AMEND_MSG))\n-\t\t\tres = do_commit(msg_file, author, opts, flags);\n+\t\t\tres = do_commit(r, msg_file, author, opts, flags);\n \t\telse\n \t\t\tres = error(_(\"unable to parse commit author\"));\n \t}\n@@ -1909,18 +1927,19 @@ static int prepare_revs(struct replay_opts *opts)\n \treturn 0;\n }\n \n-static int read_and_refresh_cache(struct replay_opts *opts)\n+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_preload(&the_index, NULL, 0) < 0) {\n+\tif (read_index_preload(r->index, NULL, 0) < 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 \t}\n-\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);\n+\trefresh_index(r->index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);\n \tif (index_fd >= 0) {\n-\t\tif (write_locked_index(&the_index, &index_lock,\n+\t\tif (write_locked_index(r->index, &index_lock,\n \t\t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED)) {\n \t\t\treturn error(_(\"git %s: failed to refresh the index\"),\n \t\t\t\t_(action_name(opts)));\n@@ -2583,7 +2602,9 @@ static int save_opts(struct replay_opts *opts)\n \treturn res;\n }\n \n-static int make_patch(struct commit *commit, struct replay_opts *opts)\n+static int make_patch(struct repository *r,\n+\t\t      struct commit *commit,\n+\t\t      struct replay_opts *opts)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct rev_info log_tree_opt;\n@@ -2599,7 +2620,7 @@ static int make_patch(struct commit *commit, struct replay_opts *opts)\n \n \tstrbuf_addf(&buf, \"%s/patch\", get_dir(opts));\n \tmemset(&log_tree_opt, 0, sizeof(log_tree_opt));\n-\trepo_init_revisions(the_repository, &log_tree_opt, NULL);\n+\trepo_init_revisions(r, &log_tree_opt, NULL);\n \tlog_tree_opt.abbrev = 0;\n \tlog_tree_opt.diff = 1;\n \tlog_tree_opt.diffopt.output_format = DIFF_FORMAT_PATCH;\n@@ -2639,17 +2660,19 @@ static int intend_to_amend(void)\n \treturn write_message(p, strlen(p), rebase_path_amend(), 1);\n }\n \n-static int error_with_patch(struct commit *commit,\n-\tconst char *subject, int subject_len,\n-\tstruct replay_opts *opts, int exit_code, int to_amend)\n+static int error_with_patch(struct repository *r,\n+\t\t\t    struct commit *commit,\n+\t\t\t    const char *subject, int subject_len,\n+\t\t\t    struct replay_opts *opts,\n+\t\t\t    int exit_code, int to_amend)\n {\n \tif (commit) {\n-\t\tif (make_patch(commit, opts))\n+\t\tif (make_patch(r, commit, opts))\n \t\t\treturn -1;\n \t} else if (copy_file(rebase_path_message(),\n-\t\t\t     git_path_merge_msg(the_repository), 0666))\n+\t\t\t     git_path_merge_msg(r), 0666))\n \t\treturn error(_(\"unable to copy '%s' to '%s'\"),\n-\t\t\t     git_path_merge_msg(the_repository), rebase_path_message());\n+\t\t\t     git_path_merge_msg(r), rebase_path_message());\n \n \tif (to_amend) {\n \t\tif (intend_to_amend())\n@@ -2680,21 +2703,24 @@ static int error_with_patch(struct commit *commit,\n \treturn exit_code;\n }\n \n-static int error_failed_squash(struct commit *commit,\n-\tstruct replay_opts *opts, int subject_len, const char *subject)\n+static int error_failed_squash(struct repository *r,\n+\t\t\t       struct commit *commit,\n+\t\t\t       struct replay_opts *opts,\n+\t\t\t       int subject_len,\n+\t\t\t       const char *subject)\n {\n \tif (copy_file(rebase_path_message(), rebase_path_squash_msg(), 0666))\n \t\treturn error(_(\"could not copy '%s' to '%s'\"),\n \t\t\trebase_path_squash_msg(), rebase_path_message());\n-\tunlink(git_path_merge_msg(the_repository));\n-\tif (copy_file(git_path_merge_msg(the_repository), rebase_path_message(), 0666))\n+\tunlink(git_path_merge_msg(r));\n+\tif (copy_file(git_path_merge_msg(r), rebase_path_message(), 0666))\n \t\treturn error(_(\"could not copy '%s' to '%s'\"),\n \t\t\t     rebase_path_message(),\n-\t\t\t     git_path_merge_msg(the_repository));\n-\treturn error_with_patch(commit, subject, subject_len, opts, 1, 0);\n+\t\t\t     git_path_merge_msg(r));\n+\treturn error_with_patch(r, commit, subject, subject_len, opts, 1, 0);\n }\n \n-static int do_exec(const char *command_line)\n+static int do_exec(struct repository *r, const char *command_line)\n {\n \tstruct argv_array child_env = ARGV_ARRAY_INIT;\n \tconst char *child_argv[] = { NULL, NULL };\n@@ -2709,10 +2735,10 @@ static int do_exec(const char *command_line)\n \t\t\t\t\t  child_env.argv);\n \n \t/* force re-reading of the cache */\n-\tif (discard_cache() < 0 || read_cache() < 0)\n+\tif (discard_index(r->index) < 0 || read_index(r->index) < 0)\n \t\treturn error(_(\"could not read index\"));\n \n-\tdirty = require_clean_work_tree(the_repository, \"rebase\", NULL, 1, 1);\n+\tdirty = require_clean_work_tree(r, \"rebase\", NULL, 1, 1);\n \n \tif (status) {\n \t\twarning(_(\"execution failed: %s\\n%s\"\n@@ -2778,9 +2804,9 @@ static int safe_append(const char *filename, const char *fmt, ...)\n \treturn 0;\n }\n \n-static int do_label(const char *name, int len)\n+static int do_label(struct repository *r, const char *name, int len)\n {\n-\tstruct ref_store *refs = get_main_ref_store(the_repository);\n+\tstruct ref_store *refs = get_main_ref_store(r);\n \tstruct ref_transaction *transaction;\n \tstruct strbuf ref_name = STRBUF_INIT, err = STRBUF_INIT;\n \tstruct strbuf msg = STRBUF_INIT;\n@@ -2821,7 +2847,9 @@ static int do_label(const char *name, int len)\n static const char *reflog_message(struct replay_opts *opts,\n \tconst char *sub_action, const char *fmt, ...);\n \n-static int do_reset(const char *name, int len, struct replay_opts *opts)\n+static int do_reset(struct repository *r,\n+\t\t    const char *name, int len,\n+\t\t    struct replay_opts *opts)\n {\n \tstruct strbuf ref_name = STRBUF_INIT;\n \tstruct object_id oid;\n@@ -2867,13 +2895,13 @@ static int do_reset(const char *name, int len, struct replay_opts *opts)\n \tmemset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));\n \tsetup_unpack_trees_porcelain(&unpack_tree_opts, \"reset\");\n \tunpack_tree_opts.head_idx = 1;\n-\tunpack_tree_opts.src_index = &the_index;\n-\tunpack_tree_opts.dst_index = &the_index;\n+\tunpack_tree_opts.src_index = r->index;\n+\tunpack_tree_opts.dst_index = r->index;\n \tunpack_tree_opts.fn = oneway_merge;\n \tunpack_tree_opts.merge = 1;\n \tunpack_tree_opts.update = 1;\n \n-\tif (read_cache_unmerged()) {\n+\tif (read_index_unmerged(r->index)) {\n \t\trollback_lock_file(&lock);\n \t\tstrbuf_release(&ref_name);\n \t\treturn error_resolve_conflict(_(action_name(opts)));\n@@ -2895,9 +2923,9 @@ static int do_reset(const char *name, int len, struct replay_opts *opts)\n \t}\n \n \ttree = parse_tree_indirect(&oid);\n-\tprime_cache_tree(&the_index, tree);\n+\tprime_cache_tree(r->index, tree);\n \n-\tif (write_locked_index(&the_index, &lock, COMMIT_LOCK) < 0)\n+\tif (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0)\n \t\tret = error(_(\"could not write index\"));\n \tfree((void *)desc.buffer);\n \n@@ -2930,7 +2958,9 @@ static struct commit *lookup_label(const char *label, int len,\n \treturn commit;\n }\n \n-static int do_merge(struct commit *commit, const char *arg, int arg_len,\n+static int do_merge(struct repository *r,\n+\t\t    struct commit *commit,\n+\t\t    const char *arg, int arg_len,\n \t\t    int flags, struct replay_opts *opts)\n {\n \tint run_commit_flags = (flags & TODO_EDIT_MERGE_MSG) ?\n@@ -2997,7 +3027,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t\t\tret = error(_(\"octopus merge cannot be executed on \"\n \t\t\t\t      \"top of a [new root]\"));\n \t\telse\n-\t\t\tret = fast_forward_to(&to_merge->item->object.oid,\n+\t\t\tret = fast_forward_to(r, &to_merge->item->object.oid,\n \t\t\t\t\t      &head_commit->object.oid, 0,\n \t\t\t\t\t      opts);\n \t\tgoto leave_merge;\n@@ -3016,11 +3046,11 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t\twrite_author_script(message);\n \t\tfind_commit_subject(message, &body);\n \t\tlen = strlen(body);\n-\t\tret = write_message(body, len, git_path_merge_msg(the_repository), 0);\n+\t\tret = write_message(body, len, git_path_merge_msg(r), 0);\n \t\tunuse_commit_buffer(commit, message);\n \t\tif (ret) {\n \t\t\terror_errno(_(\"could not write '%s'\"),\n-\t\t\t\t    git_path_merge_msg(the_repository));\n+\t\t\t\t    git_path_merge_msg(r));\n \t\t\tgoto leave_merge;\n \t\t}\n \t} else {\n@@ -3042,11 +3072,11 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t\t\tlen = buf.len;\n \t\t}\n \n-\t\tret = write_message(p, len, git_path_merge_msg(the_repository), 0);\n+\t\tret = write_message(p, len, git_path_merge_msg(r), 0);\n \t\tstrbuf_release(&buf);\n \t\tif (ret) {\n \t\t\terror_errno(_(\"could not write '%s'\"),\n-\t\t\t\t    git_path_merge_msg(the_repository));\n+\t\t\t\t    git_path_merge_msg(r));\n \t\t\tgoto leave_merge;\n \t\t}\n \t}\n@@ -3082,7 +3112,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \n \tif (can_fast_forward) {\n \t\trollback_lock_file(&lock);\n-\t\tret = fast_forward_to(&commit->object.oid,\n+\t\tret = fast_forward_to(r, &commit->object.oid,\n \t\t\t\t      &head_commit->object.oid, 0, opts);\n \t\tgoto leave_merge;\n \t}\n@@ -3107,7 +3137,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t\targv_array_push(&cmd.args, \"--no-log\");\n \t\targv_array_push(&cmd.args, \"--no-stat\");\n \t\targv_array_push(&cmd.args, \"-F\");\n-\t\targv_array_push(&cmd.args, git_path_merge_msg(the_repository));\n+\t\targv_array_push(&cmd.args, git_path_merge_msg(r));\n \t\tif (opts->gpg_sign)\n \t\t\targv_array_push(&cmd.args, opts->gpg_sign);\n \n@@ -3117,22 +3147,23 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t\t\t\t\toid_to_hex(&j->item->object.oid));\n \n \t\tstrbuf_release(&ref_name);\n-\t\tunlink(git_path_cherry_pick_head(the_repository));\n+\t\tunlink(git_path_cherry_pick_head(r));\n \t\trollback_lock_file(&lock);\n \n \t\trollback_lock_file(&lock);\n \t\tret = run_command(&cmd);\n \n \t\t/* force re-reading of the cache */\n-\t\tif (!ret && (discard_cache() < 0 || read_cache() < 0))\n+\t\tif (!ret && (discard_index(r->index) < 0 ||\n+\t\t\t     read_index(r->index) < 0))\n \t\t\tret = error(_(\"could not read index\"));\n \t\tgoto leave_merge;\n \t}\n \n \tmerge_commit = to_merge->item;\n \twrite_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,\n-\t\t      git_path_merge_head(the_repository), 0);\n-\twrite_message(\"no-ff\", 5, git_path_merge_mode(the_repository), 0);\n+\t\t      git_path_merge_head(r), 0);\n+\twrite_message(\"no-ff\", 5, git_path_merge_mode(r), 0);\n \n \tbases = get_merge_bases(head_commit, merge_commit);\n \tif (bases && oideq(&merge_commit->object.oid,\n@@ -3146,7 +3177,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t\tcommit_list_insert(j->item, &reversed);\n \tfree_commit_list(bases);\n \n-\tread_cache();\n+\tread_index(r->index);\n \tinit_merge_options(&o);\n \to.branch1 = \"HEAD\";\n \to.branch2 = ref_name.buf;\n@@ -3171,23 +3202,23 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t */\n \tret = !ret;\n \n-\tif (active_cache_changed &&\n-\t    write_locked_index(&the_index, &lock, COMMIT_LOCK)) {\n+\tif (r->index->cache_changed &&\n+\t    write_locked_index(r->index, &lock, COMMIT_LOCK)) {\n \t\tret = error(_(\"merge: Unable to write new index file\"));\n \t\tgoto leave_merge;\n \t}\n \n \trollback_lock_file(&lock);\n \tif (ret)\n-\t\trepo_rerere(the_repository, opts->allow_rerere_auto);\n+\t\trepo_rerere(r, opts->allow_rerere_auto);\n \telse\n \t\t/*\n \t\t * In case of problems, we now want to return a positive\n \t\t * value (a negative one would indicate that the `merge`\n \t\t * command needs to be rescheduled).\n \t\t */\n-\t\tret = !!run_git_commit(git_path_merge_msg(the_repository), opts,\n-\t\t\t\t     run_commit_flags);\n+\t\tret = !!run_git_commit(r, git_path_merge_msg(r), opts,\n+\t\t\t\t       run_commit_flags);\n \n leave_merge:\n \tstrbuf_release(&ref_name);\n@@ -3297,7 +3328,9 @@ N_(\"Could not execute the todo command\\n\"\n \"    git rebase --edit-todo\\n\"\n \"    git rebase --continue\\n\");\n \n-static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n+static int pick_commits(struct repository *r,\n+\t\t\tstruct todo_list *todo_list,\n+\t\t\tstruct replay_opts *opts)\n {\n \tint res = 0, reschedule = 0;\n \n@@ -3305,7 +3338,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \tif (opts->allow_ff)\n \t\tassert(!(opts->signoff || opts->no_commit ||\n \t\t\t\topts->record_origin || opts->edit));\n-\tif (read_and_refresh_cache(opts))\n+\tif (read_and_refresh_cache(r, opts))\n \t\treturn -1;\n \n \twhile (todo_list->current < todo_list->nr) {\n@@ -3338,7 +3371,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\t\tsetenv(\"GIT_REFLOG_ACTION\", reflog_message(opts,\n \t\t\t\t\tcommand_to_string(item->command), NULL),\n \t\t\t\t\t1);\n-\t\t\tres = do_pick_commit(item->command, item->commit,\n+\t\t\tres = do_pick_commit(r, item->command, item->commit,\n \t\t\t\t\topts, is_final_fixup(todo_list));\n \t\t\tif (is_rebase_i(opts) && res < 0) {\n \t\t\t\t/* Reschedule */\n@@ -3358,7 +3391,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\t\t\t\t_(\"Stopped at %s...  %.*s\\n\"),\n \t\t\t\t\t\tshort_commit_name(commit),\n \t\t\t\t\t\titem->arg_len, item->arg);\n-\t\t\t\treturn error_with_patch(commit,\n+\t\t\t\treturn error_with_patch(r, commit,\n \t\t\t\t\titem->arg, item->arg_len, opts, res,\n \t\t\t\t\t!res);\n \t\t\t}\n@@ -3368,7 +3401,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\tif (res && is_fixup(item->command)) {\n \t\t\t\tif (res == 1)\n \t\t\t\t\tintend_to_amend();\n-\t\t\t\treturn error_failed_squash(item->commit, opts,\n+\t\t\t\treturn error_failed_squash(r, item->commit, opts,\n \t\t\t\t\titem->arg_len, item->arg);\n \t\t\t} else if (res && is_rebase_i(opts) && item->commit) {\n \t\t\t\tint to_amend = 0;\n@@ -3387,7 +3420,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\t\t      oideq(&opts->squash_onto, &oid))))\n \t\t\t\t\tto_amend = 1;\n \n-\t\t\t\treturn res | error_with_patch(item->commit,\n+\t\t\t\treturn res | error_with_patch(r, item->commit,\n \t\t\t\t\t\titem->arg, item->arg_len, opts,\n \t\t\t\t\t\tres, to_amend);\n \t\t\t}\n@@ -3397,7 +3430,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\tstruct stat st;\n \n \t\t\t*end_of_arg = '\\0';\n-\t\t\tres = do_exec(item->arg);\n+\t\t\tres = do_exec(r, item->arg);\n \t\t\t*end_of_arg = saved;\n \n \t\t\t/* Reread the todo file if it has changed. */\n@@ -3414,13 +3447,13 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\t\ttodo_list->current = -1;\n \t\t\t}\n \t\t} else if (item->command == TODO_LABEL) {\n-\t\t\tif ((res = do_label(item->arg, item->arg_len)))\n+\t\t\tif ((res = do_label(r, item->arg, item->arg_len)))\n \t\t\t\treschedule = 1;\n \t\t} else if (item->command == TODO_RESET) {\n-\t\t\tif ((res = do_reset(item->arg, item->arg_len, opts)))\n+\t\t\tif ((res = do_reset(r, item->arg, item->arg_len, opts)))\n \t\t\t\treschedule = 1;\n \t\t} else if (item->command == TODO_MERGE) {\n-\t\t\tif ((res = do_merge(item->commit,\n+\t\t\tif ((res = do_merge(r, item->commit,\n \t\t\t\t\t    item->arg, item->arg_len,\n \t\t\t\t\t    item->flags, opts)) < 0)\n \t\t\t\treschedule = 1;\n@@ -3429,7 +3462,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\t\t\t\t    peek_command(todo_list, 1));\n \t\t\tif (res > 0)\n \t\t\t\t/* failed with merge conflicts */\n-\t\t\t\treturn error_with_patch(item->commit,\n+\t\t\t\treturn error_with_patch(r, item->commit,\n \t\t\t\t\t\t\titem->arg,\n \t\t\t\t\t\t\titem->arg_len, opts,\n \t\t\t\t\t\t\tres, 0);\n@@ -3445,7 +3478,8 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\tif (save_todo(todo_list, opts))\n \t\t\t\treturn -1;\n \t\t\tif (item->commit)\n-\t\t\t\treturn error_with_patch(item->commit,\n+\t\t\t\treturn error_with_patch(r,\n+\t\t\t\t\t\t\titem->commit,\n \t\t\t\t\t\t\titem->arg,\n \t\t\t\t\t\t\titem->arg_len, opts,\n \t\t\t\t\t\t\tres, 0);\n@@ -3510,7 +3544,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\tstruct object_id orig, head;\n \n \t\t\tmemset(&log_tree_opt, 0, sizeof(log_tree_opt));\n-\t\t\trepo_init_revisions(the_repository, &log_tree_opt, NULL);\n+\t\t\trepo_init_revisions(r, &log_tree_opt, NULL);\n \t\t\tlog_tree_opt.diff = 1;\n \t\t\tlog_tree_opt.diffopt.output_format =\n \t\t\t\tDIFF_FORMAT_DIFFSTAT;\n@@ -3577,16 +3611,17 @@ static int continue_single_pick(void)\n \treturn run_command_v_opt(argv, RUN_GIT_CMD);\n }\n \n-static int commit_staged_changes(struct replay_opts *opts,\n+static int commit_staged_changes(struct repository *r,\n+\t\t\t\t struct replay_opts *opts,\n \t\t\t\t struct todo_list *todo_list)\n {\n \tunsigned int flags = ALLOW_EMPTY | EDIT_MSG;\n \tunsigned int final_fixup = 0, is_clean;\n \n-\tif (has_unstaged_changes(the_repository, 1))\n+\tif (has_unstaged_changes(r, 1))\n \t\treturn error(_(\"cannot rebase: You have unstaged changes.\"));\n \n-\tis_clean = !has_uncommitted_changes(the_repository, 0);\n+\tis_clean = !has_uncommitted_changes(r, 0);\n \n \tif (file_exists(rebase_path_amend())) {\n \t\tstruct strbuf rev = STRBUF_INIT;\n@@ -3686,7 +3721,7 @@ static int commit_staged_changes(struct replay_opts *opts,\n \t}\n \n \tif (is_clean) {\n-\t\tconst char *cherry_pick_head = git_path_cherry_pick_head(the_repository);\n+\t\tconst char *cherry_pick_head = git_path_cherry_pick_head(r);\n \n \t\tif (file_exists(cherry_pick_head) && unlink(cherry_pick_head))\n \t\t\treturn error(_(\"could not remove CHERRY_PICK_HEAD\"));\n@@ -3694,7 +3729,7 @@ static int commit_staged_changes(struct replay_opts *opts,\n \t\t\treturn 0;\n \t}\n \n-\tif (run_git_commit(final_fixup ? NULL : rebase_path_message(),\n+\tif (run_git_commit(r, final_fixup ? NULL : rebase_path_message(),\n \t\t\t   opts, flags))\n \t\treturn error(_(\"could not commit staged changes.\"));\n \tunlink(rebase_path_amend());\n@@ -3714,12 +3749,12 @@ static int commit_staged_changes(struct replay_opts *opts,\n \treturn 0;\n }\n \n-int sequencer_continue(struct replay_opts *opts)\n+int sequencer_continue(struct repository *r, struct replay_opts *opts)\n {\n \tstruct todo_list todo_list = TODO_LIST_INIT;\n \tint res;\n \n-\tif (read_and_refresh_cache(opts))\n+\tif (read_and_refresh_cache(r, opts))\n \t\treturn -1;\n \n \tif (read_populate_opts(opts))\n@@ -3727,7 +3762,7 @@ int sequencer_continue(struct replay_opts *opts)\n \tif (is_rebase_i(opts)) {\n \t\tif ((res = read_populate_todo(&todo_list, opts)))\n \t\t\tgoto release_todo_list;\n-\t\tif (commit_staged_changes(opts, &todo_list))\n+\t\tif (commit_staged_changes(r, opts, &todo_list))\n \t\t\treturn -1;\n \t} else if (!file_exists(get_todo_path(opts)))\n \t\treturn continue_single_pick();\n@@ -3736,14 +3771,14 @@ int sequencer_continue(struct replay_opts *opts)\n \n \tif (!is_rebase_i(opts)) {\n \t\t/* Verify that the conflict has been resolved */\n-\t\tif (file_exists(git_path_cherry_pick_head(the_repository)) ||\n-\t\t    file_exists(git_path_revert_head(the_repository))) {\n+\t\tif (file_exists(git_path_cherry_pick_head(r)) ||\n+\t\t    file_exists(git_path_revert_head(r))) {\n \t\t\tres = continue_single_pick();\n \t\t\tif (res)\n \t\t\t\tgoto release_todo_list;\n \t\t}\n \t\tif (index_differs_from(\"HEAD\", NULL, 0)) {\n-\t\t\tres = error_dirty_index(opts);\n+\t\t\tres = error_dirty_index(r->index, opts);\n \t\t\tgoto release_todo_list;\n \t\t}\n \t\ttodo_list.current++;\n@@ -3757,27 +3792,30 @@ int sequencer_continue(struct replay_opts *opts)\n \t\tstrbuf_release(&buf);\n \t}\n \n-\tres = pick_commits(&todo_list, opts);\n+\tres = pick_commits(r, &todo_list, opts);\n release_todo_list:\n \ttodo_list_release(&todo_list);\n \treturn res;\n }\n \n-static int single_pick(struct commit *cmit, struct replay_opts *opts)\n+static int single_pick(struct repository *r,\n+\t\t       struct commit *cmit,\n+\t\t       struct replay_opts *opts)\n {\n \tsetenv(GIT_REFLOG_ACTION, action_name(opts), 0);\n-\treturn do_pick_commit(opts->action == REPLAY_PICK ?\n+\treturn do_pick_commit(r, opts->action == REPLAY_PICK ?\n \t\tTODO_PICK : TODO_REVERT, cmit, opts, 0);\n }\n \n-int sequencer_pick_revisions(struct replay_opts *opts)\n+int sequencer_pick_revisions(struct repository *r,\n+\t\t\t     struct replay_opts *opts)\n {\n \tstruct todo_list todo_list = TODO_LIST_INIT;\n \tstruct object_id oid;\n \tint i, res;\n \n \tassert(opts->revs);\n-\tif (read_and_refresh_cache(opts))\n+\tif (read_and_refresh_cache(r, opts))\n \t\treturn -1;\n \n \tfor (i = 0; i < opts->revs->pending.nr; i++) {\n@@ -3789,8 +3827,8 @@ int sequencer_pick_revisions(struct replay_opts *opts)\n \t\t\tcontinue;\n \n \t\tif (!get_oid(name, &oid)) {\n-\t\t\tif (!lookup_commit_reference_gently(the_repository, &oid, 1)) {\n-\t\t\t\tenum object_type type = oid_object_info(the_repository,\n+\t\t\tif (!lookup_commit_reference_gently(r, &oid, 1)) {\n+\t\t\t\tenum object_type type = oid_object_info(r,\n \t\t\t\t\t\t\t\t\t&oid,\n \t\t\t\t\t\t\t\t\tNULL);\n \t\t\t\treturn error(_(\"%s: can't cherry-pick a %s\"),\n@@ -3819,7 +3857,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)\n \t\t\treturn error(_(\"empty commit set passed\"));\n \t\tif (get_revision(opts->revs))\n \t\t\tBUG(\"unexpected extra commit from walk\");\n-\t\treturn single_pick(cmit, opts);\n+\t\treturn single_pick(r, cmit, opts);\n \t}\n \n \t/*\n@@ -3838,7 +3876,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)\n \tif (save_opts(opts))\n \t\treturn -1;\n \tupdate_abort_safety_file();\n-\tres = pick_commits(&todo_list, opts);\n+\tres = pick_commits(r, &todo_list, opts);\n \ttodo_list_release(&todo_list);\n \treturn res;\n }\n@@ -4242,7 +4280,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,\n \treturn 0;\n }\n \n-int sequencer_make_script(FILE *out, int argc, const char **argv,\n+int sequencer_make_script(struct repository *r, FILE *out,\n+\t\t\t  int argc, const char **argv,\n \t\t\t  unsigned flags)\n {\n \tchar *format = NULL;\n@@ -4254,7 +4293,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,\n \tconst char *insn = flags & TODO_LIST_ABBREVIATE_CMDS ? \"p\" : \"pick\";\n \tint rebase_merges = flags & TODO_LIST_REBASE_MERGES;\n \n-\trepo_init_revisions(the_repository, &revs, NULL);\n+\trepo_init_revisions(r, &revs, NULL);\n \trevs.verbose_header = 1;\n \tif (!rebase_merges)\n \t\trevs.max_parents = 1;\ndiff --git a/sequencer.h b/sequencer.h\nindex c986bc8251..ad151e95c7 100644\n--- a/sequencer.h\n+++ b/sequencer.h\n@@ -5,6 +5,7 @@\n #include \"strbuf.h\"\n \n struct commit;\n+struct repository;\n \n const char *git_path_commit_editmsg(void);\n const char *git_path_seq_dir(void);\n@@ -64,8 +65,9 @@ struct replay_opts {\n \n /* Call this to setup defaults before parsing command line options */\n void sequencer_init_config(struct replay_opts *opts);\n-int sequencer_pick_revisions(struct replay_opts *opts);\n-int sequencer_continue(struct replay_opts *opts);\n+int sequencer_pick_revisions(struct repository *repo,\n+\t\t\t     struct replay_opts *opts);\n+int sequencer_continue(struct repository *repo, struct replay_opts *opts);\n int sequencer_rollback(struct replay_opts *opts);\n int sequencer_remove_state(struct replay_opts *opts);\n \n@@ -79,7 +81,8 @@ int sequencer_remove_state(struct replay_opts *opts);\n  * commits should be rebased onto the new base, this flag needs to be passed.\n  */\n #define TODO_LIST_REBASE_COUSINS (1U << 4)\n-int sequencer_make_script(FILE *out, int argc, const char **argv,\n+int sequencer_make_script(struct repository *repo, FILE *out,\n+\t\t\t  int argc, const char **argv,\n \t\t\t  unsigned flags);\n \n int sequencer_add_exec_commands(const char *command);\n@@ -98,7 +101,7 @@ extern const char sign_off_header[];\n  */\n void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag);\n \n-void append_conflicts_hint(struct strbuf *msgbuf);\n+void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf);\n int message_is_empty(const struct strbuf *sb,\n \t\t     enum commit_msg_cleanup_mode cleanup_mode);\n int template_untouched(const struct strbuf *sb, const char *template_file,\n@@ -112,6 +115,8 @@ void commit_post_rewrite(const struct commit *current_head,\n \n #define SUMMARY_INITIAL_COMMIT   (1 << 0)\n #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)\n-void print_commit_summary(const char *prefix, const struct object_id *oid,\n+void print_commit_summary(struct repository *repo,\n+\t\t\t  const char *prefix,\n+\t\t\t  const struct object_id *oid,\n \t\t\t  unsigned int flags);\n #endif\n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360924","messageId":"20181019145237.16079-9-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 08/19] notes-merge.c: remove implicit dependency the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:26Z","receivedAt":"2018-10-19T14: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 notes-merge.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/notes-merge.c b/notes-merge.c\nindex c3bee1a87d..b6a998bfd4 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -558,7 +558,7 @@ int notes_merge(struct notes_merge_options *o,\n \telse if (!check_refname_format(o->local_ref, 0) &&\n \t\tis_null_oid(&local_oid))\n \t\tlocal = NULL; /* local_oid == null_oid indicates unborn ref */\n-\telse if (!(local = lookup_commit_reference(the_repository, &local_oid)))\n+\telse if (!(local = lookup_commit_reference(o->repo, &local_oid)))\n \t\tdie(\"Could not parse local commit %s (%s)\",\n \t\t    oid_to_hex(&local_oid), o->local_ref);\n \ttrace_printf(\"\\tlocal commit: %.7s\\n\", oid_to_hex(&local_oid));\n@@ -576,7 +576,7 @@ int notes_merge(struct notes_merge_options *o,\n \t\t\tdie(\"Failed to resolve remote notes ref '%s'\",\n \t\t\t    o->remote_ref);\n \t\t}\n-\t} else if (!(remote = lookup_commit_reference(the_repository, &remote_oid))) {\n+\t} else if (!(remote = lookup_commit_reference(o->repo, &remote_oid))) {\n \t\tdie(\"Could not parse remote commit %s (%s)\",\n \t\t    oid_to_hex(&remote_oid), o->remote_ref);\n \t}\n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360925","messageId":"20181019145237.16079-8-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 07/19] notes-merge.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:25Z","receivedAt":"2018-10-19T14:52:57Z","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/notes.c |  2 +-\n notes-merge.c   | 12 +++++++-----\n notes-merge.h   |  6 +++++-\n 3 files changed, 13 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex c05cd004ab..d8bd01656a 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -808,7 +808,7 @@ static int merge(int argc, const char **argv, const char *prefix)\n \t\tusage_with_options(git_notes_merge_usage, options);\n \t}\n \n-\tinit_notes_merge_options(&o);\n+\tinit_notes_merge_options(&o, the_repository);\n \to.verbosity = verbosity + NOTES_MERGE_VERBOSITY_DEFAULT;\n \n \tif (do_abort)\ndiff --git a/notes-merge.c b/notes-merge.c\nindex bd05d50b05..c3bee1a87d 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -18,11 +18,13 @@ struct notes_merge_pair {\n \tstruct object_id obj, base, local, remote;\n };\n \n-void init_notes_merge_options(struct notes_merge_options *o)\n+void init_notes_merge_options(struct notes_merge_options *o,\n+\t\t\t      struct repository *repo)\n {\n \tmemset(o, 0, sizeof(struct notes_merge_options));\n \tstrbuf_init(&(o->commit_msg), 0);\n \to->verbosity = NOTES_MERGE_VERBOSITY_DEFAULT;\n+\to->repo = repo;\n }\n \n static int path_to_oid(const char *path, struct object_id *oid)\n@@ -127,7 +129,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,\n \ttrace_printf(\"\\tdiff_tree_remote(base = %.7s, remote = %.7s)\\n\",\n \t       oid_to_hex(base), oid_to_hex(remote));\n \n-\trepo_diff_setup(the_repository, &opt);\n+\trepo_diff_setup(o->repo, &opt);\n \topt.flags.recursive = 1;\n \topt.output_format = DIFF_FORMAT_NO_OUTPUT;\n \tdiff_setup_done(&opt);\n@@ -190,7 +192,7 @@ static void diff_tree_local(struct notes_merge_options *o,\n \ttrace_printf(\"\\tdiff_tree_local(len = %i, base = %.7s, local = %.7s)\\n\",\n \t       len, oid_to_hex(base), oid_to_hex(local));\n \n-\trepo_diff_setup(the_repository, &opt);\n+\trepo_diff_setup(o->repo, &opt);\n \topt.flags.recursive = 1;\n \topt.output_format = DIFF_FORMAT_NO_OUTPUT;\n \tdiff_setup_done(&opt);\n@@ -350,7 +352,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,\n \n \tstatus = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,\n \t\t\t  &local, o->local_ref, &remote, o->remote_ref,\n-\t\t\t  &the_index, NULL);\n+\t\t\t  o->repo->index, NULL);\n \n \tfree(base.ptr);\n \tfree(local.ptr);\n@@ -711,7 +713,7 @@ int notes_merge_commit(struct notes_merge_options *o,\n \t\t/* write file as blob, and add to partial_tree */\n \t\tif (stat(path.buf, &st))\n \t\t\tdie_errno(\"Failed to stat '%s'\", path.buf);\n-\t\tif (index_path(&the_index, &blob_oid, path.buf, &st, HASH_WRITE_OBJECT))\n+\t\tif (index_path(o->repo->index, &blob_oid, path.buf, &st, HASH_WRITE_OBJECT))\n \t\t\tdie(\"Failed to write blob object from '%s'\", path.buf);\n \t\tif (add_note(partial_tree, &obj_oid, &blob_oid, NULL))\n \t\t\tdie(\"Failed to add resolved note '%s' to notes tree\",\ndiff --git a/notes-merge.h b/notes-merge.h\nindex 6c74e9385b..fe70cbd5e8 100644\n--- a/notes-merge.h\n+++ b/notes-merge.h\n@@ -7,6 +7,8 @@\n struct commit;\n struct object_id;\n \n+struct repository;\n+\n #define NOTES_MERGE_WORKTREE \"NOTES_MERGE_WORKTREE\"\n \n enum notes_merge_verbosity {\n@@ -15,6 +17,7 @@ enum notes_merge_verbosity {\n };\n \n struct notes_merge_options {\n+\tstruct repository *repo;\n \tconst char *local_ref;\n \tconst char *remote_ref;\n \tstruct strbuf commit_msg;\n@@ -23,7 +26,8 @@ struct notes_merge_options {\n \tunsigned has_worktree:1;\n };\n \n-void init_notes_merge_options(struct notes_merge_options *o);\n+void init_notes_merge_options(struct notes_merge_options *o,\n+\t\t\t      struct repository *repo);\n \n /*\n  * Merge notes from o->remote_ref into o->local_ref\n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360926","messageId":"20181019145237.16079-10-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 09/19] repository.c: replace hold_locked_index() with repo_hold_locked_index()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:27Z","receivedAt":"2018-10-19T14:52:58Z","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       | 8 ++++----\n wt-status.c       | 2 +-\n 11 files changed, 24 insertions(+), 15 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex fdae1d423b..122e6ddf92 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4710,7 +4710,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 15b142d646..dfefe85770 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 59c8a93046..ef2483ce45 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@@ -826,7 +827,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 c0fb83d285..c186812ff2 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3510,7 +3510,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 1df5c16dbc..7ad3330942 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1726,11 +1726,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 5dd1486718..39b5a80d43 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@@ -257,3 +258,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 887e26d45b..13927de7e0 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -702,7 +702,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 2c2ea2b45d..ced05cd73d 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -535,7 +535,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@@ -1935,7 +1935,7 @@ 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+\tint index_fd = repo_hold_locked_index(r, &index_lock, 0);\n \tif (read_index_preload(r->index, NULL, 0) < 0) {\n \t\trollback_lock_file(&index_lock);\n \t\treturn error(_(\"git %s: failed to read the index\"),\n@@ -2866,7 +2866,7 @@ static int do_reset(struct repository *r,\n \tstruct unpack_trees_options unpack_tree_opts;\n \tint ret = 0, i;\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@@ -2981,7 +2981,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 3632276236..da28921772 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -2371,7 +2371,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.19.1.647.g708186aaf9\n\n"},{"id":"360927","messageId":"20181019145237.16079-11-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 10/19] checkout: avoid the_index when possible","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:28Z","receivedAt":"2018-10-19T14:52:59Z","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 acdafc6e4c..38b28c20e2 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.19.1.647.g708186aaf9\n\n"},{"id":"360929","messageId":"20181019145237.16079-13-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 12/19] read-cache.c: replace update_index_if_able with repo_&","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:30Z","receivedAt":"2018-10-19T14:53:00Z","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 cache.h            |  6 ------\n read-cache.c       | 14 ++++++++------\n repository.h       |  6 ++++++\n wt-status.c        |  2 +-\n 7 files changed, 18 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 7eda5e4b7e..d7afaa9ed4 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1392,7 +1392,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 c48c34e866..cff8ec3d65 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/cache.h b/cache.h\nindex d9303ae25f..73bf68d8a5 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -816,12 +816,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 8844f723e9..46e5e4000a 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2661,9 +2661,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@@ -2679,11 +2679,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 da28921772..bdc4c36f93 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -2374,7 +2374,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.19.1.647.g708186aaf9\n\n"},{"id":"360928","messageId":"20181019145237.16079-14-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 13/19] transport.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:31Z","receivedAt":"2018-10-19T14:53:01Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"note, there's still another hidden dependency related to this: even\nthough we pass a repo to transport_push() we still use\nis_bare_repository() which pretty much assumes the_repository (and\nsome other global state).\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/push.c | 3 ++-\n transport.c    | 7 ++++---\n transport.h    | 3 ++-\n 3 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex d09a42062c..efb3e38a8d 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -355,7 +355,8 @@ static int push_with_options(struct transport *transport, struct refspec *rs,\n \n \tif (verbosity > 0)\n \t\tfprintf(stderr, _(\"Pushing to %s\\n\"), transport->url);\n-\terr = transport_push(transport, rs, flags, &reject_reasons);\n+\terr = transport_push(the_repository, transport,\n+\t\t\t     rs, flags, &reject_reasons);\n \tif (err != 0) {\n \t\tfprintf(stderr, \"%s\", push_get_color(PUSH_COLOR_ERROR));\n \t\terror(_(\"failed to push some refs to '%s'\"), transport->url);\ndiff --git a/transport.c b/transport.c\nindex f4ffbd96cb..b86b2b12c6 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -1105,7 +1105,8 @@ static int run_pre_push_hook(struct transport *transport,\n \treturn ret;\n }\n \n-int transport_push(struct transport *transport,\n+int transport_push(struct repository *repo,\n+\t\t   struct transport *transport,\n \t\t   struct refspec *rs, int flags,\n \t\t   unsigned int *reject_reasons)\n {\n@@ -1172,7 +1173,7 @@ int transport_push(struct transport *transport,\n \t\t\t\t\toid_array_append(&commits,\n \t\t\t\t\t\t\t  &ref->new_oid);\n \n-\t\t\tif (!push_unpushed_submodules(&the_index,\n+\t\t\tif (!push_unpushed_submodules(repo->index,\n \t\t\t\t\t\t      &commits,\n \t\t\t\t\t\t      transport->remote,\n \t\t\t\t\t\t      rs,\n@@ -1197,7 +1198,7 @@ int transport_push(struct transport *transport,\n \t\t\t\t\toid_array_append(&commits,\n \t\t\t\t\t\t\t  &ref->new_oid);\n \n-\t\t\tif (find_unpushed_submodules(&the_index,\n+\t\t\tif (find_unpushed_submodules(repo->index,\n \t\t\t\t\t\t     &commits,\n \t\t\t\t\t\t     transport->remote->name,\n \t\t\t\t\t\t     &needs_pushing)) {\ndiff --git a/transport.h b/transport.h\nindex 9baeca2d7a..f2ee7c4f49 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -223,7 +223,8 @@ void transport_set_verbosity(struct transport *transport, int verbosity,\n #define REJECT_FETCH_FIRST     0x08\n #define REJECT_NEEDS_FORCE     0x10\n \n-int transport_push(struct transport *connection,\n+int transport_push(struct repository *repo,\n+\t\t   struct transport *connection,\n \t\t   struct refspec *rs, int flags,\n \t\t   unsigned int * reject_reasons);\n \n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360930","messageId":"20181019145237.16079-12-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 11/19] read-cache.c: kill read_index()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:29Z","receivedAt":"2018-10-19T14:53:02Z","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 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         | 22 +++++++++++-----------\n sha1-name.c         |  6 +++---\n 15 files changed, 46 insertions(+), 47 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 122e6ddf92..f5d507a64f 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4017,7 +4017,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 d84c937780..6e3de62379 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -183,7 +183,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(the_repository);\n \tcommit->object.parsed = 1;\n@@ -265,7 +265,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 3ee9a9d2a9..d2af94500c 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2328,7 +2328,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 f7bbba944d..7eda5e4b7e 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1363,7 +1363,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_preload(&the_index, &s.pathspec, progress_flag);\n+\trepo_read_index_preload(the_repository, &s.pathspec, progress_flag);\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/cache.h b/cache.h\nindex ef2483ce45..d9303ae25f 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@@ -659,16 +659,11 @@ 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 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 c186812ff2..b025c10e31 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3443,7 +3443,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 9e7152ab14..5327c59923 100644\n--- a/preload-index.c\n+++ b/preload-index.c\n@@ -7,6 +7,7 @@\n #include \"fsmonitor.h\"\n #include \"config.h\"\n #include \"progress.h\"\n+#include \"repository.h\"\n \n #ifdef NO_PTHREADS\n static void preload_index(struct index_state *index,\n@@ -153,12 +154,12 @@ static void preload_index(struct index_state *index,\n }\n #endif\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 7ad3330942..8844f723e9 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1726,11 +1726,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@@ -3196,12 +3191,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 13927de7e0..7abf7c8d41 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -558,7 +558,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@@ -592,7 +592,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr)\n \n \tif (setup_rerere(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@@ -1104,7 +1104,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(&merge_rr, RERERE_NOAUTOUPDATE);\ndiff --git a/revision.c b/revision.c\nindex b5108b75ab..3138c11ec5 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1372,7 +1372,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);\n \n \tif (revs->single_worktree)\n@@ -1518,7 +1518,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 ced05cd73d..3620a42649 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -441,9 +441,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@@ -478,7 +478,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@@ -538,7 +538,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@@ -1709,7 +1709,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(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@@ -1936,7 +1936,7 @@ static int read_and_refresh_cache(struct repository *r,\n {\n \tstruct lock_file index_lock = LOCK_INIT;\n \tint index_fd = repo_hold_locked_index(r, &index_lock, 0);\n-\tif (read_index_preload(r->index, NULL, 0) < 0) {\n+\tif (repo_read_index_preload(r, NULL, 0) < 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@@ -2742,7 +2742,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@@ -2908,7 +2908,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@@ -3162,7 +3162,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@@ -3184,7 +3184,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@@ -3785,7 +3785,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(\"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 faa60f69e3..8669ad0b47 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1749,9 +1749,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.19.1.647.g708186aaf9\n\n"},{"id":"360931","messageId":"20181019145237.16079-15-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 14/19] sha1-name.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:32Z","receivedAt":"2018-10-19T14:53:03Z","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 8d97c84725..17faea8846 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -66,7 +66,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@@ -374,7 +375,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 d8508ddf79..9d40b5c073 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -1006,7 +1006,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 061d4fd864..ed28e81a22 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -506,7 +506,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 455f62246d..38d7d8fd74 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -932,7 +932,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 73bf68d8a5..91c092cf76 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1327,7 +1327,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 c0e2bd6a06..a683a75a35 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -59,7 +59,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 3138c11ec5..ebbf382e3f 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1577,8 +1577,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@@ -1712,7 +1712,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@@ -2440,7 +2440,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 8669ad0b47..1465b9f1da 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1539,7 +1539,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@@ -1556,35 +1556,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@@ -1623,7 +1628,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@@ -1636,11 +1642,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@@ -1652,11 +1658,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@@ -1690,7 +1696,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@@ -1749,13 +1756,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@@ -1768,7 +1775,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@@ -1833,12 +1840,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.19.1.647.g708186aaf9\n\n"},{"id":"360932","messageId":"20181019145237.16079-17-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 16/19] merge-recursive.c: remove implicit dependency on the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:34Z","receivedAt":"2018-10-19T14:53:04Z","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 184945ae67..ad0a5b0202 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@@ -420,7 +423,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@@ -1200,9 +1203,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@@ -3286,8 +3289,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@@ -3423,8 +3426,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@@ -3468,7 +3471,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@@ -3481,17 +3484,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@@ -3508,15 +3511,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.19.1.647.g708186aaf9\n\n"},{"id":"360933","messageId":"20181019145237.16079-16-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 15/19] merge-recursive.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:33Z","receivedAt":"2018-10-19T14:53:05Z","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         | 151 +++++++++++++++++++++-----------------\n merge-recursive.h         |   6 +-\n sequencer.c               |   4 +-\n 7 files changed, 94 insertions(+), 75 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex d2af94500c..65e10a5eb3 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1597,7 +1597,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 38b28c20e2..8ecb4c43c7 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 db22119c93..d2d636d979 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -701,7 +701,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 b025c10e31..184945ae67 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -318,22 +318,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@@ -361,7 +363,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@@ -371,16 +373,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@@ -395,12 +397,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@@ -408,16 +411,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@@ -487,17 +490,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@@ -657,7 +660,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@@ -713,13 +716,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@@ -769,7 +773,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@@ -778,12 +783,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@@ -826,7 +831,7 @@ 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 index_state *istate, const char *path)\n {\n \t/*\n \t * This may look like it can be simplified to:\n@@ -845,19 +850,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@@ -917,7 +922,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->repo->index, path))\n \t\treturn err(o, _(\"refusing to lose untracked file at '%s'\"),\n \t\t\t   path);\n \n@@ -967,7 +972,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@@ -1085,7 +1090,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@@ -1096,7 +1101,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@@ -1116,7 +1122,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@@ -1246,7 +1252,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@@ -1380,7 +1387,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->repo->index, 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@@ -1418,8 +1425,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->repo->index, path))) {\n \t\tupdate_path = alt_path = unique_path(o, path, change_branch);\n \t}\n \n@@ -1429,7 +1436,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@@ -1505,7 +1512,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@@ -1567,12 +1574,12 @@ static int handle_file(struct merge_options *o,\n \t\tremove_file(o, 0, rename->path, ren_src_was_dirty);\n \t\tdst_name = unique_path(o, rename->path, cur_branch);\n \t} else {\n-\t\tif (dir_in_way(rename->path, !o->call_depth, 0)) {\n+\t\tif (dir_in_way(o->repo->index, rename->path, !o->call_depth, 0)) {\n \t\t\tdst_name = unique_path(o, rename->path, cur_branch);\n \t\t\toutput(o, 1, _(\"%s is a directory in %s adding as %s instead\"),\n \t\t\t       rename->path, other_branch, dst_name);\n \t\t} else if (!o->call_depth &&\n-\t\t\t   would_lose_untracked(rename->path)) {\n+\t\t\t   would_lose_untracked(o->repo->index, rename->path)) {\n \t\t\tdst_name = unique_path(o, rename->path, cur_branch);\n \t\t\toutput(o, 1, _(\"Refusing to lose untracked file at %s; \"\n \t\t\t\t       \"adding as %s instead\"),\n@@ -1637,14 +1644,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 if (handle_file(o, a, 2, ci) || handle_file(o, b, 3, ci))\n \t\treturn -1;\n \n@@ -1654,6 +1661,7 @@ static int handle_rename_rename_1to2(struct merge_options *o,\n static int handle_rename_rename_2to1(struct merge_options *o,\n \t\t\t\t     struct rename_conflict_info *ci)\n {\n+\tstruct index_state *istate = o->repo->index;\n \t/* Two files, a & b, were renamed to the same thing, c. */\n \tstruct diff_filespec *a = ci->pair1->one;\n \tstruct diff_filespec *b = ci->pair2->one;\n@@ -1672,8 +1680,12 @@ static int handle_rename_rename_2to1(struct merge_options *o,\n \t       a->path, c1->path, ci->branch1,\n \t       b->path, c2->path, ci->branch2);\n \n-\tremove_file(o, 1, a->path, o->call_depth || would_lose_untracked(a->path));\n-\tremove_file(o, 1, b->path, o->call_depth || would_lose_untracked(b->path));\n+\tremove_file(o, 1, a->path,\n+\t\t    (o->call_depth ||\n+\t\t     would_lose_untracked(istate, a->path)));\n+\tremove_file(o, 1, b->path,\n+\t\t    (o->call_depth ||\n+\t\t     would_lose_untracked(istate, b->path)));\n \n \tpath_side_1_desc = xstrfmt(\"%s (was %s)\", path, a->path);\n \tpath_side_2_desc = xstrfmt(\"%s (was %s)\", path, b->path);\n@@ -1706,7 +1718,7 @@ static int handle_rename_rename_2to1(struct merge_options *o,\n \t\tif (was_dirty(o, path))\n \t\t\toutput(o, 1, _(\"Refusing to lose dirty file at %s\"),\n \t\t\t       path);\n-\t\telse if (would_lose_untracked(path))\n+\t\telse if (would_lose_untracked(istate, path))\n \t\t\t/*\n \t\t\t * Only way we get here is if both renames were from\n \t\t\t * a directory rename AND user had an untracked file\n@@ -1757,7 +1769,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@@ -2936,8 +2948,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@@ -3018,7 +3030,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@@ -3051,8 +3063,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@@ -3071,7 +3083,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@@ -3217,7 +3229,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@@ -3228,7 +3240,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@@ -3263,10 +3275,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@@ -3294,7 +3307,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@@ -3309,7 +3322,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@@ -3425,7 +3438,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@@ -3441,9 +3454,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@@ -3510,7 +3523,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@@ -3518,7 +3531,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@@ -3542,10 +3555,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 3620a42649..c5073e0b92 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -540,7 +540,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@@ -3185,7 +3185,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.19.1.647.g708186aaf9\n\n"},{"id":"360934","messageId":"20181019145237.16079-18-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 17/19] read-cache.c: remove the_* from index_has_changes()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:35Z","receivedAt":"2018-10-19T14:53:06Z","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 65e10a5eb3..37b52be7db 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1771,7 +1771,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@@ -1829,7 +1829,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@@ -1883,7 +1883,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 91c092cf76..4b3ec4ff82 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -701,9 +701,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 ad0a5b0202..22b382e85f 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3282,7 +3282,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 46e5e4000a..19389c6f30 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2372,22 +2372,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.19.1.647.g708186aaf9\n\n"},{"id":"360936","messageId":"20181019145237.16079-20-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 19/19] Flip NO_THE_REPOSITORY_COMPATIBILITY_MACROS","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:37Z","receivedAt":"2018-10-19T14:53:08Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Similar to NO_THE_INDEX_COMPATIBILITY_MACROS, this switch is now off\nby default. It remains here just to make it easier to merge in-flight\ntopics where the old functions are still used. Then you can just stick\n\n    #define USE_THE_REPOSITORY_COMPATIBILITY_MACROS\n\nat the beginning of those files.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.h     | 2 +-\n rerere.h   | 2 +-\n revision.h | 2 +-\n 3 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/diff.h b/diff.h\nindex ce5e8a8183..de7cb7018f 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -341,7 +341,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb);\n int git_diff_heuristic_config(const char *var, const char *value, void *cb);\n void init_diff_ui_defaults(void);\n int git_diff_ui_config(const char *var, const char *value, void *cb);\n-#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS\n+#ifdef USE_THE_REPOSITORY_COMPATIBILITY_MACROS\n #define diff_setup(diffopts) repo_diff_setup(the_repository, diffopts)\n #endif\n void repo_diff_setup(struct repository *, struct diff_options *);\ndiff --git a/rerere.h b/rerere.h\nindex 5ad8864b3c..8ddd0b20da 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -24,7 +24,7 @@ struct rerere_id {\n };\n \n int setup_rerere(struct string_list *, int);\n-#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS\n+#ifdef USE_THE_REPOSITORY_COMPATIBILITY_MACROS\n #define rerere(flags) repo_rerere(the_repository, flags)\n #endif\n int repo_rerere(struct repository *, int);\ndiff --git a/revision.h b/revision.h\nindex bc30a3023e..5b6ab10143 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -271,7 +271,7 @@ struct setup_revision_opt {\n \tunsigned revarg_opt;\n };\n \n-#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS\n+#ifdef USE_THE_REPOSITORY_COMPATIBILITY_MACROS\n #define init_revisions(revs, prefix) repo_init_revisions(the_repository, revs, prefix)\n #endif\n void repo_init_revisions(struct repository *r,\n-- \n2.19.1.647.g708186aaf9\n\n"},{"id":"360935","messageId":"20181019145237.16079-19-pclouds@gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"[PATCH 18/19] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-19T14:52:36Z","receivedAt":"2018-10-19T14:53:09Z","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                 | 3 ++-\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/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 52 files changed, 49 insertions(+), 24 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex 60d284796d..e56ffa9112 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 ad49806ebf..72e9765edf 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 37b52be7db..4e36c186fc 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 a443af9ee9..d004343211 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -1001,7 +1001,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 17faea8846..72be3e8065 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 88b86c8d9f..2f820910b7 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 8ecb4c43c7..b1ed49d020 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 8d9a7dc206..7e21380200 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 d7afaa9ed4..9ba55b2653 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 cff8ec3d65..d673ba197d 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 06eb421720..916f14e634 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 9d40b5c073..75543fe458 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 ed28e81a22..04682c02ad 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 7f9919a362..c9ea56a214 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -5,7 +5,6 @@\n  *\n  * Copyright (C) Linus Torvalds, 2005\n  */\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"repository.h\"\n #include \"config.h\"\ndiff --git a/builtin/merge-index.c b/builtin/merge-index.c\nindex c99443b095..38ea6ad6ca 100644\n--- a/builtin/merge-index.c\n+++ b/builtin/merge-index.c\n@@ -1,3 +1,4 @@\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"builtin.h\"\n #include \"run-command.h\"\n \ndiff --git a/builtin/merge-ours.c b/builtin/merge-ours.c\nindex c84c6e05e9..7c4a80ed3b 100644\n--- a/builtin/merge-ours.c\n+++ b/builtin/merge-ours.c\n@@ -7,6 +7,7 @@\n  *\n  * Pretend we resolved the heads, but declare our tree trumps everybody else.\n  */\n+#define USE_THE_INDEX_COMPATIBILITY_MACROS\n #include \"git-compat-util.h\"\n #include \"builtin.h\"\n #include \"diff.h\"\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex 8fc108d305..6fd6586069 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -76,7 +76,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 d2d636d979..eaf5608948 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 b059b86aee..d6f9b749ab 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 9b0fce07ca..61af382d98 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 fbbc98e516..6bbe614b02 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/replace.c b/builtin/replace.c\nindex a58b9c6d13..379e220949 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 6d37a35e2e..1d8f3c6235 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 38d7d8fd74..baa5514038 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 80474c3ff5..972209452e 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 07c10bcb7d..d8a879b19c 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 0ab6784ffe..f0e470a508 100644\n--- a/cache-tree.h\n+++ b/cache-tree.h\n@@ -51,7 +51,7 @@ void prime_cache_tree(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 4b3ec4ff82..2df03a1ab1 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 47c2fca8dc..5e713ddf5f 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 5920f8019b..c1eb62acd6 100644\n--- a/git.c\n+++ b/git.c\n@@ -414,9 +414,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 1fcda73cb3..b0ae38563c 100644\n--- a/name-hash.c\n+++ b/name-hash.c\n@@ -5,7 +5,6 @@\n  *\n  * Copyright (C) 2008 Linus Torvalds\n  */\n-#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n \n struct dir_entry {\ndiff --git a/pathspec.c b/pathspec.c\nindex 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 19389c6f30..7255f453f6 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 39b5a80d43..fca30c1086 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 d9d3046689..4c727d2459 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 e4890566da..6f223f3870 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 51bfac6aa0..dbb62d61aa 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.19.1.647.g708186aaf9\n\n"},{"id":"360961","messageId":"CAGZ79kbQ_QLb_Oa3mg3q2FJUNoLkk_nzqoURHKY1U1i8iUSg4w@mail.gmail.com","threadId":"49616","inReplyTo":"20181019145237.16079-1-pclouds@gmail.com","subject":"Re: [PATCH/WIP 00/19] Kill the_index, final part","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-10-19T17:38:21Z","receivedAt":"2018-10-19T17:38:36Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Fri, Oct 19, 2018 at 7:52 AM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n>\n> Stefan I see you start removing more references of the_repository in\n> another series (haven't really looked at it yet) so this is just heads\n> up so we could coordinate if needed. Still WIP, not really ready for\n> review yet.\n\nI'll take a brief look anyway, otherwise you wouldn't have put in on\na mailing list :-P\n\nYes, coordination would be good; stolee brought up a good point\nregarding testing these changes. Killing of the index in itself can be\njust tested by checking if behavior stays the same, but killing of\nthe_repository is a slightly different beast, as it relates to submodules,\nwhich means any global state that is still around, need to go into\nthe repository struct (we might have missed some there, whereas\nthe index struct has been around for a long time).\n\n> This series removes use of the_index outside builtin/ and t/helper/.\n> The only the_index reference left is in repository.c. The macro\n> NO_THE_REPOSITORY_COMPATIBILITY_MACROS is now flipped to\n> USE_THE_INDEX_COMPATIBILITY_MACROS. \"the_index\" is forbidden by\n> default.\n\nWow, that is really cool. Looking forward for the patches. :-)\n\n> After this I think we can start pushing the_repository outside library\n> code. Then perhaps clean them up in builtin code too and you can\n> finally get rid of it. But I don't think that'll happen in a year's\n> time.\n\nThat sounds realistic.\n\nStefan\n"},{"id":"361920","messageId":"CACsJy8Aff3qkP6PYH9MXPDxjD94XoQSJYeinw+r62E9Zhj-02g@mail.gmail.com","threadId":"49616","inReplyTo":"CAGZ79kbQ_QLb_Oa3mg3q2FJUNoLkk_nzqoURHKY1U1i8iUSg4w@mail.gmail.com","subject":"Re: [PATCH/WIP 00/19] Kill the_index, final part","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-29T16:42:42Z","receivedAt":"2018-10-29T16:43:10Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Oct 19, 2018 at 7:38 PM Stefan Beller <sbeller@google.com> wrote:\n>\n> On Fri, Oct 19, 2018 at 7:52 AM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n> >\n> > Stefan I see you start removing more references of the_repository in\n> > another series (haven't really looked at it yet) so this is just heads\n> > up so we could coordinate if needed. Still WIP, not really ready for\n> > review yet.\n>\n> I'll take a brief look anyway, otherwise you wouldn't have put in on\n> a mailing list :-P\n\nThanks. Just fyi. Since there are still plenty conflicts when merging\nthis with 'pu', I'll just wait until things settle a bit in 'master'\nbefore resending.\n-- \nDuy\n"}]}