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

Function copy_templates

setup.c:2352–2403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2350}
2351
2352static void copy_templates(struct repository *repo, const char *option_template)
2353{
2354 const char *template_dir = get_template_dir(option_template);
2355 struct strbuf path = STRBUF_INIT;
2356 struct strbuf template_path = STRBUF_INIT;
2357 size_t template_len;
2358 struct repository_format template_format = REPOSITORY_FORMAT_INIT;
2359 struct strbuf err = STRBUF_INIT;
2360 DIR *dir;
2361 char *to_free = NULL;
2362
2363 if (!template_dir || !*template_dir)
2364 return;
2365
2366 strbuf_addstr(&template_path, template_dir);
2367 strbuf_complete(&template_path, '/');
2368 template_len = template_path.len;
2369
2370 dir = opendir(template_path.buf);
2371 if (!dir) {
2372 warning(_("templates not found in %s"), template_dir);
2373 goto free_return;
2374 }
2375
2376 /* Make sure that template is from the correct vintage */
2377 strbuf_addstr(&template_path, "config");
2378 read_repository_format(&template_format, template_path.buf);
2379 strbuf_setlen(&template_path, template_len);
2380
2381 /*
2382 * No mention of version at all is OK, but anything else should be
2383 * verified.
2384 */
2385 if (template_format.version >= 0 &&
2386 verify_repository_format(&template_format, &err) < 0) {
2387 warning(_("not copying templates from '%s': %s"),
2388 template_dir, err.buf);
2389 strbuf_release(&err);
2390 goto close_free_return;
2391 }
2392
2393 strbuf_addstr(&path, repo_get_common_dir(repo));
2394 strbuf_complete(&path, '/');
2395 copy_templates_1(repo, &path, &template_path, dir);
2396close_free_return:
2397 closedir(dir);
2398free_return:
2399 free(to_free);
2400 strbuf_release(&path);
2401 strbuf_release(&template_path);
2402 clear_repository_format(&template_format);
2403}
2404
2405/*
2406 * If the git_dir is not directly inside the working tree, then git will not

Callers 1

create_default_filesFunction · 0.85

Calls 13

get_template_dirFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_completeFunction · 0.85
opendirFunction · 0.85
warningFunction · 0.85
read_repository_formatFunction · 0.85
strbuf_setlenFunction · 0.85
verify_repository_formatFunction · 0.85
strbuf_releaseFunction · 0.85
repo_get_common_dirFunction · 0.85
copy_templates_1Function · 0.85
closedirFunction · 0.85

Tested by

no test coverage detected