Skip to content

Commit a60645f

Browse files
pcloudsgitster
authored andcommitted
setup: remember whether repository was found
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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e37c132 commit a60645f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ int split_cmdline(char *cmdline, const char ***argv);
10991099

11001100
/* git.c */
11011101
struct startup_info {
1102+
int have_repository;
11021103
};
11031104
extern struct startup_info *startup_info;
11041105

setup.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ const char *read_gitfile_gently(const char *path)
317317
* We cannot decide in this function whether we are in the work tree or
318318
* not, since the config can only be read _after_ this function was called.
319319
*/
320-
const char *setup_git_directory_gently(int *nongit_ok)
320+
static const char *setup_git_directory_gently_1(int *nongit_ok)
321321
{
322322
const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
323323
const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);
@@ -473,6 +473,16 @@ const char *setup_git_directory_gently(int *nongit_ok)
473473
return cwd + offset;
474474
}
475475

476+
const char *setup_git_directory_gently(int *nongit_ok)
477+
{
478+
const char *prefix;
479+
480+
prefix = setup_git_directory_gently_1(nongit_ok);
481+
if (startup_info)
482+
startup_info->have_repository = !nongit_ok || !*nongit_ok;
483+
return prefix;
484+
}
485+
476486
int git_config_perm(const char *var, const char *value)
477487
{
478488
int i;

0 commit comments

Comments
 (0)