Skip to content

Commit 7fdfaae

Browse files
committed
read-cache: use istate->repo for trace2 logging
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>
1 parent ca1db8a commit 7fdfaae

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

read-cache.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
22062206
size_t extension_offset = 0;
22072207
int nr_threads, cpus;
22082208
struct index_entry_offset_table *ieot = NULL;
2209+
struct repository *r;
22092210

22102211
if (istate->initialized)
22112212
return istate->cache_nr;
@@ -2309,13 +2310,12 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
23092310
}
23102311
munmap((void *)mmap, mmap_size);
23112312

2312-
/*
2313-
* TODO trace2: replace "the_repository" with the actual repo instance
2314-
* that is associated with the given "istate".
2315-
*/
2316-
trace2_data_intmax("index", the_repository, "read/version",
2313+
r=istate->repo;
2314+
if (!r)
2315+
BUG("istate->repo is NULL in do_read_index");
2316+
trace2_data_intmax("index", r, "read/version",
23172317
istate->version);
2318-
trace2_data_intmax("index", the_repository, "read/cache_nr",
2318+
trace2_data_intmax("index", r, "read/cache_nr",
23192319
istate->cache_nr);
23202320

23212321
/*

0 commit comments

Comments
 (0)