[GSoC] read-cache: use index state repository for trace2 logging#2253
Open
jayesh0104 wants to merge 1 commit intogit:masterfrom
Open
[GSoC] read-cache: use index state repository for trace2 logging#2253jayesh0104 wants to merge 1 commit intogit:masterfrom
jayesh0104 wants to merge 1 commit intogit:masterfrom
Conversation
Replace uses of the_repository in trace2_data_intmax() with istate->repo, which represents the repository associated with the index state. This avoids relying on global repository state and aligns with other parts of the codebase (e.g., sparse-index.c) that pass the repository instance explicitly. No functional change intended. Signed-off-by: jayesh0104 <jayeshdaga99@gmail.com>
f535060 to
ba6d2ad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HIGH LEVEL
The current implementation of trace2_data_intmax() in read-cache.c relies on the global the_repository instance.
As part of the ongoing effort to "lib-ify" the Git codebase and reduce dependence on global state, this patch transitions those calls to use the repository instance associated with the index_state.
Low-level (Implementation & Justification)
In read-cache.c, the index_state (istate) typically carries a pointer to its associated repository. However, because istate->repo is not guaranteed to be initialized in all code paths (e.g., certain low-level utility or testing contexts), this patch implements a defensive fallback pattern.
Changes:
Introduced a local repository pointer r that prefers istate->repo but falls back to the_repository if the former is NULL.
Updated trace2_data_intmax() calls to use this context-aware pointer.
Benefits:
Thread Safety & Modernization: Aligns with the project's goal of moving away from the_repository.
Robustness: The ternary fallback ensures we avoid potential NULL pointer dereferences while maintaining existing logging behavior in edge cases.
Consistency: Follows patterns seen in other modernized areas of the codebase.
Summary
Transitioned trace2 logging in read-cache.c from global to local repository context.
Implemented a safety fallback to the_repository to handle uninitialized istate->repo pointers.
No functional changes to telemetry output are intended.
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