Skip to content

[GSoC] read-cache: use index state repository for trace2 logging#2253

Open
jayesh0104 wants to merge 1 commit intogit:masterfrom
jayesh0104:trace2-istate-repo
Open

[GSoC] read-cache: use index state repository for trace2 logging#2253
jayesh0104 wants to merge 1 commit intogit:masterfrom
jayesh0104:trace2-istate-repo

Conversation

@jayesh0104
Copy link
Copy Markdown

@jayesh0104 jayesh0104 commented Mar 24, 2026

HIGH LEVEL

trace2_data_intmax() calls in read-cache.c currently use the global
'the_repository' instance, even though index_state already carries an
explicit repository pointer (istate->repo).

Use istate->repo directly in these calls, making the repository context
associated with the index explicit.

Low-level (Implementation & Justification)

index_state instances are initialized via INDEX_STATE_INIT(r), which sets
istate->repo. Therefore, istate->repo is expected to be non-NULL in normal
code paths.

Using the global 'the_repository' in this context is redundant and can
obscure the actual repository associated with the index being read.

In particular, relying on the global repository may lead to misleading
trace2 output in scenarios where multiple repository instances are in use
(e.g., tests or future refactoring toward improved library boundaries),
as events could be attributed to the wrong repository.

Changes:

  • Replace uses of the_repository in trace2_data_intmax() with istate->repo
  • Enforce the expectation that istate->repo is non-NULL via BUG()
  • Remove the now-obsolete TODO comment

Example:

  • trace2_data_intmax("index", the_repository, "read/version", ...)
  • trace2_data_intmax("index", istate->repo, "read/version", ...)

Summary

Use the repository associated with index_state for trace2 logging instead
of the global repository instance, making the repository context explicit
and consistent with existing initialization guarantees.

Changes since v1:

  • Dropped fallback to the_repository; rely on istate->repo invariant
  • Added BUG() check for NULL istate->repo
  • Removed TODO comment
  • Improved commit message with detailed rationale
  • Cleaned up duplicate commits and fixed history

cc: Karthik Nayak karthik.188@gmail.com
cc: Justin Tobler jltobler@gmail.com
cc: Ayush Chandekar ayu.chandekar@gmail.com
cc: Siddharth Asthana siddharthasthana31@gmail.com

@jayesh0104
Copy link
Copy Markdown
Author

/submit

@gitgitgadget-git
Copy link
Copy Markdown

Submitted as pull.2253.git.git.1774606086325.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2253/jayesh0104/trace2-istate-repo-v1

To fetch this version to local tag pr-git-2253/jayesh0104/trace2-istate-repo-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2253/jayesh0104/trace2-istate-repo-v1

trace2_data_intmax() calls in do_read_index() currently use the
global 'the_repository' instance, even though the index_state
already carries an explicit repository pointer (istate->repo).

index_state instances are initialized via INDEX_STATE_INIT(r),
which sets istate->repo. Using the_repository here is therefore
redundant and obscures the actual repository context associated
with the index being read.

In particular, using the global repository can lead to misleading
trace2 output in scenarios where multiple repository instances are
in use (such as tests or future refactoring toward better library
boundaries), as events may be attributed to the wrong repository.

Switch these calls to use istate->repo directly, making the
association between the index and its repository explicit.

Since istate->repo is expected to be non-NULL, enforce this
assumption with a BUG() check so that any violation of this
invariant is caught early.

Also remove the now-obsolete TODO comment.

Signed-off-by: Jayesh Daga <jayeshdaga99@gmail.com>
@jayesh0104
Copy link
Copy Markdown
Author

/submit

@gitgitgadget-git
Copy link
Copy Markdown

Submitted as pull.2253.v2.git.git.1774682046750.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2253/jayesh0104/trace2-istate-repo-v2

To fetch this version to local tag pr-git-2253/jayesh0104/trace2-istate-repo-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2253/jayesh0104/trace2-istate-repo-v2

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