Skip to content

Commit 0d885f2

Browse files
Unique-Usmangitster
authored andcommitted
config: teach repo_config to allow repo to be NULL
The `repo` value can be NULL if a builtin command is run outside any repository. The current implementation of `repo_config()` will fail if `repo` is NULL. If the `repo` is NULL the `repo_config()` can ignore the repository configuration but it should read the other configuration sources like the system-side configuration instead of failing. Teach the `repo_config()` to allow `repo` to be NULL by calling the `read_very_early_config()` which read config but only enumerate system and global settings. This will be useful in the following commits. Suggested-by: Junio C Hamano <[email protected]> Mentored-by: Christian Couder <[email protected]> Signed-off-by: Usman Akinyemi <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e969bc8 commit 0d885f2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

config.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,10 @@ void repo_config_clear(struct repository *repo)
25212521

25222522
void repo_config(struct repository *repo, config_fn_t fn, void *data)
25232523
{
2524+
if (!repo) {
2525+
read_very_early_config(fn, data);
2526+
return;
2527+
}
25242528
git_config_check_init(repo);
25252529
configset_iter(repo->config, fn, data);
25262530
}

config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ void read_very_early_config(config_fn_t cb, void *data);
219219
* repo-specific one; by overwriting, the higher-priority repo-specific
220220
* value is left at the end).
221221
*
222+
* In cases where the repository variable is NULL, repo_config() will
223+
* call read_early_config().
224+
*
222225
* Unlike git_config_from_file(), this function respects includes.
223226
*/
224227
void repo_config(struct repository *r, config_fn_t fn, void *);

0 commit comments

Comments
 (0)