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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Nov 26, 2010 at 22:32 UTC
dbdf5854b21852676de6a8baf052147217ce809b
2 files changed
+15
-5
cache.h
+1
@@ -986,6 +986,7 @@ extern int git_config_parse_parameter(const char *text);
986
extern int git_config_parse_environment(void);
987
extern int git_config_from_parameters(config_fn_t fn, void *data);
988
extern int git_config(config_fn_t fn, void *);
989
+extern int git_config_early(config_fn_t fn, void *, const char *repo_config);
990
extern int git_parse_ulong(const char *, unsigned long *);
991
extern int git_config_int(const char *, const char *);
992
extern unsigned long git_config_ulong(const char *, const char *);
config.c
+14
-5
@@ -835,10 +835,9 @@ int git_config_from_parameters(config_fn_t fn, void *data)
835
return 0;
836
}
837
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)
839
{
840
int ret = 0, found = 0;
841
- char *repo_config = NULL;
841
const char *home = NULL;
842
843
/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
@@ -860,12 +859,10 @@ int git_config(config_fn_t fn, void *data)
859
free(user_config);
860
}
861
863
- repo_config = git_pathdup("config");
864
- if (!access(repo_config, R_OK)) {
862
+ if (repo_config && !access(repo_config, R_OK)) {
863
ret += git_config_from_file(fn, repo_config, data);
864
found += 1;
865
}
868
- free(repo_config);
866
867
ret += git_config_from_parameters(fn, data);
868
if (config_parameters)
@@ -876,6 +873,18 @@ int git_config(config_fn_t fn, void *data)
873
return ret;
874
}
875
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
+
888
/*
889
* Find all the stuff for git_config_set() below.
890
*/