Skip to content

Commit dbdf585

Browse files
pcloudsgitster
authored andcommitted
Add git_config_early()
This version of git_config() will be used during repository setup. As a repository is being set up, $GIT_DIR is not nailed down yet, git_pathdup() should not be used to get $GIT_DIR/config. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80d868b commit dbdf585

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ extern int git_config_parse_parameter(const char *text);
986986
extern int git_config_parse_environment(void);
987987
extern int git_config_from_parameters(config_fn_t fn, void *data);
988988
extern int git_config(config_fn_t fn, void *);
989+
extern int git_config_early(config_fn_t fn, void *, const char *repo_config);
989990
extern int git_parse_ulong(const char *, unsigned long *);
990991
extern int git_config_int(const char *, const char *);
991992
extern unsigned long git_config_ulong(const char *, const char *);

config.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,9 @@ int git_config_from_parameters(config_fn_t fn, void *data)
835835
return 0;
836836
}
837837

838-
int git_config(config_fn_t fn, void *data)
838+
int git_config_early(config_fn_t fn, void *data, const char *repo_config)
839839
{
840840
int ret = 0, found = 0;
841-
char *repo_config = NULL;
842841
const char *home = NULL;
843842

844843
/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
@@ -860,12 +859,10 @@ int git_config(config_fn_t fn, void *data)
860859
free(user_config);
861860
}
862861

863-
repo_config = git_pathdup("config");
864-
if (!access(repo_config, R_OK)) {
862+
if (repo_config && !access(repo_config, R_OK)) {
865863
ret += git_config_from_file(fn, repo_config, data);
866864
found += 1;
867865
}
868-
free(repo_config);
869866

870867
ret += git_config_from_parameters(fn, data);
871868
if (config_parameters)
@@ -876,6 +873,18 @@ int git_config(config_fn_t fn, void *data)
876873
return ret;
877874
}
878875

876+
int git_config(config_fn_t fn, void *data)
877+
{
878+
char *repo_config = NULL;
879+
int ret;
880+
881+
repo_config = git_pathdup("config");
882+
ret = git_config_early(fn, data, repo_config);
883+
if (repo_config)
884+
free(repo_config);
885+
return ret;
886+
}
887+
879888
/*
880889
* Find all the stuff for git_config_set() below.
881890
*/

0 commit comments

Comments
 (0)