MCPcopy Index your code
hub / github.com/git/git / read_index_from

Function read_index_from

read-cache.c:2348–2413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2346}
2347
2348int 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));

Callers 13

write_index_as_treeFunction · 0.85
repo_read_indexFunction · 0.85
read_apply_cacheFunction · 0.85
apply_patchFunction · 0.85
run_applyFunction · 0.85
fall_back_threewayFunction · 0.85
prepare_to_commitFunction · 0.85
validate_no_submodulesFunction · 0.85
cmd_fsckFunction · 0.85
prepare_indexFunction · 0.85
prepare_to_commitFunction · 0.85

Calls 14

trace_performance_enterFunction · 0.85
do_read_indexFunction · 0.85
is_null_oidFunction · 0.85
post_read_index_fromFunction · 0.85
release_indexFunction · 0.85
index_state_initFunction · 0.85
oid_to_hexFunction · 0.85
xstrfmtFunction · 0.85
file_existsFunction · 0.85
xstrdupFunction · 0.85
oideqFunction · 0.85
freshen_shared_indexFunction · 0.85

Tested by

no test coverage detected