git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] read-cache: use istate->repo for trace2 logging

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 28, 2026, 18:36 UTC
Message-ID
<xmqqy0jbhkch.fsf@gitster.g>
In-Reply-To
<pull.2253.v2.git.git.1774682046750.gitgitgadget@gmail.com>
"Jayesh Daga via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> 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.
Show 22 quoted lines
> 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;
Show 7 quoted lines
> +	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.
Previous: Jayesh Daga via GitGitGadgetNext: Derrick Stolee
Message 6 of 14 in “read-cache: use index state repository for trace2 logging”
  1. read-cache: use index state repository for trace2 loggingJayesh Daga via GitGitGadget, Mar 27, 2026
  2. Derrick StoleeMar 27, 2026
  3. Junio C HamanoMar 27, 2026
  4. jayesh0104Mar 28, 2026
  5. read-cache: use istate->repo for trace2 loggingJayesh Daga via GitGitGadget, Mar 28, 2026
  6. Junio C HamanoMar 28, 2026
  7. Derrick StoleeMar 29, 2026
  8. 0/2 [GSoC] read-cache: use index state repository for trace2 loggingJayesh Daga via GitGitGadget, Mar 30, 2026
  9. 1/2 repo: add paths.git_dir repo info keyjayesh0104 via GitGitGadget, Mar 30, 2026
  10. 2/2 read-cache: use istate->repo for trace2 loggingJayesh Daga via GitGitGadget, Mar 30, 2026
  11. read-cache: use istate->repo for trace2 loggingJayesh Daga via GitGitGadget, Mar 30, 2026
  12. Junio C HamanoMar 30, 2026
  13. Derrick StoleeApr 2, 2026
  14. Jayesh DagaApr 2, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.