Skip to content

read-cache: use istate->repo in overlay_tree_on_index() - #2315

Open
poojarysrujith wants to merge 1 commit into
gitgitgadget:masterfrom
poojarysrujith:libification-overlay-tree-repo-clean
Open

poojarysrujith wants to merge 1 commit into
gitgitgadget:masterfrom
poojarysrujith:libification-overlay-tree-repo-clean

Conversation

@poojarysrujith

@poojarysrujith poojarysrujith commented Nov 16, 2026 •

Copy link
Copy Markdown

cc: Derrick Stolee stolee@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>
@poojarysrujith

Copy link
Copy Markdown
Author

/preview

@gitgitgadget

gitgitgadget Bot commented Nov 16, 2026

Copy link
Copy Markdown

Preview email sent as pull.2315.git.1794824970596.gitgitgadget@gmail.com

@poojarysrujith

Copy link
Copy Markdown
Author

/submit

@gitgitgadget

gitgitgadget Bot commented Nov 16, 2026

Copy link
Copy Markdown

Submitted as pull.2315.git.1794825269464.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2315/poojarysrujith/libification-overlay-tree-repo-clean-v1

To fetch this version to local tag pr-2315/poojarysrujith/libification-overlay-tree-repo-clean-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2315/poojarysrujith/libification-overlay-tree-repo-clean-v1

@gitgitgadget

gitgitgadget Bot commented Nov 16, 2026

Copy link
Copy Markdown

Derrick Stolee wrote on the Git mailing list (how to reply to this email):

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

@gitgitgadget

gitgitgadget Bot commented Nov 16, 2026

Copy link
Copy Markdown

User Derrick Stolee <stolee@gmail.com> has been added to the cc: list.

@gitgitgadget

gitgitgadget Bot commented Nov 16, 2026

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant