From: Junio C Hamano <gitster@pobox.com>
To: "Jayesh Daga via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Karthik Nayak <karthik.188@gmail.com>,
Justin Tobler <jltobler@gmail.com>,
Ayush Chandekar <ayu.chandekar@gmail.com>,
Siddharth Asthana <siddharthasthana31@gmail.com>,
Jayesh Daga <jayeshdaga99@gmail.com>
Subject: Re: [PATCH v2] read-cache: use istate->repo for trace2 logging
Date: Sat, 28 Mar 2026 11:36:46 -0700 [thread overview]
Message-ID: <xmqqy0jbhkch.fsf@gitster.g> (raw)
In-Reply-To: <pull.2253.v2.git.git.1774682046750.gitgitgadget@gmail.com> (Jayesh Daga via GitGitGadget's message of "Sat, 28 Mar 2026 07:14:06 +0000")
"Jayesh Daga via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Jayesh Daga <jayeshdaga99@gmail.com>
>
> 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).
Drop "currently". The canonical order in log messages in this
project is to describe the current state of the relevant part of the
codebase in present tense, pulling attention of readers to what the
author finds problematic, and propose a solution. And finally give
orders to somebody sitting in front of the keyboard to make the
change.
> 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.
Even worse, it could do a wrong thing, so saying "redundant" here
somewhat misses the point.
> 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.
Exactly.
> diff --git a/read-cache.c b/read-cache.c
> index 5049f9baca..46ffb49cab 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;
> @@ -2309,13 +2310,12 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
> }
> munmap((void *)mmap, mmap_size);
>
> - /*
> - * 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;
Have SP on both sides of an assignment operator '=', i.e.
r = istate->repo;
> + if (!r)
> + BUG("istate->repo is NULL in do_read_index");
> + 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);
Or you can do without an intermediate variable 'r'. Replacing
"the_repository" with "istate->repo" would make the resulting line
shorter already, and more importantly, readers do not have to
remember that 'r' is an alias for 'istate->repo' while reading the
code.
Thanks.
next prev parent reply other threads:[~2026-03-28 18:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 10:08 [PATCH] read-cache: use index state repository for trace2 logging Jayesh Daga via GitGitGadget
2026-03-27 13:48 ` 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 [this message]
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=xmqqy0jbhkch.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=ayu.chandekar@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=jayeshdaga99@gmail.com \
--cc=jltobler@gmail.com \
--cc=karthik.188@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox