| 2346 | } |
| 2347 | |
| 2348 | int read_index_from(struct index_state *istate, const char *path, |
| 2349 | const char *gitdir) |
| 2350 | { |
| 2351 | struct split_index *split_index; |
| 2352 | int ret; |
| 2353 | char *base_oid_hex; |
| 2354 | char *base_path; |
| 2355 | |
| 2356 | /* istate->initialized covers both .git/index and .git/sharedindex.xxx */ |
| 2357 | if (istate->initialized) |
| 2358 | return istate->cache_nr; |
| 2359 | |
| 2360 | trace2_region_enter_printf("index", "do_read_index", istate->repo, |
| 2361 | "%s", path); |
| 2362 | trace_performance_enter(); |
| 2363 | ret = do_read_index(istate, path, 0); |
| 2364 | trace_performance_leave("read cache %s", path); |
| 2365 | trace2_region_leave_printf("index", "do_read_index", istate->repo, |
| 2366 | "%s", path); |
| 2367 | |
| 2368 | split_index = istate->split_index; |
| 2369 | if (!split_index || is_null_oid(&split_index->base_oid)) { |
| 2370 | post_read_index_from(istate); |
| 2371 | return ret; |
| 2372 | } |
| 2373 | |
| 2374 | trace_performance_enter(); |
| 2375 | if (split_index->base) |
| 2376 | release_index(split_index->base); |
| 2377 | else |
| 2378 | ALLOC_ARRAY(split_index->base, 1); |
| 2379 | index_state_init(split_index->base, istate->repo); |
| 2380 | |
| 2381 | base_oid_hex = oid_to_hex(&split_index->base_oid); |
| 2382 | base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex); |
| 2383 | if (file_exists(base_path)) { |
| 2384 | trace2_region_enter_printf("index", "shared/do_read_index", |
| 2385 | the_repository, "%s", base_path); |
| 2386 | |
| 2387 | ret = do_read_index(split_index->base, base_path, 0); |
| 2388 | trace2_region_leave_printf("index", "shared/do_read_index", |
| 2389 | the_repository, "%s", base_path); |
| 2390 | } else { |
| 2391 | char *path_copy = xstrdup(path); |
| 2392 | char *base_path2 = xstrfmt("%s/sharedindex.%s", |
| 2393 | dirname(path_copy), base_oid_hex); |
| 2394 | free(path_copy); |
| 2395 | trace2_region_enter_printf("index", "shared/do_read_index", |
| 2396 | the_repository, "%s", base_path2); |
| 2397 | ret = do_read_index(split_index->base, base_path2, 1); |
| 2398 | trace2_region_leave_printf("index", "shared/do_read_index", |
| 2399 | the_repository, "%s", base_path2); |
| 2400 | free(base_path2); |
| 2401 | } |
| 2402 | if (!oideq(&split_index->base_oid, &split_index->base->oid)) |
| 2403 | die(_("broken index, expect %s in %s, got %s"), |
| 2404 | base_oid_hex, base_path, |
| 2405 | oid_to_hex(&split_index->base->oid)); |
no test coverage detected