setup: make read_early_config() reusable
The pager configuration needs to be read early, possibly before discovering any .git/ directory. Let's not hide this function in pager.c, but make it available to other callers. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
16ac8b8db6
commit
0654aa57f3
1
cache.h
1
cache.h
|
@ -1760,6 +1760,7 @@ extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
|
||||||
const unsigned char *sha1, void *data);
|
const unsigned char *sha1, void *data);
|
||||||
extern void git_config_push_parameter(const char *text);
|
extern void git_config_push_parameter(const char *text);
|
||||||
extern int git_config_from_parameters(config_fn_t fn, void *data);
|
extern int git_config_from_parameters(config_fn_t fn, void *data);
|
||||||
|
extern void read_early_config(config_fn_t cb, void *data);
|
||||||
extern void git_config(config_fn_t fn, void *);
|
extern void git_config(config_fn_t fn, void *);
|
||||||
extern int git_config_with_options(config_fn_t fn, void *,
|
extern int git_config_with_options(config_fn_t fn, void *,
|
||||||
struct git_config_source *config_source,
|
struct git_config_source *config_source,
|
||||||
|
|
31
config.c
31
config.c
|
@ -1412,6 +1412,37 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void read_early_config(config_fn_t cb, void *data)
|
||||||
|
{
|
||||||
|
git_config_with_options(cb, data, NULL, 1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note that this is a really dirty hack that does the wrong thing in
|
||||||
|
* many cases. The crux of the problem is that we cannot run
|
||||||
|
* setup_git_directory() early on in git's setup, so we have no idea if
|
||||||
|
* we are in a repository or not, and therefore are not sure whether
|
||||||
|
* and how to read repository-local config.
|
||||||
|
*
|
||||||
|
* So if we _aren't_ in a repository (or we are but we would reject its
|
||||||
|
* core.repositoryformatversion), we'll read whatever is in .git/config
|
||||||
|
* blindly. Similarly, if we _are_ in a repository, but not at the
|
||||||
|
* root, we'll fail to find .git/config (because it's really
|
||||||
|
* ../.git/config, etc). See t7006 for a complete set of failures.
|
||||||
|
*
|
||||||
|
* However, we have historically provided this hack because it does
|
||||||
|
* work some of the time (namely when you are at the top-level of a
|
||||||
|
* valid repository), and would rarely make things worse (i.e., you do
|
||||||
|
* not generally have a .git/config file sitting around).
|
||||||
|
*/
|
||||||
|
if (!startup_info->have_repository) {
|
||||||
|
struct git_config_source repo_config;
|
||||||
|
|
||||||
|
memset(&repo_config, 0, sizeof(repo_config));
|
||||||
|
repo_config.file = ".git/config";
|
||||||
|
git_config_with_options(cb, data, &repo_config, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void git_config_check_init(void);
|
static void git_config_check_init(void);
|
||||||
|
|
||||||
void git_config(config_fn_t fn, void *data)
|
void git_config(config_fn_t fn, void *data)
|
||||||
|
|
31
pager.c
31
pager.c
|
@ -43,37 +43,6 @@ static int core_pager_config(const char *var, const char *value, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_early_config(config_fn_t cb, void *data)
|
|
||||||
{
|
|
||||||
git_config_with_options(cb, data, NULL, 1);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Note that this is a really dirty hack that does the wrong thing in
|
|
||||||
* many cases. The crux of the problem is that we cannot run
|
|
||||||
* setup_git_directory() early on in git's setup, so we have no idea if
|
|
||||||
* we are in a repository or not, and therefore are not sure whether
|
|
||||||
* and how to read repository-local config.
|
|
||||||
*
|
|
||||||
* So if we _aren't_ in a repository (or we are but we would reject its
|
|
||||||
* core.repositoryformatversion), we'll read whatever is in .git/config
|
|
||||||
* blindly. Similarly, if we _are_ in a repository, but not at the
|
|
||||||
* root, we'll fail to find .git/config (because it's really
|
|
||||||
* ../.git/config, etc). See t7006 for a complete set of failures.
|
|
||||||
*
|
|
||||||
* However, we have historically provided this hack because it does
|
|
||||||
* work some of the time (namely when you are at the top-level of a
|
|
||||||
* valid repository), and would rarely make things worse (i.e., you do
|
|
||||||
* not generally have a .git/config file sitting around).
|
|
||||||
*/
|
|
||||||
if (!startup_info->have_repository) {
|
|
||||||
struct git_config_source repo_config;
|
|
||||||
|
|
||||||
memset(&repo_config, 0, sizeof(repo_config));
|
|
||||||
repo_config.file = ".git/config";
|
|
||||||
git_config_with_options(cb, data, &repo_config, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *git_pager(int stdout_is_tty)
|
const char *git_pager(int stdout_is_tty)
|
||||||
{
|
{
|
||||||
const char *pager;
|
const char *pager;
|
||||||
|
|
Loading…
Reference in New Issue