Skip to content

Commit 0654aa5

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16ac8b8 commit 0654aa5

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,7 @@ extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
17601760
const unsigned char *sha1, void *data);
17611761
extern void git_config_push_parameter(const char *text);
17621762
extern int git_config_from_parameters(config_fn_t fn, void *data);
1763+
extern void read_early_config(config_fn_t cb, void *data);
17631764
extern void git_config(config_fn_t fn, void *);
17641765
extern int git_config_with_options(config_fn_t fn, void *,
17651766
struct git_config_source *config_source,

config.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,37 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
14121412
}
14131413
}
14141414

1415+
void read_early_config(config_fn_t cb, void *data)
1416+
{
1417+
git_config_with_options(cb, data, NULL, 1);
1418+
1419+
/*
1420+
* Note that this is a really dirty hack that does the wrong thing in
1421+
* many cases. The crux of the problem is that we cannot run
1422+
* setup_git_directory() early on in git's setup, so we have no idea if
1423+
* we are in a repository or not, and therefore are not sure whether
1424+
* and how to read repository-local config.
1425+
*
1426+
* So if we _aren't_ in a repository (or we are but we would reject its
1427+
* core.repositoryformatversion), we'll read whatever is in .git/config
1428+
* blindly. Similarly, if we _are_ in a repository, but not at the
1429+
* root, we'll fail to find .git/config (because it's really
1430+
* ../.git/config, etc). See t7006 for a complete set of failures.
1431+
*
1432+
* However, we have historically provided this hack because it does
1433+
* work some of the time (namely when you are at the top-level of a
1434+
* valid repository), and would rarely make things worse (i.e., you do
1435+
* not generally have a .git/config file sitting around).
1436+
*/
1437+
if (!startup_info->have_repository) {
1438+
struct git_config_source repo_config;
1439+
1440+
memset(&repo_config, 0, sizeof(repo_config));
1441+
repo_config.file = ".git/config";
1442+
git_config_with_options(cb, data, &repo_config, 1);
1443+
}
1444+
}
1445+
14151446
static void git_config_check_init(void);
14161447

14171448
void git_config(config_fn_t fn, void *data)

pager.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,6 @@ static int core_pager_config(const char *var, const char *value, void *data)
4343
return 0;
4444
}
4545

46-
static void read_early_config(config_fn_t cb, void *data)
47-
{
48-
git_config_with_options(cb, data, NULL, 1);
49-
50-
/*
51-
* Note that this is a really dirty hack that does the wrong thing in
52-
* many cases. The crux of the problem is that we cannot run
53-
* setup_git_directory() early on in git's setup, so we have no idea if
54-
* we are in a repository or not, and therefore are not sure whether
55-
* and how to read repository-local config.
56-
*
57-
* So if we _aren't_ in a repository (or we are but we would reject its
58-
* core.repositoryformatversion), we'll read whatever is in .git/config
59-
* blindly. Similarly, if we _are_ in a repository, but not at the
60-
* root, we'll fail to find .git/config (because it's really
61-
* ../.git/config, etc). See t7006 for a complete set of failures.
62-
*
63-
* However, we have historically provided this hack because it does
64-
* work some of the time (namely when you are at the top-level of a
65-
* valid repository), and would rarely make things worse (i.e., you do
66-
* not generally have a .git/config file sitting around).
67-
*/
68-
if (!startup_info->have_repository) {
69-
struct git_config_source repo_config;
70-
71-
memset(&repo_config, 0, sizeof(repo_config));
72-
repo_config.file = ".git/config";
73-
git_config_with_options(cb, data, &repo_config, 1);
74-
}
75-
}
76-
7746
const char *git_pager(int stdout_is_tty)
7847
{
7948
const char *pager;

0 commit comments

Comments
 (0)