sha1_file.c: move delayed getenv(altdb) back to setup_git_env()
getenv() is supposed to work on the main repository only. This delayed getenv() code in sha1_file.c makes it more difficult to convert sha1_file.c to a generic object store that could be used by both submodule and main repositories. Move the getenv() back in setup_git_env() where other env vars are also fetched. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Mar 3, 2018 at 18:35 UTC
7bc0dcaa6120efec8cf8caef8511c09d35dbcf09
4 files changed
+9
-5
environment.c
+1
@@ -174,6 +174,7 @@ void setup_git_env(const char *git_dir)
174
args.object_dir = getenv_safe(&to_free, DB_ENVIRONMENT);
175
args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT);
176
args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT);
177
+ args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT);
178
repo_set_gitdir(the_repository, git_dir, &args);
179
argv_array_clear(&to_free);
180
repository.c
+3
@@ -60,6 +60,8 @@ void repo_set_gitdir(struct repository *repo,
60
repo_set_commondir(repo, o->commondir);
61
expand_base_dir(&repo->objectdir, o->object_dir,
62
repo->commondir, "objects");
63
+ free(repo->alternate_db);
64
+ repo->alternate_db = xstrdup_or_null(o->alternate_db);
65
expand_base_dir(&repo->graft_file, o->graft_file,
66
repo->commondir, "info/grafts");
67
expand_base_dir(&repo->index_file, o->index_file,
@@ -215,6 +217,7 @@ void repo_clear(struct repository *repo)
217
FREE_AND_NULL(repo->gitdir);
218
FREE_AND_NULL(repo->commondir);
219
FREE_AND_NULL(repo->objectdir);
220
+ FREE_AND_NULL(repo->alternate_db);
221
FREE_AND_NULL(repo->graft_file);
222
FREE_AND_NULL(repo->index_file);
223
FREE_AND_NULL(repo->worktree);
repository.h
+4
@@ -26,6 +26,9 @@ struct repository {
26
*/
27
char *objectdir;
28
29
+ /* Path to extra alternate object database if not NULL */
30
+ char *alternate_db;
31
+
32
/*
33
* Path to the repository's graft file.
34
* Cannot be NULL after initialization.
@@ -93,6 +96,7 @@ struct set_gitdir_args {
96
const char *object_dir;
97
const char *graft_file;
98
const char *index_file;
99
+ const char *alternate_db;
100
};
101
102
extern void repo_set_gitdir(struct repository *repo,
sha1_file.c
+1
-5
@@ -667,15 +667,11 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
667
668
void prepare_alt_odb(void)
669
{
670
- const char *alt;
671
-
670
if (alt_odb_tail)
671
return;
672
675
- alt = getenv(ALTERNATE_DB_ENVIRONMENT);
676
-
673
alt_odb_tail = &alt_odb_list;
678
- link_alt_odb_entries(alt, PATH_SEP, NULL, 0);
674
+ link_alt_odb_entries(the_repository->alternate_db, PATH_SEP, NULL, 0);
675
676
read_info_alternates(get_object_directory(), 0);
677
}