Commit 9bd81e42 authored by Junio C Hamano's avatar Junio C Hamano

Merge branch 'js/config-cb'

* js/config-cb:
  Provide git_config with a callback-data parameter

Conflicts:

	builtin-add.c
	builtin-cat-file.c
parents 450c5aed ef90d6d4
......@@ -2,7 +2,8 @@
static const char *alias_key;
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 (!v)
......@@ -17,6 +18,6 @@ char *alias_lookup(const char *alias)
{
alias_key = alias;
alias_val = NULL;
git_config(alias_lookup_cb);
git_config(alias_lookup_cb, NULL);
return alias_val;
}
......@@ -220,7 +220,7 @@ static void write_global_extended_header(const unsigned char *sha1)
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 (value && !strcmp(value, "user")) {
......@@ -231,7 +231,7 @@ static int git_tar_config(const char *var, const char *value)
}
return 0;
}
return git_default_config(var, value);
return git_default_config(var, value, cb);
}
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;
git_config(git_tar_config);
git_config(git_tar_config, NULL);
archive_time = args->time;
verbose = args->verbose;
......
......@@ -207,13 +207,13 @@ static struct option builtin_add_options[] = {
OPT_END(),
};
static int add_config(const char *var, const char *value)
static int add_config(const char *var, const char *value, void *cb)
{
if (!strcasecmp(var, "add.ignore-errors")) {
ignore_add_errors = git_config_bool(var, value);
return 0;
}
return git_default_config(var, value);
return git_default_config(var, value, cb);
}
int cmd_add(int argc, const char **argv, const char *prefix)
......@@ -231,7 +231,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (add_interactive)
exit(interactive_add(argc, argv, prefix));
git_config(add_config);
git_config(add_config, NULL);
newfd = hold_locked_index(&lock_file, 1);
......
......@@ -2985,11 +2985,11 @@ static int apply_patch(int fd, const char *filename, int inaccurate_eof)
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"))
return git_config_string(&apply_default_whitespace, var, value);
return git_default_config(var, value);
return git_default_config(var, value, cb);
}
......@@ -3005,7 +3005,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
prefix = setup_git_directory_gently(&is_not_gitdir);
prefix_length = prefix ? strlen(prefix) : 0;
git_config(git_apply_config);
git_config(git_apply_config, NULL);
if (apply_default_whitespace)
parse_whitespace_option(apply_default_whitespace);
......
......@@ -1993,7 +1993,7 @@ static void prepare_blame_range(struct scoreboard *sb,
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")) {
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);
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)
......@@ -2141,7 +2141,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
cmd_is_annotate = !strcmp(argv[0], "annotate");
git_config(git_blame_config);
git_config(git_blame_config, NULL);
save_commit_buffer = 0;
opt = 0;
......
......@@ -63,7 +63,7 @@ static int parse_branch_color_slot(const char *var, int ofs)
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")) {
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]);
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)
......@@ -461,7 +461,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT_END(),
};
git_config(git_branch_config);
git_config(git_branch_config, NULL);
if (branch_use_color == -1)
branch_use_color = git_use_color_default;
......
......@@ -222,7 +222,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
OPT_END()
};
git_config(git_default_config);
git_config(git_default_config, NULL);
if (argc != 3 && argc != 2)
usage_with_options(cat_file_usage, options);
......
......@@ -166,7 +166,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
int read_from_stdin = 0;
int prefix_length;
git_config(git_default_config);
git_config(git_default_config, NULL);
state.base_dir = "";
prefix_length = prefix ? strlen(prefix) : 0;
......
......@@ -516,7 +516,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
memset(&opts, 0, sizeof(opts));
memset(&new, 0, sizeof(new));
git_config(git_default_config);
git_config(git_default_config, NULL);
opts.track = git_branch_track;
......
......@@ -19,11 +19,11 @@ static const char *const builtin_clean_usage[] = {
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"))
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)
......@@ -50,7 +50,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
OPT_END()
};
git_config(git_clean_config);
git_config(git_clean_config, NULL);
if (force < 0)
force = 0;
else
......
......@@ -418,7 +418,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (option_reference)
setup_reference(git_dir);
git_config(git_default_config);
git_config(git_default_config, NULL);
if (option_bare) {
strcpy(branch_top, "refs/heads/");
......
......@@ -60,7 +60,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
struct strbuf buffer;
int encoding_is_utf8;
git_config(git_default_config);
git_config(git_default_config, NULL);
if (argc < 2)
usage(commit_tree_usage);
......
......@@ -806,7 +806,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
const char *index_file;
int commitable;
git_config(git_status_config);
git_config(git_status_config, NULL);
if (wt_status_use_color == -1)
wt_status_use_color = git_use_color_default;
......@@ -860,7 +860,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 (!v)
......@@ -869,7 +869,7 @@ int git_commit_config(const char *k, const char *v)
return 0;
}
return git_status_config(k, v);
return git_status_config(k, v, cb);
}
static const char commit_utf8_warn[] =
......@@ -897,7 +897,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
unsigned char commit_sha1[20];
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);
......
......@@ -18,7 +18,7 @@ static char key_delim = ' ';
static char term = '\n';
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_)
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;
}
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];
const char *vptr = value;
......@@ -121,14 +121,14 @@ static int get_value(const char* key_, const char* regex_)
}
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)
git_config_from_file(show_config, global);
git_config_from_file(show_config, local);
git_config_from_file(show_config, global, NULL);
git_config_from_file(show_config, local, NULL);
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)
git_config_from_file(show_config, system_wide);
git_config_from_file(show_config, system_wide, NULL);
free(key);
if (regexp) {
......@@ -182,7 +182,7 @@ static int get_color_found;
static const char *get_color_slot;
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 (!value)
......@@ -218,7 +218,7 @@ static int get_color(int argc, const char **argv)
get_color_found = 0;
parsed_color[0] = '\0';
git_config(git_get_color_config);
git_config(git_get_color_config, NULL);
if (!get_color_found && def_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 get_colorbool_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)) {
get_colorbool_found =
......@@ -265,7 +266,7 @@ static int get_colorbool(int argc, const char **argv)
get_colorbool_found = -1;
get_diff_color_found = -1;
get_color_slot = argv[0];
git_config(git_get_colorbool_config);
git_config(git_get_colorbool_config, NULL);
if (get_colorbool_found < 0) {
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")) {
if (argc != 2)
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,
strerror(errno));
return 0;
......
......@@ -21,7 +21,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
prefix = setup_git_directory_gently(&nongit);
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;
if (!setup_diff_no_index(&rev, argc, argv, nongit, prefix))
......
......@@ -17,7 +17,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
int result;
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;
argc = setup_revisions(argc, argv, &rev, NULL);
......
......@@ -68,7 +68,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
int read_stdin = 0;
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;
opt->abbrev = 0;
opt->diff = 1;
......
......@@ -234,7 +234,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
*/
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)
diff_use_color_default = git_use_color_default;
......
......@@ -372,7 +372,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
};
/* we handle encodings */
git_config(git_default_config);
git_config(git_default_config, NULL);
init_revisions(&revs, prefix);
argc = setup_revisions(argc, argv, &revs, NULL);
......
......@@ -635,7 +635,7 @@ static int remove_duplicates(int nr_heads, char **heads)
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) {
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 git_default_config(var, value);
return git_default_config(var, value, cb);
}
static struct lock_file lock;
......@@ -657,7 +657,7 @@ static void fetch_pack_setup(void)
static int did_setup;
if (did_setup)
return;
git_config(fetch_pack_config);
git_config(fetch_pack_config, NULL);
if (0 <= transfer_unpack_limit)
unpack_limit = transfer_unpack_limit;
else if (0 <= fetch_unpack_limit)
......
......@@ -10,7 +10,7 @@ static const char *fmt_merge_msg_usage =
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;
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];
const char *current_branch;
git_config(fmt_merge_msg_config);
git_config(fmt_merge_msg_config, NULL);
while (argc > 1) {
if (!strcmp(argv[1], "--log") || !strcmp(argv[1], "--summary"))
......
......@@ -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_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 (value && !strcmp(value, "notbare"))
......@@ -67,7 +67,7 @@ static int gc_config(const char *var, const char *value)
prune_expire = xstrdup(value);
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)
......@@ -226,7 +226,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
OPT_END()
};
git_config(gc_config);
git_config(gc_config, NULL);
if (pack_refs < 0)
pack_refs = !is_bare_repository();
......
......@@ -18,7 +18,7 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
int get_verbosely = 0;
int get_recover = 0;
git_config(git_default_config);
git_config(git_default_config, NULL);
while (arg < argc && argv[arg][0] == '-') {
if (argv[arg][1] == 't') {
......
......@@ -144,7 +144,7 @@ static void copy_templates(const char *template_dir)
strcpy(template_path + template_len, "config");
repository_format_version = 0;
git_config_from_file(check_repository_format_version,
template_path);
template_path, NULL);
template_path[template_len] = 0;
if (repository_format_version &&
......@@ -198,7 +198,7 @@ static int create_default_files(const char *template_path)
*/
copy_templates(template_path);
git_config(git_default_config);
git_config(git_default_config, NULL);
/*
* We would have created the above under user's umask -- under
......
......@@ -230,7 +230,7 @@ static int cmd_log_walk(struct rev_info *rev)
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"))
return git_config_string(&fmt_pretty, var, value);
......@@ -246,14 +246,14 @@ static int git_log_config(const char *var, const char *value)
default_show_root = git_config_bool(var, value);
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)
{
struct rev_info rev;
git_config(git_log_config);
git_config(git_log_config, NULL);
if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default;
......@@ -329,7 +329,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
struct object_array_entry *objects;
int i, count, ret = 0;
git_config(git_log_config);
git_config(git_log_config, NULL);
if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default;
......@@ -393,7 +393,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
{
struct rev_info rev;
git_config(git_log_config);
git_config(git_log_config, NULL);
if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default;
......@@ -426,7 +426,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
{
struct rev_info rev;
git_config(git_log_config);
git_config(git_log_config, NULL);
if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default;
......@@ -481,7 +481,7 @@ static void add_header(const char *value)
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 (!value)
......@@ -514,7 +514,7 @@ static int git_format_config(const char *var, const char *value)
return 0;
}
return git_log_config(var, value);
return git_log_config(var, value, cb);
}
......@@ -781,7 +781,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
char *add_signoff = NULL;
struct strbuf buf;
git_config(git_format_config);
git_config(git_format_config, NULL);
init_revisions(&rev, prefix);
rev.commit_format = CMIT_FMT_EMAIL;
rev.verbose_header = 1;
......
......@@ -437,7 +437,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
memset(&dir, 0, sizeof(dir));
if (prefix)
prefix_offset = strlen(prefix);
git_config(git_default_config);
git_config(git_default_config, NULL);
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
......
......@@ -122,7 +122,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
unsigned char sha1[20];
struct tree *tree;
git_config(git_default_config);
git_config(git_default_config, NULL);
ls_tree_prefix = prefix;
if (prefix && *prefix)
chomp_prefix = strlen(prefix);
......
......@@ -968,7 +968,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
/* NEEDSWORK: might want to do the optional .git/ directory
* discovery
*/
git_config(git_default_config);
git_config(git_default_config, NULL);
def_charset = (git_commit_encoding ? git_commit_encoding : "utf-8");
metainfo_charset = def_charset;
......
......@@ -28,7 +28,7 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
unsigned char rev1key[20], rev2key[20];
int show_all = 0;
git_config(git_default_config);
git_config(git_default_config, NULL);
while (1 < argc && argv[1][0] == '-') {
const char *arg = argv[1];
......
......@@ -1340,7 +1340,7 @@ static struct commit *get_ref(const char *ref)
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")) {
verbosity = git_config_int(var, value);
......@@ -1354,7 +1354,7 @@ static int merge_config(const char *var, const char *value)
merge_rename_limit = git_config_int(var, value);
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)
......@@ -1375,7 +1375,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
subtree_merge = 1;
}
git_config(merge_config);
git_config(merge_config, NULL);
if (getenv("GIT_MERGE_VERBOSITY"))
verbosity = strtol(getenv("GIT_MERGE_VERBOSITY"), NULL, 10);
......
......@@ -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 changed = {NULL, 0, 0, 0};
git_config(git_default_config);
git_config(git_default_config, NULL);
newfd = hold_locked_index(&lock_file, 1);
if (read_cache() < 0)
......
......@@ -195,7 +195,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
OPT_END(),
};
git_config(git_default_config);
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, opts, name_rev_usage, 0);
if (!!all + !!transform_stdin + !!argc > 1) {
error("Specify either a list, or --all, not both!");
......
......@@ -1760,7 +1760,7 @@ static void prepare_pack(int window, int depth)
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")) {
window = git_config_int(k, v);
......@@ -1813,7 +1813,7 @@ static int git_pack_config(const char *k, const char *v)
pack_size_limit_cfg = git_config_ulong(k, v);
return 0;
}
return git_default_config(k, v);
return git_default_config(k, v, cb);
}
static void read_object_list_from_stdin(void)
......@@ -2033,7 +2033,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
rp_av[1] = "--objects"; /* --thin will make it --objects-edge */
rp_ac = 2;
git_config(git_pack_config);
git_config(git_pack_config, NULL);
if (!pack_compression_seen && core_compression_seen)
pack_compression_level = core_compression_level;
......
......@@ -104,12 +104,10 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
opts.src_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);
git_config(git_default_config);
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
......
......@@ -329,7 +329,7 @@ static int collect_reflog(const char *ref, const unsigned char *sha1, int unused
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 (!value)
......@@ -343,7 +343,7 @@ static int reflog_expire_config(const char *var, const char *value)
default_reflog_expire_unreachable = approxidate(value);
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)
......@@ -352,7 +352,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
unsigned long now = time(NULL);
int i, status, do_all;