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>
This commit is contained in:
Johannes Schindelin 2008-05-14 18:46:53 +01:00 committed by Junio C Hamano
parent 0bdf93cbf0
commit ef90d6d420
74 changed files with 176 additions and 173 deletions

View File

@ -2,7 +2,8 @@
static const char *alias_key; static const char *alias_key;
static char *alias_val; static char *alias_val;
static int alias_lookup_cb(const char *k, const char *v)
static int alias_lookup_cb(const char *k, const char *v, void *cb)
{ {
if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) { if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) {
if (!v) if (!v)
@ -17,6 +18,6 @@ char *alias_lookup(const char *alias)
{ {
alias_key = alias; alias_key = alias;
alias_val = NULL; alias_val = NULL;
git_config(alias_lookup_cb); git_config(alias_lookup_cb, NULL);
return alias_val; return alias_val;
} }

View File

@ -220,7 +220,7 @@ static void write_global_extended_header(const unsigned char *sha1)
strbuf_release(&ext_header); strbuf_release(&ext_header);
} }
static int git_tar_config(const char *var, const char *value) static int git_tar_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "tar.umask")) { if (!strcmp(var, "tar.umask")) {
if (value && !strcmp(value, "user")) { if (value && !strcmp(value, "user")) {
@ -231,7 +231,7 @@ static int git_tar_config(const char *var, const char *value)
} }
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static int write_tar_entry(const unsigned char *sha1, static int write_tar_entry(const unsigned char *sha1,
@ -268,7 +268,7 @@ int write_tar_archive(struct archiver_args *args)
{ {
int plen = args->base ? strlen(args->base) : 0; int plen = args->base ? strlen(args->base) : 0;
git_config(git_tar_config); git_config(git_tar_config, NULL);
archive_time = args->time; archive_time = args->time;
verbose = args->verbose; verbose = args->verbose;

View File

@ -203,7 +203,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (add_interactive) if (add_interactive)
exit(interactive_add(argc, argv, prefix)); exit(interactive_add(argc, argv, prefix));
git_config(git_default_config); git_config(git_default_config, NULL);
newfd = hold_locked_index(&lock_file, 1); newfd = hold_locked_index(&lock_file, 1);

View File

@ -2979,11 +2979,11 @@ static int apply_patch(int fd, const char *filename, int inaccurate_eof)
return 0; return 0;
} }
static int git_apply_config(const char *var, const char *value) static int git_apply_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "apply.whitespace")) if (!strcmp(var, "apply.whitespace"))
return git_config_string(&apply_default_whitespace, var, value); return git_config_string(&apply_default_whitespace, var, value);
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
@ -2999,7 +2999,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
prefix = setup_git_directory_gently(&is_not_gitdir); prefix = setup_git_directory_gently(&is_not_gitdir);
prefix_length = prefix ? strlen(prefix) : 0; prefix_length = prefix ? strlen(prefix) : 0;
git_config(git_apply_config); git_config(git_apply_config, NULL);
if (apply_default_whitespace) if (apply_default_whitespace)
parse_whitespace_option(apply_default_whitespace); parse_whitespace_option(apply_default_whitespace);

View File

@ -1993,7 +1993,7 @@ static void prepare_blame_range(struct scoreboard *sb,
usage(blame_usage); usage(blame_usage);
} }
static int git_blame_config(const char *var, const char *value) static int git_blame_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "blame.showroot")) { if (!strcmp(var, "blame.showroot")) {
show_root = git_config_bool(var, value); show_root = git_config_bool(var, value);
@ -2003,7 +2003,7 @@ static int git_blame_config(const char *var, const char *value)
blank_boundary = git_config_bool(var, value); blank_boundary = git_config_bool(var, value);
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static struct commit *fake_working_tree_commit(const char *path, const char *contents_from) static struct commit *fake_working_tree_commit(const char *path, const char *contents_from)
@ -2141,7 +2141,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
cmd_is_annotate = !strcmp(argv[0], "annotate"); cmd_is_annotate = !strcmp(argv[0], "annotate");
git_config(git_blame_config); git_config(git_blame_config, NULL);
save_commit_buffer = 0; save_commit_buffer = 0;
opt = 0; opt = 0;

View File

@ -63,7 +63,7 @@ static int parse_branch_color_slot(const char *var, int ofs)
die("bad config variable '%s'", var); die("bad config variable '%s'", var);
} }
static int git_branch_config(const char *var, const char *value) static int git_branch_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "color.branch")) { if (!strcmp(var, "color.branch")) {
branch_use_color = git_config_colorbool(var, value, -1); branch_use_color = git_config_colorbool(var, value, -1);
@ -76,7 +76,7 @@ static int git_branch_config(const char *var, const char *value)
color_parse(value, var, branch_colors[slot]); color_parse(value, var, branch_colors[slot]);
return 0; return 0;
} }
return git_color_default_config(var, value); return git_color_default_config(var, value, cb);
} }
static const char *branch_get_color(enum color_branch ix) static const char *branch_get_color(enum color_branch ix)
@ -461,7 +461,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT_END(), OPT_END(),
}; };
git_config(git_branch_config); git_config(git_branch_config, NULL);
if (branch_use_color == -1) if (branch_use_color == -1)
branch_use_color = git_use_color_default; branch_use_color = git_use_color_default;

View File

@ -85,7 +85,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
int opt; int opt;
const char *exp_type, *obj_name; const char *exp_type, *obj_name;
git_config(git_default_config); git_config(git_default_config, NULL);
if (argc != 3) if (argc != 3)
usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>"); usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
exp_type = argv[1]; exp_type = argv[1];

View File

@ -166,7 +166,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
int read_from_stdin = 0; int read_from_stdin = 0;
int prefix_length; int prefix_length;
git_config(git_default_config); git_config(git_default_config, NULL);
state.base_dir = ""; state.base_dir = "";
prefix_length = prefix ? strlen(prefix) : 0; prefix_length = prefix ? strlen(prefix) : 0;

View File

@ -514,7 +514,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
memset(&new, 0, sizeof(new)); memset(&new, 0, sizeof(new));
git_config(git_default_config); git_config(git_default_config, NULL);
opts.track = git_branch_track; opts.track = git_branch_track;

View File

@ -19,11 +19,11 @@ static const char *const builtin_clean_usage[] = {
NULL NULL
}; };
static int git_clean_config(const char *var, const char *value) static int git_clean_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "clean.requireforce")) if (!strcmp(var, "clean.requireforce"))
force = !git_config_bool(var, value); force = !git_config_bool(var, value);
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
int cmd_clean(int argc, const char **argv, const char *prefix) int cmd_clean(int argc, const char **argv, const char *prefix)
@ -50,7 +50,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
OPT_END() OPT_END()
}; };
git_config(git_clean_config); git_config(git_clean_config, NULL);
if (force < 0) if (force < 0)
force = 0; force = 0;
else else

View File

@ -60,7 +60,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
struct strbuf buffer; struct strbuf buffer;
int encoding_is_utf8; int encoding_is_utf8;
git_config(git_default_config); git_config(git_default_config, NULL);
if (argc < 2) if (argc < 2)
usage(commit_tree_usage); usage(commit_tree_usage);

View File

@ -773,7 +773,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
const char *index_file; const char *index_file;
int commitable; int commitable;
git_config(git_status_config); git_config(git_status_config, NULL);
if (wt_status_use_color == -1) if (wt_status_use_color == -1)
wt_status_use_color = git_use_color_default; wt_status_use_color = git_use_color_default;
@ -827,7 +827,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
} }
} }
int git_commit_config(const char *k, const char *v) int git_commit_config(const char *k, const char *v, void *cb)
{ {
if (!strcmp(k, "commit.template")) { if (!strcmp(k, "commit.template")) {
if (!v) if (!v)
@ -836,7 +836,7 @@ int git_commit_config(const char *k, const char *v)
return 0; return 0;
} }
return git_status_config(k, v); return git_status_config(k, v, cb);
} }
static const char commit_utf8_warn[] = static const char commit_utf8_warn[] =
@ -864,7 +864,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
unsigned char commit_sha1[20]; unsigned char commit_sha1[20];
struct ref_lock *ref_lock; struct ref_lock *ref_lock;
git_config(git_commit_config); git_config(git_commit_config, NULL);
argc = parse_and_validate_options(argc, argv, builtin_commit_usage); argc = parse_and_validate_options(argc, argv, builtin_commit_usage);

View File

@ -18,7 +18,7 @@ static char key_delim = ' ';
static char term = '\n'; static char term = '\n';
static enum { T_RAW, T_INT, T_BOOL, T_BOOL_OR_INT } type = T_RAW; static enum { T_RAW, T_INT, T_BOOL, T_BOOL_OR_INT } type = T_RAW;
static int show_all_config(const char *key_, const char *value_) static int show_all_config(const char *key_, const char *value_, void *cb)
{ {
if (value_) if (value_)
printf("%s%c%s%c", key_, delim, value_, term); printf("%s%c%s%c", key_, delim, value_, term);
@ -27,7 +27,7 @@ static int show_all_config(const char *key_, const char *value_)
return 0; return 0;
} }
static int show_config(const char* key_, const char* value_) static int show_config(const char* key_, const char* value_, void *cb)
{ {
char value[256]; char value[256];
const char *vptr = value; const char *vptr = value;
@ -121,14 +121,14 @@ static int get_value(const char* key_, const char* regex_)
} }
if (do_all && system_wide) if (do_all && system_wide)
git_config_from_file(show_config, system_wide); git_config_from_file(show_config, system_wide, NULL);
if (do_all && global) if (do_all && global)
git_config_from_file(show_config, global); git_config_from_file(show_config, global, NULL);
git_config_from_file(show_config, local); git_config_from_file(show_config, local, NULL);
if (!do_all && !seen && global) if (!do_all && !seen && global)
git_config_from_file(show_config, global); git_config_from_file(show_config, global, NULL);
if (!do_all && !seen && system_wide) if (!do_all && !seen && system_wide)
git_config_from_file(show_config, system_wide); git_config_from_file(show_config, system_wide, NULL);
free(key); free(key);
if (regexp) { if (regexp) {
@ -182,7 +182,7 @@ static int get_color_found;
static const char *get_color_slot; static const char *get_color_slot;
static char parsed_color[COLOR_MAXLEN]; static char parsed_color[COLOR_MAXLEN];
static int git_get_color_config(const char *var, const char *value) static int git_get_color_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, get_color_slot)) { if (!strcmp(var, get_color_slot)) {
if (!value) if (!value)
@ -218,7 +218,7 @@ static int get_color(int argc, const char **argv)
get_color_found = 0; get_color_found = 0;
parsed_color[0] = '\0'; parsed_color[0] = '\0';
git_config(git_get_color_config); git_config(git_get_color_config, NULL);
if (!get_color_found && def_color) if (!get_color_found && def_color)
color_parse(def_color, "command line", parsed_color); color_parse(def_color, "command line", parsed_color);
@ -230,7 +230,8 @@ static int get_color(int argc, const char **argv)
static int stdout_is_tty; static int stdout_is_tty;
static int get_colorbool_found; static int get_colorbool_found;
static int get_diff_color_found; static int get_diff_color_found;
static int git_get_colorbool_config(const char *var, const char *value) static int git_get_colorbool_config(const char *var, const char *value,
void *cb)
{ {
if (!strcmp(var, get_color_slot)) { if (!strcmp(var, get_color_slot)) {
get_colorbool_found = get_colorbool_found =
@ -265,7 +266,7 @@ static int get_colorbool(int argc, const char **argv)
get_colorbool_found = -1; get_colorbool_found = -1;
get_diff_color_found = -1; get_diff_color_found = -1;
get_color_slot = argv[0]; get_color_slot = argv[0];
git_config(git_get_colorbool_config); git_config(git_get_colorbool_config, NULL);
if (get_colorbool_found < 0) { if (get_colorbool_found < 0) {
if (!strcmp(get_color_slot, "color.diff")) if (!strcmp(get_color_slot, "color.diff"))
@ -298,7 +299,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l")) { else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l")) {
if (argc != 2) if (argc != 2)
usage(git_config_set_usage); usage(git_config_set_usage);
if (git_config(show_all_config) < 0 && file && errno) if (git_config(show_all_config, NULL) < 0 &&
file && errno)
die("unable to read config file %s: %s", file, die("unable to read config file %s: %s", file,
strerror(errno)); strerror(errno));
return 0; return 0;

View File

@ -21,7 +21,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
prefix = setup_git_directory_gently(&nongit); prefix = setup_git_directory_gently(&nongit);
init_revisions(&rev, prefix); init_revisions(&rev, prefix);
git_config(git_diff_basic_config); /* no "diff" UI options */ git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
rev.abbrev = 0; rev.abbrev = 0;
if (!setup_diff_no_index(&rev, argc, argv, nongit, prefix)) if (!setup_diff_no_index(&rev, argc, argv, nongit, prefix))

View File

@ -17,7 +17,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
int result; int result;
init_revisions(&rev, prefix); init_revisions(&rev, prefix);
git_config(git_diff_basic_config); /* no "diff" UI options */ git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
rev.abbrev = 0; rev.abbrev = 0;
argc = setup_revisions(argc, argv, &rev, NULL); argc = setup_revisions(argc, argv, &rev, NULL);

View File

@ -68,7 +68,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
int read_stdin = 0; int read_stdin = 0;
init_revisions(opt, prefix); init_revisions(opt, prefix);
git_config(git_diff_basic_config); /* no "diff" UI options */ git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
nr_sha1 = 0; nr_sha1 = 0;
opt->abbrev = 0; opt->abbrev = 0;
opt->diff = 1; opt->diff = 1;

View File

@ -234,7 +234,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
*/ */
prefix = setup_git_directory_gently(&nongit); prefix = setup_git_directory_gently(&nongit);
git_config(git_diff_ui_config); git_config(git_diff_ui_config, NULL);
if (diff_use_color_default == -1) if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default; diff_use_color_default = git_use_color_default;

View File

@ -372,7 +372,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
}; };
/* we handle encodings */ /* we handle encodings */
git_config(git_default_config); git_config(git_default_config, NULL);
init_revisions(&revs, prefix); init_revisions(&revs, prefix);
argc = setup_revisions(argc, argv, &revs, NULL); argc = setup_revisions(argc, argv, &revs, NULL);

View File

@ -635,7 +635,7 @@ static int remove_duplicates(int nr_heads, char **heads)
return dst; return dst;
} }
static int fetch_pack_config(const char *var, const char *value) static int fetch_pack_config(const char *var, const char *value, void *cb)
{ {
if (strcmp(var, "fetch.unpacklimit") == 0) { if (strcmp(var, "fetch.unpacklimit") == 0) {
fetch_unpack_limit = git_config_int(var, value); fetch_unpack_limit = git_config_int(var, value);
@ -647,7 +647,7 @@ static int fetch_pack_config(const char *var, const char *value)
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static struct lock_file lock; static struct lock_file lock;
@ -657,7 +657,7 @@ static void fetch_pack_setup(void)
static int did_setup; static int did_setup;
if (did_setup) if (did_setup)
return; return;
git_config(fetch_pack_config); git_config(fetch_pack_config, NULL);
if (0 <= transfer_unpack_limit) if (0 <= transfer_unpack_limit)
unpack_limit = transfer_unpack_limit; unpack_limit = transfer_unpack_limit;
else if (0 <= fetch_unpack_limit) else if (0 <= fetch_unpack_limit)

View File

@ -10,7 +10,7 @@ static const char *fmt_merge_msg_usage =
static int merge_summary; static int merge_summary;
static int fmt_merge_msg_config(const char *key, const char *value) static int fmt_merge_msg_config(const char *key, const char *value, void *cb)
{ {
static int found_merge_log = 0; static int found_merge_log = 0;
if (!strcmp("merge.log", key)) { if (!strcmp("merge.log", key)) {
@ -260,7 +260,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
unsigned char head_sha1[20]; unsigned char head_sha1[20];
const char *current_branch; const char *current_branch;
git_config(fmt_merge_msg_config); git_config(fmt_merge_msg_config, NULL);
while (argc > 1) { while (argc > 1) {
if (!strcmp(argv[1], "--log") || !strcmp(argv[1], "--summary")) if (!strcmp(argv[1], "--log") || !strcmp(argv[1], "--summary"))

View File

@ -35,7 +35,7 @@ static const char *argv_repack[MAX_ADD] = {"repack", "-d", "-l", NULL};
static const char *argv_prune[] = {"prune", "--expire", NULL, NULL}; static const char *argv_prune[] = {"prune", "--expire", NULL, NULL};
static const char *argv_rerere[] = {"rerere", "gc", NULL}; static const char *argv_rerere[] = {"rerere", "gc", NULL};
static int gc_config(const char *var, const char *value) static int gc_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "gc.packrefs")) { if (!strcmp(var, "gc.packrefs")) {
if (value && !strcmp(value, "notbare")) if (value && !strcmp(value, "notbare"))
@ -67,7 +67,7 @@ static int gc_config(const char *var, const char *value)
prune_expire = xstrdup(value); prune_expire = xstrdup(value);
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static void append_option(const char **cmd, const char *opt, int max_length) static void append_option(const char **cmd, const char *opt, int max_length)
@ -226,7 +226,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
OPT_END() OPT_END()
}; };
git_config(gc_config); git_config(gc_config, NULL);
if (pack_refs < 0) if (pack_refs < 0)
pack_refs = !is_bare_repository(); pack_refs = !is_bare_repository();

View File

@ -18,7 +18,7 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
int get_verbosely = 0; int get_verbosely = 0;
int get_recover = 0; int get_recover = 0;
git_config(git_default_config); git_config(git_default_config, NULL);
while (arg < argc && argv[arg][0] == '-') { while (arg < argc && argv[arg][0] == '-') {
if (argv[arg][1] == 't') { if (argv[arg][1] == 't') {

View File

@ -142,7 +142,7 @@ static void copy_templates(const char *git_dir, int len, const char *template_di
strcpy(template_path + template_len, "config"); strcpy(template_path + template_len, "config");
repository_format_version = 0; repository_format_version = 0;
git_config_from_file(check_repository_format_version, git_config_from_file(check_repository_format_version,
template_path); template_path, NULL);
template_path[template_len] = 0; template_path[template_len] = 0;
if (repository_format_version && if (repository_format_version &&
@ -197,7 +197,7 @@ static int create_default_files(const char *git_dir, const char *template_path)
path[len] = 0; path[len] = 0;
copy_templates(path, len, template_path); copy_templates(path, len, template_path);
git_config(git_default_config); git_config(git_default_config, NULL);
/* /*
* We would have created the above under user's umask -- under * We would have created the above under user's umask -- under

View File

@ -222,7 +222,7 @@ static int cmd_log_walk(struct rev_info *rev)
return 0; return 0;
} }
static int git_log_config(const char *var, const char *value) static int git_log_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "format.pretty")) if (!strcmp(var, "format.pretty"))
return git_config_string(&fmt_pretty, var, value); return git_config_string(&fmt_pretty, var, value);
@ -236,14 +236,14 @@ static int git_log_config(const char *var, const char *value)
default_show_root = git_config_bool(var, value); default_show_root = git_config_bool(var, value);
return 0; return 0;
} }
return git_diff_ui_config(var, value); return git_diff_ui_config(var, value, cb);
} }
int cmd_whatchanged(int argc, const char **argv, const char *prefix) int cmd_whatchanged(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
git_config(git_log_config); git_config(git_log_config, NULL);
if (diff_use_color_default == -1) if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default; diff_use_color_default = git_use_color_default;
@ -319,7 +319,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
struct object_array_entry *objects; struct object_array_entry *objects;
int i, count, ret = 0; int i, count, ret = 0;
git_config(git_log_config); git_config(git_log_config, NULL);
if (diff_use_color_default == -1) if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default; diff_use_color_default = git_use_color_default;
@ -383,7 +383,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
git_config(git_log_config); git_config(git_log_config, NULL);
if (diff_use_color_default == -1) if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default; diff_use_color_default = git_use_color_default;
@ -416,7 +416,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
git_config(git_log_config); git_config(git_log_config, NULL);
if (diff_use_color_default == -1) if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default; diff_use_color_default = git_use_color_default;
@ -471,7 +471,7 @@ static void add_header(const char *value)
extra_hdr[extra_hdr_nr++] = xstrndup(value, len); extra_hdr[extra_hdr_nr++] = xstrndup(value, len);
} }
static int git_format_config(const char *var, const char *value) static int git_format_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "format.headers")) { if (!strcmp(var, "format.headers")) {
if (!value) if (!value)
@ -497,7 +497,7 @@ static int git_format_config(const char *var, const char *value)
return 0; return 0;
} }
return git_log_config(var, value); return git_log_config(var, value, cb);
} }
@ -764,7 +764,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
char *add_signoff = NULL; char *add_signoff = NULL;
struct strbuf buf; struct strbuf buf;
git_config(git_format_config); git_config(git_format_config, NULL);
init_revisions(&rev, prefix); init_revisions(&rev, prefix);
rev.commit_format = CMIT_FMT_EMAIL; rev.commit_format = CMIT_FMT_EMAIL;
rev.verbose_header = 1; rev.verbose_header = 1;

View File

@ -437,7 +437,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
memset(&dir, 0, sizeof(dir)); memset(&dir, 0, sizeof(dir));
if (prefix) if (prefix)
prefix_offset = strlen(prefix); prefix_offset = strlen(prefix);
git_config(git_default_config); git_config(git_default_config, NULL);
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
const char *arg = argv[i]; const char *arg = argv[i];

View File

@ -122,7 +122,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
unsigned char sha1[20]; unsigned char sha1[20];
struct tree *tree; struct tree *tree;
git_config(git_default_config); git_config(git_default_config, NULL);
ls_tree_prefix = prefix; ls_tree_prefix = prefix;
if (prefix && *prefix) if (prefix && *prefix)
chomp_prefix = strlen(prefix); chomp_prefix = strlen(prefix);

View File

@ -962,7 +962,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
/* NEEDSWORK: might want to do the optional .git/ directory /* NEEDSWORK: might want to do the optional .git/ directory
* discovery * discovery
*/ */
git_config(git_default_config); git_config(git_default_config, NULL);
def_charset = (git_commit_encoding ? git_commit_encoding : "utf-8"); def_charset = (git_commit_encoding ? git_commit_encoding : "utf-8");
metainfo_charset = def_charset; metainfo_charset = def_charset;

View File

@ -28,7 +28,7 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
unsigned char rev1key[20], rev2key[20]; unsigned char rev1key[20], rev2key[20];
int show_all = 0; int show_all = 0;
git_config(git_default_config); git_config(git_default_config, NULL);
while (1 < argc && argv[1][0] == '-') { while (1 < argc && argv[1][0] == '-') {
const char *arg = argv[1]; const char *arg = argv[1];

View File

@ -1336,7 +1336,7 @@ static struct commit *get_ref(const char *ref)
return (struct commit *)object; return (struct commit *)object;
} }
static int merge_config(const char *var, const char *value) static int merge_config(const char *var, const char *value, void *cb)
{ {
if (!strcasecmp(var, "merge.verbosity")) { if (!strcasecmp(var, "merge.verbosity")) {
verbosity = git_config_int(var, value); verbosity = git_config_int(var, value);
@ -1346,7 +1346,7 @@ static int merge_config(const char *var, const char *value)
rename_limit = git_config_int(var, value); rename_limit = git_config_int(var, value);
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
int cmd_merge_recursive(int argc, const char **argv, const char *prefix) int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
@ -1367,7 +1367,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
subtree_merge = 1; subtree_merge = 1;
} }
git_config(merge_config); git_config(merge_config, NULL);
if (getenv("GIT_MERGE_VERBOSITY")) if (getenv("GIT_MERGE_VERBOSITY"))
verbosity = strtol(getenv("GIT_MERGE_VERBOSITY"), NULL, 10); verbosity = strtol(getenv("GIT_MERGE_VERBOSITY"), NULL, 10);

View File

@ -81,7 +81,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
struct path_list deleted = {NULL, 0, 0, 0}; struct path_list deleted = {NULL, 0, 0, 0};
struct path_list changed = {NULL, 0, 0, 0}; struct path_list changed = {NULL, 0, 0, 0};
git_config(git_default_config); git_config(git_default_config, NULL);
newfd = hold_locked_index(&lock_file, 1); newfd = hold_locked_index(&lock_file, 1);
if (read_cache() < 0) if (read_cache() < 0)

View File

@ -195,7 +195,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
OPT_END(), OPT_END(),
}; };
git_config(git_default_config); git_config(git_default_config, NULL);
argc = parse_options(argc, argv, opts, name_rev_usage, 0); argc = parse_options(argc, argv, opts, name_rev_usage, 0);
if (!!all + !!transform_stdin + !!argc > 1) { if (!!all + !!transform_stdin + !!argc > 1) {
error("Specify either a list, or --all, not both!"); error("Specify either a list, or --all, not both!");

View File

@ -1718,7 +1718,7 @@ static void prepare_pack(int window, int depth)
free(delta_list); free(delta_list);
} }
static int git_pack_config(const char *k, const char *v) static int git_pack_config(const char *k, const char *v, void *cb)
{ {
if(!strcmp(k, "pack.window")) { if(!strcmp(k, "pack.window")) {
window = git_config_int(k, v); window = git_config_int(k, v);
@ -1771,7 +1771,7 @@ static int git_pack_config(const char *k, const char *v)
pack_size_limit_cfg = git_config_ulong(k, v); pack_size_limit_cfg = git_config_ulong(k, v);
return 0; return 0;
} }
return git_default_config(k, v); return git_default_config(k, v, cb);
} }
static void read_object_list_from_stdin(void) static void read_object_list_from_stdin(void)
@ -1963,7 +1963,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
rp_av[1] = "--objects"; /* --thin will make it --objects-edge */ rp_av[1] = "--objects"; /* --thin will make it --objects-edge */
rp_ac = 2; rp_ac = 2;
git_config(git_pack_config); git_config(git_pack_config, NULL);
if (!pack_compression_seen && core_compression_seen) if (!pack_compression_seen && core_compression_seen)
pack_compression_level = core_compression_level; pack_compression_level = core_compression_level;

View File

@ -104,12 +104,10 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
opts.src_index = &the_index; opts.src_index = &the_index;
opts.dst_index = &the_index; opts.dst_index = &the_index;
git_config(git_default_config); git_config(git_default_config, NULL);
newfd = hold_locked_index(&lock_file, 1); newfd = hold_locked_index(&lock_file, 1);
git_config(git_default_config);
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
const char *arg = argv[i]; const char *arg = argv[i];

View File

@ -329,7 +329,7 @@ static int collect_reflog(const char *ref, const unsigned char *sha1, int unused
return 0; return 0;
} }
static int reflog_expire_config(const char *var, const char *value) static int reflog_expire_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "gc.reflogexpire")) { if (!strcmp(var, "gc.reflogexpire")) {
if (!value) if (!value)
@ -343,7 +343,7 @@ static int reflog_expire_config(const char *var, const char *value)
default_reflog_expire_unreachable = approxidate(value); default_reflog_expire_unreachable = approxidate(value);
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
@ -352,7 +352,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
unsigned long now = time(NULL); unsigned long now = time(NULL);
int i, status, do_all; int i, status, do_all;
git_config(reflog_expire_config); git_config(reflog_expire_config, NULL);
save_commit_buffer = 0; save_commit_buffer = 0;
do_all = status = 0; do_all = status = 0;

View File

@ -153,7 +153,7 @@ struct branch_info {
static struct path_list branch_list; static struct path_list branch_list;
static int config_read_branches(const char *key, const char *value) static int config_read_branches(const char *key, const char *value, void *cb)
{ {
if (!prefixcmp(key, "branch.")) { if (!prefixcmp(key, "branch.")) {
char *name; char *name;
@ -200,7 +200,7 @@ static void read_branches(void)
{ {
if (branch_list.nr) if (branch_list.nr)
return; return;
git_config(config_read_branches); git_config(config_read_branches, NULL);
sort_path_list(&branch_list); sort_path_list(&branch_list);
} }
@ -514,7 +514,7 @@ struct remote_group {
struct path_list *list; struct path_list *list;
} remote_group; } remote_group;
static int get_remote_group(const char *key, const char *value) static int get_remote_group(const char *key, const char *value, void *cb)
{ {
if (!prefixcmp(key, "remotes.") && if (!prefixcmp(key, "remotes.") &&
!strcmp(key + 8, remote_group.name)) { !strcmp(key + 8, remote_group.name)) {
@ -546,7 +546,7 @@ static int update(int argc, const char **argv)
remote_group.list = &list; remote_group.list = &list;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
remote_group.name = argv[i]; remote_group.name = argv[i];
result = git_config(get_remote_group); result = git_config(get_remote_group, NULL);
} }
if (!result && !list.nr && argc == 2 && !strcmp(argv[1], "default")) if (!result && !list.nr && argc == 2 && !strcmp(argv[1], "default"))

View File

@ -339,7 +339,7 @@ tail_optimization:
return write_rr(rr, fd); return write_rr(rr, fd);
} }
static int git_rerere_config(const char *var, const char *value) static int git_rerere_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "gc.rerereresolved")) if (!strcmp(var, "gc.rerereresolved"))
cutoff_resolve = git_config_int(var, value); cutoff_resolve = git_config_int(var, value);
@ -348,7 +348,7 @@ static int git_rerere_config(const char *var, const char *value)
else if (!strcmp(var, "rerere.enabled")) else if (!strcmp(var, "rerere.enabled"))
rerere_enabled = git_config_bool(var, value); rerere_enabled = git_config_bool(var, value);
else else
return git_default_config(var, value); return git_default_config(var, value, cb);
return 0; return 0;
} }
@ -376,7 +376,7 @@ static int setup_rerere(struct path_list *merge_rr)
{ {
int fd; int fd;
git_config(git_rerere_config); git_config(git_rerere_config, NULL);
if (!is_rerere_enabled()) if (!is_rerere_enabled())
return -1; return -1;

View File

@ -186,7 +186,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
OPT_END() OPT_END()
}; };
git_config(git_default_config); git_config(git_default_config, NULL);
argc = parse_options(argc, argv, options, git_reset_usage, argc = parse_options(argc, argv, options, git_reset_usage,
PARSE_OPT_KEEP_DASHDASH); PARSE_OPT_KEEP_DASHDASH);

View File

@ -546,7 +546,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
int bisect_find_all = 0; int bisect_find_all = 0;
int quiet = 0; int quiet = 0;
git_config(git_default_config); git_config(git_default_config, NULL);
init_revisions(&revs, prefix); init_revisions(&revs, prefix);
revs.abbrev = 0; revs.abbrev = 0;
revs.commit_format = CMIT_FMT_UNSPECIFIED; revs.commit_format = CMIT_FMT_UNSPECIFIED;

View File

@ -381,7 +381,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
return cmd_parseopt(argc - 1, argv + 1, prefix); return cmd_parseopt(argc - 1, argv + 1, prefix);
prefix = setup_git_directory(); prefix = setup_git_directory();
git_config(git_default_config); git_config(git_default_config, NULL);
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
const char *arg = argv[i]; const char *arg = argv[i];

View File

@ -269,7 +269,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
const char *message, *encoding; const char *message, *encoding;
const char *defmsg = xstrdup(git_path("MERGE_MSG")); const char *defmsg = xstrdup(git_path("MERGE_MSG"));
git_config(git_default_config); git_config(git_default_config, NULL);
me = action == REVERT ? "revert" : "cherry-pick"; me = action == REVERT ? "revert" : "cherry-pick";
setenv(GIT_REFLOG_ACTION, me, 0); setenv(GIT_REFLOG_ACTION, me, 0);
parse_args(argc, argv); parse_args(argc, argv);

View File

@ -144,7 +144,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
const char **pathspec; const char **pathspec;
char *seen; char *seen;
git_config(git_default_config); git_config(git_default_config, NULL);
newfd = hold_locked_index(&lock_file, 1); newfd = hold_locked_index(&lock_file, 1);

View File

@ -533,7 +533,7 @@ static void append_one_rev(const char *av)
die("bad sha1 reference %s", av); die("bad sha1 reference %s", av);
} }
static int git_show_branch_config(const char *var, const char *value) static int git_show_branch_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "showbranch.default")) { if (!strcmp(var, "showbranch.default")) {
if (!value) if (!value)
@ -547,7 +547,7 @@ static int git_show_branch_config(const char *var, const char *value)
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static int omit_in_dense(struct commit *commit, struct commit **rev, int n) static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
@ -611,7 +611,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
int reflog = 0; int reflog = 0;
const char *reflog_base = NULL; const char *reflog_base = NULL;
git_config(git_show_branch_config); git_config(git_show_branch_config, NULL);
/* If nothing is specified, try the default first */ /* If nothing is specified, try the default first */
if (ac == 1 && default_num) { if (ac == 1 && default_num) {

View File

@ -35,7 +35,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
OPT_END(), OPT_END(),
}; };
git_config(git_default_config); git_config(git_default_config, NULL);
argc = parse_options(argc, argv, options, git_symbolic_ref_usage, 0); argc = parse_options(argc, argv, options, git_symbolic_ref_usage, 0);
if (msg &&!*msg) if (msg &&!*msg)
die("Refusing to perform update with empty message"); die("Refusing to perform update with empty message");

View File

@ -256,7 +256,7 @@ static void set_signingkey(const char *value)
die("signing key value too long (%.10s...)", value); die("signing key value too long (%.10s...)", value);
} }
static int git_tag_config(const char *var, const char *value) static int git_tag_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "user.signingkey")) { if (!strcmp(var, "user.signingkey")) {
if (!value) if (!value)
@ -265,7 +265,7 @@ static int git_tag_config(const char *var, const char *value)
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static void write_tag_body(int fd, const unsigned char *sha1) static void write_tag_body(int fd, const unsigned char *sha1)
@ -408,7 +408,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
OPT_END() OPT_END()
}; };
git_config(git_tag_config); git_config(git_tag_config, NULL);
argc = parse_options(argc, argv, options, git_tag_usage, 0); argc = parse_options(argc, argv, options, git_tag_usage, 0);

View File

@ -493,7 +493,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
int i; int i;
unsigned char sha1[20]; unsigned char sha1[20];
git_config(git_default_config); git_config(git_default_config, NULL);
quiet = !isatty(2); quiet = !isatty(2);

View File

@ -567,7 +567,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
int lock_error = 0; int lock_error = 0;
struct lock_file *lock_file; struct lock_file *lock_file;
git_config(git_default_config); git_config(git_default_config, NULL);
/* We can't free this memory, it becomes part of a linked list parsed atexit() */ /* We can't free this memory, it becomes part of a linked list parsed atexit() */
lock_file = xcalloc(1, sizeof(struct lock_file)); lock_file = xcalloc(1, sizeof(struct lock_file));

View File

@ -22,7 +22,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
OPT_END(), OPT_END(),
}; };
git_config(git_default_config); git_config(git_default_config, NULL);
argc = parse_options(argc, argv, options, git_update_ref_usage, 0); argc = parse_options(argc, argv, options, git_update_ref_usage, 0);
if (msg && !*msg) if (msg && !*msg)
die("Refusing to perform update with empty message."); die("Refusing to perform update with empty message.");

View File

@ -55,7 +55,7 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
int no_more_options = 0; int no_more_options = 0;
int nothing_done = 1; int nothing_done = 1;
git_config(git_default_config); git_config(git_default_config, NULL);
while (1 < argc) { while (1 < argc) {
if (!no_more_options && argv[1][0] == '-') { if (!no_more_options && argv[1][0] == '-') {
if (!strcmp("-v", argv[1])) if (!strcmp("-v", argv[1]))

View File

@ -90,7 +90,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
{ {
int i = 1, verbose = 0, had_error = 0; int i = 1, verbose = 0, had_error = 0;
git_config(git_default_config); git_config(git_default_config, NULL);
if (argc == 1) if (argc == 1)
usage(builtin_verify_tag_usage); usage(builtin_verify_tag_usage);

View File

@ -18,7 +18,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
unsigned char sha1[20]; unsigned char sha1[20];
const char *me = "git-write-tree"; const char *me = "git-write-tree";
git_config(git_default_config); git_config(git_default_config, NULL);
while (1 < argc) { while (1 < argc) {
const char *arg = argv[1]; const char *arg = argv[1];
if (!strcmp(arg, "--missing-ok")) if (!strcmp(arg, "--missing-ok"))

10
cache.h
View File

@ -711,10 +711,10 @@ extern int matches_pack_name(struct packed_git *p, const char *name);
/* Dumb servers support */ /* Dumb servers support */
extern int update_server_info(int); extern int update_server_info(int);
typedef int (*config_fn_t)(const char *, const char *); typedef int (*config_fn_t)(const char *, const char *, void *);
extern int git_default_config(const char *, const char *); extern int git_default_config(const char *, const char *, void *);
extern int git_config_from_file(config_fn_t fn, const char *); extern int git_config_from_file(config_fn_t fn, const char *, void *);
extern int git_config(config_fn_t fn); extern int git_config(config_fn_t fn, void *);
extern int git_parse_long(const char *, long *); extern int git_parse_long(const char *, long *);
extern int git_parse_ulong(const char *, unsigned long *); extern int git_parse_ulong(const char *, unsigned long *);
extern int git_config_int(const char *, const char *); extern int git_config_int(const char *, const char *);
@ -726,7 +726,7 @@ extern int git_config_set(const char *, const char *);
extern int git_config_set_multivar(const char *, const char *, const char *, int); extern int git_config_set_multivar(const char *, const char *, const char *, int);
extern int git_config_rename_section(const char *, const char *); extern int git_config_rename_section(const char *, const char *);
extern const char *git_etc_gitconfig(void); extern const char *git_etc_gitconfig(void);
extern int check_repository_format_version(const char *var, const char *value); extern int check_repository_format_version(const char *var, const char *value, void *cb);
extern int git_env_bool(const char *, int); extern int git_env_bool(const char *, int);
extern int git_config_system(void); extern int git_config_system(void);
extern int git_config_global(void); extern int git_config_global(void);

View File

@ -145,14 +145,14 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
return 0; return 0;
} }
int git_color_default_config(const char *var, const char *value) int git_color_default_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "color.ui")) { if (!strcmp(var, "color.ui")) {
git_use_color_default = git_config_colorbool(var, value, -1); git_use_color_default = git_config_colorbool(var, value, -1);
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static int color_vfprintf(FILE *fp, const char *color, const char *fmt, static int color_vfprintf(FILE *fp, const char *color, const char *fmt,

View File

@ -13,7 +13,7 @@ extern int git_use_color_default;
/* /*
* Use this instead of git_default_config if you need the value of color.ui. * Use this instead of git_default_config if you need the value of color.ui.
*/ */
int git_color_default_config(const char *var, const char *value); int git_color_default_config(const char *var, const char *value, void *cb);
int git_config_colorbool(const char *var, const char *value, int stdout_is_tty); int git_config_colorbool(const char *var, const char *value, int stdout_is_tty);
void color_parse(const char *var, const char *value, char *dst); void color_parse(const char *var, const char *value, char *dst);

View File

@ -111,7 +111,7 @@ static inline int iskeychar(int c)
return isalnum(c) || 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; int c;
char *value; char *value;
@ -139,7 +139,7 @@ static int get_value(config_fn_t fn, char *name, unsigned int len)
if (!value) if (!value)
return -1; return -1;
} }
return fn(name, value); return fn(name, value, data);
} }
static int get_extended_base_var(char *name, int baselen, int c) 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 comment = 0;
int baselen = 0; int baselen = 0;
@ -228,7 +228,7 @@ static int git_parse_file(config_fn_t fn)
if (!isalpha(c)) if (!isalpha(c))
break; break;
var[baselen] = tolower(c); var[baselen] = tolower(c);
if (get_value(fn, var, baselen+1) < 0) if (get_value(fn, data, var, baselen+1) < 0)
break; break;
} }
die("bad config file line %d in %s", config_linenr, config_file_name); 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; 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 */ /* This needs a better name */
if (!strcmp(var, "core.filemode")) { if (!strcmp(var, "core.filemode")) {
@ -512,7 +512,7 @@ int git_default_config(const char *var, const char *value)
return 0; 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; int ret;
FILE *f = fopen(filename, "r"); 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_file_name = filename;
config_linenr = 1; config_linenr = 1;
config_file_eof = 0; config_file_eof = 0;
ret = git_parse_file(fn); ret = git_parse_file(fn, data);
fclose(f); fclose(f);
config_file_name = NULL; config_file_name = NULL;
} }
@ -561,7 +561,7 @@ int git_config_global(void)
return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0); 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; int ret = 0;
char *repo_config = NULL; char *repo_config = NULL;
@ -574,7 +574,8 @@ int git_config(config_fn_t fn)
filename = getenv(CONFIG_ENVIRONMENT); filename = getenv(CONFIG_ENVIRONMENT);
if (!filename) { if (!filename) {
if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) 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"); home = getenv("HOME");
filename = getenv(CONFIG_LOCAL_ENVIRONMENT); filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
if (!filename) if (!filename)
@ -584,11 +585,11 @@ int git_config(config_fn_t fn)
if (git_config_global() && home) { if (git_config_global() && home) {
char *user_config = xstrdup(mkpath("%s/.gitconfig", home)); char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
if (!access(user_config, R_OK)) 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); free(user_config);
} }
ret += git_config_from_file(fn, filename); ret += git_config_from_file(fn, filename, data);
free(repo_config); free(repo_config);
return ret; return ret;
} }
@ -618,7 +619,7 @@ static int matches(const char* key, const char* value)
!regexec(store.value_regex, value, 0, NULL, 0))); !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; const char *ep;
size_t section_len; 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 * As a side effect, we make sure to transform only a valid
* existing config file. * 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); error("invalid config file %s", config_filename);
free(store.key); free(store.key);
if (store.value_regex != NULL) { if (store.value_regex != NULL) {

View File

@ -360,7 +360,8 @@ static char *git_proxy_command;
static const char *rhost_name; static const char *rhost_name;
static int rhost_len; static int rhost_len;
static int git_proxy_command_options(const char *var, const char *value) static int git_proxy_command_options(const char *var, const char *value,
void *cb)
{ {
if (!strcmp(var, "core.gitproxy")) { if (!strcmp(var, "core.gitproxy")) {
const char *for_pos; const char *for_pos;
@ -404,7 +405,7 @@ static int git_proxy_command_options(const char *var, const char *value)
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static int git_use_proxy(const char *host) static int git_use_proxy(const char *host)
@ -412,7 +413,7 @@ static int git_use_proxy(const char *host)
rhost_name = host; rhost_name = host;
rhost_len = strlen(host); rhost_len = strlen(host);
git_proxy_command = getenv("GIT_PROXY_COMMAND"); git_proxy_command = getenv("GIT_PROXY_COMMAND");
git_config(git_proxy_command_options); git_config(git_proxy_command_options, NULL);
rhost_name = NULL; rhost_name = NULL;
return (git_proxy_command && *git_proxy_command); return (git_proxy_command && *git_proxy_command);
} }

View File

@ -323,7 +323,7 @@ static struct convert_driver {
char *clean; char *clean;
} *user_convert, **user_convert_tail; } *user_convert, **user_convert_tail;
static int read_convert_config(const char *var, const char *value) static int read_convert_config(const char *var, const char *value, void *cb)
{ {
const char *ep, *name; const char *ep, *name;
int namelen; int namelen;
@ -385,7 +385,7 @@ static void setup_convert_check(struct git_attr_check *check)
attr_ident = git_attr("ident", 5); attr_ident = git_attr("ident", 5);
attr_filter = git_attr("filter", 6); attr_filter = git_attr("filter", 6);
user_convert_tail = &user_convert; user_convert_tail = &user_convert;
git_config(read_convert_config); git_config(read_convert_config, NULL);
} }
check[0].attr = attr_crlf; check[0].attr = attr_crlf;
check[1].attr = attr_ident; check[1].attr = attr_ident;

View File

@ -306,7 +306,7 @@ struct daemon_service {
static struct daemon_service *service_looking_at; static struct daemon_service *service_looking_at;
static int service_enabled; static int service_enabled;
static int git_daemon_config(const char *var, const char *value) static int git_daemon_config(const char *var, const char *value, void *cb)
{ {
if (!prefixcmp(var, "daemon.") && if (!prefixcmp(var, "daemon.") &&
!strcmp(var + 7, service_looking_at->config_name)) { !strcmp(var + 7, service_looking_at->config_name)) {
@ -356,7 +356,7 @@ static int run_service(struct interp *itable, struct daemon_service *service)
if (service->overridable) { if (service->overridable) {
service_looking_at = service; service_looking_at = service;
service_enabled = -1; service_enabled = -1;
git_config(git_daemon_config); git_config(git_daemon_config, NULL);
if (0 <= service_enabled) if (0 <= service_enabled)
enabled = service_enabled; enabled = service_enabled;
} }

8
diff.c
View File

@ -129,7 +129,7 @@ static int parse_funcname_pattern(const char *var, const char *ep, const char *v
* never be affected by the setting of diff.renames * never be affected by the setting of diff.renames
* the user happens to have in the configuration file. * the user happens to have in the configuration file.
*/ */
int git_diff_ui_config(const char *var, const char *value) int git_diff_ui_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "diff.renamelimit")) { if (!strcmp(var, "diff.renamelimit")) {
diff_rename_limit_default = git_config_int(var, value); diff_rename_limit_default = git_config_int(var, value);
@ -166,10 +166,10 @@ int git_diff_ui_config(const char *var, const char *value)
return parse_lldiff_command(var, ep, value); return parse_lldiff_command(var, ep, value);
} }
return git_diff_basic_config(var, value); return git_diff_basic_config(var, value, cb);
} }
int git_diff_basic_config(const char *var, const char *value) int git_diff_basic_config(const char *var, const char *value, void *cb)
{ {
if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) { if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) {
int slot = parse_diff_color_slot(var, 11); int slot = parse_diff_color_slot(var, 11);
@ -190,7 +190,7 @@ int git_diff_basic_config(const char *var, const char *value)
} }
} }
return git_color_default_config(var, value); return git_color_default_config(var, value, cb);
} }
static char *quote_two(const char *one, const char *two) static char *quote_two(const char *one, const char *two)

4
diff.h
View File

@ -180,8 +180,8 @@ extern void diff_unmerge(struct diff_options *,
#define DIFF_SETUP_USE_CACHE 2 #define DIFF_SETUP_USE_CACHE 2
#define DIFF_SETUP_USE_SIZE_CACHE 4 #define DIFF_SETUP_USE_SIZE_CACHE 4
extern int git_diff_basic_config(const char *var, const char *value); extern int git_diff_basic_config(const char *var, const char *value, void *cb);
extern int git_diff_ui_config(const char *var, const char *value); extern int git_diff_ui_config(const char *var, const char *value, void *cb);
extern int diff_use_color_default; extern int diff_use_color_default;
extern void diff_setup(struct diff_options *); extern void diff_setup(struct diff_options *);
extern int diff_opt_parse(struct diff_options *, const char **, int); extern int diff_opt_parse(struct diff_options *, const char **, int);

View File

@ -2352,7 +2352,7 @@ static void import_marks(const char *input_file)
fclose(f); fclose(f);
} }
static int git_pack_config(const char *k, const char *v) static int git_pack_config(const char *k, const char *v, void *cb)
{ {
if (!strcmp(k, "pack.depth")) { if (!strcmp(k, "pack.depth")) {
max_depth = git_config_int(k, v); max_depth = git_config_int(k, v);
@ -2370,7 +2370,7 @@ static int git_pack_config(const char *k, const char *v)
pack_compression_seen = 1; pack_compression_seen = 1;
return 0; return 0;
} }
return git_default_config(k, v); return git_default_config(k, v, cb);
} }
static const char fast_import_usage[] = static const char fast_import_usage[] =
@ -2381,7 +2381,7 @@ int main(int argc, const char **argv)
unsigned int i, show_stats = 1; unsigned int i, show_stats = 1;
setup_git_directory(); setup_git_directory();
git_config(git_pack_config); git_config(git_pack_config, NULL);
if (!pack_compression_seen && core_compression_seen) if (!pack_compression_seen && core_compression_seen)
pack_compression_level = core_compression_level; pack_compression_level = core_compression_level;

View File

@ -43,7 +43,7 @@ int main(int argc, char **argv)
int no_more_flags = 0; int no_more_flags = 0;
int hashstdin = 0; int hashstdin = 0;
git_config(git_default_config); git_config(git_default_config, NULL);
for (i = 1 ; i < argc; i++) { for (i = 1 ; i < argc; i++) {
if (!no_more_flags && argv[i][0] == '-') { if (!no_more_flags && argv[i][0] == '-') {

6
help.c
View File

@ -252,7 +252,7 @@ static int add_man_viewer_info(const char *var, const char *value)
return 0; return 0;
} }
static int git_help_config(const char *var, const char *value) static int git_help_config(const char *var, const char *value, void *cb)
{ {
if (!strcmp(var, "help.format")) { if (!strcmp(var, "help.format")) {
if (!value) if (!value)
@ -269,7 +269,7 @@ static int git_help_config(const char *var, const char *value)
if (!prefixcmp(var, "man.")) if (!prefixcmp(var, "man."))
return add_man_viewer_info(var, value); return add_man_viewer_info(var, value);
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
/* most GUI terminals set COLUMNS (although some don't export it) */ /* most GUI terminals set COLUMNS (although some don't export it) */
@ -641,7 +641,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
const char *alias; const char *alias;
setup_git_directory_gently(&nongit); setup_git_directory_gently(&nongit);
git_config(git_help_config); git_config(git_help_config, NULL);
argc = parse_options(argc, argv, builtin_help_options, argc = parse_options(argc, argv, builtin_help_options,
builtin_help_usage, 0); builtin_help_usage, 0);

6
http.c
View File

@ -90,7 +90,7 @@ static void process_curl_messages(void)
} }
#endif #endif
static int http_options(const char *var, const char *value) static int http_options(const char *var, const char *value, void *cb)
{ {
if (!strcmp("http.sslverify", var)) { if (!strcmp("http.sslverify", var)) {
if (curl_ssl_verify == -1) { if (curl_ssl_verify == -1) {
@ -169,7 +169,7 @@ static int http_options(const char *var, const char *value)
} }
/* Fall back on the default ones */ /* Fall back on the default ones */
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static CURL* get_curl_handle(void) static CURL* get_curl_handle(void)
@ -263,7 +263,7 @@ void http_init(struct remote *remote)
if (low_speed_time != NULL) if (low_speed_time != NULL)
curl_low_speed_time = strtol(low_speed_time, NULL, 10); curl_low_speed_time = strtol(low_speed_time, NULL, 10);
git_config(http_options); git_config(http_options, NULL);
if (curl_ssl_verify == -1) if (curl_ssl_verify == -1)
curl_ssl_verify = 1; curl_ssl_verify = 1;

View File

@ -1247,7 +1247,7 @@ static imap_server_conf_t server =
static char *imap_folder; static char *imap_folder;
static int static int
git_imap_config(const char *key, const char *val) git_imap_config(const char *key, const char *val, void *cb)
{ {
char imap_key[] = "imap."; char imap_key[] = "imap.";
@ -1296,7 +1296,7 @@ main(int argc, char **argv)
/* init the random number generator */ /* init the random number generator */
arc4_init(); arc4_init();
git_config( git_imap_config ); git_config(git_imap_config, NULL);
if (!imap_folder) { if (!imap_folder) {
fprintf( stderr, "no imap store specified\n" ); fprintf( stderr, "no imap store specified\n" );

View File

@ -765,7 +765,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
} }
} }
static int git_index_pack_config(const char *k, const char *v) static int git_index_pack_config(const char *k, const char *v, void *cb)
{ {
if (!strcmp(k, "pack.indexversion")) { if (!strcmp(k, "pack.indexversion")) {
pack_idx_default_version = git_config_int(k, v); pack_idx_default_version = git_config_int(k, v);
@ -773,7 +773,7 @@ static int git_index_pack_config(const char *k, const char *v)
die("bad pack.indexversion=%d", pack_idx_default_version); die("bad pack.indexversion=%d", pack_idx_default_version);
return 0; return 0;
} }
return git_default_config(k, v); return git_default_config(k, v, cb);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
@ -786,7 +786,7 @@ int main(int argc, char **argv)
struct pack_idx_entry **idx_objects; struct pack_idx_entry **idx_objects;
unsigned char sha1[20]; unsigned char sha1[20];
git_config(git_index_pack_config); git_config(git_index_pack_config, NULL);
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
char *arg = argv[i]; char *arg = argv[i];

View File

@ -225,7 +225,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
static struct ll_merge_driver *ll_user_merge, **ll_user_merge_tail; static struct ll_merge_driver *ll_user_merge, **ll_user_merge_tail;
static const char *default_ll_merge; static const char *default_ll_merge;
static int read_merge_config(const char *var, const char *value) static int read_merge_config(const char *var, const char *value, void *cb)
{ {
struct ll_merge_driver *fn; struct ll_merge_driver *fn;
const char *ep, *name; const char *ep, *name;
@ -309,7 +309,7 @@ static void initialize_ll_merge(void)
if (ll_user_merge_tail) if (ll_user_merge_tail)
return; return;
ll_user_merge_tail = &ll_user_merge; ll_user_merge_tail = &ll_user_merge;
git_config(read_merge_config); git_config(read_merge_config, NULL);
} }
static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr) static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr)

View File

@ -33,7 +33,7 @@ void setup_pager(void)
return; return;
if (!pager) { if (!pager) {
if (!pager_program) if (!pager_program)
git_config(git_default_config); git_config(git_default_config, NULL);
pager = pager_program; pager = pager_program;
} }
if (!pager) if (!pager)

View File

@ -19,7 +19,7 @@ static int report_status;
static char capabilities[] = " report-status delete-refs "; static char capabilities[] = " report-status delete-refs ";
static int capabilities_sent; static int capabilities_sent;
static int receive_pack_config(const char *var, const char *value) static int receive_pack_config(const char *var, const char *value, void *cb)
{ {
if (strcmp(var, "receive.denynonfastforwards") == 0) { if (strcmp(var, "receive.denynonfastforwards") == 0) {
deny_non_fast_forwards = git_config_bool(var, value); deny_non_fast_forwards = git_config_bool(var, value);
@ -41,7 +41,7 @@ static int receive_pack_config(const char *var, const char *value)
return 0; return 0;
} }
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
static int show_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) static int show_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
@ -489,7 +489,7 @@ int main(int argc, char **argv)
if (is_repository_shallow()) if (is_repository_shallow())
die("attempt to push into a shallow repository"); die("attempt to push into a shallow repository");
git_config(receive_pack_config); git_config(receive_pack_config, NULL);
if (0 <= transfer_unpack_limit) if (0 <= transfer_unpack_limit)
unpack_limit = transfer_unpack_limit; unpack_limit = transfer_unpack_limit;

View File

@ -288,7 +288,7 @@ static void read_branches_file(struct remote *remote)
remote->fetch_tags = 1; /* always auto-follow */ remote->fetch_tags = 1; /* always auto-follow */
} }
static int handle_config(const char *key, const char *value) static int handle_config(const char *key, const char *value, void *cb)
{ {
const char *name; const char *name;
const char *subkey; const char *subkey;
@ -410,7 +410,7 @@ static void read_config(void)
current_branch = current_branch =
make_branch(head_ref + strlen("refs/heads/"), 0); make_branch(head_ref + strlen("refs/heads/"), 0);
} }
git_config(handle_config); git_config(handle_config, NULL);
alias_all_urls(); alias_all_urls();
} }

View File

@ -300,7 +300,7 @@ void setup_work_tree(void)
static int check_repository_format_gently(int *nongit_ok) static int check_repository_format_gently(int *nongit_ok)
{ {
git_config(check_repository_format_version); git_config(check_repository_format_version, NULL);
if (GIT_REPO_VERSION < repository_format_version) { if (GIT_REPO_VERSION < repository_format_version) {
if (!nongit_ok) if (!nongit_ok)
die ("Expected git repo version <= %d, found %d", die ("Expected git repo version <= %d, found %d",
@ -524,7 +524,7 @@ int git_config_perm(const char *var, const char *value)
return i & 0666; return i & 0666;
} }
int check_repository_format_version(const char *var, const char *value) int check_repository_format_version(const char *var, const char *value, void *cb)
{ {
if (strcmp(var, "core.repositoryformatversion") == 0) if (strcmp(var, "core.repositoryformatversion") == 0)
repository_format_version = git_config_int(var, value); repository_format_version = git_config_int(var, value);

View File

@ -31,7 +31,7 @@ int main(int argc, char **argv)
die("Not a valid object name %s", argv[1]); die("Not a valid object name %s", argv[1]);
setup_git_directory(); setup_git_directory();
git_config(git_default_config); git_config(git_default_config, NULL);
puts(create_temp_file(sha1)); puts(create_temp_file(sha1));
return 0; return 0;

8
var.c
View File

@ -39,13 +39,13 @@ static const char *read_var(const char *var)
return val; return val;
} }
static int show_config(const char *var, const char *value) static int show_config(const char *var, const char *value, void *cb)
{ {
if (value) if (value)
printf("%s=%s\n", var, value); printf("%s=%s\n", var, value);
else else
printf("%s\n", var); printf("%s\n", var);
return git_default_config(var, value); return git_default_config(var, value, cb);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
@ -60,11 +60,11 @@ int main(int argc, char **argv)
val = NULL; val = NULL;
if (strcmp(argv[1], "-l") == 0) { if (strcmp(argv[1], "-l") == 0) {
git_config(show_config); git_config(show_config, NULL);
list_vars(); list_vars();
return 0; return 0;
} }
git_config(git_default_config); git_config(git_default_config, NULL);
val = read_var(argv[1]); val = read_var(argv[1]);
if (!val) if (!val)
usage(var_usage); usage(var_usage);

View File

@ -362,7 +362,7 @@ void wt_status_print(struct wt_status *s)
} }
} }
int git_status_config(const char *k, const char *v) int git_status_config(const char *k, const char *v, void *cb)
{ {
if (!strcmp(k, "status.submodulesummary")) { if (!strcmp(k, "status.submodulesummary")) {
int is_bool; int is_bool;
@ -386,5 +386,5 @@ int git_status_config(const char *k, const char *v)
wt_status_relative_paths = git_config_bool(k, v); wt_status_relative_paths = git_config_bool(k, v);
return 0; return 0;
} }
return git_color_default_config(k, v); return git_color_default_config(k, v, cb);
} }

View File

@ -27,7 +27,7 @@ struct wt_status {
const char *prefix; const char *prefix;
}; };
int git_status_config(const char *var, const char *value); int git_status_config(const char *var, const char *value, void *cb);
extern int wt_status_use_color; extern int wt_status_use_color;
extern int wt_status_relative_paths; extern int wt_status_relative_paths;
void wt_status_prepare(struct wt_status *s); void wt_status_prepare(struct wt_status *s);