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

Function sync_submodule

builtin/submodule--helper.c:1429–1520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1427#define SYNC_CB_INIT { 0 }
1428
1429static void sync_submodule(const char *path, const char *prefix,
1430 const char *super_prefix, unsigned int flags)
1431{
1432 const struct submodule *sub;
1433 char *remote_key = NULL;
1434 char *sub_origin_url, *super_config_url, *displaypath, *default_remote;
1435 struct strbuf sb = STRBUF_INIT;
1436 char *sub_config_path = NULL;
1437 int code;
1438
1439 if (!is_submodule_active(the_repository, path))
1440 return;
1441
1442 if (validate_submodule_path(path) < 0)
1443 die(NULL);
1444
1445 sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
1446
1447 if (sub && sub->url) {
1448 if (starts_with_dot_dot_slash(sub->url) ||
1449 starts_with_dot_slash(sub->url)) {
1450 char *up_path = get_up_path(path);
1451
1452 sub_origin_url = resolve_relative_url(sub->url, up_path, 1);
1453 super_config_url = resolve_relative_url(sub->url, NULL, 1);
1454 free(up_path);
1455 } else {
1456 sub_origin_url = xstrdup(sub->url);
1457 super_config_url = xstrdup(sub->url);
1458 }
1459 } else {
1460 sub_origin_url = xstrdup("");
1461 super_config_url = xstrdup("");
1462 }
1463
1464 displaypath = get_submodule_displaypath(path, prefix, super_prefix);
1465
1466 if (!(flags & OPT_QUIET))
1467 printf(_("Synchronizing submodule url for '%s'\n"),
1468 displaypath);
1469
1470 strbuf_reset(&sb);
1471 strbuf_addf(&sb, "submodule.%s.url", sub->name);
1472 if (repo_config_set_gently(the_repository, sb.buf, super_config_url))
1473 die(_("failed to register url for submodule path '%s'"),
1474 displaypath);
1475
1476 if (!is_submodule_populated_gently(path, NULL))
1477 goto cleanup;
1478
1479 strbuf_reset(&sb);
1480 code = get_default_remote_submodule(path, &default_remote);
1481 if (code)
1482 exit(code);
1483
1484 remote_key = xstrfmt("remote.%s.url", default_remote);
1485 free(default_remote);
1486

Callers 2

sync_submodule_cbFunction · 0.85
module_set_urlFunction · 0.85

Calls 15

is_submodule_activeFunction · 0.85
validate_submodule_pathFunction · 0.85
submodule_from_pathFunction · 0.85
null_oidFunction · 0.85
starts_with_dot_slashFunction · 0.85
get_up_pathFunction · 0.85
resolve_relative_urlFunction · 0.85
xstrdupFunction · 0.85
strbuf_addfFunction · 0.85
repo_config_set_gentlyFunction · 0.85

Tested by

no test coverage detected