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>
Johannes Schindelin committed
Mar 13, 2017 at 21:11 UTC
0654aa57f30fc7984e19b91cdbee123f929ca7b1
3 files changed
+32
-31
cache.h
+1
@@ -1760,6 +1760,7 @@ extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
1760
const unsigned char *sha1, void *data);
1761
extern void git_config_push_parameter(const char *text);
1762
extern int git_config_from_parameters(config_fn_t fn, void *data);
1763
+extern void read_early_config(config_fn_t cb, void *data);
1764
extern void git_config(config_fn_t fn, void *);
1765
extern int git_config_with_options(config_fn_t fn, void *,
1766
struct git_config_source *config_source,
config.c
+31
@@ -1412,6 +1412,37 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
1412
}
1413
}
1414
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
+
1446
static void git_config_check_init(void);
1447
1448
void git_config(config_fn_t fn, void *data)
pager.c
-31
@@ -43,37 +43,6 @@ static int core_pager_config(const char *var, const char *value, void *data)
43
return 0;
44
}
45
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
-
46
const char *git_pager(int stdout_is_tty)
47
{
48
const char *pager;