diff --git a/git.c b/git.c index 387eabe38c..e5f1811b6b 100644 --- a/git.c +++ b/git.c @@ -306,7 +306,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) } else if (!strcmp(cmd, "--shallow-file")) { (*argv)++; (*argc)--; - set_alternate_shallow_file(the_repository, (*argv)[0], 1); + setenv(GIT_SHALLOW_FILE_ENVIRONMENT, (*argv)[0], 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "-C")) { diff --git a/setup.c b/setup.c index 1d8c193375..85fad0d77d 100644 --- a/setup.c +++ b/setup.c @@ -1046,7 +1046,6 @@ static void setup_git_env_internal(struct repository *repo, const char *git_dir) { char *git_replace_ref_base; - const char *shallow_file; const char *replace_ref_base; struct set_gitdir_args args = { NULL }; struct strvec to_free = STRVEC_INIT; @@ -1067,10 +1066,6 @@ static void setup_git_env_internal(struct repository *repo, : "refs/replace/"); update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); - shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); - if (shallow_file) - set_alternate_shallow_file(repo, shallow_file, 0); - if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) fetch_if_missing = 0; } @@ -1774,8 +1769,13 @@ int apply_repository_format(struct repository *repo, } if (flags & APPLY_REPOSITORY_FORMAT_HONOR_ENV) { + const char *shallow_file; + object_directory = xstrdup_or_null(getenv(DB_ENVIRONMENT)); alternate_object_directories = xstrdup_or_null(getenv(ALTERNATE_DB_ENVIRONMENT)); + shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); + if (shallow_file) + set_alternate_shallow_file(repo, shallow_file); } repo->bare_cfg = format->is_bare; diff --git a/shallow.c b/shallow.c index 07cae44ae5..c063b3deaf 100644 --- a/shallow.c +++ b/shallow.c @@ -21,12 +21,10 @@ #include "statinfo.h" #include "trace.h" -void set_alternate_shallow_file(struct repository *r, const char *path, int override) +void set_alternate_shallow_file(struct repository *r, const char *path) { if (r->parsed_objects->is_shallow != -1) BUG("is_repository_shallow must not be called before set_alternate_shallow_file"); - if (r->parsed_objects->alternate_shallow_file && !override) - return; free(r->parsed_objects->alternate_shallow_file); r->parsed_objects->alternate_shallow_file = xstrdup_or_null(path); } diff --git a/shallow.h b/shallow.h index e20ca4c21b..6a64db42c9 100644 --- a/shallow.h +++ b/shallow.h @@ -10,7 +10,7 @@ struct oid_array; struct strvec; -void set_alternate_shallow_file(struct repository *r, const char *path, int override); +void set_alternate_shallow_file(struct repository *r, const char *path); int register_shallow(struct repository *r, const struct object_id *oid); int unregister_shallow(const struct object_id *oid); int is_repository_shallow(struct repository *r);