{"thread":{"id":"50887","subject":"[PATCH][RFC] read-cache: read_index_from() accepts repo as arg","startedAt":"2019-04-07T07:37:38Z","lastAt":"2019-04-09T02:07:54Z","messageCount":4,"participants":["Kapil Jain","Duy Nguyen","Taylor Blau"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"373345","messageId":"20190407073712.1642-1-jkapil.cs@gmail.com","threadId":"50887","inReplyTo":null,"subject":"[PATCH][RFC] read-cache: read_index_from() accepts repo as arg","fromName":"Kapil Jain","fromEmail":"jkapil.cs@gmail.com","sentAt":"2019-04-07T07:37:12Z","receivedAt":"2019-04-07T07:37:38Z","isPatch":true,"sender":{"key":"jkapil.cs@gmail.com","avatar":null},"body":"Signed-off-by: Kapil Jain <jkapil.cs@gmail.com>\n---\n\nIn read-cache, the read_index_from() function had a TODO task,\nthis patch completes that. There are some other functions in the same file\nwhere this exact TODO needs to be done, will proceed to do them once this patch is accepted.\n\nrunning test gave 256 not okays, each had a label as `# TODO known breakage`, which i think\nare not concerned to this patch.\n\n apply.c            | 2 +-\n builtin/worktree.c | 2 +-\n cache-tree.c       | 2 +-\n cache.h            | 4 ++--\n read-cache.c       | 4 ++--\n repository.c       | 2 +-\n revision.c         | 2 +-\n 7 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex f15afa9f6a..3b4d128149 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4021,7 +4021,7 @@ static int read_apply_cache(struct apply_state *state)\n {\n \tif (state->index_file)\n \t\treturn read_index_from(state->repo->index, state->index_file,\n-\t\t\t\t       get_git_dir());\n+\t\t\t\t       get_git_dir(), state->repo);\n \telse\n \t\treturn repo_read_index(state->repo);\n }\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 6cc094a453..874adebd2c 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -737,7 +737,7 @@ static void validate_no_submodules(const struct worktree *wt)\n \t\t */\n \t\tfound_submodules = 1;\n \t} else if (read_index_from(&istate, worktree_git_path(wt, \"index\"),\n-\t\t\t\t   get_worktree_git_dir(wt)) > 0) {\n+\t\t\t\t   get_worktree_git_dir(wt), the_repository) > 0) {\n \t\tfor (i = 0; i < istate.cache_nr; i++) {\n \t\t\tstruct cache_entry *ce = istate.cache[i];\n \t\t\tint err;\ndiff --git a/cache-tree.c b/cache-tree.c\nindex b13bfaf71e..84f19b224e 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -616,7 +616,7 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,\n \n \thold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR);\n \n-\tentries = read_index_from(index_state, index_path, get_git_dir());\n+\tentries = read_index_from(index_state, index_path, get_git_dir(), the_repository);\n \tif (entries < 0) {\n \t\tret = WRITE_TREE_UNREADABLE_INDEX;\n \t\tgoto out;\ndiff --git a/cache.h b/cache.h\nindex ac92421f3a..3850c82fc9 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -420,7 +420,7 @@ extern struct index_state the_index;\n #define active_cache_tree (the_index.cache_tree)\n \n #define read_cache() repo_read_index(the_repository)\n-#define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))\n+#define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()), the_repository)\n #define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)\n #define is_cache_unborn() is_index_unborn(&the_index)\n #define read_cache_unmerged() repo_read_index_unmerged(the_repository)\n@@ -678,7 +678,7 @@ extern void preload_index(struct index_state *index,\n extern int do_read_index(struct index_state *istate, const char *path,\n \t\t\t int must_exist); /* for testting only! */\n extern int read_index_from(struct index_state *, const char *path,\n-\t\t\t   const char *gitdir);\n+\t\t\t   const char *gitdir, const struct repository *repo);\n extern int is_index_unborn(struct index_state *);\n \n /* For use with `write_locked_index()`. */\ndiff --git a/read-cache.c b/read-cache.c\nindex 4dc6de1b55..0444703284 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2256,7 +2256,7 @@ static void freshen_shared_index(const char *shared_index, int warn)\n }\n \n int read_index_from(struct index_state *istate, const char *path,\n-\t\t    const char *gitdir)\n+\t\t    const char *gitdir, const struct repository *repo)\n {\n \tstruct split_index *split_index;\n \tint ret;\n@@ -2292,7 +2292,7 @@ int read_index_from(struct index_state *istate, const char *path,\n \t\tsplit_index->base = xcalloc(1, sizeof(*split_index->base));\n \n \tbase_oid_hex = oid_to_hex(&split_index->base_oid);\n-\tbase_path = xstrfmt(\"%s/sharedindex.%s\", gitdir, base_oid_hex);\n+\tbase_path = xstrfmt(\"%s/sharedindex.%s\", repo->gitdir, base_oid_hex);\n \ttrace2_region_enter_printf(\"index\", \"shared/do_read_index\",\n \t\t\t\t   the_repository, \"%s\", base_path);\n \tret = do_read_index(split_index->base, base_path, 1);\ndiff --git a/repository.c b/repository.c\nindex 682c239fe3..8ac2b65f61 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -264,7 +264,7 @@ int repo_read_index(struct repository *repo)\n \tif (!repo->index)\n \t\trepo->index = xcalloc(1, sizeof(*repo->index));\n \n-\treturn read_index_from(repo->index, repo->index_file, repo->gitdir);\n+\treturn read_index_from(repo->index, repo->index_file, repo->gitdir, repo);\n }\n \n int repo_hold_locked_index(struct repository *repo,\ndiff --git a/revision.c b/revision.c\nindex eb8e51bc63..247a4d5704 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1556,7 +1556,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)\n \n \t\tif (read_index_from(&istate,\n \t\t\t\t    worktree_git_path(wt, \"index\"),\n-\t\t\t\t    get_worktree_git_dir(wt)) > 0)\n+\t\t\t\t    get_worktree_git_dir(wt), the_repository) > 0)\n \t\t\tdo_add_index_objects_to_pending(revs, &istate, flags);\n \t\tdiscard_index(&istate);\n \t}\n-- \n2.20.1\n\n"},{"id":"373346","messageId":"20190407100010.GA23427@ash","threadId":"50887","inReplyTo":"20190407073712.1642-1-jkapil.cs@gmail.com","subject":"Re: [PATCH][RFC] read-cache: read_index_from() accepts repo as arg","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-07T10:00:11Z","receivedAt":"2019-04-07T10:03:28Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Apr 07, 2019 at 01:07:12PM +0530, Kapil Jain wrote:\n> Signed-off-by: Kapil Jain <jkapil.cs@gmail.com>\n> ---\n> \n> In read-cache, the read_index_from() function had a TODO task, this\n> patch completes that.\n\nThis line at least should be above the \"---\" line (i.e. part of the\ncommit message).\n\n> diff --git a/read-cache.c b/read-cache.c\n> index 4dc6de1b55..0444703284 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -2256,7 +2256,7 @@ static void freshen_shared_index(const char *shared_index, int warn)\n>  }\n>  \n>  int read_index_from(struct index_state *istate, const char *path,\n> -\t\t    const char *gitdir)\n> +\t\t    const char *gitdir, const struct repository *repo)\n\n\"struct repository *\" by convention is always the first argument. See\n\nhttps://public-inbox.org/git/xmqqsh2p6l43.fsf@gitster-ct.c.googlers.com/\n\nYou also do not need \"gitdir\" as a separate argument because gitdir is\nan attribute of a repository. Passing it separately is just a trap to\ngive inconsistent information (e.g. one repo and one gitdir from\nanother one).\n\nI see you already use repo->gitdir below. Which means this argument\n\"gitdir\" is no longer used anyway. Please remove.\n\n>  {\n>  \tstruct split_index *split_index;\n>  \tint ret;\n> @@ -2292,7 +2292,7 @@ int read_index_from(struct index_state *istate, const char *path,\n>  \t\tsplit_index->base = xcalloc(1, sizeof(*split_index->base));\n>  \n>  \tbase_oid_hex = oid_to_hex(&split_index->base_oid);\n> -\tbase_path = xstrfmt(\"%s/sharedindex.%s\", gitdir, base_oid_hex);\n> +\tbase_path = xstrfmt(\"%s/sharedindex.%s\", repo->gitdir, base_oid_hex);\n>  \ttrace2_region_enter_printf(\"index\", \"shared/do_read_index\",\n>  \t\t\t\t   the_repository, \"%s\", base_path);\n\n\"the_repository\" here (and all others in this function) should be\nreplaced with \"repo\". The TODO comment in this function should be\nremoved as well.\n\n>  \tret = do_read_index(split_index->base, base_path, 1);\n> diff --git a/revision.c b/revision.c\n> index eb8e51bc63..247a4d5704 100644\n> --- a/revision.c\n> +++ b/revision.c\n> @@ -1556,7 +1556,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)\n>  \n>  \t\tif (read_index_from(&istate,\n>  \t\t\t\t    worktree_git_path(wt, \"index\"),\n> -\t\t\t\t    get_worktree_git_dir(wt)) > 0)\n> +\t\t\t\t    get_worktree_git_dir(wt), the_repository) > 0)\n\nWe have revs->repo to refer to the main repo being examined here. But\nif the \"gitdir\" argument is deleted, then revs->repo->gitdir gives a\n_wrong_ gitdir, it's not the same as get_worktree_git_dir(wt).\n\nSo before you can continue here, you'll need to add a function,\ne.g. repo_worktree_init() (similar to repo_init() and\nrepo_submodule_init()). This one should take \"struct worktree *\" as\nthe argument and return \"struct repository *\"\n\nSo, with something like a patch below (not tested), you should be able\nto write\n\n\tworktrees = repo_get_worktrees(revs->repo, 0);\n\t...\n\t\tstruct repository *r = repo_worktree_init(wt);\n\t\tif (read_index_from(&istate, r->index_file, r) > 0)\n\t\t\tdo_add_index_objects_to_pending(revs, &istate, flags);\n\t\trepo_clear(r);\n\n-- 8< --\ndiff --git a/repository.c b/repository.c\nindex 682c239fe3..5a0c7972db 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -10,6 +10,7 @@\n #include \"object.h\"\n #include \"lockfile.h\"\n #include \"submodule-config.h\"\n+#include \"worktree.h\"\n \n /* The main repository */\n static struct repository the_repo;\n@@ -227,6 +228,28 @@ int repo_submodule_init(struct repository *subrepo,\n \treturn ret;\n }\n \n+int repo_worktree_init(struct repository *repo,\n+\t\t       struct repository *source_repo,\n+\t\t       const struct worktree *wt)\n+{\n+\tstruct strbuf gitdir = STRBUF_INIT;\n+\tint ret;\n+\n+\tif (!wt)\n+\t\treturn -1;\n+\n+\tif (!wt->id)\n+\t\tstrbuf_addstr(&gitdir, source_repo->commondir);\n+\telse\n+\t\tstrbuf_addf(&gitdir, \"%s/worktrees/%s\",\n+\t\t\t    source_repo->commondir,\n+\t\t\t    wt->id);\n+\n+\tret = repo_init(source_repo, gitdir.buf, wt->path);\n+\tstrbuf_release(&gitdir);\n+\treturn ret ? -1 : 0;\n+}\n+\n void repo_clear(struct repository *repo)\n {\n \tFREE_AND_NULL(repo->gitdir);\ndiff --git a/repository.h b/repository.h\nindex 4fb6a5885f..d3c21c7ab5 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -122,6 +122,10 @@ void repo_set_hash_algo(struct repository *repo, int algo);\n void initialize_the_repository(void);\n int repo_init(struct repository *r, const char *gitdir, const char *worktree);\n \n+struct worktree;\n+int repo_worktree_init(struct repository *r, struct repository *source,\n+\t\t       const struct worktree *wt);\n+\n /*\n  * Initialize the repository 'subrepo' as the submodule given by the\n  * struct submodule 'sub' in parent repository 'superproject'.\ndiff --git a/worktree.c b/worktree.c\nindex b45bfeb9d3..188ea04c61 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -44,19 +44,19 @@ static void add_head_info(struct worktree *wt)\n /**\n  * get the main worktree\n  */\n-static struct worktree *get_main_worktree(void)\n+static struct worktree *get_main_worktree(struct repository *r)\n {\n \tstruct worktree *worktree = NULL;\n \tstruct strbuf path = STRBUF_INIT;\n \tstruct strbuf worktree_path = STRBUF_INIT;\n \tint is_bare = 0;\n \n-\tstrbuf_add_absolute_path(&worktree_path, get_git_common_dir());\n+\tstrbuf_add_absolute_path(&worktree_path, r->commondir);\n \tis_bare = !strbuf_strip_suffix(&worktree_path, \"/.git\");\n \tif (is_bare)\n \t\tstrbuf_strip_suffix(&worktree_path, \"/.\");\n \n-\tstrbuf_addf(&path, \"%s/HEAD\", get_git_common_dir());\n+\tstrbuf_addf(&path, \"%s/HEAD\", r->commondir);\n \n \tworktree = xcalloc(1, sizeof(*worktree));\n \tworktree->path = strbuf_detach(&worktree_path, NULL);\n@@ -68,7 +68,7 @@ static struct worktree *get_main_worktree(void)\n \treturn worktree;\n }\n \n-static struct worktree *get_linked_worktree(const char *id)\n+static struct worktree *get_linked_worktree(struct repository *r, const char *id)\n {\n \tstruct worktree *worktree = NULL;\n \tstruct strbuf path = STRBUF_INIT;\n@@ -77,7 +77,7 @@ static struct worktree *get_linked_worktree(const char *id)\n \tif (!id)\n \t\tdie(\"Missing linked worktree name\");\n \n-\tstrbuf_git_common_path(&path, the_repository, \"worktrees/%s/gitdir\", id);\n+\tstrbuf_git_common_path(&path, r, \"worktrees/%s/gitdir\", id);\n \tif (strbuf_read_file(&worktree_path, path.buf, 0) <= 0)\n \t\t/* invalid gitdir file */\n \t\tgoto done;\n@@ -90,7 +90,7 @@ static struct worktree *get_linked_worktree(const char *id)\n \t}\n \n \tstrbuf_reset(&path);\n-\tstrbuf_addf(&path, \"%s/worktrees/%s/HEAD\", get_git_common_dir(), id);\n+\tstrbuf_addf(&path, \"%s/worktrees/%s/HEAD\", r->commondir, id);\n \n \tworktree = xcalloc(1, sizeof(*worktree));\n \tworktree->path = strbuf_detach(&worktree_path, NULL);\n@@ -127,7 +127,7 @@ static int compare_worktree(const void *a_, const void *b_)\n \treturn fspathcmp((*a)->path, (*b)->path);\n }\n \n-struct worktree **get_worktrees(unsigned flags)\n+struct worktree **repo_get_worktrees(struct repository *r, unsigned flags)\n {\n \tstruct worktree **list = NULL;\n \tstruct strbuf path = STRBUF_INIT;\n@@ -137,9 +137,9 @@ struct worktree **get_worktrees(unsigned flags)\n \n \tALLOC_ARRAY(list, alloc);\n \n-\tlist[counter++] = get_main_worktree();\n+\tlist[counter++] = get_main_worktree(r);\n \n-\tstrbuf_addf(&path, \"%s/worktrees\", get_git_common_dir());\n+\tstrbuf_addf(&path, \"%s/worktrees\", r->commondir);\n \tdir = opendir(path.buf);\n \tstrbuf_release(&path);\n \tif (dir) {\n@@ -148,7 +148,7 @@ struct worktree **get_worktrees(unsigned flags)\n \t\t\tif (is_dot_or_dotdot(d->d_name))\n \t\t\t\tcontinue;\n \n-\t\t\tif ((linked = get_linked_worktree(d->d_name))) {\n+\t\t\tif ((linked = get_linked_worktree(r, d->d_name))) {\n \t\t\t\tALLOC_GROW(list, counter + 1, alloc);\n \t\t\t\tlist[counter++] = linked;\n \t\t\t}\ndiff --git a/worktree.h b/worktree.h\nindex 9e3b0b7b6f..cb4307db16 100644\n--- a/worktree.h\n+++ b/worktree.h\n@@ -30,7 +30,8 @@ struct worktree {\n  * The caller is responsible for freeing the memory from the returned\n  * worktree(s).\n  */\n-extern struct worktree **get_worktrees(unsigned flags);\n+struct worktree **repo_get_worktrees(struct repository *r, unsigned flags);\n+#define get_worktrees(flags) repo_get_worktrees(the_repository, flags)\n \n /*\n  * Returns 1 if linked worktrees exist, 0 otherwise.\n-- 8< --\n\n\n\n>  \t\t\tdo_add_index_objects_to_pending(revs, &istate, flags);\n>  \t\tdiscard_index(&istate);\n>  \t}\n> -- \n> 2.20.1\n> \n"},{"id":"373347","messageId":"20190407101938.GA24126@ash","threadId":"50887","inReplyTo":"20190407100010.GA23427@ash","subject":"Re: [PATCH][RFC] read-cache: read_index_from() accepts repo as arg","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-07T10:19:38Z","receivedAt":"2019-04-07T10:19:46Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Apr 07, 2019 at 05:00:11PM +0700, Duy Nguyen wrote:\n> So, with something like a patch below (not tested), you should be able\n> to write\n> \n> \tworktrees = repo_get_worktrees(revs->repo, 0);\n> \t...\n> \t\tstruct repository *r = repo_worktree_init(wt);\n> \t\tif (read_index_from(&istate, r->index_file, r) > 0)\n> \t\t\tdo_add_index_objects_to_pending(revs, &istate, flags);\n> \t\trepo_clear(r);\n\nActually it gets better. You can just use repo_read_index()\n\ndiff --git a/revision.c b/revision.c\nindex eb8e51bc63..93fe8bbbfe 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1546,19 +1546,18 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)\n \tif (revs->single_worktree)\n \t\treturn;\n \n-\tworktrees = get_worktrees(0);\n+\tworktrees = repo_get_worktrees(revs->repo);\n \tfor (p = worktrees; *p; p++) {\n+\t\tstruct repository repo;\n \t\tstruct worktree *wt = *p;\n-\t\tstruct index_state istate = { NULL };\n \n \t\tif (wt->is_current)\n \t\t\tcontinue; /* current index already taken care of */\n \n-\t\tif (read_index_from(&istate,\n-\t\t\t\t    worktree_git_path(wt, \"index\"),\n-\t\t\t\t    get_worktree_git_dir(wt)) > 0)\n-\t\t\tdo_add_index_objects_to_pending(revs, &istate, flags);\n-\t\tdiscard_index(&istate);\n+\t\trepo_worktree_init(repo, revs->repo, wt);\n+\t\tif (repo_read_index(repo) > 0)\n+\t\t\tdo_add_index_objects_to_pending(revs, repo->index, flags);\n+\t\trepo_clear(&repo);\n \t}\n \tfree_worktrees(worktrees);\n }\n--\nDuy\n"},{"id":"373448","messageId":"20190409020749.GC81620@Taylors-MBP.hsd1.wa.comcast.net","threadId":"50887","inReplyTo":"20190407073712.1642-1-jkapil.cs@gmail.com","subject":"Re: [PATCH][RFC] read-cache: read_index_from() accepts repo as arg","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2019-04-09T02:07:49Z","receivedAt":"2019-04-09T02:07:54Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi Kapil,\n\nOn Sun, Apr 07, 2019 at 01:07:12PM +0530, Kapil Jain wrote:\n> Signed-off-by: Kapil Jain <jkapil.cs@gmail.com>\n> ---\n>\n> In read-cache, the read_index_from() function had a TODO task,\n> this patch completes that. There are some other functions in the same file\n> where this exact TODO needs to be done, will proceed to do them once this patch is accepted.\n>\n> running test gave 256 not okays, each had a label as `# TODO known breakage`, which i think\n> are not concerned to this patch.\n\nPlease make sure to wrap your commit messages at 72 characters per-line.\nIncidentally, I just wrote another email about this same topic [1],\nwhich has some good advice for how to do this in an automated way.\n\n>  apply.c            | 2 +-\n>  builtin/worktree.c | 2 +-\n>  cache-tree.c       | 2 +-\n>  cache.h            | 4 ++--\n>  read-cache.c       | 4 ++--\n>  repository.c       | 2 +-\n>  revision.c         | 2 +-\n>  7 files changed, 9 insertions(+), 9 deletions(-)\n>\n> diff --git a/apply.c b/apply.c\n> index f15afa9f6a..3b4d128149 100644\n> --- a/apply.c\n> +++ b/apply.c\n> @@ -4021,7 +4021,7 @@ static int read_apply_cache(struct apply_state *state)\n>  {\n>  \tif (state->index_file)\n>  \t\treturn read_index_from(state->repo->index, state->index_file,\n> -\t\t\t\t       get_git_dir());\n> +\t\t\t\t       get_git_dir(), state->repo);\n>  \telse\n>  \t\treturn repo_read_index(state->repo);\n>  }\n> diff --git a/builtin/worktree.c b/builtin/worktree.c\n> index 6cc094a453..874adebd2c 100644\n> --- a/builtin/worktree.c\n> +++ b/builtin/worktree.c\n> @@ -737,7 +737,7 @@ static void validate_no_submodules(const struct worktree *wt)\n>  \t\t */\n>  \t\tfound_submodules = 1;\n>  \t} else if (read_index_from(&istate, worktree_git_path(wt, \"index\"),\n> -\t\t\t\t   get_worktree_git_dir(wt)) > 0) {\n> +\t\t\t\t   get_worktree_git_dir(wt), the_repository) > 0) {\n>  \t\tfor (i = 0; i < istate.cache_nr; i++) {\n>  \t\t\tstruct cache_entry *ce = istate.cache[i];\n>  \t\t\tint err;\n> diff --git a/cache-tree.c b/cache-tree.c\n> index b13bfaf71e..84f19b224e 100644\n> --- a/cache-tree.c\n> +++ b/cache-tree.c\n> @@ -616,7 +616,7 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,\n>\n>  \thold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR);\n>\n> -\tentries = read_index_from(index_state, index_path, get_git_dir());\n> +\tentries = read_index_from(index_state, index_path, get_git_dir(), the_repository);\n>  \tif (entries < 0) {\n>  \t\tret = WRITE_TREE_UNREADABLE_INDEX;\n>  \t\tgoto out;\n> diff --git a/cache.h b/cache.h\n> index ac92421f3a..3850c82fc9 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -420,7 +420,7 @@ extern struct index_state the_index;\n>  #define active_cache_tree (the_index.cache_tree)\n>\n>  #define read_cache() repo_read_index(the_repository)\n> -#define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))\n> +#define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()), the_repository)\n>  #define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)\n>  #define is_cache_unborn() is_index_unborn(&the_index)\n>  #define read_cache_unmerged() repo_read_index_unmerged(the_repository)\n> @@ -678,7 +678,7 @@ extern void preload_index(struct index_state *index,\n>  extern int do_read_index(struct index_state *istate, const char *path,\n>  \t\t\t int must_exist); /* for testting only! */\n>  extern int read_index_from(struct index_state *, const char *path,\n> -\t\t\t   const char *gitdir);\n> +\t\t\t   const char *gitdir, const struct repository *repo);\n>  extern int is_index_unborn(struct index_state *);\n>\n>  /* For use with `write_locked_index()`. */\n> diff --git a/read-cache.c b/read-cache.c\n> index 4dc6de1b55..0444703284 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -2256,7 +2256,7 @@ static void freshen_shared_index(const char *shared_index, int warn)\n>  }\n>\n>  int read_index_from(struct index_state *istate, const char *path,\n> -\t\t    const char *gitdir)\n> +\t\t    const char *gitdir, const struct repository *repo)\n>  {\n>  \tstruct split_index *split_index;\n>  \tint ret;\n> @@ -2292,7 +2292,7 @@ int read_index_from(struct index_state *istate, const char *path,\n>  \t\tsplit_index->base = xcalloc(1, sizeof(*split_index->base));\n>\n>  \tbase_oid_hex = oid_to_hex(&split_index->base_oid);\n> -\tbase_path = xstrfmt(\"%s/sharedindex.%s\", gitdir, base_oid_hex);\n> +\tbase_path = xstrfmt(\"%s/sharedindex.%s\", repo->gitdir, base_oid_hex);\n>  \ttrace2_region_enter_printf(\"index\", \"shared/do_read_index\",\n>  \t\t\t\t   the_repository, \"%s\", base_path);\n>  \tret = do_read_index(split_index->base, base_path, 1);\n> diff --git a/repository.c b/repository.c\n> index 682c239fe3..8ac2b65f61 100644\n> --- a/repository.c\n> +++ b/repository.c\n> @@ -264,7 +264,7 @@ int repo_read_index(struct repository *repo)\n>  \tif (!repo->index)\n>  \t\trepo->index = xcalloc(1, sizeof(*repo->index));\n>\n> -\treturn read_index_from(repo->index, repo->index_file, repo->gitdir);\n> +\treturn read_index_from(repo->index, repo->index_file, repo->gitdir, repo);\n>  }\n>\n>  int repo_hold_locked_index(struct repository *repo,\n> diff --git a/revision.c b/revision.c\n> index eb8e51bc63..247a4d5704 100644\n> --- a/revision.c\n> +++ b/revision.c\n> @@ -1556,7 +1556,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)\n>\n>  \t\tif (read_index_from(&istate,\n>  \t\t\t\t    worktree_git_path(wt, \"index\"),\n> -\t\t\t\t    get_worktree_git_dir(wt)) > 0)\n> +\t\t\t\t    get_worktree_git_dir(wt), the_repository) > 0)\n>  \t\t\tdo_add_index_objects_to_pending(revs, &istate, flags);\n>  \t\tdiscard_index(&istate);\n>  \t}\n> --\n> 2.20.1\n>\nThanks,\nTaylor\n\n[1]: https://public-inbox.org/git/20190409020004.GA81620@Taylors-MBP.hsd1.wa.comcast.net/\n"}]}