From: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> Attempts to access gitdir are everywhere, even before cmd_*() is called (in particular for alias handling, pager configuration, work tree, and other core configuration). Because the repository has not been found, repository-specific information (GIT_DIR/config) can not be read. This can lead to obscure bugs. The sooner we set up gitdir, the less trouble we may have to deal with. Currently, the cmd_*() functions learn whether a repository was found through the *nongit_ok return value to setup_git_directory_gently(). If run_builtin() is to take care of this sooner, then they will have to get it from somewhere else. startup_info is a good place for this. As a bonus, this information can be used to teach functions such as git_config() to avoid trying to access a repository if none is present. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx> --- cache.h | 1 + setup.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletions(-) diff --git a/cache.h b/cache.h index 1479824..030ba01 100644 --- a/cache.h +++ b/cache.h @@ -1060,6 +1060,7 @@ int split_cmdline(char *cmdline, const char ***argv); /* git.c */ struct startup_info { + int have_repository; }; extern struct startup_info *startup_info; diff --git a/setup.c b/setup.c index 5716d90..3b4ff09 100644 --- a/setup.c +++ b/setup.c @@ -315,7 +315,7 @@ const char *read_gitfile_gently(const char *path) * We cannot decide in this function whether we are in the work tree or * not, since the config can only be read _after_ this function was called. */ -const char *setup_git_directory_gently(int *nongit_ok) +static const char *setup_git_directory_gently_1(int *nongit_ok) { const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT); const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT); @@ -443,6 +443,16 @@ const char *setup_git_directory_gently(int *nongit_ok) return cwd + offset; } +const char *setup_git_directory_gently(int *nongit_ok) +{ + const char *prefix; + + prefix = setup_git_directory_gently_1(nongit_ok); + if (startup_info) + startup_info->have_repository = !nongit_ok || !*nongit_ok; + return prefix; +} + int git_config_perm(const char *var, const char *value) { int i; -- 1.7.0.4 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html