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

Function module_migrate

builtin/submodule--helper.c:1362–1420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1360}
1361
1362static int module_migrate(int argc UNUSED, const char **argv UNUSED,
1363 const char *prefix UNUSED, struct repository *repo)
1364{
1365 struct strbuf module_dir = STRBUF_INIT;
1366 DIR *dir;
1367 struct dirent *de;
1368 int repo_version = 0;
1369
1370 repo_git_path_append(repo, &module_dir, "modules/");
1371
1372 dir = opendir(module_dir.buf);
1373 if (!dir)
1374 die(_("could not open '%s'"), module_dir.buf);
1375
1376 while ((de = readdir(dir))) {
1377 struct strbuf gitdir_path = STRBUF_INIT;
1378 char *key;
1379 const char *value;
1380
1381 if (is_dot_or_dotdot(de->d_name))
1382 continue;
1383
1384 strbuf_addf(&gitdir_path, "%s/%s", module_dir.buf, de->d_name);
1385 if (!is_git_directory(gitdir_path.buf)) {
1386 strbuf_release(&gitdir_path);
1387 continue;
1388 }
1389 strbuf_release(&gitdir_path);
1390
1391 key = xstrfmt("submodule.%s.gitdir", de->d_name);
1392 if (!repo_config_get_string_tmp(repo, key, &value)) {
1393 /* Already has a gitdir config, nothing to do. */
1394 free(key);
1395 continue;
1396 }
1397 free(key);
1398
1399 create_default_gitdir_config(de->d_name);
1400 }
1401
1402 closedir(dir);
1403 strbuf_release(&module_dir);
1404
1405 repo_config_get_int(the_repository, "core.repositoryformatversion", &repo_version);
1406 if (repo_version == 0 &&
1407 repo_config_set_gently(repo, "core.repositoryformatversion", "1"))
1408 die(_("could not set core.repositoryformatversion to 1.\n"
1409 "Please set it for migration to work, for example:\n"
1410 "git config core.repositoryformatversion 1"));
1411
1412 if (repo_config_set_gently(repo, "extensions.submodulePathConfig", "true"))
1413 die(_("could not enable submodulePathConfig extension. It is required\n"
1414 "for migration to work. Please enable it in the root repo:\n"
1415 "git config extensions.submodulePathConfig true"));
1416
1417 repo->repository_format_submodule_path_cfg = 1;
1418
1419 return 0;

Callers

nothing calls this directly

Calls 14

repo_git_path_appendFunction · 0.85
opendirFunction · 0.85
readdirFunction · 0.85
is_dot_or_dotdotFunction · 0.85
strbuf_addfFunction · 0.85
is_git_directoryFunction · 0.85
strbuf_releaseFunction · 0.85
xstrfmtFunction · 0.85
closedirFunction · 0.85
repo_config_get_intFunction · 0.85

Tested by

no test coverage detected