From a60645f9c54c3050cbe25882feba9d5b3d1ca0d6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 21:46:33 -0500 Subject: [PATCH] setup: remember whether repository was found MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit As v1.7.2~16^2 (git --paginate: paginate external commands again, 2010-07-14) explains, builtins (like git config) that do not use RUN_SETUP are not finding GIT_DIR set correctly when it is time to launch the pager from run_builtin(). If they were to search for a repository sooner, then the outcome of such early repository accesses would be more predictable and reliable. The cmd_*() functions learn whether a repository was found through the *nongit_ok return value from setup_git_directory_gently(). If run_builtin() is to take care of the repository search itself, that datum needs to be retrievable from somewhere else. Use the startup_info struct for this. As a bonus, this information becomes available to functions such as git_config() which might want to avoid trying to access a repository when none is present. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- cache.h | 1 + setup.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cache.h b/cache.h index 0822c3b8b..f9e82a8ac 100644 --- a/cache.h +++ b/cache.h @@ -1099,6 +1099,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 276916052..28a2b69d0 100644 --- a/setup.c +++ b/setup.c @@ -317,7 +317,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); @@ -473,6 +473,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; -- 2.26.2