1752
1753
int apply_repository_format(struct repository *repo,
1754
const struct repository_format *format,
1755
+ enum apply_repository_format_flags flags,
1756
struct strbuf *err)
1757
{
1758
+ char *object_directory = NULL, *alternate_object_directories = NULL;
1759
+
1760
if (verify_repository_format(format, err) < 0)
1761
return -1;
1762
1763
+ if (flags & APPLY_REPOSITORY_FORMAT_HONOR_ENV) {
1764
+ object_directory = xstrdup_or_null(getenv(DB_ENVIRONMENT));
1765
+ alternate_object_directories = xstrdup_or_null(getenv(ALTERNATE_DB_ENVIRONMENT));
1766
+ }
1767
+
1768
repo_set_hash_algo(repo, format->hash_algo);
1769
+ repo->objects = odb_new(repo, object_directory,
1770
+ alternate_object_directories);
1771
repo_set_compat_hash_algo(repo, format->compat_hash_algo);
1772
repo_set_ref_storage_format(repo,
1773
format->ref_storage_format,
1783
repo->repository_format_precious_objects =
1784
format->precious_objects;
1785
1786
+ free(alternate_object_directories);
1787
+ free(object_directory);
1788
return 0;
1789
}
1790
1797
* If successful and fmt is not NULL, fill fmt with data.
1798
*/
1799
static void check_and_apply_repository_format(struct repository *repo,
1788
- struct repository_format *fmt)
1800
+ struct repository_format *fmt,
1801
+ enum apply_repository_format_flags flags)
1802
{
1803
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
1804
struct strbuf err = STRBUF_INIT;
1807
fmt = &repo_fmt;
1808
1809
check_repository_format_gently(repo_get_git_dir(repo), fmt, NULL);
1797
- if (apply_repository_format(repo, fmt, &err) < 0)
1810
+ if (apply_repository_format(repo, fmt, flags, &err) < 0)
1811
die("%s", err.buf);
1812
startup_info->have_repository = 1;
1813
1887
}
1888
1889
if (is_git_directory(".")) {
1877
- struct strvec to_free = STRVEC_INIT;
1878
-
1890
set_git_dir(repo, ".", 0);
1880
- repo->objects = odb_new(repo,
1881
- getenv_safe(&to_free, DB_ENVIRONMENT),
1882
- getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT));
1883
- check_and_apply_repository_format(repo, NULL);
1884
-
1885
- strvec_clear(&to_free);
1891
+ check_and_apply_repository_format(repo, NULL,
1892
+ APPLY_REPOSITORY_FORMAT_HONOR_ENV);
1893
return path;
1894
}
1895
2041
startup_info->have_repository ||
2042
/* GIT_DIR_EXPLICIT */
2043
getenv(GIT_DIR_ENVIRONMENT)) {
2037
- struct strvec to_free = STRVEC_INIT;
2038
-
2044
if (!repo->gitdir) {
2045
const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
2046
if (!gitdir)
2051
if (startup_info->have_repository) {
2052
struct strbuf err = STRBUF_INIT;
2053
2049
- repo->objects = odb_new(repo,
2050
- getenv_safe(&to_free, DB_ENVIRONMENT),
2051
- getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT));
2052
- if (apply_repository_format(repo, &repo_fmt, &err) < 0)
2054
+ if (apply_repository_format(repo, &repo_fmt,
2055
+ APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
2056
die("%s", err.buf);
2057
2058
clear_repository_format(&repo_fmt);
2059
strbuf_release(&err);
2060
}
2058
-
2059
- strvec_clear(&to_free);
2061
}
2062
/*
2063
* Since precompose_string_if_needed() needs to look at
2806
int exist_ok = flags & INIT_DB_EXIST_OK;
2807
char *original_git_dir = real_pathdup(git_dir, 1);
2808
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
2808
- struct strvec to_free = STRVEC_INIT;
2809
2810
if (real_git_dir) {
2811
struct stat st;
2826
}
2827
startup_info->have_repository = 1;
2828
2829
- repo->objects = odb_new(repo, getenv_safe(&to_free, DB_ENVIRONMENT),
2830
- getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT));
2831
-
2829
/*
2830
* Check to see if the repository version is right.
2831
* Note that a newly created repository does not have
2832
* config file, so this will not fail. What we are catching
2833
* is an attempt to reinitialize new repository with an old tool.
2834
*/
2838
- check_and_apply_repository_format(repo, &repo_fmt);
2835
+ check_and_apply_repository_format(repo, &repo_fmt,
2836
+ APPLY_REPOSITORY_FORMAT_HONOR_ENV);
2837
2838
repository_format_configure(repo, &repo_fmt, hash, ref_storage_format);
2839
2890
}
2891
2892
clear_repository_format(&repo_fmt);
2895
- strvec_clear(&to_free);
2893
free(original_git_dir);
2894
return 0;
2895
}