Skip to content

Commit 554913d

Browse files
committed
Merge branch 'ta/config-set-2'
Update git_config() users with callback functions for a very narrow scope with calls to config-set API that lets us query a single variable. * ta/config-set-2: builtin/apply.c: replace `git_config()` with `git_config_get_string_const()` merge-recursive.c: replace `git_config()` with `git_config_get_int()` ll-merge.c: refactor `read_merge_config()` to use `git_config_string()` fast-import.c: replace `git_config()` with `git_config_get_*()` family branch.c: replace `git_config()` with `git_config_get_string() alias.c: replace `git_config()` with `git_config_get_string()` imap-send.c: replace `git_config()` with `git_config_get_*()` family pager.c: replace `git_config()` with `git_config_get_value()` builtin/gc.c: replace `git_config()` with `git_config_get_*()` family rerere.c: replace `git_config()` with `git_config_get_*()` family fetchpack.c: replace `git_config()` with `git_config_get_*()` family archive.c: replace `git_config()` with `git_config_get_bool()` family read-cache.c: replace `git_config()` with `git_config_get_*()` family http-backend.c: replace `git_config()` with `git_config_get_bool()` family daemon.c: replace `git_config()` with `git_config_get_bool()` family
2 parents 7f346e9 + b35b10d commit 554913d

File tree

15 files changed

+152
-313
lines changed

15 files changed

+152
-313
lines changed

alias.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
#include "cache.h"
22

3-
static const char *alias_key;
4-
static char *alias_val;
5-
6-
static int alias_lookup_cb(const char *k, const char *v, void *cb)
7-
{
8-
const char *name;
9-
if (skip_prefix(k, "alias.", &name) && !strcmp(name, alias_key)) {
10-
if (!v)
11-
return config_error_nonbool(k);
12-
alias_val = xstrdup(v);
13-
return 0;
14-
}
15-
return 0;
16-
}
17-
183
char *alias_lookup(const char *alias)
194
{
20-
alias_key = alias;
21-
alias_val = NULL;
22-
git_config(alias_lookup_cb, NULL);
23-
return alias_val;
5+
char *v = NULL;
6+
struct strbuf key = STRBUF_INIT;
7+
strbuf_addf(&key, "alias.%s", alias);
8+
git_config_get_string(key.buf, &v);
9+
strbuf_release(&key);
10+
return v;
2411
}
2512

2613
#define SPLIT_CMDLINE_BAD_ENDING 1

archive.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,6 @@ static int parse_archive_args(int argc, const char **argv,
402402
return argc;
403403
}
404404

405-
static int git_default_archive_config(const char *var, const char *value,
406-
void *cb)
407-
{
408-
if (!strcmp(var, "uploadarchive.allowunreachable"))
409-
remote_allow_unreachable = git_config_bool(var, value);
410-
return git_default_config(var, value, cb);
411-
}
412-
413405
int write_archive(int argc, const char **argv, const char *prefix,
414406
int setup_prefix, const char *name_hint, int remote)
415407
{
@@ -420,7 +412,9 @@ int write_archive(int argc, const char **argv, const char *prefix,
420412
if (setup_prefix && prefix == NULL)
421413
prefix = setup_git_directory_gently(&nongit);
422414

423-
git_config(git_default_archive_config, NULL);
415+
git_config_get_bool("uploadarchive.allowunreachable", &remote_allow_unreachable);
416+
git_config(git_default_config, NULL);
417+
424418
init_tar_archiver();
425419
init_zip_archiver();
426420

branch.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,30 +140,17 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
140140
return 0;
141141
}
142142

143-
struct branch_desc_cb {
144-
const char *config_name;
145-
const char *value;
146-
};
147-
148-
static int read_branch_desc_cb(const char *var, const char *value, void *cb)
149-
{
150-
struct branch_desc_cb *desc = cb;
151-
if (strcmp(desc->config_name, var))
152-
return 0;
153-
free((char *)desc->value);
154-
return git_config_string(&desc->value, var, value);
155-
}
156-
157143
int read_branch_desc(struct strbuf *buf, const char *branch_name)
158144
{
159-
struct branch_desc_cb cb;
145+
char *v = NULL;
160146
struct strbuf name = STRBUF_INIT;
161147
strbuf_addf(&name, "branch.%s.description", branch_name);
162-
cb.config_name = name.buf;
163-
cb.value = NULL;
164-
git_config(read_branch_desc_cb, &cb);
165-
if (cb.value)
166-
strbuf_addstr(buf, cb.value);
148+
if (git_config_get_string(name.buf, &v)) {
149+
strbuf_release(&name);
150+
return -1;
151+
}
152+
strbuf_addstr(buf, v);
153+
free(v);
167154
strbuf_release(&name);
168155
return 0;
169156
}

builtin/apply.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4274,13 +4274,11 @@ static int apply_patch(int fd, const char *filename, int options)
42744274
return 0;
42754275
}
42764276

4277-
static int git_apply_config(const char *var, const char *value, void *cb)
4277+
static void git_apply_config(void)
42784278
{
4279-
if (!strcmp(var, "apply.whitespace"))
4280-
return git_config_string(&apply_default_whitespace, var, value);
4281-
else if (!strcmp(var, "apply.ignorewhitespace"))
4282-
return git_config_string(&apply_default_ignorewhitespace, var, value);
4283-
return git_default_config(var, value, cb);
4279+
git_config_get_string_const("apply.whitespace", &apply_default_whitespace);
4280+
git_config_get_string_const("apply.ignorewhitespace", &apply_default_ignorewhitespace);
4281+
git_config(git_default_config, NULL);
42844282
}
42854283

42864284
static int option_parse_exclude(const struct option *opt,
@@ -4428,7 +4426,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
44284426

44294427
prefix = prefix_;
44304428
prefix_length = prefix ? strlen(prefix) : 0;
4431-
git_config(git_apply_config, NULL);
4429+
git_apply_config();
44324430
if (apply_default_whitespace)
44334431
parse_whitespace_option(apply_default_whitespace);
44344432
if (apply_default_ignorewhitespace)

builtin/gc.c

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,44 +55,33 @@ static void remove_pidfile_on_signal(int signo)
5555
raise(signo);
5656
}
5757

58-
static int gc_config(const char *var, const char *value, void *cb)
58+
static void gc_config(void)
5959
{
60-
if (!strcmp(var, "gc.packrefs")) {
60+
const char *value;
61+
62+
if (!git_config_get_value("gc.packrefs", &value)) {
6163
if (value && !strcmp(value, "notbare"))
6264
pack_refs = -1;
6365
else
64-
pack_refs = git_config_bool(var, value);
65-
return 0;
66-
}
67-
if (!strcmp(var, "gc.aggressivewindow")) {
68-
aggressive_window = git_config_int(var, value);
69-
return 0;
70-
}
71-
if (!strcmp(var, "gc.aggressivedepth")) {
72-
aggressive_depth = git_config_int(var, value);
73-
return 0;
74-
}
75-
if (!strcmp(var, "gc.auto")) {
76-
gc_auto_threshold = git_config_int(var, value);
77-
return 0;
78-
}
79-
if (!strcmp(var, "gc.autopacklimit")) {
80-
gc_auto_pack_limit = git_config_int(var, value);
81-
return 0;
66+
pack_refs = git_config_bool("gc.packrefs", value);
8267
}
83-
if (!strcmp(var, "gc.autodetach")) {
84-
detach_auto = git_config_bool(var, value);
85-
return 0;
86-
}
87-
if (!strcmp(var, "gc.pruneexpire")) {
88-
if (value && strcmp(value, "now")) {
68+
69+
git_config_get_int("gc.aggressivewindow", &aggressive_window);
70+
git_config_get_int("gc.aggressivedepth", &aggressive_depth);
71+
git_config_get_int("gc.auto", &gc_auto_threshold);
72+
git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
73+
git_config_get_bool("gc.autodetach", &detach_auto);
74+
75+
if (!git_config_get_string_const("gc.pruneexpire", &prune_expire)) {
76+
if (strcmp(prune_expire, "now")) {
8977
unsigned long now = approxidate("now");
90-
if (approxidate(value) >= now)
91-
return error(_("Invalid %s: '%s'"), var, value);
78+
if (approxidate(prune_expire) >= now) {
79+
git_die_config("gc.pruneexpire", _("Invalid gc.pruneexpire: '%s'"),
80+
prune_expire);
81+
}
9282
}
93-
return git_config_string(&prune_expire, var, value);
9483
}
95-
return git_default_config(var, value, cb);
84+
git_config(git_default_config, NULL);
9685
}
9786

9887
static int too_many_loose_objects(void)
@@ -301,7 +290,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
301290
argv_array_pushl(&prune, "prune", "--expire", NULL );
302291
argv_array_pushl(&rerere, "rerere", "gc", NULL);
303292

304-
git_config(gc_config, NULL);
293+
gc_config();
305294

306295
if (pack_refs < 0)
307296
pack_refs = !is_bare_repository();

daemon.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,6 @@ struct daemon_service {
230230
int overridable;
231231
};
232232

233-
static struct daemon_service *service_looking_at;
234-
static int service_enabled;
235-
236-
static int git_daemon_config(const char *var, const char *value, void *cb)
237-
{
238-
const char *service;
239-
240-
if (skip_prefix(var, "daemon.", &service) &&
241-
!strcmp(service, service_looking_at->config_name)) {
242-
service_enabled = git_config_bool(var, value);
243-
return 0;
244-
}
245-
246-
/* we are not interested in parsing any other configuration here */
247-
return 0;
248-
}
249-
250233
static int daemon_error(const char *dir, const char *msg)
251234
{
252235
if (!informative_errors)
@@ -324,6 +307,7 @@ static int run_service(const char *dir, struct daemon_service *service)
324307
{
325308
const char *path;
326309
int enabled = service->enabled;
310+
struct strbuf var = STRBUF_INIT;
327311

328312
loginfo("Request %s for '%s'", service->name, dir);
329313

@@ -354,11 +338,9 @@ static int run_service(const char *dir, struct daemon_service *service)
354338
}
355339

356340
if (service->overridable) {
357-
service_looking_at = service;
358-
service_enabled = -1;
359-
git_config(git_daemon_config, NULL);
360-
if (0 <= service_enabled)
361-
enabled = service_enabled;
341+
strbuf_addf(&var, "daemon.%s", service->config_name);
342+
git_config_get_bool(var.buf, &enabled);
343+
strbuf_release(&var);
362344
}
363345
if (!enabled) {
364346
logerror("'%s': service not enabled for '%s'",

fast-import.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,36 +3274,34 @@ static void parse_option(const char *option)
32743274
die("This version of fast-import does not support option: %s", option);
32753275
}
32763276

3277-
static int git_pack_config(const char *k, const char *v, void *cb)
3277+
static void git_pack_config(void)
32783278
{
3279-
if (!strcmp(k, "pack.depth")) {
3280-
max_depth = git_config_int(k, v);
3279+
int indexversion_value;
3280+
unsigned long packsizelimit_value;
3281+
3282+
if (!git_config_get_ulong("pack.depth", &max_depth)) {
32813283
if (max_depth > MAX_DEPTH)
32823284
max_depth = MAX_DEPTH;
3283-
return 0;
32843285
}
3285-
if (!strcmp(k, "pack.compression")) {
3286-
int level = git_config_int(k, v);
3287-
if (level == -1)
3288-
level = Z_DEFAULT_COMPRESSION;
3289-
else if (level < 0 || level > Z_BEST_COMPRESSION)
3290-
die("bad pack compression level %d", level);
3291-
pack_compression_level = level;
3286+
if (!git_config_get_int("pack.compression", &pack_compression_level)) {
3287+
if (pack_compression_level == -1)
3288+
pack_compression_level = Z_DEFAULT_COMPRESSION;
3289+
else if (pack_compression_level < 0 ||
3290+
pack_compression_level > Z_BEST_COMPRESSION)
3291+
git_die_config("pack.compression",
3292+
"bad pack compression level %d", pack_compression_level);
32923293
pack_compression_seen = 1;
3293-
return 0;
32943294
}
3295-
if (!strcmp(k, "pack.indexversion")) {
3296-
pack_idx_opts.version = git_config_int(k, v);
3295+
if (!git_config_get_int("pack.indexversion", &indexversion_value)) {
3296+
pack_idx_opts.version = indexversion_value;
32973297
if (pack_idx_opts.version > 2)
3298-
die("bad pack.indexversion=%"PRIu32,
3299-
pack_idx_opts.version);
3300-
return 0;
3298+
git_die_config("pack.indexversion",
3299+
"bad pack.indexversion=%"PRIu32, pack_idx_opts.version);
33013300
}
3302-
if (!strcmp(k, "pack.packsizelimit")) {
3303-
max_packsize = git_config_ulong(k, v);
3304-
return 0;
3305-
}
3306-
return git_default_config(k, v, cb);
3301+
if (!git_config_get_ulong("pack.packsizelimit", &packsizelimit_value))
3302+
max_packsize = packsizelimit_value;
3303+
3304+
git_config(git_default_config, NULL);
33073305
}
33083306

33093307
static const char fast_import_usage[] =
@@ -3356,7 +3354,7 @@ int main(int argc, char **argv)
33563354

33573355
setup_git_directory();
33583356
reset_pack_idx_option(&pack_idx_opts);
3359-
git_config(git_pack_config, NULL);
3357+
git_pack_config();
33603358
if (!pack_compression_seen && core_compression_seen)
33613359
pack_compression_level = core_compression_level;
33623360

fetch-pack.c

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -869,42 +869,23 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
869869
return ref;
870870
}
871871

872-
static int fetch_pack_config(const char *var, const char *value, void *cb)
872+
static void fetch_pack_config(void)
873873
{
874-
if (strcmp(var, "fetch.unpacklimit") == 0) {
875-
fetch_unpack_limit = git_config_int(var, value);
876-
return 0;
877-
}
878-
879-
if (strcmp(var, "transfer.unpacklimit") == 0) {
880-
transfer_unpack_limit = git_config_int(var, value);
881-
return 0;
882-
}
883-
884-
if (strcmp(var, "repack.usedeltabaseoffset") == 0) {
885-
prefer_ofs_delta = git_config_bool(var, value);
886-
return 0;
887-
}
888-
889-
if (!strcmp(var, "fetch.fsckobjects")) {
890-
fetch_fsck_objects = git_config_bool(var, value);
891-
return 0;
892-
}
893-
894-
if (!strcmp(var, "transfer.fsckobjects")) {
895-
transfer_fsck_objects = git_config_bool(var, value);
896-
return 0;
897-
}
874+
git_config_get_int("fetch.unpacklimit", &fetch_unpack_limit);
875+
git_config_get_int("transfer.unpacklimit", &transfer_unpack_limit);
876+
git_config_get_bool("repack.usedeltabaseoffset", &prefer_ofs_delta);
877+
git_config_get_bool("fetch.fsckobjects", &fetch_fsck_objects);
878+
git_config_get_bool("transfer.fsckobjects", &transfer_fsck_objects);
898879

899-
return git_default_config(var, value, cb);
880+
git_config(git_default_config, NULL);
900881
}
901882

902883
static void fetch_pack_setup(void)
903884
{
904885
static int did_setup;
905886
if (did_setup)
906887
return;
907-
git_config(fetch_pack_config, NULL);
888+
fetch_pack_config();
908889
if (0 <= transfer_unpack_limit)
909890
unpack_limit = transfer_unpack_limit;
910891
else if (0 <= fetch_unpack_limit)

0 commit comments

Comments
 (0)