{"thread":{"id":"49791","subject":"[PATCH v2 00/22] Kill the_index part 5","startedAt":"2018-11-10T05:49:24Z","lastAt":"2018-11-12T05:53:45Z","messageCount":24,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":22},"messages":[{"id":"362866","messageId":"20181110054910.10568-1-pclouds@gmail.com","threadId":"49791","inReplyTo":null,"subject":"[PATCH v2 00/22] Kill the_index part 5","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:48Z","receivedAt":"2018-11-10T05:49:24Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"(Please ignore v1 which contains unrelated patches)\n\nI lied about part 5 being final. This series contains most of my WIP\nseries [2] except sha1-name.c, read-cache.c and merge-recursive.c\nbecause there will be conflicts on 'pu' so they will be in part 6. At\nleast this only results in two small conflicts in sequencer.c.\n\nI did start pushing the_repository out of library code [1] in the bottom\nhalf of this series. There aren't big surprises except that cache-tree\nAPI now take _both_ struct repository and struct index_state. The\nreason is cache-tree can work on temporary indexes and repo->index is\nabout $GIT_DIR/index.\n\n[1] Stefan and I make a good team. He keeps adding the_repository. I\nkeep removing. We both hold hands leading commit counts (with Brian\njust a bit behind frantically replacing sha1 with oid to keep up).\nMeanwhile Junio is crying in the corner because of too many conflicts.\n:-D\n\n[2] https://public-inbox.org/git/20181019145237.16079-1-pclouds@gmail.com/\n\nNguyễn Thái Ngọc Duy (22):\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: reduce the_repository references\n  notes-merge.c: remove implicit dependency on the_index\n  notes-merge.c: remove implicit dependency the_repository\n  transport.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  blame.c: remove implicit dependency the_repository\n  bisect.c: remove the_repository reference\n  branch.c: remove the_repository reference\n  bundle.c: remove the_repository references\n  cache-tree.c: remove the_repository references\n  delta-islands.c: remove the_repository references\n  diff-lib.c: remove the_repository references\n  line-log.c: remove the_repository reference\n  notes-cache.c: remove the_repository references\n  pack-check.c: remove the_repository references\n  pack-*.c: remove the_repository references\n  rerere.c: remove the_repository references\n  rebase-interactive.c: remove the_repository references\n\n bisect.c                      |  48 ++--\n bisect.h                      |   5 +-\n blame.c                       |  39 +--\n branch.c                      |  21 +-\n branch.h                      |   8 +-\n builtin/am.c                  |   4 +-\n builtin/bisect--helper.c      |   2 +-\n builtin/branch.c              |   6 +-\n builtin/bundle.c              |   7 +-\n builtin/checkout.c            |   5 +-\n builtin/commit.c              |   8 +-\n builtin/fsck.c                |   3 +-\n builtin/merge-ours.c          |   2 +-\n builtin/merge.c               |   2 +-\n builtin/notes.c               |   2 +-\n builtin/pack-objects.c        |   6 +-\n builtin/pull.c                |   3 +-\n builtin/push.c                |   3 +-\n builtin/read-tree.c           |   4 +-\n builtin/rebase--interactive.c |  19 +-\n builtin/rebase.c              |  13 +-\n builtin/rerere.c              |  10 +-\n builtin/reset.c               |   4 +-\n builtin/revert.c              |   8 +-\n bundle.c                      |  26 +-\n bundle.h                      |   9 +-\n cache-tree.c                  |  26 +-\n cache-tree.h                  |   4 +-\n combine-diff.c                |   2 +-\n delta-islands.c               |  24 +-\n delta-islands.h               |   9 +-\n diff-lib.c                    |   7 +-\n diff.c                        |  12 +-\n diff.h                        |   5 +-\n diffcore-pickaxe.c            |   4 +-\n grep.c                        |   2 +-\n line-log.c                    |   2 +-\n list-objects-filter.c         |  10 +-\n list-objects-filter.h         |   2 +\n list-objects.c                |  13 +-\n notes-cache.c                 |  12 +-\n notes-cache.h                 |   6 +-\n notes-merge.c                 |  16 +-\n notes-merge.h                 |   5 +-\n pack-bitmap-write.c           |   6 +-\n pack-bitmap.c                 |  13 +-\n pack-bitmap.h                 |   3 +-\n pack-check.c                  |   9 +-\n pack-objects.c                |   6 +-\n pack-objects.h                |   5 +-\n pack.h                        |   4 +-\n read-cache.c                  |   2 +-\n rebase-interactive.c          |   6 +-\n rebase-interactive.h          |   5 +-\n ref-filter.c                  |   2 +-\n rerere.c                      |  26 +-\n rerere.h                      |   6 +-\n sequencer.c                   | 453 +++++++++++++++++++---------------\n sequencer.h                   |  27 +-\n transport.c                   |   9 +-\n transport.h                   |   3 +-\n unpack-trees.c                |   2 +-\n userdiff.c                    |   5 +-\n userdiff.h                    |   4 +-\n wt-status.c                   |  94 ++++---\n wt-status.h                   |  21 +-\n 66 files changed, 650 insertions(+), 489 deletions(-)\n\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362867","messageId":"20181110054910.10568-2-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 01/22] wt-status.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:49Z","receivedAt":"2018-11-10T05:49:26Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/commit.c |  2 +-\n builtin/pull.c   |  3 +-\n builtin/rebase.c |  7 +++--\n sequencer.c      |  8 ++---\n wt-status.c      | 76 +++++++++++++++++++++++++++---------------------\n wt-status.h      | 17 +++++++----\n 6 files changed, 66 insertions(+), 47 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 074bd9a551..6637a928a7 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(the_repository, s);\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 c21aa276f1..6026ce1a69 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/builtin/rebase.c b/builtin/rebase.c\nindex 0ee06aa363..b9eb958454 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -983,7 +983,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\t\t\t     &lock_file);\n \t\trollback_lock_file(&lock_file);\n \n-\t\tif (has_unstaged_changes(1)) {\n+\t\tif (has_unstaged_changes(the_repository, 1)) {\n \t\t\tputs(_(\"You must edit all merge conflicts and then\\n\"\n \t\t\t       \"mark them as resolved using git add\"));\n \t\t\texit(1);\n@@ -1351,7 +1351,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\tupdate_index_if_able(&the_index, &lock_file);\n \t\trollback_lock_file(&lock_file);\n \n-\t\tif (has_unstaged_changes(1) || has_uncommitted_changes(1)) {\n+\t\tif (has_unstaged_changes(the_repository, 1) ||\n+\t\t    has_uncommitted_changes(the_repository, 1)) {\n \t\t\tconst char *autostash =\n \t\t\t\tstate_dir_path(\"autostash\", &options);\n \t\t\tstruct child_process stash = CHILD_PROCESS_INIT;\n@@ -1397,7 +1398,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tif (require_clean_work_tree(\"rebase\",\n+\tif (require_clean_work_tree(the_repository, \"rebase\",\n \t\t\t\t    _(\"Please commit or stash them.\"), 1, 1)) {\n \t\tret = 1;\n \t\tgoto cleanup;\ndiff --git a/sequencer.c b/sequencer.c\nindex 9e1ab3a2a7..0b8f18fd36 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -2773,7 +2773,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@@ -3714,10 +3714,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;\n@@ -4847,7 +4847,7 @@ int complete_action(struct replay_opts *opts, unsigned flags,\n \tif (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head))\n \t\treturn -1;\n ;\n-\tif (require_clean_work_tree(\"rebase\", \"\", 1, 1))\n+\tif (require_clean_work_tree(the_repository, \"rebase\", \"\", 1, 1))\n \t\treturn -1;\n \n \treturn sequencer_continue(opts);\ndiff --git a/wt-status.c b/wt-status.c\nindex 187568a112..6d401b2c24 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -119,9 +119,10 @@ 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 repository *r, struct wt_status *s)\n {\n \tmemset(s, 0, sizeof(*s));\n+\ts->repo = r;\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 +495,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 +567,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 +587,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 +612,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 +645,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 +687,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 +702,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 +1013,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 +1330,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 +2139,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 +2178,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 +2307,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 +2326,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 +2346,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 +2359,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..8375e816fb 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 repository *r, struct wt_status *s);\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.1231.g84aef82467\n\n"},{"id":"362868","messageId":"20181110054910.10568-4-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 03/22] list-objects-filter.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:51Z","receivedAt":"2018-11-10T05:49:26Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"While at there, since we have access to struct repository now,\neliminate the only the_repository reference in this file.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n list-objects-filter.c | 10 +++++++---\n list-objects-filter.h |  2 ++\n list-objects.c        |  9 ++++++---\n 3 files changed, 15 insertions(+), 6 deletions(-)\n\ndiff --git a/list-objects-filter.c b/list-objects-filter.c\nindex 765f3df3b0..a62624a1ce 100644\n--- a/list-objects-filter.c\n+++ b/list-objects-filter.c\n@@ -34,6 +34,7 @@ struct filter_blobs_none_data {\n };\n \n static enum list_objects_filter_result filter_blobs_none(\n+\tstruct repository *r,\n \tenum list_objects_filter_situation filter_situation,\n \tstruct object *obj,\n \tconst char *pathname,\n@@ -88,6 +89,7 @@ struct filter_trees_none_data {\n };\n \n static enum list_objects_filter_result filter_trees_none(\n+\tstruct repository *r,\n \tenum list_objects_filter_situation filter_situation,\n \tstruct object *obj,\n \tconst char *pathname,\n@@ -144,6 +146,7 @@ struct filter_blobs_limit_data {\n };\n \n static enum list_objects_filter_result filter_blobs_limit(\n+\tstruct repository *r,\n \tenum list_objects_filter_situation filter_situation,\n \tstruct object *obj,\n \tconst char *pathname,\n@@ -171,7 +174,7 @@ static enum list_objects_filter_result filter_blobs_limit(\n \t\tassert(obj->type == OBJ_BLOB);\n \t\tassert((obj->flags & SEEN) == 0);\n \n-\t\tt = oid_object_info(the_repository, &obj->oid, &object_length);\n+\t\tt = oid_object_info(r, &obj->oid, &object_length);\n \t\tif (t != OBJ_BLOB) { /* probably OBJ_NONE */\n \t\t\t/*\n \t\t\t * We DO NOT have the blob locally, so we cannot\n@@ -249,6 +252,7 @@ struct filter_sparse_data {\n };\n \n static enum list_objects_filter_result filter_sparse(\n+\tstruct repository *r,\n \tenum list_objects_filter_situation filter_situation,\n \tstruct object *obj,\n \tconst char *pathname,\n@@ -268,7 +272,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    r->index);\n \t\tif (val < 0)\n \t\t\tval = filter_data->array_frame[filter_data->nr].defval;\n \n@@ -331,7 +335,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    r->index);\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 52b4a84da9..1d45a4ad57 100644\n--- a/list-objects-filter.h\n+++ b/list-objects-filter.h\n@@ -4,6 +4,7 @@\n struct list_objects_filter_options;\n struct object;\n struct oidset;\n+struct repository;\n \n /*\n  * During list-object traversal we allow certain objects to be\n@@ -60,6 +61,7 @@ enum list_objects_filter_situation {\n };\n \n typedef enum list_objects_filter_result (*filter_object_fn)(\n+\tstruct repository *r,\n \tenum list_objects_filter_situation filter_situation,\n \tstruct object *obj,\n \tconst char *pathname,\ndiff --git a/list-objects.c b/list-objects.c\nindex c41cc80db5..0cfd646026 100644\n--- a/list-objects.c\n+++ b/list-objects.c\n@@ -55,7 +55,8 @@ static void process_blob(struct traversal_context *ctx,\n \tpathlen = path->len;\n \tstrbuf_addstr(path, name);\n \tif ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn)\n-\t\tr = ctx->filter_fn(LOFS_BLOB, obj,\n+\t\tr = ctx->filter_fn(ctx->revs->repo,\n+\t\t\t\t   LOFS_BLOB, obj,\n \t\t\t\t   path->buf, &path->buf[pathlen],\n \t\t\t\t   ctx->filter_data);\n \tif (r & LOFR_MARK_SEEN)\n@@ -175,7 +176,8 @@ static void process_tree(struct traversal_context *ctx,\n \n \tstrbuf_addstr(base, name);\n \tif ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn)\n-\t\tr = ctx->filter_fn(LOFS_BEGIN_TREE, obj,\n+\t\tr = ctx->filter_fn(ctx->revs->repo,\n+\t\t\t\t   LOFS_BEGIN_TREE, obj,\n \t\t\t\t   base->buf, &base->buf[baselen],\n \t\t\t\t   ctx->filter_data);\n \tif (r & LOFR_MARK_SEEN)\n@@ -191,7 +193,8 @@ static void process_tree(struct traversal_context *ctx,\n \t\tprocess_tree_contents(ctx, tree, base);\n \n \tif ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn) {\n-\t\tr = ctx->filter_fn(LOFS_END_TREE, obj,\n+\t\tr = ctx->filter_fn(ctx->revs->repo,\n+\t\t\t\t   LOFS_END_TREE, obj,\n \t\t\t\t   base->buf, &base->buf[baselen],\n \t\t\t\t   ctx->filter_data);\n \t\tif (r & LOFR_MARK_SEEN)\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362869","messageId":"20181110054910.10568-5-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 04/22] list-objects.c: reduce the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:52Z","receivedAt":"2018-11-10T05:49:28Z","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 | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/list-objects.c b/list-objects.c\nindex 0cfd646026..cf7f25bed3 100644\n--- a/list-objects.c\n+++ b/list-objects.c\n@@ -123,7 +123,7 @@ static void process_tree_contents(struct traversal_context *ctx,\n \t\t}\n \n \t\tif (S_ISDIR(entry.mode)) {\n-\t\t\tstruct tree *t = lookup_tree(the_repository, entry.oid);\n+\t\t\tstruct tree *t = lookup_tree(ctx->revs->repo, entry.oid);\n \t\t\tt->object.flags |= NOT_USER_GIVEN;\n \t\t\tprocess_tree(ctx, t, base, entry.path);\n \t\t}\n@@ -131,7 +131,7 @@ static void process_tree_contents(struct traversal_context *ctx,\n \t\t\tprocess_gitlink(ctx, entry.oid->hash,\n \t\t\t\t\tbase, entry.path);\n \t\telse {\n-\t\t\tstruct blob *b = lookup_blob(the_repository, entry.oid);\n+\t\t\tstruct blob *b = lookup_blob(ctx->revs->repo, entry.oid);\n \t\t\tb->object.flags |= NOT_USER_GIVEN;\n \t\t\tprocess_blob(ctx, b, base, entry.path);\n \t\t}\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362870","messageId":"20181110054910.10568-6-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 05/22] notes-merge.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:53Z","receivedAt":"2018-11-10T05:49:29Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/notes.c |  2 +-\n notes-merge.c   | 12 +++++++-----\n notes-merge.h   |  5 ++++-\n 3 files changed, 12 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex c05cd004ab..15a6c78855 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(the_repository, &o);\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..0c22f09b28 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 repository *r,\n+\t\t\t      struct notes_merge_options *o)\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 = r;\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..99f9c709c5 100644\n--- a/notes-merge.h\n+++ b/notes-merge.h\n@@ -6,6 +6,7 @@\n \n struct commit;\n struct object_id;\n+struct repository;\n \n #define NOTES_MERGE_WORKTREE \"NOTES_MERGE_WORKTREE\"\n \n@@ -15,6 +16,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 +25,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 repository *r,\n+\t\t\t      struct notes_merge_options *o);\n \n /*\n  * Merge notes from o->remote_ref into o->local_ref\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362871","messageId":"20181110054910.10568-7-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 06/22] notes-merge.c: remove implicit dependency the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:54Z","receivedAt":"2018-11-10T05:49:30Z","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 0c22f09b28..72688d301b 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.1231.g84aef82467\n\n"},{"id":"362872","messageId":"20181110054910.10568-8-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 07/22] transport.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:55Z","receivedAt":"2018-11-10T05:49:32Z","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 5a74b609ff..71f663743f 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 *r,\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_repository,\n+\t\t\tif (!push_unpushed_submodules(r,\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_repository,\n+\t\t\tif (find_unpushed_submodules(r,\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.1231.g84aef82467\n\n"},{"id":"362873","messageId":"20181110054910.10568-9-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 08/22] sequencer.c: remove implicit dependency on the_index","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:56Z","receivedAt":"2018-11-10T05:49:34Z","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--interactive.c |   4 +-\n builtin/revert.c              |   4 +-\n sequencer.c                   | 321 +++++++++++++++++++---------------\n sequencer.h                   |  15 +-\n 6 files changed, 197 insertions(+), 152 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 6637a928a7..e89bf35634 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--interactive.c b/builtin/rebase--interactive.c\nindex a2ab68ed06..b7ce48a1ec 100644\n--- a/builtin/rebase--interactive.c\n+++ b/builtin/rebase--interactive.c\n@@ -105,7 +105,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,\n \tif (restrict_revision)\n \t\targv_array_push(&make_script_args, restrict_revision);\n \n-\tret = sequencer_make_script(todo_list,\n+\tret = sequencer_make_script(the_repository, todo_list,\n \t\t\t\t    make_script_args.argc, make_script_args.argv,\n \t\t\t\t    flags);\n \tfclose(todo_list);\n@@ -235,7 +235,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)\n \t\trerere_clear(&merge_rr);\n \t\t/* fallthrough */\n \tcase CONTINUE:\n-\t\tret = sequencer_continue(&opts);\n+\t\tret = sequencer_continue(the_repository, &opts);\n \t\tbreak;\n \t}\n \tcase EDIT_TODO:\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 0b8f18fd36..6cf3f65b0c 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -445,9 +445,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@@ -472,15 +472,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@@ -506,24 +509,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@@ -537,7 +542,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@@ -566,7 +571,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@@ -576,26 +581,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@@ -616,7 +621,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@@ -838,7 +843,9 @@ static int run_command_silent_on_success(struct child_process *cmd)\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@@ -861,7 +868,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@@ -1070,7 +1077,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@@ -1080,7 +1089,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@@ -1136,7 +1145,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@@ -1147,7 +1158,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@@ -1180,7 +1191,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@@ -1246,7 +1257,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@@ -1290,7 +1302,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@@ -1303,7 +1315,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@@ -1352,7 +1364,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@@ -1367,20 +1380,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@@ -1408,7 +1421,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@@ -1425,7 +1440,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@@ -1658,11 +1673,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@@ -1678,7 +1696,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@@ -1693,9 +1711,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@@ -1731,7 +1749,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@@ -1804,12 +1822,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@@ -1821,23 +1839,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@@ -1866,11 +1884,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@@ -1879,7 +1897,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@@ -1915,18 +1933,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@@ -2644,7 +2663,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@@ -2660,7 +2681,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@@ -2700,17 +2721,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@@ -2741,21 +2764,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@@ -2770,10 +2796,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@@ -2839,9 +2865,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@@ -2882,7 +2908,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@@ -2928,13 +2956,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@@ -2956,9 +2984,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@@ -2991,7 +3019,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@@ -3058,7 +3088,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@@ -3077,11 +3107,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@@ -3103,11 +3133,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@@ -3143,7 +3173,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@@ -3168,7 +3198,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@@ -3178,22 +3208,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@@ -3207,7 +3238,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@@ -3232,23 +3263,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@@ -3425,7 +3456,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@@ -3433,7 +3466,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@@ -3469,7 +3502,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@@ -3489,7 +3522,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@@ -3499,7 +3532,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@@ -3518,7 +3551,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@@ -3528,7 +3561,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@@ -3545,13 +3578,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@@ -3560,7 +3593,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@@ -3576,7 +3609,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@@ -3641,7 +3675,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@@ -3708,16 +3742,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@@ -3817,7 +3852,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@@ -3825,7 +3860,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@@ -3845,12 +3880,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@@ -3858,7 +3893,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@@ -3867,14 +3902,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@@ -3888,27 +3923,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@@ -3920,8 +3958,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@@ -3950,7 +3988,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@@ -3969,7 +4007,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@@ -4373,7 +4411,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@@ -4385,7 +4424,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;\n@@ -4850,7 +4889,7 @@ int complete_action(struct replay_opts *opts, unsigned flags,\n \tif (require_clean_work_tree(the_repository, \"rebase\", \"\", 1, 1))\n \t\treturn -1;\n \n-\treturn sequencer_continue(opts);\n+\treturn sequencer_continue(the_repository, opts);\n }\n \n struct subject2item_entry {\ndiff --git a/sequencer.h b/sequencer.h\nindex 660cff5050..ba86515ad6 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@@ -74,8 +75,9 @@ int write_message(const void *buf, size_t len, const char *filename,\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@@ -89,7 +91,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@@ -112,7 +115,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@@ -128,7 +131,9 @@ int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit);\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 \n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362874","messageId":"20181110054910.10568-10-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 09/22] sequencer.c: remove implicit dependency on the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:57Z","receivedAt":"2018-11-10T05:49:35Z","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--interactive.c |  11 +--\n builtin/revert.c              |   2 +-\n rebase-interactive.c          |   4 +-\n sequencer.c                   | 134 ++++++++++++++++++----------------\n sequencer.h                   |  12 +--\n 5 files changed, 86 insertions(+), 77 deletions(-)\n\ndiff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c\nindex b7ce48a1ec..d867050fd2 100644\n--- a/builtin/rebase--interactive.c\n+++ b/builtin/rebase--interactive.c\n@@ -114,7 +114,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,\n \t\terror(_(\"could not generate todo list\"));\n \telse {\n \t\tdiscard_cache();\n-\t\tret = complete_action(opts, flags, shortrevisions, onto_name, onto,\n+\t\tret = complete_action(the_repository, opts, flags,\n+\t\t\t\t      shortrevisions, onto_name, onto,\n \t\t\t\t      head_hash, cmd, autosquash);\n \t}\n \n@@ -252,16 +253,16 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)\n \t}\n \tcase SHORTEN_OIDS:\n \tcase EXPAND_OIDS:\n-\t\tret = transform_todos(flags);\n+\t\tret = transform_todos(the_repository, flags);\n \t\tbreak;\n \tcase CHECK_TODO_LIST:\n-\t\tret = check_todo_list();\n+\t\tret = check_todo_list(the_repository);\n \t\tbreak;\n \tcase REARRANGE_SQUASH:\n-\t\tret = rearrange_squash();\n+\t\tret = rearrange_squash(the_repository);\n \t\tbreak;\n \tcase ADD_EXEC:\n-\t\tret = sequencer_add_exec_commands(cmd);\n+\t\tret = sequencer_add_exec_commands(the_repository, cmd);\n \t\tbreak;\n \tdefault:\n \t\tBUG(\"invalid command '%d'\", command);\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/rebase-interactive.c b/rebase-interactive.c\nindex 78f3263fc1..3cc19283ff 100644\n--- a/rebase-interactive.c\n+++ b/rebase-interactive.c\n@@ -69,7 +69,7 @@ int edit_todo_list(unsigned flags)\n \n \tstrbuf_release(&buf);\n \n-\ttransform_todos(flags | TODO_LIST_SHORTEN_IDS);\n+\ttransform_todos(the_repository, flags | TODO_LIST_SHORTEN_IDS);\n \n \tif (strbuf_read_file(&buf, todo_file, 0) < 0)\n \t\treturn error_errno(_(\"could not read '%s'.\"), todo_file);\n@@ -85,7 +85,7 @@ int edit_todo_list(unsigned flags)\n \tif (launch_sequence_editor(todo_file, NULL, NULL))\n \t\treturn -1;\n \n-\ttransform_todos(flags & ~(TODO_LIST_SHORTEN_IDS));\n+\ttransform_todos(the_repository, flags & ~(TODO_LIST_SHORTEN_IDS));\n \n \treturn 0;\n }\ndiff --git a/sequencer.c b/sequencer.c\nindex 6cf3f65b0c..111cb747d6 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -356,7 +356,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@@ -367,7 +368,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@@ -440,9 +441,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@@ -553,8 +554,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@@ -600,15 +601,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@@ -1225,7 +1227,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@@ -1233,7 +1235,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@@ -1273,7 +1275,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@@ -1440,7 +1442,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@@ -1544,8 +1546,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@@ -1574,7 +1578,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@@ -1813,7 +1817,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@@ -1883,7 +1887,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@@ -1990,7 +1994,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@@ -2075,11 +2080,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@@ -2095,7 +2101,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@@ -2156,8 +2162,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@@ -2172,7 +2179,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@@ -2203,7 +2210,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@@ -2520,12 +2527,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@@ -2534,7 +2541,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@@ -2548,7 +2555,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@@ -3427,14 +3434,14 @@ static int checkout_onto(struct replay_opts *opts,\n \treturn update_ref(NULL, \"ORIG_HEAD\", &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR);\n }\n \n-static int stopped_at_head(void)\n+static int stopped_at_head(struct repository *r)\n {\n \tstruct object_id head;\n \tstruct commit *commit;\n \tstruct commit_message message;\n \n \tif (get_oid(\"HEAD\", &head) ||\n-\t    !(commit = lookup_commit(the_repository, &head)) ||\n+\t    !(commit = lookup_commit(r, &head)) ||\n \t    parse_commit(commit) || get_message(commit, &message))\n \t\tfprintf(stderr, _(\"Stopped at HEAD\\n\"));\n \telse {\n@@ -3495,7 +3502,7 @@ static int pick_commits(struct repository *r,\n \t\t\tdelete_ref(NULL, \"REBASE_HEAD\", NULL, REF_NO_DEREF);\n \n \t\t\tif (item->command == TODO_BREAK)\n-\t\t\t\treturn stopped_at_head();\n+\t\t\t\treturn stopped_at_head(r);\n \t\t}\n \t\tif (item->command <= TODO_SQUASH) {\n \t\t\tif (is_rebase_i(opts))\n@@ -3572,7 +3579,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@@ -3732,12 +3739,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@@ -3836,7 +3843,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@@ -3891,20 +3898,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@@ -4477,7 +4484,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@@ -4488,7 +4496,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@@ -4533,7 +4541,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@@ -4544,7 +4552,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@@ -4613,7 +4621,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 missing_commit_check_level check_level = get_missing_commit_check_level();\n \tstruct strbuf todo_file = STRBUF_INIT;\n@@ -4630,7 +4638,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 == MISSING_COMMIT_CHECK_IGNORE)\n \t\tgoto leave_check;\n@@ -4649,7 +4657,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@@ -4713,7 +4721,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-static int skip_unnecessary_picks(struct object_id *output_oid)\n+static int skip_unnecessary_picks(struct repository *r, struct object_id *output_oid)\n {\n \tconst char *todo_file = rebase_path_todo();\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -4731,7 +4739,7 @@ static int skip_unnecessary_picks(struct object_id *output_oid)\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@@ -4792,7 +4800,7 @@ static int skip_unnecessary_picks(struct object_id *output_oid)\n \treturn 0;\n }\n \n-int complete_action(struct replay_opts *opts, unsigned flags,\n+int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,\n \t\t    const char *shortrevisions, const char *onto_name,\n \t\t    const char *onto, const char *orig_head, const char *cmd,\n \t\t    unsigned autosquash)\n@@ -4810,16 +4818,16 @@ int complete_action(struct replay_opts *opts, unsigned flags,\n \t    write_message(\"noop\\n\", 5, todo_file, 0))\n \t\treturn -1;\n \n-\tif (autosquash && rearrange_squash())\n+\tif (autosquash && rearrange_squash(r))\n \t\treturn -1;\n \n \tif (cmd && *cmd)\n-\t\tsequencer_add_exec_commands(cmd);\n+\t\tsequencer_add_exec_commands(r, cmd);\n \n \tif (strbuf_read_file(buf, todo_file, 0) < 0)\n \t\treturn error_errno(_(\"could not read '%s'.\"), todo_file);\n \n-\tif (parse_insn_buffer(buf->buf, &todo_list)) {\n+\tif (parse_insn_buffer(r, buf->buf, &todo_list)) {\n \t\ttodo_list_release(&todo_list);\n \t\treturn error(_(\"unusable todo list: '%s'\"), todo_file);\n \t}\n@@ -4848,7 +4856,7 @@ int complete_action(struct replay_opts *opts, unsigned flags,\n \t\treturn error(_(\"could not copy '%s' to '%s'.\"), todo_file,\n \t\t\t     rebase_path_todo_backup());\n \n-\tif (transform_todos(flags | TODO_LIST_SHORTEN_IDS))\n+\tif (transform_todos(r, flags | TODO_LIST_SHORTEN_IDS))\n \t\treturn error(_(\"could not transform the todo list\"));\n \n \tstrbuf_reset(buf);\n@@ -4872,24 +4880,24 @@ int complete_action(struct replay_opts *opts, unsigned flags,\n \n \ttodo_list_release(&todo_list);\n \n-\tif (check_todo_list()) {\n+\tif (check_todo_list(r)) {\n \t\tcheckout_onto(opts, onto_name, onto, orig_head);\n \t\treturn -1;\n \t}\n \n-\tif (transform_todos(flags & ~(TODO_LIST_SHORTEN_IDS)))\n+\tif (transform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS)))\n \t\treturn error(_(\"could not transform the todo list\"));\n \n-\tif (opts->allow_ff && skip_unnecessary_picks(&oid))\n+\tif (opts->allow_ff && skip_unnecessary_picks(r, &oid))\n \t\treturn error(_(\"could not skip unnecessary pick commands\"));\n \n \tif (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head))\n \t\treturn -1;\n ;\n-\tif (require_clean_work_tree(the_repository, \"rebase\", \"\", 1, 1))\n+\tif (require_clean_work_tree(r, \"rebase\", \"\", 1, 1))\n \t\treturn -1;\n \n-\treturn sequencer_continue(the_repository, opts);\n+\treturn sequencer_continue(r, opts);\n }\n \n struct subject2item_entry {\n@@ -4916,7 +4924,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@@ -4927,7 +4935,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 ba86515ad6..d2c18edd3a 100644\n--- a/sequencer.h\n+++ b/sequencer.h\n@@ -78,7 +78,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@@ -95,15 +95,15 @@ 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 sequencer_add_exec_commands(struct repository *r, const char *command);\n+int transform_todos(struct repository *r, unsigned flags);\n enum missing_commit_check_level get_missing_commit_check_level(void);\n-int check_todo_list(void);\n-int complete_action(struct replay_opts *opts, unsigned flags,\n+int check_todo_list(struct repository *r);\n+int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,\n \t\t    const char *shortrevisions, const char *onto_name,\n \t\t    const char *onto, const char *orig_head, const char *cmd,\n \t\t    unsigned autosquash);\n-int rearrange_squash(void);\n+int rearrange_squash(struct repository *r);\n \n extern const char sign_off_header[];\n \n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362875","messageId":"20181110054910.10568-12-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 11/22] bisect.c: remove the_repository reference","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:59Z","receivedAt":"2018-11-10T05:49:36Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n bisect.c                 | 48 +++++++++++++++++++++++-----------------\n bisect.h                 |  5 ++++-\n builtin/bisect--helper.c |  2 +-\n 3 files changed, 33 insertions(+), 22 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 487675c672..4c1b80bff6 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -626,14 +626,15 @@ static struct commit_list *managed_skipped(struct commit_list *list,\n \treturn skip_away(list, count);\n }\n \n-static void bisect_rev_setup(struct rev_info *revs, const char *prefix,\n+static void bisect_rev_setup(struct repository *r, struct rev_info *revs,\n+\t\t\t     const char *prefix,\n \t\t\t     const char *bad_format, const char *good_format,\n \t\t\t     int read_paths)\n {\n \tstruct argv_array rev_argv = ARGV_ARRAY_INIT;\n \tint i;\n \n-\trepo_init_revisions(the_repository, revs, prefix);\n+\trepo_init_revisions(r, revs, prefix);\n \trevs->abbrev = 0;\n \trevs->commit_format = CMIT_FMT_UNSPECIFIED;\n \n@@ -723,23 +724,25 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)\n \treturn run_command_v_opt(argv_show_branch, RUN_GIT_CMD);\n }\n \n-static struct commit *get_commit_reference(const struct object_id *oid)\n+static struct commit *get_commit_reference(struct repository *r,\n+\t\t\t\t\t   const struct object_id *oid)\n {\n-\tstruct commit *r = lookup_commit_reference(the_repository, oid);\n-\tif (!r)\n+\tstruct commit *c = lookup_commit_reference(r, oid);\n+\tif (!c)\n \t\tdie(_(\"Not a valid commit name %s\"), oid_to_hex(oid));\n-\treturn r;\n+\treturn c;\n }\n \n-static struct commit **get_bad_and_good_commits(int *rev_nr)\n+static struct commit **get_bad_and_good_commits(struct repository *r,\n+\t\t\t\t\t\tint *rev_nr)\n {\n \tstruct commit **rev;\n \tint i, n = 0;\n \n \tALLOC_ARRAY(rev, 1 + good_revs.nr);\n-\trev[n++] = get_commit_reference(current_bad_oid);\n+\trev[n++] = get_commit_reference(r, current_bad_oid);\n \tfor (i = 0; i < good_revs.nr; i++)\n-\t\trev[n++] = get_commit_reference(good_revs.oid + i);\n+\t\trev[n++] = get_commit_reference(r, good_revs.oid + i);\n \t*rev_nr = n;\n \n \treturn rev;\n@@ -823,12 +826,13 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)\n \tfree_commit_list(result);\n }\n \n-static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)\n+static int check_ancestors(struct repository *r, int rev_nr,\n+\t\t\t   struct commit **rev, const char *prefix)\n {\n \tstruct rev_info revs;\n \tint res;\n \n-\tbisect_rev_setup(&revs, prefix, \"^%s\", \"%s\", 0);\n+\tbisect_rev_setup(r, &revs, prefix, \"^%s\", \"%s\", 0);\n \n \tbisect_common(&revs);\n \tres = (revs.commits != NULL);\n@@ -847,7 +851,9 @@ static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)\n  * If a merge base must be tested by the user, its source code will be\n  * checked out to be tested by the user and we will exit.\n  */\n-static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)\n+static void check_good_are_ancestors_of_bad(struct repository *r,\n+\t\t\t\t\t    const char *prefix,\n+\t\t\t\t\t    int no_checkout)\n {\n \tchar *filename = git_pathdup(\"BISECT_ANCESTORS_OK\");\n \tstruct stat st;\n@@ -866,8 +872,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)\n \t\tgoto done;\n \n \t/* Check if all good revs are ancestor of the bad rev. */\n-\trev = get_bad_and_good_commits(&rev_nr);\n-\tif (check_ancestors(rev_nr, rev, prefix))\n+\trev = get_bad_and_good_commits(r, &rev_nr);\n+\tif (check_ancestors(r, rev_nr, rev, prefix))\n \t\tcheck_merge_bases(rev_nr, rev, no_checkout);\n \tfree(rev);\n \n@@ -885,12 +891,14 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)\n /*\n  * This does \"git diff-tree --pretty COMMIT\" without one fork+exec.\n  */\n-static void show_diff_tree(const char *prefix, struct commit *commit)\n+static void show_diff_tree(struct repository *r,\n+\t\t\t   const char *prefix,\n+\t\t\t   struct commit *commit)\n {\n \tstruct rev_info opt;\n \n \t/* diff-tree init */\n-\trepo_init_revisions(the_repository, &opt, prefix);\n+\trepo_init_revisions(r, &opt, prefix);\n \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n \topt.abbrev = 0;\n \topt.diff = 1;\n@@ -945,7 +953,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)\n  * If no_checkout is non-zero, the bisection process does not\n  * checkout the trial commit but instead simply updates BISECT_HEAD.\n  */\n-int bisect_next_all(const char *prefix, int no_checkout)\n+int bisect_next_all(struct repository *r, const char *prefix, int no_checkout)\n {\n \tstruct rev_info revs;\n \tstruct commit_list *tried;\n@@ -957,9 +965,9 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \tif (read_bisect_refs())\n \t\tdie(_(\"reading bisect refs failed\"));\n \n-\tcheck_good_are_ancestors_of_bad(prefix, no_checkout);\n+\tcheck_good_are_ancestors_of_bad(r, prefix, no_checkout);\n \n-\tbisect_rev_setup(&revs, prefix, \"%s\", \"^%s\", 1);\n+\tbisect_rev_setup(r, &revs, prefix, \"%s\", \"^%s\", 1);\n \trevs.limited = 1;\n \n \tbisect_common(&revs);\n@@ -993,7 +1001,7 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \t\texit_if_skipped_commits(tried, current_bad_oid);\n \t\tprintf(\"%s is the first %s commit\\n\", oid_to_hex(bisect_rev),\n \t\t\tterm_bad);\n-\t\tshow_diff_tree(prefix, revs.commits->item);\n+\t\tshow_diff_tree(r, prefix, revs.commits->item);\n \t\t/* This means the bisection process succeeded. */\n \t\texit(10);\n \t}\ndiff --git a/bisect.h b/bisect.h\nindex 34df209351..821d16e4dd 100644\n--- a/bisect.h\n+++ b/bisect.h\n@@ -2,6 +2,7 @@\n #define BISECT_H\n \n struct commit_list;\n+struct repository;\n \n /*\n  * Find bisection. If something is found, `reaches` will be the number of\n@@ -30,7 +31,9 @@ struct rev_list_info {\n \tconst char *header_prefix;\n };\n \n-extern int bisect_next_all(const char *prefix, int no_checkout);\n+extern int bisect_next_all(struct repository *r,\n+\t\t\t   const char *prefix,\n+\t\t\t   int no_checkout);\n \n extern int estimate_bisect_steps(int all);\n \ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 4b5fadcbe1..417d141c09 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -137,7 +137,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \n \tswitch (cmdmode) {\n \tcase NEXT_ALL:\n-\t\treturn bisect_next_all(prefix, no_checkout);\n+\t\treturn bisect_next_all(the_repository, prefix, no_checkout);\n \tcase WRITE_TERMS:\n \t\tif (argc != 2)\n \t\t\treturn error(_(\"--write-terms requires two arguments\"));\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362876","messageId":"20181110054910.10568-13-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 12/22] branch.c: remove the_repository reference","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:00Z","receivedAt":"2018-11-10T05:49:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n branch.c           | 21 +++++++++++----------\n branch.h           |  8 ++++++--\n builtin/am.c       |  2 +-\n builtin/branch.c   |  6 ++++--\n builtin/checkout.c |  5 +++--\n builtin/reset.c    |  2 +-\n builtin/revert.c   |  2 +-\n 7 files changed, 27 insertions(+), 19 deletions(-)\n\ndiff --git a/branch.c b/branch.c\nindex 776f55fc66..28b81a7e02 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -242,7 +242,8 @@ N_(\"\\n\"\n \"will track its remote counterpart, you may want to use\\n\"\n \"\\\"git push -u\\\" to set the upstream config as you push.\");\n \n-void create_branch(const char *name, const char *start_name,\n+void create_branch(struct repository *r,\n+\t\t   const char *name, const char *start_name,\n \t\t   int force, int clobber_head_ok, int reflog,\n \t\t   int quiet, enum branch_track track)\n {\n@@ -300,7 +301,7 @@ void create_branch(const char *name, const char *start_name,\n \t\tbreak;\n \t}\n \n-\tif ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)\n+\tif ((commit = lookup_commit_reference(r, &oid)) == NULL)\n \t\tdie(_(\"Not a valid branch point: '%s'.\"), start_name);\n \toidcpy(&oid, &commit->object.oid);\n \n@@ -336,15 +337,15 @@ void create_branch(const char *name, const char *start_name,\n \tfree(real_ref);\n }\n \n-void remove_branch_state(void)\n+void remove_branch_state(struct repository *r)\n {\n-\tunlink(git_path_cherry_pick_head(the_repository));\n-\tunlink(git_path_revert_head(the_repository));\n-\tunlink(git_path_merge_head(the_repository));\n-\tunlink(git_path_merge_rr(the_repository));\n-\tunlink(git_path_merge_msg(the_repository));\n-\tunlink(git_path_merge_mode(the_repository));\n-\tunlink(git_path_squash_msg(the_repository));\n+\tunlink(git_path_cherry_pick_head(r));\n+\tunlink(git_path_revert_head(r));\n+\tunlink(git_path_merge_head(r));\n+\tunlink(git_path_merge_rr(r));\n+\tunlink(git_path_merge_msg(r));\n+\tunlink(git_path_merge_mode(r));\n+\tunlink(git_path_squash_msg(r));\n }\n \n void die_if_checked_out(const char *branch, int ignore_current_worktree)\ndiff --git a/branch.h b/branch.h\nindex 5cace4581f..29c1afa4d0 100644\n--- a/branch.h\n+++ b/branch.h\n@@ -1,6 +1,7 @@\n #ifndef BRANCH_H\n #define BRANCH_H\n \n+struct repository;\n struct strbuf;\n \n enum branch_track {\n@@ -19,6 +20,8 @@ extern enum branch_track git_branch_track;\n /*\n  * Creates a new branch, where:\n  *\n+ *   - r is the repository to add a branch to\n+ *\n  *   - name is the new branch name\n  *\n  *   - start_name is the name of the existing branch that the new branch should\n@@ -37,7 +40,8 @@ extern enum branch_track git_branch_track;\n  *     that start_name is a tracking branch for (if any).\n  *\n  */\n-void create_branch(const char *name, const char *start_name,\n+void create_branch(struct repository *r,\n+\t\t   const char *name, const char *start_name,\n \t\t   int force, int clobber_head_ok,\n \t\t   int reflog, int quiet, enum branch_track track);\n \n@@ -60,7 +64,7 @@ extern int validate_new_branchname(const char *name, struct strbuf *ref, int for\n  * Remove information about the state of working on the current\n  * branch. (E.g., MERGE_HEAD)\n  */\n-void remove_branch_state(void);\n+void remove_branch_state(struct repository *r);\n \n /*\n  * Configure local branch \"local\" as downstream to branch \"remote\"\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 3ee9a9d2a9..232f3962d7 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2022,7 +2022,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem\n \tif (merge_tree(remote_tree))\n \t\treturn -1;\n \n-\tremove_branch_state();\n+\tremove_branch_state(the_repository);\n \n \treturn 0;\n }\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 0c55f7f065..1be727209b 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -783,7 +783,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\t * create_branch takes care of setting up the tracking\n \t\t * info and making sure new_upstream is correct\n \t\t */\n-\t\tcreate_branch(branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);\n+\t\tcreate_branch(the_repository, branch->name, new_upstream,\n+\t\t\t      0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);\n \t} else if (unset_upstream) {\n \t\tstruct branch *branch = branch_get(argv[0]);\n \t\tstruct strbuf buf = STRBUF_INIT;\n@@ -814,7 +815,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tif (track == BRANCH_TRACK_OVERRIDE)\n \t\t\tdie(_(\"the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead.\"));\n \n-\t\tcreate_branch(argv[0], (argc == 2) ? argv[1] : head,\n+\t\tcreate_branch(the_repository,\n+\t\t\t      argv[0], (argc == 2) ? argv[1] : head,\n \t\t\t      force, 0, reflog, quiet, track);\n \n \t} else\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex acdafc6e4c..169e797675 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -753,7 +753,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,\n \t\t\tfree(refname);\n \t\t}\n \t\telse\n-\t\t\tcreate_branch(opts->new_branch, new_branch_info->name,\n+\t\t\tcreate_branch(the_repository,\n+\t\t\t\t      opts->new_branch, new_branch_info->name,\n \t\t\t\t      opts->new_branch_force ? 1 : 0,\n \t\t\t\t      opts->new_branch_force ? 1 : 0,\n \t\t\t\t      opts->new_branch_log,\n@@ -811,7 +812,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,\n \t\t\t\tdelete_reflog(old_branch_info->path);\n \t\t}\n \t}\n-\tremove_branch_state();\n+\tremove_branch_state(the_repository);\n \tstrbuf_release(&msg);\n \tif (!opts->quiet &&\n \t    (new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, \"HEAD\"))))\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 6d37a35e2e..5b4bbb0fb5 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -400,7 +400,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \t\t\tprint_new_head_line(lookup_commit_reference(the_repository, &oid));\n \t}\n \tif (!pathspec.nr)\n-\t\tremove_branch_state();\n+\t\tremove_branch_state(the_repository);\n \n \treturn update_ref_status;\n }\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 1fa75b2773..df662d4324 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -195,7 +195,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)\n \tif (cmd == 'q') {\n \t\tint ret = sequencer_remove_state(opts);\n \t\tif (!ret)\n-\t\t\tremove_branch_state();\n+\t\t\tremove_branch_state(the_repository);\n \t\treturn ret;\n \t}\n \tif (cmd == 'c')\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362877","messageId":"20181110054910.10568-15-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 14/22] cache-tree.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:02Z","receivedAt":"2018-11-10T05:49:40Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This case is more interesting than other boring \"remove the_repo\"\ncommits because while we need access to the object database, we cannot\nsimply use r->index because unpack-trees.c can operate on a temporary\nindex, not $GIT_DIR/index. Ideally we should be able to pass an object\ndatabase to lookup_tree() but that ship has sailed.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/read-tree.c |  4 +++-\n builtin/rebase.c    |  2 +-\n builtin/reset.c     |  2 +-\n cache-tree.c        | 26 +++++++++++++++-----------\n cache-tree.h        |  4 ++--\n read-cache.c        |  2 +-\n sequencer.c         |  2 +-\n unpack-trees.c      |  2 +-\n 8 files changed, 25 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/read-tree.c b/builtin/read-tree.c\nindex fbbc98e516..c05c12d034 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -255,7 +255,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)\n \t * what came from the tree.\n \t */\n \tif (nr_trees == 1 && !opts.prefix)\n-\t\tprime_cache_tree(&the_index, trees[0]);\n+\t\tprime_cache_tree(the_repository,\n+\t\t\t\t the_repository->index,\n+\t\t\t\t trees[0]);\n \n \tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n \t\tdie(\"unable to write new index file\");\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex b9eb958454..d9bedecf86 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -582,7 +582,7 @@ static int reset_head(struct object_id *oid, const char *action,\n \t}\n \n \ttree = parse_tree_indirect(oid);\n-\tprime_cache_tree(the_repository->index, tree);\n+\tprime_cache_tree(the_repository, the_repository->index, tree);\n \n \tif (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0)\n \t\tret = error(_(\"could not write index\"));\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 5b4bbb0fb5..161b5e0cae 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -93,7 +93,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)\n \n \tif (reset_type == MIXED || reset_type == HARD) {\n \t\ttree = parse_tree_indirect(oid);\n-\t\tprime_cache_tree(&the_index, tree);\n+\t\tprime_cache_tree(the_repository, the_repository->index, tree);\n \t}\n \n \tret = 0;\ndiff --git a/cache-tree.c b/cache-tree.c\nindex 9d454d24bc..190c6e5aa6 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -659,7 +659,9 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,\n \treturn ret;\n }\n \n-static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)\n+static void prime_cache_tree_rec(struct repository *r,\n+\t\t\t\t struct cache_tree *it,\n+\t\t\t\t struct tree *tree)\n {\n \tstruct tree_desc desc;\n \tstruct name_entry entry;\n@@ -673,24 +675,25 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)\n \t\t\tcnt++;\n \t\telse {\n \t\t\tstruct cache_tree_sub *sub;\n-\t\t\tstruct tree *subtree = lookup_tree(the_repository,\n-\t\t\t\t\t\t\t   entry.oid);\n+\t\t\tstruct tree *subtree = lookup_tree(r, entry.oid);\n \t\t\tif (!subtree->object.parsed)\n \t\t\t\tparse_tree(subtree);\n \t\t\tsub = cache_tree_sub(it, entry.path);\n \t\t\tsub->cache_tree = cache_tree();\n-\t\t\tprime_cache_tree_rec(sub->cache_tree, subtree);\n+\t\t\tprime_cache_tree_rec(r, sub->cache_tree, subtree);\n \t\t\tcnt += sub->cache_tree->entry_count;\n \t\t}\n \t}\n \tit->entry_count = cnt;\n }\n \n-void prime_cache_tree(struct index_state *istate, struct tree *tree)\n+void prime_cache_tree(struct repository *r,\n+\t\t      struct index_state *istate,\n+\t\t      struct tree *tree)\n {\n \tcache_tree_free(&istate->cache_tree);\n \tistate->cache_tree = cache_tree();\n-\tprime_cache_tree_rec(istate->cache_tree, tree);\n+\tprime_cache_tree_rec(r, istate->cache_tree, tree);\n \tistate->cache_changed |= CACHE_TREE_CHANGED;\n }\n \n@@ -726,7 +729,8 @@ int cache_tree_matches_traversal(struct cache_tree *root,\n \treturn 0;\n }\n \n-static void verify_one(struct index_state *istate,\n+static void verify_one(struct repository *r,\n+\t\t       struct index_state *istate,\n \t\t       struct cache_tree *it,\n \t\t       struct strbuf *path)\n {\n@@ -736,13 +740,13 @@ static void verify_one(struct index_state *istate,\n \n \tfor (i = 0; i < it->subtree_nr; i++) {\n \t\tstrbuf_addf(path, \"%s/\", it->down[i]->name);\n-\t\tverify_one(istate, it->down[i]->cache_tree, path);\n+\t\tverify_one(r, istate, it->down[i]->cache_tree, path);\n \t\tstrbuf_setlen(path, len);\n \t}\n \n \tif (it->entry_count < 0 ||\n \t    /* no verification on tests (t7003) that replace trees */\n-\t    lookup_replace_object(the_repository, &it->oid) != &it->oid)\n+\t    lookup_replace_object(r, &it->oid) != &it->oid)\n \t\treturn;\n \n \tif (path->len) {\n@@ -793,12 +797,12 @@ static void verify_one(struct index_state *istate,\n \tstrbuf_release(&tree_buf);\n }\n \n-void cache_tree_verify(struct index_state *istate)\n+void cache_tree_verify(struct repository *r, struct index_state *istate)\n {\n \tstruct strbuf path = STRBUF_INIT;\n \n \tif (!istate->cache_tree)\n \t\treturn;\n-\tverify_one(istate, istate->cache_tree, &path);\n+\tverify_one(r, istate, istate->cache_tree, &path);\n \tstrbuf_release(&path);\n }\ndiff --git a/cache-tree.h b/cache-tree.h\nindex 0ab6784ffe..326209198b 100644\n--- a/cache-tree.h\n+++ b/cache-tree.h\n@@ -32,7 +32,7 @@ struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);\n \n int cache_tree_fully_valid(struct cache_tree *);\n int cache_tree_update(struct index_state *, int);\n-void cache_tree_verify(struct index_state *);\n+void cache_tree_verify(struct repository *, struct index_state *);\n \n /* bitmasks to write_cache_as_tree flags */\n #define WRITE_TREE_MISSING_OK 1\n@@ -47,7 +47,7 @@ void cache_tree_verify(struct index_state *);\n #define WRITE_TREE_PREFIX_ERROR (-3)\n \n int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix);\n-void prime_cache_tree(struct index_state *, struct tree *);\n+void prime_cache_tree(struct repository *, struct index_state *, struct tree *);\n \n int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);\n \ndiff --git a/read-cache.c b/read-cache.c\nindex f3a848d61c..69944fc933 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -3126,7 +3126,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,\n \tstruct split_index *si = istate->split_index;\n \n \tif (git_env_bool(\"GIT_TEST_CHECK_CACHE_TREE\", 0))\n-\t\tcache_tree_verify(istate);\n+\t\tcache_tree_verify(the_repository, istate);\n \n \tif ((flags & SKIP_IF_UNCHANGED) && !istate->cache_changed) {\n \t\tif (flags & COMMIT_LOCK)\ndiff --git a/sequencer.c b/sequencer.c\nindex 111cb747d6..726f727644 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -2991,7 +2991,7 @@ static int do_reset(struct repository *r,\n \t}\n \n \ttree = parse_tree_indirect(&oid);\n-\tprime_cache_tree(r->index, tree);\n+\tprime_cache_tree(r, r->index, tree);\n \n \tif (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0)\n \t\tret = error(_(\"could not write index\"));\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 7570df481b..6d53cbfc86 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -1630,7 +1630,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n \t\tmove_index_extensions(&o->result, o->src_index);\n \t\tif (!ret) {\n \t\t\tif (git_env_bool(\"GIT_TEST_CHECK_CACHE_TREE\", 0))\n-\t\t\t\tcache_tree_verify(&o->result);\n+\t\t\t\tcache_tree_verify(the_repository, &o->result);\n \t\t\tif (!o->result.cache_tree)\n \t\t\t\to->result.cache_tree = cache_tree();\n \t\t\tif (!cache_tree_fully_valid(o->result.cache_tree))\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362878","messageId":"20181110054910.10568-16-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 15/22] delta-islands.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:03Z","receivedAt":"2018-11-10T05:49:40Z","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/pack-objects.c |  4 ++--\n delta-islands.c        | 24 ++++++++++++++----------\n delta-islands.h        |  9 ++++++---\n 3 files changed, 22 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex c99ee79c31..7812c2b1f3 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2628,7 +2628,7 @@ static void prepare_pack(int window, int depth)\n \tunsigned n;\n \n \tif (use_delta_islands)\n-\t\tresolve_tree_islands(progress, &to_pack);\n+\t\tresolve_tree_islands(the_repository, progress, &to_pack);\n \n \tget_object_details();\n \n@@ -3143,7 +3143,7 @@ static void get_object_list(int ac, const char **av)\n \t\treturn;\n \n \tif (use_delta_islands)\n-\t\tload_delta_islands();\n+\t\tload_delta_islands(the_repository);\n \n \tif (prepare_revision_walk(&revs))\n \t\tdie(_(\"revision walk setup failed\"));\ndiff --git a/delta-islands.c b/delta-islands.c\nindex 8e5018e406..191a930705 100644\n--- a/delta-islands.c\n+++ b/delta-islands.c\n@@ -190,13 +190,15 @@ static void set_island_marks(struct object *obj, struct island_bitmap *marks)\n \tisland_bitmap_or(b, marks);\n }\n \n-static void mark_remote_island_1(struct remote_island *rl, int is_core_island)\n+static void mark_remote_island_1(struct repository *r,\n+\t\t\t\t struct remote_island *rl,\n+\t\t\t\t int is_core_island)\n {\n \tuint32_t i;\n \n \tfor (i = 0; i < rl->oids.nr; ++i) {\n \t\tstruct island_bitmap *marks;\n-\t\tstruct object *obj = parse_object(the_repository, &rl->oids.oid[i]);\n+\t\tstruct object *obj = parse_object(r, &rl->oids.oid[i]);\n \n \t\tif (!obj)\n \t\t\tcontinue;\n@@ -211,7 +213,7 @@ static void mark_remote_island_1(struct remote_island *rl, int is_core_island)\n \t\twhile (obj && obj->type == OBJ_TAG) {\n \t\t\tobj = ((struct tag *)obj)->tagged;\n \t\t\tif (obj) {\n-\t\t\t\tparse_object(the_repository, &obj->oid);\n+\t\t\t\tparse_object(r, &obj->oid);\n \t\t\t\tmarks = create_or_get_island_marks(obj);\n \t\t\t\tisland_bitmap_set(marks, island_counter);\n \t\t\t}\n@@ -237,7 +239,9 @@ static int tree_depth_compare(const void *a, const void *b)\n \treturn todo_a->depth - todo_b->depth;\n }\n \n-void resolve_tree_islands(int progress, struct packing_data *to_pack)\n+void resolve_tree_islands(struct repository *r,\n+\t\t\t  int progress,\n+\t\t\t  struct packing_data *to_pack)\n {\n \tstruct progress *progress_state = NULL;\n \tstruct tree_islands_todo *todo;\n@@ -281,7 +285,7 @@ void resolve_tree_islands(int progress, struct packing_data *to_pack)\n \n \t\troot_marks = kh_value(island_marks, pos);\n \n-\t\ttree = lookup_tree(the_repository, &ent->idx.oid);\n+\t\ttree = lookup_tree(r, &ent->idx.oid);\n \t\tif (!tree || parse_tree(tree) < 0)\n \t\t\tdie(_(\"bad tree object %s\"), oid_to_hex(&ent->idx.oid));\n \n@@ -292,7 +296,7 @@ void resolve_tree_islands(int progress, struct packing_data *to_pack)\n \t\t\tif (S_ISGITLINK(entry.mode))\n \t\t\t\tcontinue;\n \n-\t\t\tobj = lookup_object(the_repository, entry.oid->hash);\n+\t\t\tobj = lookup_object(r, entry.oid->hash);\n \t\t\tif (!obj)\n \t\t\t\tcontinue;\n \n@@ -415,7 +419,7 @@ static struct remote_island *get_core_island(void)\n \treturn NULL;\n }\n \n-static void deduplicate_islands(void)\n+static void deduplicate_islands(struct repository *r)\n {\n \tstruct remote_island *island, *core = NULL, **list;\n \tunsigned int island_count, dst, src, ref, i = 0;\n@@ -444,20 +448,20 @@ static void deduplicate_islands(void)\n \tcore = get_core_island();\n \n \tfor (i = 0; i < island_count; ++i) {\n-\t\tmark_remote_island_1(list[i], core && list[i]->hash == core->hash);\n+\t\tmark_remote_island_1(r, list[i], core && list[i]->hash == core->hash);\n \t}\n \n \tfree(list);\n }\n \n-void load_delta_islands(void)\n+void load_delta_islands(struct repository *r)\n {\n \tisland_marks = kh_init_sha1();\n \tremote_islands = kh_init_str();\n \n \tgit_config(island_config_callback, NULL);\n \tfor_each_ref(find_island_for_ref, NULL);\n-\tdeduplicate_islands();\n+\tdeduplicate_islands(r);\n \n \tfprintf(stderr, _(\"Marked %d islands, done.\\n\"), island_counter);\n }\ndiff --git a/delta-islands.h b/delta-islands.h\nindex b635cd07d8..3ac8045d8c 100644\n--- a/delta-islands.h\n+++ b/delta-islands.h\n@@ -1,14 +1,17 @@\n #ifndef DELTA_ISLANDS_H\n #define DELTA_ISLANDS_H\n \n+struct commit;\n struct object_id;\n struct packing_data;\n-struct commit;\n+struct repository;\n \n int island_delta_cmp(const struct object_id *a, const struct object_id *b);\n int in_same_island(const struct object_id *, const struct object_id *);\n-void resolve_tree_islands(int progress, struct packing_data *to_pack);\n-void load_delta_islands(void);\n+void resolve_tree_islands(struct repository *r,\n+\t\t\t  int progress,\n+\t\t\t  struct packing_data *to_pack);\n+void load_delta_islands(struct repository *r);\n void propagate_island_marks(struct commit *commit);\n int compute_pack_layers(struct packing_data *to_pack);\n \n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362879","messageId":"20181110054910.10568-18-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 17/22] line-log.c: remove the_repository reference","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:05Z","receivedAt":"2018-11-10T05:49:41Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n line-log.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/line-log.c b/line-log.c\nindex d1d429d738..24e21731c4 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -479,7 +479,7 @@ static struct commit *check_single_commit(struct rev_info *revs)\n \t\tstruct object *obj = revs->pending.objects[i].item;\n \t\tif (obj->flags & UNINTERESTING)\n \t\t\tcontinue;\n-\t\tobj = deref_tag(the_repository, obj, NULL, 0);\n+\t\tobj = deref_tag(revs->repo, obj, NULL, 0);\n \t\tif (obj->type != OBJ_COMMIT)\n \t\t\tdie(\"Non commit %s?\", revs->pending.objects[i].name);\n \t\tif (commit)\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362880","messageId":"20181110054910.10568-19-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 18/22] notes-cache.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:06Z","receivedAt":"2018-11-10T05:49:43Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n combine-diff.c     |  2 +-\n diff.c             | 12 ++++++------\n diff.h             |  2 +-\n diffcore-pickaxe.c |  4 ++--\n grep.c             |  2 +-\n notes-cache.c      | 12 +++++++-----\n notes-cache.h      |  6 ++++--\n userdiff.c         |  5 +++--\n userdiff.h         |  4 +++-\n 9 files changed, 28 insertions(+), 21 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 10155e0ec8..3d796af3ca 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -991,7 +991,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \tif (!userdiff)\n \t\tuserdiff = userdiff_find_by_name(\"default\");\n \tif (opt->flags.allow_textconv)\n-\t\ttextconv = userdiff_get_textconv(userdiff);\n+\t\ttextconv = userdiff_get_textconv(opt->repo, userdiff);\n \n \t/* Read the result of merge first */\n \tif (!working_tree_file)\ndiff --git a/diff.c b/diff.c\nindex 8647db3d30..1135377a7f 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3312,14 +3312,14 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const\n \t\toptions->b_prefix = b;\n }\n \n-struct userdiff_driver *get_textconv(struct index_state *istate,\n+struct userdiff_driver *get_textconv(struct repository *r,\n \t\t\t\t     struct diff_filespec *one)\n {\n \tif (!DIFF_FILE_VALID(one))\n \t\treturn NULL;\n \n-\tdiff_filespec_load_driver(one, istate);\n-\treturn userdiff_get_textconv(one->driver);\n+\tdiff_filespec_load_driver(one, r->index);\n+\treturn userdiff_get_textconv(r, one->driver);\n }\n \n static void builtin_diff(const char *name_a,\n@@ -3368,8 +3368,8 @@ static void builtin_diff(const char *name_a,\n \t}\n \n \tif (o->flags.allow_textconv) {\n-\t\ttextconv_one = get_textconv(o->repo->index, one);\n-\t\ttextconv_two = get_textconv(o->repo->index, two);\n+\t\ttextconv_one = get_textconv(o->repo, one);\n+\t\ttextconv_two = get_textconv(o->repo, two);\n \t}\n \n \t/* Never use a non-valid filename anywhere if at all possible */\n@@ -6436,7 +6436,7 @@ int textconv_object(struct repository *r,\n \n \tdf = alloc_filespec(path);\n \tfill_filespec(df, oid, oid_valid, mode);\n-\ttextconv = get_textconv(r->index, df);\n+\ttextconv = get_textconv(r, df);\n \tif (!textconv) {\n \t\tfree_filespec(df);\n \t\treturn 0;\ndiff --git a/diff.h b/diff.h\nindex 3197a976a4..412138ba08 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -461,7 +461,7 @@ size_t fill_textconv(struct repository *r,\n  * and only if it has textconv enabled (otherwise return NULL). The result\n  * can be passed to fill_textconv().\n  */\n-struct userdiff_driver *get_textconv(struct index_state *istate,\n+struct userdiff_driver *get_textconv(struct repository *r,\n \t\t\t\t     struct diff_filespec *one);\n \n /*\ndiff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c\nindex d2361e06a1..b815f1c449 100644\n--- a/diffcore-pickaxe.c\n+++ b/diffcore-pickaxe.c\n@@ -139,8 +139,8 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,\n \t\treturn 0;\n \n \tif (o->flags.allow_textconv) {\n-\t\ttextconv_one = get_textconv(o->repo->index, p->one);\n-\t\ttextconv_two = get_textconv(o->repo->index, p->two);\n+\t\ttextconv_one = get_textconv(o->repo, p->one);\n+\t\ttextconv_two = get_textconv(o->repo, p->two);\n \t}\n \n \t/*\ndiff --git a/grep.c b/grep.c\nindex f6bd89e40b..b05b2e61bb 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1811,7 +1811,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t * is not thread-safe.\n \t\t */\n \t\tgrep_attr_lock();\n-\t\ttextconv = userdiff_get_textconv(gs->driver);\n+\t\ttextconv = userdiff_get_textconv(opt->repo, gs->driver);\n \t\tgrep_attr_unlock();\n \t}\n \ndiff --git a/notes-cache.c b/notes-cache.c\nindex d87e7ca91c..2473314d68 100644\n--- a/notes-cache.c\n+++ b/notes-cache.c\n@@ -5,7 +5,9 @@\n #include \"commit.h\"\n #include \"refs.h\"\n \n-static int notes_cache_match_validity(const char *ref, const char *validity)\n+static int notes_cache_match_validity(struct repository *r,\n+\t\t\t\t      const char *ref,\n+\t\t\t\t      const char *validity)\n {\n \tstruct object_id oid;\n \tstruct commit *commit;\n@@ -16,7 +18,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)\n \tif (read_ref(ref, &oid) < 0)\n \t\treturn 0;\n \n-\tcommit = lookup_commit_reference_gently(the_repository, &oid, 1);\n+\tcommit = lookup_commit_reference_gently(r, &oid, 1);\n \tif (!commit)\n \t\treturn 0;\n \n@@ -30,8 +32,8 @@ static int notes_cache_match_validity(const char *ref, const char *validity)\n \treturn ret;\n }\n \n-void notes_cache_init(struct notes_cache *c, const char *name,\n-\t\t     const char *validity)\n+void notes_cache_init(struct repository *r, struct notes_cache *c,\n+\t\t      const char *name, const char *validity)\n {\n \tstruct strbuf ref = STRBUF_INIT;\n \tint flags = NOTES_INIT_WRITABLE;\n@@ -40,7 +42,7 @@ void notes_cache_init(struct notes_cache *c, const char *name,\n \tc->validity = xstrdup(validity);\n \n \tstrbuf_addf(&ref, \"refs/notes/%s\", name);\n-\tif (!notes_cache_match_validity(ref.buf, validity))\n+\tif (!notes_cache_match_validity(r, ref.buf, validity))\n \t\tflags |= NOTES_INIT_EMPTY;\n \tinit_notes(&c->tree, ref.buf, combine_notes_overwrite, flags);\n \tstrbuf_release(&ref);\ndiff --git a/notes-cache.h b/notes-cache.h\nindex aeeee8409d..56f8c98e24 100644\n--- a/notes-cache.h\n+++ b/notes-cache.h\n@@ -3,13 +3,15 @@\n \n #include \"notes.h\"\n \n+struct repository;\n+\n struct notes_cache {\n \tstruct notes_tree tree;\n \tchar *validity;\n };\n \n-void notes_cache_init(struct notes_cache *c, const char *name,\n-\t\t     const char *validity);\n+void notes_cache_init(struct repository *r, struct notes_cache *c,\n+\t\t      const char *name, const char *validity);\n int notes_cache_write(struct notes_cache *c);\n \n char *notes_cache_get(struct notes_cache *c, struct object_id *oid, size_t\ndiff --git a/userdiff.c b/userdiff.c\nindex 46d34cc2a4..97007abe5b 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -290,7 +290,8 @@ struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,\n \treturn userdiff_find_by_name(check->items[0].value);\n }\n \n-struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)\n+struct userdiff_driver *userdiff_get_textconv(struct repository *r,\n+\t\t\t\t\t      struct userdiff_driver *driver)\n {\n \tif (!driver->textconv)\n \t\treturn NULL;\n@@ -300,7 +301,7 @@ struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)\n \t\tstruct strbuf name = STRBUF_INIT;\n \n \t\tstrbuf_addf(&name, \"textconv/%s\", driver->name);\n-\t\tnotes_cache_init(c, name.buf, driver->textconv);\n+\t\tnotes_cache_init(r, c, name.buf, driver->textconv);\n \t\tdriver->textconv_cache = c;\n \t\tstrbuf_release(&name);\n \t}\ndiff --git a/userdiff.h b/userdiff.h\nindex b072bfe89a..203057e13e 100644\n--- a/userdiff.h\n+++ b/userdiff.h\n@@ -4,6 +4,7 @@\n #include \"notes-cache.h\"\n \n struct index_state;\n+struct repository;\n \n struct userdiff_funcname {\n \tconst char *pattern;\n@@ -30,6 +31,7 @@ struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,\n  * Initialize any textconv-related fields in the driver and return it, or NULL\n  * if it does not have textconv enabled at all.\n  */\n-struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver);\n+struct userdiff_driver *userdiff_get_textconv(struct repository *r,\n+\t\t\t\t\t      struct userdiff_driver *driver);\n \n #endif /* USERDIFF */\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362881","messageId":"20181110054910.10568-20-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 19/22] pack-check.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:07Z","receivedAt":"2018-11-10T05:49:44Z","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/fsck.c | 3 ++-\n pack-check.c   | 9 +++++----\n pack.h         | 4 +++-\n 3 files changed, 10 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 06eb421720..8ea2823864 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -752,7 +752,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\t\tfor (p = get_all_packs(the_repository); p;\n \t\t\t     p = p->next) {\n \t\t\t\t/* verify gives error messages itself */\n-\t\t\t\tif (verify_pack(p, fsck_obj_buffer,\n+\t\t\t\tif (verify_pack(the_repository,\n+\t\t\t\t\t\tp, fsck_obj_buffer,\n \t\t\t\t\t\tprogress, count))\n \t\t\t\t\terrors_found |= ERROR_PACK;\n \t\t\t\tcount += p->num_objects;\ndiff --git a/pack-check.c b/pack-check.c\nindex fa5f0ff8fa..2cc3603189 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -48,7 +48,8 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,\n \treturn data_crc != ntohl(*index_crc);\n }\n \n-static int verify_packfile(struct packed_git *p,\n+static int verify_packfile(struct repository *r,\n+\t\t\t   struct packed_git *p,\n \t\t\t   struct pack_window **w_curs,\n \t\t\t   verify_fn fn,\n \t\t\t   struct progress *progress, uint32_t base_count)\n@@ -135,7 +136,7 @@ static int verify_packfile(struct packed_git *p,\n \t\t\tdata = NULL;\n \t\t\tdata_valid = 0;\n \t\t} else {\n-\t\t\tdata = unpack_entry(the_repository, p, entries[i].offset, &type, &size);\n+\t\t\tdata = unpack_entry(r, p, entries[i].offset, &type, &size);\n \t\t\tdata_valid = 1;\n \t\t}\n \n@@ -186,7 +187,7 @@ int verify_pack_index(struct packed_git *p)\n \treturn err;\n }\n \n-int verify_pack(struct packed_git *p, verify_fn fn,\n+int verify_pack(struct repository *r, struct packed_git *p, verify_fn fn,\n \t\tstruct progress *progress, uint32_t base_count)\n {\n \tint err = 0;\n@@ -196,7 +197,7 @@ int verify_pack(struct packed_git *p, verify_fn fn,\n \tif (!p->index_data)\n \t\treturn -1;\n \n-\terr |= verify_packfile(p, &w_curs, fn, progress, base_count);\n+\terr |= verify_packfile(r, p, &w_curs, fn, progress, base_count);\n \tunuse_pack(&w_curs);\n \n \treturn err;\ndiff --git a/pack.h b/pack.h\nindex 34a9d458b4..da99fdd1d2 100644\n--- a/pack.h\n+++ b/pack.h\n@@ -4,6 +4,8 @@\n #include \"object.h\"\n #include \"csum-file.h\"\n \n+struct repository;\n+\n /*\n  * Packed object header\n  */\n@@ -80,7 +82,7 @@ typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned lo\n extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, const struct pack_idx_option *, const unsigned char *sha1);\n extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);\n extern int verify_pack_index(struct packed_git *);\n-extern int verify_pack(struct packed_git *, verify_fn fn, struct progress *, uint32_t);\n+extern int verify_pack(struct repository *, struct packed_git *, verify_fn fn, struct progress *, uint32_t);\n extern off_t write_pack_header(struct hashfile *f, uint32_t);\n extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);\n extern char *index_pack_lockfile(int fd);\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362882","messageId":"20181110054910.10568-21-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 20/22] pack-*.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:08Z","receivedAt":"2018-11-10T05:49:46Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/pack-objects.c |  2 +-\n pack-bitmap-write.c    |  6 +++---\n pack-bitmap.c          | 13 +++++++------\n pack-bitmap.h          |  3 ++-\n pack-objects.c         |  6 ++++--\n pack-objects.h         |  5 ++++-\n 6 files changed, 21 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 7812c2b1f3..8abfb69e2d 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -3481,7 +3481,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tprepare_packing_data(&to_pack);\n+\tprepare_packing_data(the_repository, &to_pack);\n \n \tif (progress)\n \t\tprogress_state = start_progress(_(\"Enumerating objects\"), 0);\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex 9d1b951697..5566e94abe 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -77,7 +77,7 @@ void bitmap_writer_build_type_index(struct packing_data *to_pack,\n \t\t\tbreak;\n \n \t\tdefault:\n-\t\t\treal_type = oid_object_info(the_repository,\n+\t\t\treal_type = oid_object_info(to_pack->repo,\n \t\t\t\t\t\t    &entry->idx.oid, NULL);\n \t\t\tbreak;\n \t\t}\n@@ -262,7 +262,7 @@ void bitmap_writer_build(struct packing_data *to_pack)\n \tif (writer.show_progress)\n \t\twriter.progress = start_progress(\"Building bitmaps\", writer.selected_nr);\n \n-\trepo_init_revisions(the_repository, &revs, NULL);\n+\trepo_init_revisions(to_pack->repo, &revs, NULL);\n \trevs.tag_objects = 1;\n \trevs.tree_objects = 1;\n \trevs.blob_objects = 1;\n@@ -363,7 +363,7 @@ static int date_compare(const void *_a, const void *_b)\n void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack)\n {\n \tstruct bitmap_index *bitmap_git;\n-\tif (!(bitmap_git = prepare_bitmap_git()))\n+\tif (!(bitmap_git = prepare_bitmap_git(to_pack->repo)))\n \t\treturn;\n \n \twriter.reused = kh_init_sha1();\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex 5848cc93aa..4695aaf6b4 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -328,14 +328,15 @@ static int load_pack_bitmap(struct bitmap_index *bitmap_git)\n \treturn -1;\n }\n \n-static int open_pack_bitmap(struct bitmap_index *bitmap_git)\n+static int open_pack_bitmap(struct repository *r,\n+\t\t\t    struct bitmap_index *bitmap_git)\n {\n \tstruct packed_git *p;\n \tint ret = -1;\n \n \tassert(!bitmap_git->map);\n \n-\tfor (p = get_all_packs(the_repository); p; p = p->next) {\n+\tfor (p = get_all_packs(r); p; p = p->next) {\n \t\tif (open_pack_bitmap_1(bitmap_git, p) == 0)\n \t\t\tret = 0;\n \t}\n@@ -343,11 +344,11 @@ static int open_pack_bitmap(struct bitmap_index *bitmap_git)\n \treturn ret;\n }\n \n-struct bitmap_index *prepare_bitmap_git(void)\n+struct bitmap_index *prepare_bitmap_git(struct repository *r)\n {\n \tstruct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));\n \n-\tif (!open_pack_bitmap(bitmap_git) && !load_pack_bitmap(bitmap_git))\n+\tif (!open_pack_bitmap(r, bitmap_git) && !load_pack_bitmap(bitmap_git))\n \t\treturn bitmap_git;\n \n \tfree_bitmap_index(bitmap_git);\n@@ -690,7 +691,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)\n \tstruct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));\n \t/* try to open a bitmapped pack, but don't parse it yet\n \t * because we may not need to use it */\n-\tif (open_pack_bitmap(bitmap_git) < 0)\n+\tif (open_pack_bitmap(revs->repo, bitmap_git) < 0)\n \t\tgoto cleanup;\n \n \tfor (i = 0; i < revs->pending.nr; ++i) {\n@@ -955,7 +956,7 @@ void test_bitmap_walk(struct rev_info *revs)\n \tstruct bitmap_test_data tdata;\n \tstruct bitmap_index *bitmap_git;\n \n-\tif (!(bitmap_git = prepare_bitmap_git()))\n+\tif (!(bitmap_git = prepare_bitmap_git(revs->repo)))\n \t\tdie(\"failed to load bitmap indexes\");\n \n \tif (revs->pending.nr != 1)\ndiff --git a/pack-bitmap.h b/pack-bitmap.h\nindex 189dd68ad3..8418ba8c79 100644\n--- a/pack-bitmap.h\n+++ b/pack-bitmap.h\n@@ -6,6 +6,7 @@\n #include \"pack-objects.h\"\n \n struct commit;\n+struct repository;\n struct rev_info;\n \n struct bitmap_disk_header {\n@@ -39,7 +40,7 @@ typedef int (*show_reachable_fn)(\n \n struct bitmap_index;\n \n-struct bitmap_index *prepare_bitmap_git(void);\n+struct bitmap_index *prepare_bitmap_git(struct repository *r);\n void count_bitmap_commit_list(struct bitmap_index *, uint32_t *commits,\n \t\t\t      uint32_t *trees, uint32_t *blobs, uint32_t *tags);\n void traverse_bitmap_commit_list(struct bitmap_index *,\ndiff --git a/pack-objects.c b/pack-objects.c\nindex b6cdbb0166..9c45842df3 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -99,7 +99,7 @@ static void prepare_in_pack_by_idx(struct packing_data *pdata)\n \t * (i.e. in_pack_idx also zero) should return NULL.\n \t */\n \tmapping[cnt++] = NULL;\n-\tfor (p = get_all_packs(the_repository); p; p = p->next, cnt++) {\n+\tfor (p = get_all_packs(pdata->repo); p; p = p->next, cnt++) {\n \t\tif (cnt == nr) {\n \t\t\tfree(mapping);\n \t\t\treturn;\n@@ -133,8 +133,10 @@ void oe_map_new_pack(struct packing_data *pack,\n }\n \n /* assume pdata is already zero'd by caller */\n-void prepare_packing_data(struct packing_data *pdata)\n+void prepare_packing_data(struct repository *r, struct packing_data *pdata)\n {\n+\tpdata->repo = r;\n+\n \tif (git_env_bool(\"GIT_TEST_FULL_IN_PACK_ARRAY\", 0)) {\n \t\t/*\n \t\t * do not initialize in_pack_by_idx[] to force the\ndiff --git a/pack-objects.h b/pack-objects.h\nindex 86ee93feb4..9e6af3f24f 100644\n--- a/pack-objects.h\n+++ b/pack-objects.h\n@@ -5,6 +5,8 @@\n #include \"thread-utils.h\"\n #include \"pack.h\"\n \n+struct repository;\n+\n #define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024)\n \n #define OE_DFS_STATE_BITS\t2\n@@ -127,6 +129,7 @@ struct object_entry {\n };\n \n struct packing_data {\n+\tstruct repository *repo;\n \tstruct object_entry *objects;\n \tuint32_t nr_objects, nr_alloc;\n \n@@ -165,7 +168,7 @@ struct packing_data {\n \tunsigned char *layer;\n };\n \n-void prepare_packing_data(struct packing_data *pdata);\n+void prepare_packing_data(struct repository *r, struct packing_data *pdata);\n \n static inline void packing_data_lock(struct packing_data *pdata)\n {\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362883","messageId":"20181110054910.10568-22-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 21/22] rerere.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:09Z","receivedAt":"2018-11-10T05:49:47Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/am.c                  |  2 +-\n builtin/rebase--interactive.c |  2 +-\n builtin/rebase.c              |  4 ++--\n builtin/rerere.c              | 10 ++++++----\n rerere.c                      | 26 +++++++++++++-------------\n rerere.h                      |  6 +++---\n 6 files changed, 26 insertions(+), 24 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 232f3962d7..f0eeec82a9 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2033,7 +2033,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem\n static void am_rerere_clear(void)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n-\trerere_clear(&merge_rr);\n+\trerere_clear(the_repository, &merge_rr);\n \tstring_list_clear(&merge_rr, 1);\n }\n \ndiff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c\nindex d867050fd2..bd7d39e2af 100644\n--- a/builtin/rebase--interactive.c\n+++ b/builtin/rebase--interactive.c\n@@ -233,7 +233,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)\n \tcase SKIP: {\n \t\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\t\trerere_clear(&merge_rr);\n+\t\trerere_clear(the_repository, &merge_rr);\n \t\t/* fallthrough */\n \tcase CONTINUE:\n \t\tret = sequencer_continue(the_repository, &opts);\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex d9bedecf86..bc07d932a5 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -997,7 +997,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \n \t\toptions.action = \"skip\";\n \n-\t\trerere_clear(&merge_rr);\n+\t\trerere_clear(the_repository, &merge_rr);\n \t\tstring_list_clear(&merge_rr, 1);\n \n \t\tif (reset_head(NULL, \"reset\", NULL, 0, NULL, NULL) < 0)\n@@ -1010,7 +1010,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \t\toptions.action = \"abort\";\n \n-\t\trerere_clear(&merge_rr);\n+\t\trerere_clear(the_repository, &merge_rr);\n \t\tstring_list_clear(&merge_rr, 1);\n \n \t\tif (read_basic_state(&options))\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex e89ccbc524..6f28c19b20 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -82,11 +82,12 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(&merge_rr);\n+\t\trerere_clear(the_repository, &merge_rr);\n \t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(&merge_rr);\n+\t\trerere_gc(the_repository, &merge_rr);\n \telse if (!strcmp(argv[0], \"status\")) {\n-\t\tif (setup_rerere(&merge_rr, flags | RERERE_READONLY) < 0)\n+\t\tif (setup_rerere(the_repository, &merge_rr,\n+\t\t\t\t flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (i = 0; i < merge_rr.nr; i++)\n \t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -101,7 +102,8 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)\n \t\t\t\tmerge_rr.items[i].util = NULL;\n \t\t}\n \t} else if (!strcmp(argv[0], \"diff\")) {\n-\t\tif (setup_rerere(&merge_rr, flags | RERERE_READONLY) < 0)\n+\t\tif (setup_rerere(the_repository, &merge_rr,\n+\t\t\t\t flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\ndiff --git a/rerere.c b/rerere.c\nindex b5b2357411..13624038e6 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -198,10 +198,10 @@ static struct rerere_id *new_rerere_id(unsigned char *sha1)\n  * work on (i.e. what is left by the previous invocation of \"git\n  * rerere\" during the current conflict resolution session).\n  */\n-static void read_rr(struct string_list *rr)\n+static void read_rr(struct repository *r, struct string_list *rr)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tFILE *in = fopen_or_warn(git_path_merge_rr(the_repository), \"r\");\n+\tFILE *in = fopen_or_warn(git_path_merge_rr(r), \"r\");\n \n \tif (!in)\n \t\treturn;\n@@ -593,7 +593,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr)\n {\n \tint i;\n \n-\tif (setup_rerere(merge_rr, RERERE_READONLY))\n+\tif (setup_rerere(r, merge_rr, RERERE_READONLY))\n \t\treturn 0;\n \tif (read_index(r->index) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n@@ -882,7 +882,7 @@ static int is_rerere_enabled(void)\n \treturn 1;\n }\n \n-int setup_rerere(struct string_list *merge_rr, int flags)\n+int setup_rerere(struct repository *r, struct string_list *merge_rr, int flags)\n {\n \tint fd;\n \n@@ -896,9 +896,9 @@ int setup_rerere(struct string_list *merge_rr, int flags)\n \t\tfd = 0;\n \telse\n \t\tfd = hold_lock_file_for_update(&write_lock,\n-\t\t\t\t\t       git_path_merge_rr(the_repository),\n+\t\t\t\t\t       git_path_merge_rr(r),\n \t\t\t\t\t       LOCK_DIE_ON_ERROR);\n-\tread_rr(merge_rr);\n+\tread_rr(r, merge_rr);\n \treturn fd;\n }\n \n@@ -912,7 +912,7 @@ int repo_rerere(struct repository *r, int flags)\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tint fd, status;\n \n-\tfd = setup_rerere(&merge_rr, flags);\n+\tfd = setup_rerere(r, &merge_rr, flags);\n \tif (fd < 0)\n \t\treturn 0;\n \tstatus = do_plain_rerere(r, &merge_rr, fd);\n@@ -1110,7 +1110,7 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec)\n \tif (read_index(r->index) < 0)\n \t\treturn error(_(\"index file corrupt\"));\n \n-\tfd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE);\n+\tfd = setup_rerere(r, &merge_rr, RERERE_NOAUTOUPDATE);\n \tif (fd < 0)\n \t\treturn 0;\n \n@@ -1178,7 +1178,7 @@ static void prune_one(struct rerere_id *id,\n \t\tunlink_rr_item(id);\n }\n \n-void rerere_gc(struct string_list *rr)\n+void rerere_gc(struct repository *r, struct string_list *rr)\n {\n \tstruct string_list to_remove = STRING_LIST_INIT_DUP;\n \tDIR *dir;\n@@ -1188,7 +1188,7 @@ void rerere_gc(struct string_list *rr)\n \ttimestamp_t cutoff_noresolve = now - 15 * 86400;\n \ttimestamp_t cutoff_resolve = now - 60 * 86400;\n \n-\tif (setup_rerere(rr, 0) < 0)\n+\tif (setup_rerere(r, rr, 0) < 0)\n \t\treturn;\n \n \tgit_config_get_expiry_in_days(\"gc.rerereresolved\", &cutoff_resolve, now);\n@@ -1236,11 +1236,11 @@ void rerere_gc(struct string_list *rr)\n  *\n  * NEEDSWORK: shouldn't we be calling this from \"reset --hard\"?\n  */\n-void rerere_clear(struct string_list *merge_rr)\n+void rerere_clear(struct repository *r, struct string_list *merge_rr)\n {\n \tint i;\n \n-\tif (setup_rerere(merge_rr, 0) < 0)\n+\tif (setup_rerere(r, merge_rr, 0) < 0)\n \t\treturn;\n \n \tfor (i = 0; i < merge_rr->nr; i++) {\n@@ -1250,6 +1250,6 @@ void rerere_clear(struct string_list *merge_rr)\n \t\t\trmdir(rerere_path(id, NULL));\n \t\t}\n \t}\n-\tunlink_or_warn(git_path_merge_rr(the_repository));\n+\tunlink_or_warn(git_path_merge_rr(r));\n \trollback_lock_file(&write_lock);\n }\ndiff --git a/rerere.h b/rerere.h\nindex 5ad8864b3c..c32d79c3bd 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -23,7 +23,7 @@ struct rerere_id {\n \tint variant;\n };\n \n-int setup_rerere(struct string_list *, int);\n+int setup_rerere(struct repository *,struct string_list *, int);\n #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS\n #define rerere(flags) repo_rerere(the_repository, flags)\n #endif\n@@ -37,8 +37,8 @@ int repo_rerere(struct repository *, int);\n const char *rerere_path(const struct rerere_id *, const char *file);\n int rerere_forget(struct repository *, struct pathspec *);\n int rerere_remaining(struct repository *, struct string_list *);\n-void rerere_clear(struct string_list *);\n-void rerere_gc(struct string_list *);\n+void rerere_clear(struct repository *, struct string_list *);\n+void rerere_gc(struct repository *, struct string_list *);\n \n #define OPT_RERERE_AUTOUPDATE(v) OPT_UYN(0, \"rerere-autoupdate\", (v), \\\n \tN_(\"update the index with reused conflict resolution if possible\"))\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362884","messageId":"20181110054910.10568-23-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 22/22] rebase-interactive.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:10Z","receivedAt":"2018-11-10T05:49:49Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"While at there add a forward declaration for struct strbuf.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/rebase--interactive.c | 2 +-\n rebase-interactive.c          | 6 +++---\n rebase-interactive.h          | 5 ++++-\n 3 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c\nindex bd7d39e2af..dd2a55ab1d 100644\n--- a/builtin/rebase--interactive.c\n+++ b/builtin/rebase--interactive.c\n@@ -240,7 +240,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)\n \t\tbreak;\n \t}\n \tcase EDIT_TODO:\n-\t\tret = edit_todo_list(flags);\n+\t\tret = edit_todo_list(the_repository, flags);\n \t\tbreak;\n \tcase SHOW_CURRENT_PATCH: {\n \t\tstruct child_process cmd = CHILD_PROCESS_INIT;\ndiff --git a/rebase-interactive.c b/rebase-interactive.c\nindex 3cc19283ff..68aff1dac2 100644\n--- a/rebase-interactive.c\n+++ b/rebase-interactive.c\n@@ -53,7 +53,7 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty,\n \t}\n }\n \n-int edit_todo_list(unsigned flags)\n+int edit_todo_list(struct repository *r, unsigned flags)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tconst char *todo_file = rebase_path_todo();\n@@ -69,7 +69,7 @@ int edit_todo_list(unsigned flags)\n \n \tstrbuf_release(&buf);\n \n-\ttransform_todos(the_repository, flags | TODO_LIST_SHORTEN_IDS);\n+\ttransform_todos(r, flags | TODO_LIST_SHORTEN_IDS);\n \n \tif (strbuf_read_file(&buf, todo_file, 0) < 0)\n \t\treturn error_errno(_(\"could not read '%s'.\"), todo_file);\n@@ -85,7 +85,7 @@ int edit_todo_list(unsigned flags)\n \tif (launch_sequence_editor(todo_file, NULL, NULL))\n \t\treturn -1;\n \n-\ttransform_todos(the_repository, flags & ~(TODO_LIST_SHORTEN_IDS));\n+\ttransform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS));\n \n \treturn 0;\n }\ndiff --git a/rebase-interactive.h b/rebase-interactive.h\nindex 971da03776..17b6c9f6d0 100644\n--- a/rebase-interactive.h\n+++ b/rebase-interactive.h\n@@ -1,8 +1,11 @@\n #ifndef REBASE_INTERACTIVE_H\n #define REBASE_INTERACTIVE_H\n \n+struct strbuf;\n+struct repository;\n+\n void append_todo_help(unsigned edit_todo, unsigned keep_empty,\n \t\t      struct strbuf *buf);\n-int edit_todo_list(unsigned flags);\n+int edit_todo_list(struct repository *r, unsigned flags);\n \n #endif\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362885","messageId":"20181110054910.10568-17-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 16/22] diff-lib.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:04Z","receivedAt":"2018-11-10T05:49:50Z","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     | 3 ++-\n builtin/merge-ours.c | 2 +-\n diff-lib.c           | 7 ++++---\n diff.h               | 3 ++-\n sequencer.c          | 4 ++--\n 5 files changed, 11 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex e89bf35634..91b1920255 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -908,7 +908,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\t\tif (ignore_submodule_arg &&\n \t\t\t    !strcmp(ignore_submodule_arg, \"all\"))\n \t\t\t\tflags.ignore_submodules = 1;\n-\t\t\tcommittable = index_differs_from(parent, &flags, 1);\n+\t\t\tcommittable = index_differs_from(the_repository,\n+\t\t\t\t\t\t\t parent, &flags, 1);\n \t\t}\n \t}\n \tstrbuf_release(&committer_ident);\ndiff --git a/builtin/merge-ours.c b/builtin/merge-ours.c\nindex c84c6e05e9..0b07263415 100644\n--- a/builtin/merge-ours.c\n+++ b/builtin/merge-ours.c\n@@ -26,7 +26,7 @@ int cmd_merge_ours(int argc, const char **argv, const char *prefix)\n \t */\n \tif (read_cache() < 0)\n \t\tdie_errno(\"read_cache failed\");\n-\tif (index_differs_from(\"HEAD\", NULL, 0))\n+\tif (index_differs_from(the_repository, \"HEAD\", NULL, 0))\n \t\texit(2);\n \texit(0);\n }\ndiff --git a/diff-lib.c b/diff-lib.c\nindex 83fce51518..23c8d351b3 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -542,7 +542,7 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)\n {\n \tstruct rev_info revs;\n \n-\trepo_init_revisions(the_repository, &revs, NULL);\n+\trepo_init_revisions(opt->repo, &revs, NULL);\n \tcopy_pathspec(&revs.prune_data, &opt->pathspec);\n \trevs.diffopt = *opt;\n \n@@ -551,13 +551,14 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)\n \treturn 0;\n }\n \n-int index_differs_from(const char *def, const struct diff_flags *flags,\n+int index_differs_from(struct repository *r,\n+\t\t       const char *def, const struct diff_flags *flags,\n \t\t       int ita_invisible_in_index)\n {\n \tstruct rev_info rev;\n \tstruct setup_revision_opt opt;\n \n-\trepo_init_revisions(the_repository, &rev, NULL);\n+\trepo_init_revisions(r, &rev, NULL);\n \tmemset(&opt, 0, sizeof(opt));\n \topt.def = def;\n \tsetup_revisions(0, NULL, &rev, &opt);\ndiff --git a/diff.h b/diff.h\nindex ce5e8a8183..3197a976a4 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -436,7 +436,8 @@ int diff_result_code(struct diff_options *, int);\n \n void diff_no_index(struct repository *, struct rev_info *, int, const char **);\n \n-int index_differs_from(const char *def, const struct diff_flags *flags,\n+int index_differs_from(struct repository *r, const char *def,\n+\t\t       const struct diff_flags *flags,\n \t\t       int ita_invisible_in_index);\n \n /*\ndiff --git a/sequencer.c b/sequencer.c\nindex 726f727644..d726f77e11 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1713,7 +1713,7 @@ static int do_pick_commit(struct repository *r,\n \t\t\tunborn = 1;\n \t\t} else if (unborn)\n \t\t\toidcpy(&head, the_hash_algo->empty_tree);\n-\t\tif (index_differs_from(unborn ? empty_tree_oid_hex() : \"HEAD\",\n+\t\tif (index_differs_from(r, unborn ? empty_tree_oid_hex() : \"HEAD\",\n \t\t\t\t       NULL, 0))\n \t\t\treturn error_dirty_index(r->index, opts);\n \t}\n@@ -3915,7 +3915,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)\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\tif (index_differs_from(r, \"HEAD\", NULL, 0)) {\n \t\t\tres = error_dirty_index(r->index, opts);\n \t\t\tgoto release_todo_list;\n \t\t}\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362886","messageId":"20181110054910.10568-14-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 13/22] bundle.c: remove the_repository references","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:49:01Z","receivedAt":"2018-11-10T05:49:50Z","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/bundle.c |  7 ++++---\n bundle.c         | 26 ++++++++++++++------------\n bundle.h         |  9 +++++----\n transport.c      |  2 +-\n 4 files changed, 24 insertions(+), 20 deletions(-)\n\ndiff --git a/builtin/bundle.c b/builtin/bundle.c\nindex d0de59b94f..9e9c65d9c6 100644\n--- a/builtin/bundle.c\n+++ b/builtin/bundle.c\n@@ -40,7 +40,7 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)\n \t\t\tusage(builtin_bundle_usage);\n \t\t\treturn 1;\n \t\t}\n-\t\tif (verify_bundle(&header, 1))\n+\t\tif (verify_bundle(the_repository, &header, 1))\n \t\t\treturn 1;\n \t\tfprintf(stderr, _(\"%s is okay\\n\"), bundle_file);\n \t\treturn 0;\n@@ -56,11 +56,12 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)\n \t\t}\n \t\tif (!startup_info->have_repository)\n \t\t\tdie(_(\"Need a repository to create a bundle.\"));\n-\t\treturn !!create_bundle(&header, bundle_file, argc, argv);\n+\t\treturn !!create_bundle(the_repository, &header,\n+\t\t\t\t       bundle_file, argc, argv);\n \t} else if (!strcmp(cmd, \"unbundle\")) {\n \t\tif (!startup_info->have_repository)\n \t\t\tdie(_(\"Need a repository to unbundle.\"));\n-\t\treturn !!unbundle(&header, bundle_fd, 0) ||\n+\t\treturn !!unbundle(the_repository, &header, bundle_fd, 0) ||\n \t\t\tlist_bundle_refs(&header, argc, argv);\n \t} else\n \t\tusage(builtin_bundle_usage);\ndiff --git a/bundle.c b/bundle.c\nindex 1ef584b93b..b94992675a 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -127,7 +127,9 @@ static int list_refs(struct ref_list *r, int argc, const char **argv)\n /* Remember to update object flag allocation in object.h */\n #define PREREQ_MARK (1u<<16)\n \n-int verify_bundle(struct bundle_header *header, int verbose)\n+int verify_bundle(struct repository *r,\n+\t\t  struct bundle_header *header,\n+\t\t  int verbose)\n {\n \t/*\n \t * Do fast check, then if any prereqs are missing then go line by line\n@@ -140,10 +142,10 @@ int verify_bundle(struct bundle_header *header, int verbose)\n \tint i, ret = 0, req_nr;\n \tconst char *message = _(\"Repository lacks these prerequisite commits:\");\n \n-\trepo_init_revisions(the_repository, &revs, NULL);\n+\trepo_init_revisions(r, &revs, NULL);\n \tfor (i = 0; i < p->nr; i++) {\n \t\tstruct ref_list_entry *e = p->list + i;\n-\t\tstruct object *o = parse_object(the_repository, &e->oid);\n+\t\tstruct object *o = parse_object(r, &e->oid);\n \t\tif (o) {\n \t\t\to->flags |= PREREQ_MARK;\n \t\t\tadd_pending_object(&revs, o, e->name);\n@@ -168,7 +170,7 @@ int verify_bundle(struct bundle_header *header, int verbose)\n \n \tfor (i = 0; i < p->nr; i++) {\n \t\tstruct ref_list_entry *e = p->list + i;\n-\t\tstruct object *o = parse_object(the_repository, &e->oid);\n+\t\tstruct object *o = parse_object(r, &e->oid);\n \t\tassert(o); /* otherwise we'd have returned early */\n \t\tif (o->flags & SHOWN)\n \t\t\tcontinue;\n@@ -180,7 +182,7 @@ int verify_bundle(struct bundle_header *header, int verbose)\n \t/* Clean up objects used, as they will be reused. */\n \tfor (i = 0; i < p->nr; i++) {\n \t\tstruct ref_list_entry *e = p->list + i;\n-\t\tcommit = lookup_commit_reference_gently(the_repository, &e->oid, 1);\n+\t\tcommit = lookup_commit_reference_gently(r, &e->oid, 1);\n \t\tif (commit)\n \t\t\tclear_commit_marks(commit, ALL_REV_FLAGS);\n \t}\n@@ -375,8 +377,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)\n \t\t\t * in terms of a tag (e.g. v2.0 from the range\n \t\t\t * \"v1.0..v2.0\")?\n \t\t\t */\n-\t\t\tstruct commit *one = lookup_commit_reference(the_repository,\n-\t\t\t\t\t\t\t\t     &oid);\n+\t\t\tstruct commit *one = lookup_commit_reference(revs->repo, &oid);\n \t\t\tstruct object *obj;\n \n \t\t\tif (e->item == &(one->object)) {\n@@ -409,8 +410,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)\n \treturn ref_count;\n }\n \n-int create_bundle(struct bundle_header *header, const char *path,\n-\t\t  int argc, const char **argv)\n+int create_bundle(struct repository *r, struct bundle_header *header,\n+\t\t  const char *path, int argc, const char **argv)\n {\n \tstruct lock_file lock = LOCK_INIT;\n \tint bundle_fd = -1;\n@@ -441,7 +442,7 @@ int create_bundle(struct bundle_header *header, const char *path,\n \n \t/* init revs to list objects for pack-objects later */\n \tsave_commit_buffer = 0;\n-\trepo_init_revisions(the_repository, &revs, NULL);\n+\trepo_init_revisions(r, &revs, NULL);\n \n \t/* write prerequisites */\n \tif (compute_and_write_prerequisites(bundle_fd, &revs, argc, argv))\n@@ -482,7 +483,8 @@ int create_bundle(struct bundle_header *header, const char *path,\n \treturn -1;\n }\n \n-int unbundle(struct bundle_header *header, int bundle_fd, int flags)\n+int unbundle(struct repository *r, struct bundle_header *header,\n+\t     int bundle_fd, int flags)\n {\n \tconst char *argv_index_pack[] = {\"index-pack\",\n \t\t\t\t\t \"--fix-thin\", \"--stdin\", NULL, NULL};\n@@ -491,7 +493,7 @@ int unbundle(struct bundle_header *header, int bundle_fd, int flags)\n \tif (flags & BUNDLE_VERBOSE)\n \t\targv_index_pack[3] = \"-v\";\n \n-\tif (verify_bundle(header, 0))\n+\tif (verify_bundle(r, header, 0))\n \t\treturn -1;\n \tip.argv = argv_index_pack;\n \tip.in = bundle_fd;\ndiff --git a/bundle.h b/bundle.h\nindex e9a4cb6a74..781e6f5c3a 100644\n--- a/bundle.h\n+++ b/bundle.h\n@@ -18,11 +18,12 @@ struct bundle_header {\n \n int is_bundle(const char *path, int quiet);\n int read_bundle_header(const char *path, struct bundle_header *header);\n-int create_bundle(struct bundle_header *header, const char *path,\n-\t\tint argc, const char **argv);\n-int verify_bundle(struct bundle_header *header, int verbose);\n+int create_bundle(struct repository *r, struct bundle_header *header,\n+\t\t  const char *path, int argc, const char **argv);\n+int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);\n #define BUNDLE_VERBOSE 1\n-int unbundle(struct bundle_header *header, int bundle_fd, int flags);\n+int unbundle(struct repository *r, struct bundle_header *header,\n+\t     int bundle_fd, int flags);\n int list_bundle_refs(struct bundle_header *header,\n \t\tint argc, const char **argv);\n \ndiff --git a/transport.c b/transport.c\nindex 71f663743f..f6e54f6412 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -154,7 +154,7 @@ static int fetch_refs_from_bundle(struct transport *transport,\n \t\t\t       int nr_heads, struct ref **to_fetch)\n {\n \tstruct bundle_transport_data *data = transport->data;\n-\treturn unbundle(&data->header, data->fd,\n+\treturn unbundle(the_repository, &data->header, data->fd,\n \t\t\ttransport->progress ? BUNDLE_VERBOSE : 0);\n }\n \n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362887","messageId":"20181110054910.10568-11-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 10/22] blame.c: remove implicit dependency the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:58Z","receivedAt":"2018-11-10T05:49:53Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n blame.c | 39 ++++++++++++++++++++++-----------------\n 1 file changed, 22 insertions(+), 17 deletions(-)\n\ndiff --git a/blame.c b/blame.c\nindex d84c937780..43861437f7 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -116,35 +116,38 @@ static void verify_working_tree_path(struct repository *r,\n \t\tdie(\"no such path '%s' in HEAD\", path);\n }\n \n-static struct commit_list **append_parent(struct commit_list **tail, const struct object_id *oid)\n+static struct commit_list **append_parent(struct repository *r,\n+\t\t\t\t\t  struct commit_list **tail,\n+\t\t\t\t\t  const struct object_id *oid)\n {\n \tstruct commit *parent;\n \n-\tparent = lookup_commit_reference(the_repository, oid);\n+\tparent = lookup_commit_reference(r, oid);\n \tif (!parent)\n \t\tdie(\"no such commit %s\", oid_to_hex(oid));\n \treturn &commit_list_insert(parent, tail)->next;\n }\n \n-static void append_merge_parents(struct commit_list **tail)\n+static void append_merge_parents(struct repository *r,\n+\t\t\t\t struct commit_list **tail)\n {\n \tint merge_head;\n \tstruct strbuf line = STRBUF_INIT;\n \n-\tmerge_head = open(git_path_merge_head(the_repository), O_RDONLY);\n+\tmerge_head = open(git_path_merge_head(r), O_RDONLY);\n \tif (merge_head < 0) {\n \t\tif (errno == ENOENT)\n \t\t\treturn;\n \t\tdie(\"cannot open '%s' for reading\",\n-\t\t    git_path_merge_head(the_repository));\n+\t\t    git_path_merge_head(r));\n \t}\n \n \twhile (!strbuf_getwholeline_fd(&line, merge_head, '\\n')) {\n \t\tstruct object_id oid;\n \t\tif (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))\n \t\t\tdie(\"unknown line in '%s': %s\",\n-\t\t\t    git_path_merge_head(the_repository), line.buf);\n-\t\ttail = append_parent(tail, &oid);\n+\t\t\t    git_path_merge_head(r), line.buf);\n+\t\ttail = append_parent(r, tail, &oid);\n \t}\n \tclose(merge_head);\n \tstrbuf_release(&line);\n@@ -155,11 +158,13 @@ static void append_merge_parents(struct commit_list **tail)\n  * want to transfer ownership of the buffer to the commit (so we\n  * must use detach).\n  */\n-static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)\n+static void set_commit_buffer_from_strbuf(struct repository *r,\n+\t\t\t\t\t  struct commit *c,\n+\t\t\t\t\t  struct strbuf *sb)\n {\n \tsize_t len;\n \tvoid *buf = strbuf_detach(sb, &len);\n-\tset_commit_buffer(the_repository, c, buf, len);\n+\tset_commit_buffer(r, c, buf, len);\n }\n \n /*\n@@ -185,7 +190,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,\n \n \tread_index(r->index);\n \ttime(&now);\n-\tcommit = alloc_commit_node(the_repository);\n+\tcommit = alloc_commit_node(r);\n \tcommit->object.parsed = 1;\n \tcommit->date = now;\n \tparent_tail = &commit->parents;\n@@ -193,8 +198,8 @@ static struct commit *fake_working_tree_commit(struct repository *r,\n \tif (!resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING, &head_oid, NULL))\n \t\tdie(\"no such ref: HEAD\");\n \n-\tparent_tail = append_parent(parent_tail, &head_oid);\n-\tappend_merge_parents(parent_tail);\n+\tparent_tail = append_parent(r, parent_tail, &head_oid);\n+\tappend_merge_parents(r, parent_tail);\n \tverify_working_tree_path(r, commit, path);\n \n \torigin = make_origin(commit, path);\n@@ -211,7 +216,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,\n \t\t    ident, ident, path,\n \t\t    (!contents_from ? path :\n \t\t     (!strcmp(contents_from, \"-\") ? \"standard input\" : contents_from)));\n-\tset_commit_buffer_from_strbuf(commit, &msg);\n+\tset_commit_buffer_from_strbuf(r, commit, &msg);\n \n \tif (!contents_from || strcmp(\"-\", contents_from)) {\n \t\tstruct stat st;\n@@ -1678,7 +1683,7 @@ static struct commit *find_single_final(struct rev_info *revs,\n \t\tstruct object *obj = revs->pending.objects[i].item;\n \t\tif (obj->flags & UNINTERESTING)\n \t\t\tcontinue;\n-\t\tobj = deref_tag(the_repository, obj, NULL, 0);\n+\t\tobj = deref_tag(revs->repo, obj, NULL, 0);\n \t\tif (obj->type != OBJ_COMMIT)\n \t\t\tdie(\"Non commit %s?\", revs->pending.objects[i].name);\n \t\tif (found)\n@@ -1709,14 +1714,14 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,\n \n \t/* Is that sole rev a committish? */\n \tobj = revs->pending.objects[0].item;\n-\tobj = deref_tag(the_repository, obj, NULL, 0);\n+\tobj = deref_tag(revs->repo, obj, NULL, 0);\n \tif (obj->type != OBJ_COMMIT)\n \t\treturn NULL;\n \n \t/* Do we have HEAD? */\n \tif (!resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING, &head_oid, NULL))\n \t\treturn NULL;\n-\thead_commit = lookup_commit_reference_gently(the_repository,\n+\thead_commit = lookup_commit_reference_gently(revs->repo,\n \t\t\t\t\t\t     &head_oid, 1);\n \tif (!head_commit)\n \t\treturn NULL;\n@@ -1745,7 +1750,7 @@ static struct commit *find_single_initial(struct rev_info *revs,\n \t\tstruct object *obj = revs->pending.objects[i].item;\n \t\tif (!(obj->flags & UNINTERESTING))\n \t\t\tcontinue;\n-\t\tobj = deref_tag(the_repository, obj, NULL, 0);\n+\t\tobj = deref_tag(revs->repo, obj, NULL, 0);\n \t\tif (obj->type != OBJ_COMMIT)\n \t\t\tdie(\"Non commit %s?\", revs->pending.objects[i].name);\n \t\tif (found)\n-- \n2.19.1.1231.g84aef82467\n\n"},{"id":"362888","messageId":"20181110054910.10568-3-pclouds@gmail.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"[PATCH v2 02/22] wt-status.c: remove implicit dependency the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-11-10T05:48:50Z","receivedAt":"2018-11-10T05:50: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 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 0c45ed9d94..c4eaf30313 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1413,7 +1413,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 6d401b2c24..e582c54238 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -755,7 +755,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@@ -1482,7 +1482,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@@ -1499,7 +1500,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@@ -1556,30 +1557,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 8375e816fb..3a95975032 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -134,7 +134,9 @@ void wt_status_prepare(struct repository *r, struct wt_status *s);\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.1231.g84aef82467\n\n"},{"id":"362965","messageId":"xmqqftw63kpq.fsf@gitster-ct.c.googlers.com","threadId":"49791","inReplyTo":"20181110054910.10568-1-pclouds@gmail.com","subject":"Re: [PATCH v2 00/22] Kill the_index part 5","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-11-12T05:53:37Z","receivedAt":"2018-11-12T05:53:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> I did start pushing the_repository out of library code [1] in the bottom\n> half of this series. There aren't big surprises except that cache-tree\n> API now take _both_ struct repository and struct index_state. The\n> reason is cache-tree can work on temporary indexes and repo->index is\n> about $GIT_DIR/index.\n\nYes, this is very sensible, and I expect many more functions would\n(and probably should) follow suit, as we'd want to be able to work\nwith temporary index (not in the sense that we'll write out on-disk\ntemporary index, but multiple in-core instances of istate that is\nnot necessarily tied to the current or the next state of\n$GIT_DIR/index) from more places.\n\n"}]}