{"thread":{"id":"66853","subject":"[PATCH] read-cache: use istate->repo in overlay_tree_on_index()","startedAt":"2026-11-16T10:34:29Z","lastAt":"2026-11-18T18:45:23Z","messageCount":4,"participants":["Srujith A Poojary via GitGitGadget","Derrick Stolee","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558531","messageId":"pull.2315.git.1794825269464.gitgitgadget@gmail.com","threadId":"66853","inReplyTo":null,"subject":"[PATCH] read-cache: use istate->repo in overlay_tree_on_index()","fromName":"Srujith A Poojary via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-16T10:34:29Z","receivedAt":"2026-11-16T10:34:29Z","isPatch":true,"sender":{"key":"name:Srujith A Poojary","avatar":null},"body":"From: Srujith A Poojary <poojarysrujith@gmail.com>\n\nUse the repository associated with the index state when\nresolving the tree name, parsing the tree, and reading\nits entries.\n\nThis avoids relying on the global repository when the\nfunction already has access to its associated repository.\n\nSigned-off-by: Srujith A Poojary <poojarysrujith@gmail.com>\n---\n    read-cache: use istate->repo in overlay_tree_on_index()\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2315%2Fpoojarysrujith%2Flibification-overlay-tree-repo-clean-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2315/poojarysrujith/libification-overlay-tree-repo-clean-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2315\n\n read-cache.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 5bbfbfeceb..063ad523d2 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -3874,6 +3874,7 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base\n void overlay_tree_on_index(struct index_state *istate,\n \t\t\t   const char *tree_name, const char *prefix)\n {\n+\tstruct repository *repo = istate->repo;\n \tstruct tree *tree;\n \tstruct object_id oid;\n \tstruct pathspec pathspec;\n@@ -3882,9 +3883,9 @@ void overlay_tree_on_index(struct index_state *istate,\n \tread_tree_fn_t fn = NULL;\n \tint err;\n \n-\tif (repo_get_oid(the_repository, tree_name, &oid))\n+\tif (repo_get_oid(repo, tree_name, &oid))\n \t\tdie(\"tree-ish %s not found.\", tree_name);\n-\ttree = repo_parse_tree_indirect(the_repository, &oid);\n+\ttree = repo_parse_tree_indirect(repo, &oid);\n \tif (!tree)\n \t\tdie(\"bad tree-ish %s\", tree_name);\n \n@@ -3919,7 +3920,7 @@ void overlay_tree_on_index(struct index_state *istate,\n \n \tif (!fn)\n \t\tfn = read_one_entry_quick;\n-\terr = read_tree(the_repository, tree, &pathspec, fn, istate);\n+\terr = read_tree(repo, tree, &pathspec, fn, istate);\n \tclear_pathspec(&pathspec);\n \tif (err)\n \t\tdie(\"unable to read tree entries %s\", tree_name);\n\nbase-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2\n-- \ngitgitgadget\n\n"},{"id":"558548","messageId":"b7abaeba-1dd9-45f3-ad63-e43c49ee48d4@gmail.com","threadId":"66853","inReplyTo":"pull.2315.git.1794825269464.gitgitgadget@gmail.com","subject":"Re: [PATCH] read-cache: use istate->repo in overlay_tree_on_index()","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2026-11-16T13:11:33Z","receivedAt":"2026-11-16T13:11:33Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 11/16/2026 5:34 AM, Srujith A Poojary via GitGitGadget wrote:\n> From: Srujith A Poojary <poojarysrujith@gmail.com>\n> \n> Use the repository associated with the index state when\n> resolving the tree name, parsing the tree, and reading\n> its entries.\n> \n> This avoids relying on the global repository when the\n> function already has access to its associated repository.\n\nCleanups are good.\n\n> +\tstruct repository *repo = istate->repo;\n\n> -\tif (repo_get_oid(the_repository, tree_name, &oid))\n> +\tif (repo_get_oid(repo, tree_name, &oid))\n\n> -\ttree = repo_parse_tree_indirect(the_repository, &oid);\n> +\ttree = repo_parse_tree_indirect(repo, &oid);\n\n> -\terr = read_tree(the_repository, tree, &pathspec, fn, istate);\n> +\terr = read_tree(repo, tree, &pathspec, fn, istate);\nThe only other way to do this would be to replace the_repository\nwith 'istate->repo' directly, but having a 'repo' variable is\njust as good.\n\nLGTM.\n-Stolee\n\n\n"},{"id":"558562","messageId":"xmqqtslglnxk.fsf@gitster.g","threadId":"66853","inReplyTo":"b7abaeba-1dd9-45f3-ad63-e43c49ee48d4@gmail.com","subject":"Re: [PATCH] read-cache: use istate->repo in overlay_tree_on_index()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-16T16:51:35Z","receivedAt":"2026-11-16T16:51:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Derrick Stolee <stolee@gmail.com> writes:\n\n> On 11/16/2026 5:34 AM, Srujith A Poojary via GitGitGadget wrote:\n>> From: Srujith A Poojary <poojarysrujith@gmail.com>\n>> \n>> Use the repository associated with the index state when\n>> resolving the tree name, parsing the tree, and reading\n>> its entries.\n>> \n>> This avoids relying on the global repository when the\n>> function already has access to its associated repository.\n>\n> Cleanups are good.\n\nAt least this one is not making things any worse.\n\nBut there are other functions in this file, like add_to_index() and\nrefresh_index(), that take istate but still mention the_repository.\nCleaning these functions that share the same issue together in a\nsingle patch would help us reduce the review load and patch churn.\n\nOn the other hand, I do not think it is a good idea to try losing\nUSE_THE_REPOSITORY from this file all at once.  There are many\nlower-level functions that do not take istate (or repo), and it\nneeds a design based on deeper thinking (which has not been made\nhere for the obvious reason of not needing one yet) to decide what\nto do with them [*].  We do not want to see such changes in the same\nseries of patches as a mechanical replacement patch like this one.\n\nThanks.\n\n\n[Footnote]\n\n * Passing an extra parameter, either repo or istate, to these\n   functions may be an easy way, but the overhead may make it a\n   less-than-optimal solution, for example.  Teaching ce which\n   istate it belongs to is an absolute no-no, as these things are\n   born without their own istate, and are transfered between\n   different istates; besides they are so numerous.  Those are\n   merely one or two examples that need to be considered before we\n   know what the right approach is.\n\n\n>> +\tstruct repository *repo = istate->repo;\n>\n>> -\tif (repo_get_oid(the_repository, tree_name, &oid))\n>> +\tif (repo_get_oid(repo, tree_name, &oid))\n>\n>> -\ttree = repo_parse_tree_indirect(the_repository, &oid);\n>> +\ttree = repo_parse_tree_indirect(repo, &oid);\n>\n>> -\terr = read_tree(the_repository, tree, &pathspec, fn, istate);\n>> +\terr = read_tree(repo, tree, &pathspec, fn, istate);\n> The only other way to do this would be to replace the_repository\n> with 'istate->repo' directly, but having a 'repo' variable is\n> just as good.\n>\n> LGTM.\n> -Stolee\n\n"},{"id":"558736","messageId":"pull.2315.v2.git.1795027523258.gitgitgadget@gmail.com","threadId":"66853","inReplyTo":"pull.2315.git.1794825269464.gitgitgadget@gmail.com","subject":"[PATCH v2] read-cache: use istate->repo in index operations","fromName":"Srujith A Poojary via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-18T18:45:23Z","receivedAt":"2026-11-18T18:45:23Z","isPatch":true,"sender":{"key":"name:Srujith A Poojary","avatar":null},"body":"From: Srujith A Poojary <poojarysrujith@gmail.com>\n\nUse the repository associated with the index state in\nadd_to_index(), refresh_index(), and overlay_tree_on_index.\n\nThese functions already receive an index state, so use its\nrepository instead of relying on the global repository for\nrepository-specific configuration, progress reporting, and\ntree operations.\n\nThis removes unnecessary dependencies on the global repository\nfrom these code paths.\n\nSigned-off-by: Srujith A Poojary <poojarysrujith@gmail.com>\n---\n    read-cache: use istate->repo in index operations\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2315%2Fpoojarysrujith%2Flibification-overlay-tree-repo-clean-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2315/poojarysrujith/libification-overlay-tree-repo-clean-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/2315\n\nRange-diff vs v1:\n\n 1:  6eabf019e9 ! 1:  19ab253b22 read-cache: use istate->repo in overlay_tree_on_index()\n     @@ Metadata\n      Author: Srujith A Poojary <poojarysrujith@gmail.com>\n      \n       ## Commit message ##\n     -    read-cache: use istate->repo in overlay_tree_on_index()\n     +    read-cache: use istate->repo in index operations\n      \n     -    Use the repository associated with the index state when\n     -    resolving the tree name, parsing the tree, and reading\n     -    its entries.\n     +    Use the repository associated with the index state in\n     +    add_to_index(), refresh_index(), and overlay_tree_on_index.\n      \n     -    This avoids relying on the global repository when the\n     -    function already has access to its associated repository.\n     +    These functions already receive an index state, so use its\n     +    repository instead of relying on the global repository for\n     +    repository-specific configuration, progress reporting, and\n     +    tree operations.\n     +\n     +    This removes unnecessary dependencies on the global repository\n     +    from these code paths.\n      \n          Signed-off-by: Srujith A Poojary <poojarysrujith@gmail.com>\n      \n       ## read-cache.c ##\n     +@@ read-cache.c: int add_to_index(struct index_state *istate, const char *path, struct stat *st,\n     + \t * case of the file being added to the repository matches (is folded into) the existing\n     + \t * entry's directory case.\n     + \t */\n     +-\tif (repo_ignore_case(the_repository)) {\n     ++\tif (repo_ignore_case(istate->repo)) {\n     + \t\tadjust_dirname_case(istate, ce->name);\n     + \t}\n     + \tif (!(flags & ADD_CACHE_RENORMALIZE)) {\n     + \t\talias = index_file_exists(istate, ce->name,\n     +-\t\t\t\t\t  ce_namelen(ce), repo_ignore_case(the_repository));\n     ++\t\t\t\t\t  ce_namelen(ce), repo_ignore_case(istate->repo));\n     + \t\tif (alias &&\n     + \t\t    !ce_stage(alias) &&\n     + \t\t    !ie_match_stat(istate, alias, st, ce_option)) {\n     +@@ read-cache.c: int add_to_index(struct index_state *istate, const char *path, struct stat *st,\n     + \t} else\n     + \t\tset_object_name_for_intent_to_add_entry(ce);\n     + \n     +-\tif (repo_ignore_case(the_repository) && alias && different_name(ce, alias))\n     ++\tif (repo_ignore_case(istate->repo) && alias && different_name(ce, alias))\n     + \t\tce = create_alias_ce(istate, ce, alias);\n     + \tce->ce_flags |= CE_ADDED;\n     + \n     +@@ read-cache.c: int refresh_index(struct index_state *istate, unsigned int flags,\n     + \tint t2_sum_scan = 0;\n     + \n     + \tif (flags & REFRESH_PROGRESS && isatty(2))\n     +-\t\tprogress = start_delayed_progress(the_repository,\n     ++\t\tprogress = start_delayed_progress(istate->repo,\n     + \t\t\t\t\t\t  _(\"Refresh index\"),\n     + \t\t\t\t\t\t  istate->cache_nr);\n     + \n      @@ read-cache.c: static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base\n       void overlay_tree_on_index(struct index_state *istate,\n       \t\t\t   const char *tree_name, const char *prefix)\n\n\n read-cache.c | 15 ++++++++-------\n 1 file changed, 8 insertions(+), 7 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 5bbfbfeceb..5ca2561e7a 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -908,12 +908,12 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,\n \t * case of the file being added to the repository matches (is folded into) the existing\n \t * entry's directory case.\n \t */\n-\tif (repo_ignore_case(the_repository)) {\n+\tif (repo_ignore_case(istate->repo)) {\n \t\tadjust_dirname_case(istate, ce->name);\n \t}\n \tif (!(flags & ADD_CACHE_RENORMALIZE)) {\n \t\talias = index_file_exists(istate, ce->name,\n-\t\t\t\t\t  ce_namelen(ce), repo_ignore_case(the_repository));\n+\t\t\t\t\t  ce_namelen(ce), repo_ignore_case(istate->repo));\n \t\tif (alias &&\n \t\t    !ce_stage(alias) &&\n \t\t    !ie_match_stat(istate, alias, st, ce_option)) {\n@@ -934,7 +934,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,\n \t} else\n \t\tset_object_name_for_intent_to_add_entry(ce);\n \n-\tif (repo_ignore_case(the_repository) && alias && different_name(ce, alias))\n+\tif (repo_ignore_case(istate->repo) && alias && different_name(ce, alias))\n \t\tce = create_alias_ce(istate, ce, alias);\n \tce->ce_flags |= CE_ADDED;\n \n@@ -1537,7 +1537,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,\n \tint t2_sum_scan = 0;\n \n \tif (flags & REFRESH_PROGRESS && isatty(2))\n-\t\tprogress = start_delayed_progress(the_repository,\n+\t\tprogress = start_delayed_progress(istate->repo,\n \t\t\t\t\t\t  _(\"Refresh index\"),\n \t\t\t\t\t\t  istate->cache_nr);\n \n@@ -3874,6 +3874,7 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base\n void overlay_tree_on_index(struct index_state *istate,\n \t\t\t   const char *tree_name, const char *prefix)\n {\n+\tstruct repository *repo = istate->repo;\n \tstruct tree *tree;\n \tstruct object_id oid;\n \tstruct pathspec pathspec;\n@@ -3882,9 +3883,9 @@ void overlay_tree_on_index(struct index_state *istate,\n \tread_tree_fn_t fn = NULL;\n \tint err;\n \n-\tif (repo_get_oid(the_repository, tree_name, &oid))\n+\tif (repo_get_oid(repo, tree_name, &oid))\n \t\tdie(\"tree-ish %s not found.\", tree_name);\n-\ttree = repo_parse_tree_indirect(the_repository, &oid);\n+\ttree = repo_parse_tree_indirect(repo, &oid);\n \tif (!tree)\n \t\tdie(\"bad tree-ish %s\", tree_name);\n \n@@ -3919,7 +3920,7 @@ void overlay_tree_on_index(struct index_state *istate,\n \n \tif (!fn)\n \t\tfn = read_one_entry_quick;\n-\terr = read_tree(the_repository, tree, &pathspec, fn, istate);\n+\terr = read_tree(repo, tree, &pathspec, fn, istate);\n \tclear_pathspec(&pathspec);\n \tif (err)\n \t\tdie(\"unable to read tree entries %s\", tree_name);\n\nbase-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2\n-- \ngitgitgadget\n\n"}]}