Skip to content

Commit 7bc0dca

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0ac5af5 commit 7bc0dca

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ void setup_git_env(const char *git_dir)
174174
args.object_dir = getenv_safe(&to_free, DB_ENVIRONMENT);
175175
args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT);
176176
args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT);
177+
args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT);
177178
repo_set_gitdir(the_repository, git_dir, &args);
178179
argv_array_clear(&to_free);
179180

repository.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ void repo_set_gitdir(struct repository *repo,
6060
repo_set_commondir(repo, o->commondir);
6161
expand_base_dir(&repo->objectdir, o->object_dir,
6262
repo->commondir, "objects");
63+
free(repo->alternate_db);
64+
repo->alternate_db = xstrdup_or_null(o->alternate_db);
6365
expand_base_dir(&repo->graft_file, o->graft_file,
6466
repo->commondir, "info/grafts");
6567
expand_base_dir(&repo->index_file, o->index_file,
@@ -215,6 +217,7 @@ void repo_clear(struct repository *repo)
215217
FREE_AND_NULL(repo->gitdir);
216218
FREE_AND_NULL(repo->commondir);
217219
FREE_AND_NULL(repo->objectdir);
220+
FREE_AND_NULL(repo->alternate_db);
218221
FREE_AND_NULL(repo->graft_file);
219222
FREE_AND_NULL(repo->index_file);
220223
FREE_AND_NULL(repo->worktree);

repository.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ struct repository {
2626
*/
2727
char *objectdir;
2828

29+
/* Path to extra alternate object database if not NULL */
30+
char *alternate_db;
31+
2932
/*
3033
* Path to the repository's graft file.
3134
* Cannot be NULL after initialization.
@@ -93,6 +96,7 @@ struct set_gitdir_args {
9396
const char *object_dir;
9497
const char *graft_file;
9598
const char *index_file;
99+
const char *alternate_db;
96100
};
97101

98102
extern void repo_set_gitdir(struct repository *repo,

sha1_file.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,11 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
667667

668668
void prepare_alt_odb(void)
669669
{
670-
const char *alt;
671-
672670
if (alt_odb_tail)
673671
return;
674672

675-
alt = getenv(ALTERNATE_DB_ENVIRONMENT);
676-
677673
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);
679675

680676
read_info_alternates(get_object_directory(), 0);
681677
}

0 commit comments

Comments
 (0)