Skip to content

Commit b92266b

Browse files
pks-tgitster
authored andcommitted
config: make dependency on repo in read_early_config() explicit
The `read_early_config()` function can be used to read configuration where a repository has not yet been set up. As such, it is optional whether or not `the_repository` has already been initialized. If it was initialized we use its commondir and gitdir. If not, the function will try to detect the Git directories by itself and, if found, also parse their config files. This means that we implicitly rely on `the_repository`. Make this dependency explicit by passing a `struct repository`. This allows us to again drop the `USE_THE_REPOSITORY_VARIABLE` define in "config.c". Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c0b03e8 commit b92266b

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

alias.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "alias.h"
35
#include "config.h"
@@ -37,7 +39,7 @@ char *alias_lookup(const char *alias)
3739
{
3840
struct config_alias_data data = { alias, NULL };
3941

40-
read_early_config(config_alias_cb, &data);
42+
read_early_config(the_repository, config_alias_cb, &data);
4143

4244
return data.v;
4345
}
@@ -46,7 +48,7 @@ void list_aliases(struct string_list *list)
4648
{
4749
struct config_alias_data data = { NULL, NULL, list };
4850

49-
read_early_config(config_alias_cb, &data);
51+
read_early_config(the_repository, config_alias_cb, &data);
5052
}
5153

5254
void quote_cmdline(struct strbuf *buf, const char **argv)

config.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
*
77
*/
88

9-
#define USE_THE_REPOSITORY_VARIABLE
10-
119
#include "git-compat-util.h"
1210
#include "abspath.h"
1311
#include "advice.h"
@@ -2204,17 +2202,17 @@ static void configset_iter(struct config_set *set, config_fn_t fn, void *data)
22042202
}
22052203
}
22062204

2207-
void read_early_config(config_fn_t cb, void *data)
2205+
void read_early_config(struct repository *repo, config_fn_t cb, void *data)
22082206
{
22092207
struct config_options opts = {0};
22102208
struct strbuf commondir = STRBUF_INIT;
22112209
struct strbuf gitdir = STRBUF_INIT;
22122210

22132211
opts.respect_includes = 1;
22142212

2215-
if (have_git_dir()) {
2216-
opts.commondir = repo_get_common_dir(the_repository);
2217-
opts.git_dir = repo_get_git_dir(the_repository);
2213+
if (repo && repo->gitdir) {
2214+
opts.commondir = repo_get_common_dir(repo);
2215+
opts.git_dir = repo_get_git_dir(repo);
22182216
/*
22192217
* When setup_git_directory() was not yet asked to discover the
22202218
* GIT_DIR, we ask discover_git_directory() to figure out whether there

config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ int git_config_from_parameters(config_fn_t fn, void *data);
198198
* `the_repository` has not yet been set up, try to discover the Git
199199
* directory to read the configuration from.
200200
*/
201-
void read_early_config(config_fn_t cb, void *data);
201+
void read_early_config(struct repository *repo, config_fn_t cb, void *data);
202202

203203
/*
204204
* Read config but only enumerate system and global settings.

help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ const char *help_unknown_cmd(const char *cmd)
618618
memset(&other_cmds, 0, sizeof(other_cmds));
619619
memset(&aliases, 0, sizeof(aliases));
620620

621-
read_early_config(git_unknown_cmd_config, NULL);
621+
read_early_config(the_repository, git_unknown_cmd_config, NULL);
622622

623623
/*
624624
* Disable autocorrection prompt in a non-interactive session

pager.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "config.h"
35
#include "editor.h"
@@ -92,7 +94,8 @@ const char *git_pager(int stdout_is_tty)
9294
pager = getenv("GIT_PAGER");
9395
if (!pager) {
9496
if (!pager_program)
95-
read_early_config(core_pager_config, NULL);
97+
read_early_config(the_repository,
98+
core_pager_config, NULL);
9699
pager = pager_program;
97100
}
98101
if (!pager)
@@ -298,7 +301,7 @@ int check_pager_config(const char *cmd)
298301
data.want = -1;
299302
data.value = NULL;
300303

301-
read_early_config(pager_command_config, &data);
304+
read_early_config(the_repository, pager_command_config, &data);
302305

303306
if (data.value)
304307
pager_program = data.value;

t/helper/test-config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ int cmd__config(int argc, const char **argv)
9696
struct config_set cs;
9797

9898
if (argc == 3 && !strcmp(argv[1], "read_early_config")) {
99-
read_early_config(early_config_cb, (void *)argv[2]);
99+
read_early_config(the_repository, early_config_cb,
100+
(void *)argv[2]);
100101
return 0;
101102
}
102103

trace2/tr2_cfg.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "config.h"
35
#include "strbuf.h"
@@ -124,7 +126,7 @@ void tr2_cfg_list_config_fl(const char *file, int line)
124126
struct tr2_cfg_data data = { file, line };
125127

126128
if (tr2_cfg_load_patterns() > 0)
127-
read_early_config(tr2_cfg_cb, &data);
129+
read_early_config(the_repository, tr2_cfg_cb, &data);
128130
}
129131

130132
void tr2_list_env_vars_fl(const char *file, int line)

0 commit comments

Comments
 (0)