summaryrefslogtreecommitdiffstats
path: root/config.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-09-12 13:29:45 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-12 19:15:40 +0200
commitb92266b79c7bb741e3600e9dc206b693d8062fa9 (patch)
tree33f43c13c0dd58b470e91cab1caf0bccf24422ab /config.c
parentconfig: document `read_early_config()` and `read_very_early_config()` (diff)
downloadgit-b92266b79c7bb741e3600e9dc206b693d8062fa9.tar.xz
git-b92266b79c7bb741e3600e9dc206b693d8062fa9.zip
config: make dependency on repo in `read_early_config()` explicit
The `read_early_config()` function can be used to read configuration where a repository has not yet been set up. As such, it is optional whether or not `the_repository` has already been initialized. If it was initialized we use its commondir and gitdir. If not, the function will try to detect the Git directories by itself and, if found, also parse their config files. This means that we implicitly rely on `the_repository`. Make this dependency explicit by passing a `struct repository`. This allows us to again drop the `USE_THE_REPOSITORY_VARIABLE` define in "config.c". Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/config.c b/config.c
index a8357ea954..043e1c8a07 100644
--- a/config.c
+++ b/config.c
@@ -6,8 +6,6 @@
*
*/
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
@@ -2204,7 +2202,7 @@ static void configset_iter(struct config_set *set, config_fn_t fn, void *data)
}
}
-void read_early_config(config_fn_t cb, void *data)
+void read_early_config(struct repository *repo, config_fn_t cb, void *data)
{
struct config_options opts = {0};
struct strbuf commondir = STRBUF_INIT;
@@ -2212,9 +2210,9 @@ void read_early_config(config_fn_t cb, void *data)
opts.respect_includes = 1;
- if (have_git_dir()) {
- opts.commondir = repo_get_common_dir(the_repository);
- opts.git_dir = repo_get_git_dir(the_repository);
+ if (repo && repo->gitdir) {
+ opts.commondir = repo_get_common_dir(repo);
+ opts.git_dir = repo_get_git_dir(repo);
/*
* When setup_git_directory() was not yet asked to discover the
* GIT_DIR, we ask discover_git_directory() to figure out whether there