read-cache: use istate->repo for trace2 logging

trace2 calls in read-cache.c use the global 'the_repository', even though the relevant index_state provides an explicit repository pointer via 'istate->repo'. Using the global repository can result in incorrect trace2 output when multiple repository instances are in use, as events may be attributed to the wrong repository. Use 'istate->repo' instead to ensure correct repository attribution. Signed-off-by: Jayesh Daga <jayeshdaga99@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jayesh Daga committed Mar 30, 2026 at 18:38 UTC a7aca156779f6c40d454f04ed151d2f482396f0f
1 file changed +8 -24
read-cache.c
+8 -24
@@ -2309,13 +2309,9 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
2309 }
2310 munmap((void *)mmap, mmap_size);
2311
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",
2312 + trace2_data_intmax("index", istate->repo, "read/version",
2313 istate->version);
2318 - trace2_data_intmax("index", the_repository, "read/cache_nr",
2314 + trace2_data_intmax("index", istate->repo, "read/cache_nr",
2315 istate->cache_nr);
2316
2317 /*
@@ -2360,16 +2356,12 @@ int read_index_from(struct index_state *istate, const char *path,
2356 if (istate->initialized)
2357 return istate->cache_nr;
2358
2363 - /*
2364 - * TODO trace2: replace "the_repository" with the actual repo instance
2365 - * that is associated with the given "istate".
2366 - */
2367 - trace2_region_enter_printf("index", "do_read_index", the_repository,
2359 + trace2_region_enter_printf("index", "do_read_index", istate->repo,
2360 "%s", path);
2361 trace_performance_enter();
2362 ret = do_read_index(istate, path, 0);
2363 trace_performance_leave("read cache %s", path);
2372 - trace2_region_leave_printf("index", "do_read_index", the_repository,
2364 + trace2_region_leave_printf("index", "do_read_index", istate->repo,
2365 "%s", path);
2366
2367 split_index = istate->split_index;
@@ -3096,13 +3088,9 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
3088 istate->timestamp.nsec = ST_MTIME_NSEC(st);
3089 trace_performance_since(start, "write index, changed mask = %x", istate->cache_changed);
3090
3099 - /*
3100 - * TODO trace2: replace "the_repository" with the actual repo instance
3101 - * that is associated with the given "istate".
3102 - */
3103 - trace2_data_intmax("index", the_repository, "write/version",
3091 + trace2_data_intmax("index", istate->repo, "write/version",
3092 istate->version);
3105 - trace2_data_intmax("index", the_repository, "write/cache_nr",
3093 + trace2_data_intmax("index", istate->repo, "write/cache_nr",
3094 istate->cache_nr);
3095
3096 ret = 0;
@@ -3144,14 +3132,10 @@ static int do_write_locked_index(struct index_state *istate,
3132 return ret;
3133 }
3134
3147 - /*
3148 - * TODO trace2: replace "the_repository" with the actual repo instance
3149 - * that is associated with the given "istate".
3150 - */
3151 - trace2_region_enter_printf("index", "do_write_index", the_repository,
3135 + trace2_region_enter_printf("index", "do_write_index", istate->repo,
3136 "%s", get_lock_file_path(lock));
3137 ret = do_write_index(istate, lock->tempfile, write_extensions, flags);
3154 - trace2_region_leave_printf("index", "do_write_index", the_repository,
3138 + trace2_region_leave_printf("index", "do_write_index", istate->repo,
3139 "%s", get_lock_file_path(lock));
3140
3141 if (was_full)