Skip to content

Commit 800a7f9

Browse files
jeffhostetlergitster
authored andcommitted
config: add read_very_early_config()
Created an even lighter version of read_early_config() that only looks at system and global config settings. It omits repo-local, worktree-local, and command-line settings. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a7bc01e commit 800a7f9

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

config.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,22 +1688,23 @@ static int do_git_config_sequence(const struct config_options *opts,
16881688
ret += git_config_from_file(fn, user_config, data);
16891689

16901690
current_parsing_scope = CONFIG_SCOPE_REPO;
1691-
if (repo_config && !access_or_die(repo_config, R_OK, 0))
1691+
if (!opts->ignore_repo && repo_config &&
1692+
!access_or_die(repo_config, R_OK, 0))
16921693
ret += git_config_from_file(fn, repo_config, data);
16931694

16941695
/*
16951696
* Note: this should have a new scope, CONFIG_SCOPE_WORKTREE.
16961697
* But let's not complicate things before it's actually needed.
16971698
*/
1698-
if (repository_format_worktree_config) {
1699+
if (!opts->ignore_worktree && repository_format_worktree_config) {
16991700
char *path = git_pathdup("config.worktree");
17001701
if (!access_or_die(path, R_OK, 0))
17011702
ret += git_config_from_file(fn, path, data);
17021703
free(path);
17031704
}
17041705

17051706
current_parsing_scope = CONFIG_SCOPE_CMDLINE;
1706-
if (git_config_from_parameters(fn, data) < 0)
1707+
if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)
17071708
die(_("unable to parse command-line config"));
17081709

17091710
current_parsing_scope = CONFIG_SCOPE_UNKNOWN;
@@ -1794,6 +1795,22 @@ void read_early_config(config_fn_t cb, void *data)
17941795
strbuf_release(&gitdir);
17951796
}
17961797

1798+
/*
1799+
* Read config but only enumerate system and global settings.
1800+
* Omit any repo-local, worktree-local, or command-line settings.
1801+
*/
1802+
void read_very_early_config(config_fn_t cb, void *data)
1803+
{
1804+
struct config_options opts = { 0 };
1805+
1806+
opts.respect_includes = 1;
1807+
opts.ignore_repo = 1;
1808+
opts.ignore_worktree = 1;
1809+
opts.ignore_cmdline = 1;
1810+
1811+
config_with_options(cb, data, NULL, &opts);
1812+
}
1813+
17971814
static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)
17981815
{
17991816
struct config_set_element k;

config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ typedef int (*config_parser_event_fn_t)(enum config_event_t type,
5555

5656
struct config_options {
5757
unsigned int respect_includes : 1;
58+
unsigned int ignore_repo : 1;
59+
unsigned int ignore_worktree : 1;
60+
unsigned int ignore_cmdline : 1;
5861
const char *commondir;
5962
const char *git_dir;
6063
config_parser_event_fn_t event_fn;
@@ -83,6 +86,7 @@ extern int git_config_from_blob_oid(config_fn_t fn, const char *name,
8386
extern void git_config_push_parameter(const char *text);
8487
extern int git_config_from_parameters(config_fn_t fn, void *data);
8588
extern void read_early_config(config_fn_t cb, void *data);
89+
extern void read_very_early_config(config_fn_t cb, void *data);
8690
extern void git_config(config_fn_t fn, void *);
8791
extern int config_with_options(config_fn_t fn, void *,
8892
struct git_config_source *config_source,

0 commit comments

Comments
 (0)