From: "Jayesh Daga via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Justin Tobler <jltobler@gmail.com>,
Ayush Chandekar <ayu.chandekar@gmail.com>,
Siddharth Asthana <siddharthasthana31@gmail.com>,
Jayesh Daga <jayeshdaga99@gmail.com>,
jayesh0104 <jayeshdaga99@gmail.com>
Subject: [PATCH] read-cache: use index state repository for trace2 logging
Date: Fri, 27 Mar 2026 10:08:06 +0000 [thread overview]
Message-ID: <pull.2253.git.git.1774606086325.gitgitgadget@gmail.com> (raw)
From: jayesh0104 <jayeshdaga99@gmail.com>
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>
---
[GSoC] read-cache: use index state repository for trace2 logging
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.
+ struct repository *r = istate->repo ? istate->repo : the_repository;
- trace2_data_intmax("index", the_repository, "read/version", istate->version);
+ trace2_data_intmax("index", r, "read/version", istate->version);
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
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2253%2Fjayesh0104%2Ftrace2-istate-repo-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2253/jayesh0104/trace2-istate-repo-v1
Pull-Request: https://github.com/git/git/pull/2253
read-cache.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 5049f9baca..2c5c5165e0 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2206,6 +2206,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
size_t extension_offset = 0;
int nr_threads, cpus;
struct index_entry_offset_table *ieot = NULL;
+ struct repository *r;
if (istate->initialized)
return istate->cache_nr;
@@ -2313,9 +2314,10 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
* TODO trace2: replace "the_repository" with the actual repo instance
* that is associated with the given "istate".
*/
- trace2_data_intmax("index", the_repository, "read/version",
+ r = istate->repo ? istate->repo : the_repository;
+ trace2_data_intmax("index", r, "read/version",
istate->version);
- trace2_data_intmax("index", the_repository, "read/cache_nr",
+ trace2_data_intmax("index", r, "read/cache_nr",
istate->cache_nr);
/*
base-commit: ca1db8a0f7dc0dbea892e99f5b37c5fe5861be71
--
gitgitgadget
next reply other threads:[~2026-03-27 10:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 10:08 Jayesh Daga via GitGitGadget [this message]
2026-03-27 13:48 ` [PATCH] read-cache: use index state repository for trace2 logging Derrick Stolee
2026-03-27 16:28 ` Junio C Hamano
2026-03-28 5:25 ` jayesh0104
2026-03-28 7:14 ` [PATCH v2] read-cache: use istate->repo " Jayesh Daga via GitGitGadget
2026-03-28 18:36 ` Junio C Hamano
2026-03-29 14:57 ` Derrick Stolee
2026-03-30 17:27 ` [PATCH v3 0/2] [GSoC] read-cache: use index state repository " Jayesh Daga via GitGitGadget
2026-03-30 17:27 ` [PATCH v3 1/2] repo: add paths.git_dir repo info key jayesh0104 via GitGitGadget
2026-03-30 17:27 ` [PATCH v3 2/2] read-cache: use istate->repo for trace2 logging Jayesh Daga via GitGitGadget
2026-03-30 18:38 ` [PATCH v4] " Jayesh Daga via GitGitGadget
2026-03-30 20:04 ` Junio C Hamano
2026-04-02 14:26 ` Derrick Stolee
2026-04-02 15:25 ` [PATCH] " Jayesh Daga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.2253.git.git.1774606086325.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=ayu.chandekar@gmail.com \
--cc=git@vger.kernel.org \
--cc=jayeshdaga99@gmail.com \
--cc=jltobler@gmail.com \
--cc=siddharthasthana31@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.