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 <tanayabh@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tanay Abhra committed Aug 7, 2014 at 09:21 UTC 5801d3b41680a4499350754d8e00f5c8c09d790e
1 file changed +20 -31
builtin/gc.c
+20 -31
@@ -55,44 +55,33 @@ static void remove_pidfile_on_signal(int signo)
55 raise(signo);
56 }
57
58 -static int gc_config(const char *var, const char *value, void *cb)
58 +static void gc_config(void)
59 {
60 - if (!strcmp(var, "gc.packrefs")) {
60 + const char *value;
61 +
62 + if (!git_config_get_value("gc.packrefs", &value)) {
63 if (value && !strcmp(value, "notbare"))
64 pack_refs = -1;
65 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);
67 }
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")) {
77 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 + }
82 }
93 - return git_config_string(&prune_expire, var, value);
83 }
95 - return git_default_config(var, value, cb);
84 + git_config(git_default_config, NULL);
85 }
86
87 static int too_many_loose_objects(void)
@@ -301,7 +290,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
290 argv_array_pushl(&prune, "prune", "--expire", NULL );
291 argv_array_pushl(&rerere, "rerere", "gc", NULL);
292
304 - git_config(gc_config, NULL);
293 + gc_config();
294
295 if (pack_refs < 0)
296 pack_refs = !is_bare_repository();