* [PATCH] read-cache: use istate->repo in overlay_tree_on_index()
@ 2026-11-16 10:34 Srujith A Poojary via GitGitGadget
2026-11-16 13:11 ` Derrick Stolee
2026-11-18 18:45 ` [PATCH v2] read-cache: use istate->repo in index operations Srujith A Poojary via GitGitGadget
0 siblings, 2 replies; 4+ messages in thread
From: Srujith A Poojary via GitGitGadget @ 2026-11-16 10:34 UTC (permalink / raw)
To: git; +Cc: Srujith A Poojary, Srujith A Poojary
From: Srujith A Poojary <poojarysrujith@gmail.com>
Use the repository associated with the index state when
resolving the tree name, parsing the tree, and reading
its entries.
This avoids relying on the global repository when the
function already has access to its associated repository.
Signed-off-by: Srujith A Poojary <poojarysrujith@gmail.com>
---
read-cache: use istate->repo in overlay_tree_on_index()
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2315%2Fpoojarysrujith%2Flibification-overlay-tree-repo-clean-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2315/poojarysrujith/libification-overlay-tree-repo-clean-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2315
read-cache.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 5bbfbfeceb..063ad523d2 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3874,6 +3874,7 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base
void overlay_tree_on_index(struct index_state *istate,
const char *tree_name, const char *prefix)
{
+ struct repository *repo = istate->repo;
struct tree *tree;
struct object_id oid;
struct pathspec pathspec;
@@ -3882,9 +3883,9 @@ void overlay_tree_on_index(struct index_state *istate,
read_tree_fn_t fn = NULL;
int err;
- if (repo_get_oid(the_repository, tree_name, &oid))
+ if (repo_get_oid(repo, tree_name, &oid))
die("tree-ish %s not found.", tree_name);
- tree = repo_parse_tree_indirect(the_repository, &oid);
+ tree = repo_parse_tree_indirect(repo, &oid);
if (!tree)
die("bad tree-ish %s", tree_name);
@@ -3919,7 +3920,7 @@ void overlay_tree_on_index(struct index_state *istate,
if (!fn)
fn = read_one_entry_quick;
- err = read_tree(the_repository, tree, &pathspec, fn, istate);
+ err = read_tree(repo, tree, &pathspec, fn, istate);
clear_pathspec(&pathspec);
if (err)
die("unable to read tree entries %s", tree_name);
base-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2
--
gitgitgadget
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] read-cache: use istate->repo in overlay_tree_on_index() 2026-11-16 10:34 [PATCH] read-cache: use istate->repo in overlay_tree_on_index() Srujith A Poojary via GitGitGadget @ 2026-11-16 13:11 ` Derrick Stolee 2026-11-16 16:51 ` Junio C Hamano 2026-11-18 18:45 ` [PATCH v2] read-cache: use istate->repo in index operations Srujith A Poojary via GitGitGadget 1 sibling, 1 reply; 4+ messages in thread From: Derrick Stolee @ 2026-11-16 13:11 UTC (permalink / raw) To: git On 11/16/2026 5:34 AM, Srujith A Poojary via GitGitGadget wrote: > From: Srujith A Poojary <poojarysrujith@gmail.com> > > Use the repository associated with the index state when > resolving the tree name, parsing the tree, and reading > its entries. > > This avoids relying on the global repository when the > function already has access to its associated repository. Cleanups are good. > + struct repository *repo = istate->repo; > - if (repo_get_oid(the_repository, tree_name, &oid)) > + if (repo_get_oid(repo, tree_name, &oid)) > - tree = repo_parse_tree_indirect(the_repository, &oid); > + tree = repo_parse_tree_indirect(repo, &oid); > - err = read_tree(the_repository, tree, &pathspec, fn, istate); > + err = read_tree(repo, tree, &pathspec, fn, istate); The only other way to do this would be to replace the_repository with 'istate->repo' directly, but having a 'repo' variable is just as good. LGTM. -Stolee ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] read-cache: use istate->repo in overlay_tree_on_index() 2026-11-16 13:11 ` Derrick Stolee @ 2026-11-16 16:51 ` Junio C Hamano 0 siblings, 0 replies; 4+ messages in thread From: Junio C Hamano @ 2026-11-16 16:51 UTC (permalink / raw) To: Derrick Stolee; +Cc: git Derrick Stolee <stolee@gmail.com> writes: > On 11/16/2026 5:34 AM, Srujith A Poojary via GitGitGadget wrote: >> From: Srujith A Poojary <poojarysrujith@gmail.com> >> >> Use the repository associated with the index state when >> resolving the tree name, parsing the tree, and reading >> its entries. >> >> This avoids relying on the global repository when the >> function already has access to its associated repository. > > Cleanups are good. At least this one is not making things any worse. But there are other functions in this file, like add_to_index() and refresh_index(), that take istate but still mention the_repository. Cleaning these functions that share the same issue together in a single patch would help us reduce the review load and patch churn. On the other hand, I do not think it is a good idea to try losing USE_THE_REPOSITORY from this file all at once. There are many lower-level functions that do not take istate (or repo), and it needs a design based on deeper thinking (which has not been made here for the obvious reason of not needing one yet) to decide what to do with them [*]. We do not want to see such changes in the same series of patches as a mechanical replacement patch like this one. Thanks. [Footnote] * Passing an extra parameter, either repo or istate, to these functions may be an easy way, but the overhead may make it a less-than-optimal solution, for example. Teaching ce which istate it belongs to is an absolute no-no, as these things are born without their own istate, and are transfered between different istates; besides they are so numerous. Those are merely one or two examples that need to be considered before we know what the right approach is. >> + struct repository *repo = istate->repo; > >> - if (repo_get_oid(the_repository, tree_name, &oid)) >> + if (repo_get_oid(repo, tree_name, &oid)) > >> - tree = repo_parse_tree_indirect(the_repository, &oid); >> + tree = repo_parse_tree_indirect(repo, &oid); > >> - err = read_tree(the_repository, tree, &pathspec, fn, istate); >> + err = read_tree(repo, tree, &pathspec, fn, istate); > The only other way to do this would be to replace the_repository > with 'istate->repo' directly, but having a 'repo' variable is > just as good. > > LGTM. > -Stolee ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] read-cache: use istate->repo in index operations 2026-11-16 10:34 [PATCH] read-cache: use istate->repo in overlay_tree_on_index() Srujith A Poojary via GitGitGadget 2026-11-16 13:11 ` Derrick Stolee @ 2026-11-18 18:45 ` Srujith A Poojary via GitGitGadget 1 sibling, 0 replies; 4+ messages in thread From: Srujith A Poojary via GitGitGadget @ 2026-11-18 18:45 UTC (permalink / raw) To: git; +Cc: Derrick Stolee, Srujith A Poojary, Srujith A Poojary From: Srujith A Poojary <poojarysrujith@gmail.com> Use the repository associated with the index state in add_to_index(), refresh_index(), and overlay_tree_on_index. These functions already receive an index state, so use its repository instead of relying on the global repository for repository-specific configuration, progress reporting, and tree operations. This removes unnecessary dependencies on the global repository from these code paths. Signed-off-by: Srujith A Poojary <poojarysrujith@gmail.com> --- read-cache: use istate->repo in index operations Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2315%2Fpoojarysrujith%2Flibification-overlay-tree-repo-clean-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2315/poojarysrujith/libification-overlay-tree-repo-clean-v2 Pull-Request: https://github.com/gitgitgadget/git/pull/2315 Range-diff vs v1: 1: 6eabf019e9 ! 1: 19ab253b22 read-cache: use istate->repo in overlay_tree_on_index() @@ Metadata Author: Srujith A Poojary <poojarysrujith@gmail.com> ## Commit message ## - read-cache: use istate->repo in overlay_tree_on_index() + read-cache: use istate->repo in index operations - Use the repository associated with the index state when - resolving the tree name, parsing the tree, and reading - its entries. + Use the repository associated with the index state in + add_to_index(), refresh_index(), and overlay_tree_on_index. - This avoids relying on the global repository when the - function already has access to its associated repository. + These functions already receive an index state, so use its + repository instead of relying on the global repository for + repository-specific configuration, progress reporting, and + tree operations. + + This removes unnecessary dependencies on the global repository + from these code paths. Signed-off-by: Srujith A Poojary <poojarysrujith@gmail.com> ## read-cache.c ## +@@ read-cache.c: int add_to_index(struct index_state *istate, const char *path, struct stat *st, + * case of the file being added to the repository matches (is folded into) the existing + * entry's directory case. + */ +- if (repo_ignore_case(the_repository)) { ++ if (repo_ignore_case(istate->repo)) { + adjust_dirname_case(istate, ce->name); + } + if (!(flags & ADD_CACHE_RENORMALIZE)) { + alias = index_file_exists(istate, ce->name, +- ce_namelen(ce), repo_ignore_case(the_repository)); ++ ce_namelen(ce), repo_ignore_case(istate->repo)); + if (alias && + !ce_stage(alias) && + !ie_match_stat(istate, alias, st, ce_option)) { +@@ read-cache.c: int add_to_index(struct index_state *istate, const char *path, struct stat *st, + } else + set_object_name_for_intent_to_add_entry(ce); + +- if (repo_ignore_case(the_repository) && alias && different_name(ce, alias)) ++ if (repo_ignore_case(istate->repo) && alias && different_name(ce, alias)) + ce = create_alias_ce(istate, ce, alias); + ce->ce_flags |= CE_ADDED; + +@@ read-cache.c: int refresh_index(struct index_state *istate, unsigned int flags, + int t2_sum_scan = 0; + + if (flags & REFRESH_PROGRESS && isatty(2)) +- progress = start_delayed_progress(the_repository, ++ progress = start_delayed_progress(istate->repo, + _("Refresh index"), + istate->cache_nr); + @@ read-cache.c: static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base void overlay_tree_on_index(struct index_state *istate, const char *tree_name, const char *prefix) read-cache.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/read-cache.c b/read-cache.c index 5bbfbfeceb..5ca2561e7a 100644 --- a/read-cache.c +++ b/read-cache.c @@ -908,12 +908,12 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, * case of the file being added to the repository matches (is folded into) the existing * entry's directory case. */ - if (repo_ignore_case(the_repository)) { + if (repo_ignore_case(istate->repo)) { adjust_dirname_case(istate, ce->name); } if (!(flags & ADD_CACHE_RENORMALIZE)) { alias = index_file_exists(istate, ce->name, - ce_namelen(ce), repo_ignore_case(the_repository)); + ce_namelen(ce), repo_ignore_case(istate->repo)); if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) { @@ -934,7 +934,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, } else set_object_name_for_intent_to_add_entry(ce); - if (repo_ignore_case(the_repository) && alias && different_name(ce, alias)) + if (repo_ignore_case(istate->repo) && alias && different_name(ce, alias)) ce = create_alias_ce(istate, ce, alias); ce->ce_flags |= CE_ADDED; @@ -1537,7 +1537,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, int t2_sum_scan = 0; if (flags & REFRESH_PROGRESS && isatty(2)) - progress = start_delayed_progress(the_repository, + progress = start_delayed_progress(istate->repo, _("Refresh index"), istate->cache_nr); @@ -3874,6 +3874,7 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base void overlay_tree_on_index(struct index_state *istate, const char *tree_name, const char *prefix) { + struct repository *repo = istate->repo; struct tree *tree; struct object_id oid; struct pathspec pathspec; @@ -3882,9 +3883,9 @@ void overlay_tree_on_index(struct index_state *istate, read_tree_fn_t fn = NULL; int err; - if (repo_get_oid(the_repository, tree_name, &oid)) + if (repo_get_oid(repo, tree_name, &oid)) die("tree-ish %s not found.", tree_name); - tree = repo_parse_tree_indirect(the_repository, &oid); + tree = repo_parse_tree_indirect(repo, &oid); if (!tree) die("bad tree-ish %s", tree_name); @@ -3919,7 +3920,7 @@ void overlay_tree_on_index(struct index_state *istate, if (!fn) fn = read_one_entry_quick; - err = read_tree(the_repository, tree, &pathspec, fn, istate); + err = read_tree(repo, tree, &pathspec, fn, istate); clear_pathspec(&pathspec); if (err) die("unable to read tree entries %s", tree_name); base-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2 -- gitgitgadget ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-18 18:45 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-16 10:34 [PATCH] read-cache: use istate->repo in overlay_tree_on_index() Srujith A Poojary via GitGitGadget 2026-11-16 13:11 ` Derrick Stolee 2026-11-16 16:51 ` Junio C Hamano 2026-11-18 18:45 ` [PATCH v2] read-cache: use istate->repo in index operations Srujith A Poojary via GitGitGadget
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox