summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2008-05-14 18:46:53 +0100
committerJunio C Hamano <gitster@pobox.com>2008-05-14 12:34:44 -0700
commitef90d6d4208a5130185b04f06e5f90a5f9959fe3 (patch)
tree1bcef191493614c192a6c690c6264ec8157ff8de /config.c
parent0bdf93cbf0afd568384f237378ba368e751a2f0f (diff)
downloadgit-ef90d6d4208a5130185b04f06e5f90a5f9959fe3.tar.gz
Provide git_config with a callback-data parameter
git_config() only had a function parameter, but no callback data parameter. This assumes that all callback functions only modify global variables. With this patch, every callback gets a void * parameter, and it is hoped that this will help the libification effort. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/config.c b/config.c
index 0e22c7a642..5431e2dc01 100644
--- a/config.c
+++ b/config.c
@@ -111,7 +111,7 @@ static inline int iskeychar(int c)
return isalnum(c) || c == '-';
}
-static int get_value(config_fn_t fn, char *name, unsigned int len)
+static int get_value(config_fn_t fn, void *data, char *name, unsigned int len)
{
int c;
char *value;
@@ -139,7 +139,7 @@ static int get_value(config_fn_t fn, char *name, unsigned int len)
if (!value)
return -1;
}
- return fn(name, value);
+ return fn(name, value, data);
}
static int get_extended_base_var(char *name, int baselen, int c)
@@ -197,7 +197,7 @@ static int get_base_var(char *name)
}
}
-static int git_parse_file(config_fn_t fn)
+static int git_parse_file(config_fn_t fn, void *data)
{
int comment = 0;
int baselen = 0;
@@ -228,7 +228,7 @@ static int git_parse_file(config_fn_t fn)
if (!isalpha(c))
break;
var[baselen] = tolower(c);
- if (get_value(fn, var, baselen+1) < 0)
+ if (get_value(fn, data, var, baselen+1) < 0)
break;
}
die("bad config file line %d in %s", config_linenr, config_file_name);
@@ -332,7 +332,7 @@ int git_config_string(const char **dest, const char *var, const char *value)
return 0;
}
-int git_default_config(const char *var, const char *value)
+int git_default_config(const char *var, const char *value, void *dummy)
{
/* This needs a better name */
if (!strcmp(var, "core.filemode")) {
@@ -512,7 +512,7 @@ int git_default_config(const char *var, const char *value)
return 0;
}
-int git_config_from_file(config_fn_t fn, const char *filename)
+int git_config_from_file(config_fn_t fn, const char *filename, void *data)
{
int ret;
FILE *f = fopen(filename, "r");
@@ -523,7 +523,7 @@ int git_config_from_file(config_fn_t fn, const char *filename)
config_file_name = filename;
config_linenr = 1;
config_file_eof = 0;
- ret = git_parse_file(fn);
+ ret = git_parse_file(fn, data);
fclose(f);
config_file_name = NULL;
}
@@ -561,7 +561,7 @@ int git_config_global(void)
return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0);
}
-int git_config(config_fn_t fn)
+int git_config(config_fn_t fn, void *data)
{
int ret = 0;
char *repo_config = NULL;
@@ -574,7 +574,8 @@ int git_config(config_fn_t fn)
filename = getenv(CONFIG_ENVIRONMENT);
if (!filename) {
if (git_config_system() && !access(git_etc_gitconfig(), R_OK))
- ret += git_config_from_file(fn, git_etc_gitconfig());
+ ret += git_config_from_file(fn, git_etc_gitconfig(),
+ data);
home = getenv("HOME");
filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
if (!filename)
@@ -584,11 +585,11 @@ int git_config(config_fn_t fn)
if (git_config_global() && home) {
char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
if (!access(user_config, R_OK))
- ret = git_config_from_file(fn, user_config);
+ ret = git_config_from_file(fn, user_config, data);
free(user_config);
}
- ret += git_config_from_file(fn, filename);
+ ret += git_config_from_file(fn, filename, data);
free(repo_config);
return ret;
}
@@ -618,7 +619,7 @@ static int matches(const char* key, const char* value)
!regexec(store.value_regex, value, 0, NULL, 0)));
}
-static int store_aux(const char* key, const char* value)
+static int store_aux(const char* key, const char* value, void *cb)
{
const char *ep;
size_t section_len;
@@ -947,7 +948,7 @@ int git_config_set_multivar(const char* key, const char* value,
* As a side effect, we make sure to transform only a valid
* existing config file.
*/
- if (git_config_from_file(store_aux, config_filename)) {
+ if (git_config_from_file(store_aux, config_filename, NULL)) {
error("invalid config file %s", config_filename);
free(store.key);
if (store.value_regex != NULL) {