MCPcopy Create free account
hub / github.com/git/git / repo_get_submodule_ref_store

Function repo_get_submodule_ref_store

refs.c:2381–2432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2379}
2380
2381struct ref_store *repo_get_submodule_ref_store(struct repository *repo,
2382 const char *submodule)
2383{
2384 struct strbuf submodule_sb = STRBUF_INIT;
2385 struct ref_store *refs;
2386 char *to_free = NULL;
2387 size_t len;
2388 struct repository *subrepo;
2389
2390 if (!submodule)
2391 return NULL;
2392
2393 len = strlen(submodule);
2394 while (len && is_dir_sep(submodule[len - 1]))
2395 len--;
2396 if (!len)
2397 return NULL;
2398
2399 if (submodule[len])
2400 /* We need to strip off one or more trailing slashes */
2401 submodule = to_free = xmemdupz(submodule, len);
2402
2403 refs = lookup_ref_store_map(&repo->submodule_ref_stores, submodule);
2404 if (refs)
2405 goto done;
2406
2407 strbuf_addstr(&submodule_sb, submodule);
2408 if (!is_nonbare_repository_dir(&submodule_sb))
2409 goto done;
2410
2411 if (submodule_to_gitdir(repo, &submodule_sb, submodule))
2412 goto done;
2413
2414 subrepo = xmalloc(sizeof(*subrepo));
2415
2416 if (repo_submodule_init(subrepo, repo, submodule,
2417 null_oid(repo->hash_algo))) {
2418 free(subrepo);
2419 goto done;
2420 }
2421 refs = ref_store_init(subrepo, subrepo->ref_storage_format,
2422 submodule_sb.buf,
2423 REF_STORE_READ | REF_STORE_ODB);
2424 register_ref_store_map(&repo->submodule_ref_stores, "submodule",
2425 refs, submodule);
2426
2427done:
2428 strbuf_release(&submodule_sb);
2429 free(to_free);
2430
2431 return refs;
2432}
2433
2434struct ref_store *get_worktree_ref_store(const struct worktree *wt)
2435{

Callers 5

repo_resolve_gitlink_refFunction · 0.85
get_storeFunction · 0.85
status_submoduleFunction · 0.85

Calls 11

xmemdupzFunction · 0.85
lookup_ref_store_mapFunction · 0.85
strbuf_addstrFunction · 0.85
submodule_to_gitdirFunction · 0.85
repo_submodule_initFunction · 0.85
null_oidFunction · 0.85
ref_store_initFunction · 0.85
register_ref_store_mapFunction · 0.85
strbuf_releaseFunction · 0.85
xmallocFunction · 0.70

Tested by 1

get_storeFunction · 0.68