Skip to content

Commit 5801d3b

Browse files
tanayabhgitster
authored andcommitted
builtin/gc.c: replace git_config() with git_config_get_*() family
Use `git_config_get_*()` family instead of `git_config()` to take advantage of the config-set API which provides a cleaner control flow. Signed-off-by: Tanay Abhra <[email protected]> Reviewed-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 633e5ad commit 5801d3b

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

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();

0 commit comments

Comments
 (0)