| 2417 | } |
| 2418 | |
| 2419 | void initialize_repository_version(struct repository *repo, |
| 2420 | int hash_algo, |
| 2421 | enum ref_storage_format ref_storage_format, |
| 2422 | int reinit) |
| 2423 | { |
| 2424 | struct strbuf repo_version = STRBUF_INIT; |
| 2425 | int target_version = GIT_REPO_VERSION; |
| 2426 | int default_submodule_path_config = 0; |
| 2427 | |
| 2428 | /* |
| 2429 | * Note that we initialize the repository version to 1 when the ref |
| 2430 | * storage format is unknown. This is on purpose so that we can add the |
| 2431 | * correct object format to the config during git-clone(1). The format |
| 2432 | * version will get adjusted by git-clone(1) once it has learned about |
| 2433 | * the remote repository's format. |
| 2434 | */ |
| 2435 | if (hash_algo != GIT_HASH_SHA1_LEGACY || |
| 2436 | ref_storage_format != REF_STORAGE_FORMAT_FILES || |
| 2437 | repo->ref_storage_payload) |
| 2438 | target_version = GIT_REPO_VERSION_READ; |
| 2439 | |
| 2440 | if (hash_algo != GIT_HASH_SHA1_LEGACY && hash_algo != GIT_HASH_UNKNOWN) |
| 2441 | repo_config_set(repo, "extensions.objectformat", |
| 2442 | hash_algos[hash_algo].name); |
| 2443 | else if (reinit) |
| 2444 | repo_config_set_gently(repo, "extensions.objectformat", NULL); |
| 2445 | |
| 2446 | if (repo->ref_storage_payload) { |
| 2447 | struct strbuf ref_uri = STRBUF_INIT; |
| 2448 | |
| 2449 | strbuf_addf(&ref_uri, "%s://%s", |
| 2450 | ref_storage_format_to_name(ref_storage_format), |
| 2451 | repo->ref_storage_payload); |
| 2452 | repo_config_set(repo, "extensions.refstorage", ref_uri.buf); |
| 2453 | strbuf_release(&ref_uri); |
| 2454 | } else if (ref_storage_format != REF_STORAGE_FORMAT_FILES) { |
| 2455 | repo_config_set(repo, "extensions.refstorage", |
| 2456 | ref_storage_format_to_name(ref_storage_format)); |
| 2457 | } else if (reinit) { |
| 2458 | repo_config_set_gently(repo, "extensions.refstorage", NULL); |
| 2459 | } |
| 2460 | |
| 2461 | if (reinit) { |
| 2462 | struct strbuf config = STRBUF_INIT; |
| 2463 | struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT; |
| 2464 | |
| 2465 | repo_common_path_append(repo, &config, "config"); |
| 2466 | read_repository_format(&repo_fmt, config.buf); |
| 2467 | |
| 2468 | if (repo_fmt.v1_only_extensions.nr) |
| 2469 | target_version = GIT_REPO_VERSION_READ; |
| 2470 | |
| 2471 | strbuf_release(&config); |
| 2472 | clear_repository_format(&repo_fmt); |
| 2473 | } |
| 2474 | |
| 2475 | repo_config_get_bool(repo, "init.defaultSubmodulePathConfig", |
| 2476 | &default_submodule_path_config); |
no test coverage detected