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

Function repo_submodule_init

repository.c:313–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311}
312
313int repo_submodule_init(struct repository *subrepo,
314 struct repository *superproject,
315 const char *path,
316 const struct object_id *treeish_name)
317{
318 struct strbuf gitdir = STRBUF_INIT;
319 struct strbuf worktree = STRBUF_INIT;
320 int ret = 0;
321
322 repo_worktree_path_append(superproject, &gitdir, "%s/.git", path);
323 repo_worktree_path_append(superproject, &worktree, "%s", path);
324
325 if (repo_init(subrepo, gitdir.buf, worktree.buf)) {
326 /*
327 * If initialization fails then it may be due to the submodule
328 * not being populated in the superproject's worktree. Instead
329 * we can try to initialize the submodule by finding it's gitdir
330 * in the superproject's 'modules' directory. In this case the
331 * submodule would not have a worktree.
332 */
333 const struct submodule *sub =
334 submodule_from_path(superproject, treeish_name, path);
335 if (!sub) {
336 ret = -1;
337 goto out;
338 }
339
340 strbuf_reset(&gitdir);
341 submodule_name_to_gitdir(&gitdir, superproject, sub->name);
342
343 if (repo_init(subrepo, gitdir.buf, NULL)) {
344 ret = -1;
345 goto out;
346 }
347 }
348
349 subrepo->submodule_prefix = xstrfmt("%s%s/",
350 superproject->submodule_prefix ?
351 superproject->submodule_prefix :
352 "", path);
353
354out:
355 strbuf_release(&gitdir);
356 strbuf_release(&worktree);
357 return ret;
358}
359
360static void repo_clear_path_cache(struct repo_path_cache *cache)
361{

Callers 10

merge_submoduleFunction · 0.85
check_has_commitFunction · 0.85
get_submodule_repo_forFunction · 0.85
traverse_tree_submodulesFunction · 0.85
grep_submoduleFunction · 0.85
show_submoduleFunction · 0.85
ensure_core_worktreeFunction · 0.85

Calls 6

repo_initFunction · 0.85
submodule_from_pathFunction · 0.85
submodule_name_to_gitdirFunction · 0.85
xstrfmtFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by 1