rerere.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
633e5ad326934401ef6cb128c3213386d0ebaf7a
1 file changed
+12
-31
rerere.c
+12
-31
@@ -573,15 +573,11 @@ static int do_plain_rerere(struct string_list *rr, int fd)
573
return write_rr(rr, fd);
574
}
575
576
-static int git_rerere_config(const char *var, const char *value, void *cb)
576
+static void git_rerere_config(void)
577
{
578
- if (!strcmp(var, "rerere.enabled"))
579
- rerere_enabled = git_config_bool(var, value);
580
- else if (!strcmp(var, "rerere.autoupdate"))
581
- rerere_autoupdate = git_config_bool(var, value);
582
- else
583
- return git_default_config(var, value, cb);
584
- return 0;
578
+ git_config_get_bool("rerere.enabled", &rerere_enabled);
579
+ git_config_get_bool("rerere.autoupdate", &rerere_autoupdate);
580
+ git_config(git_default_config, NULL);
581
}
582
583
static int is_rerere_enabled(void)
@@ -606,7 +602,7 @@ int setup_rerere(struct string_list *merge_rr, int flags)
602
{
603
int fd;
604
609
- git_config(git_rerere_config, NULL);
605
+ git_rerere_config();
606
if (!is_rerere_enabled())
607
return -1;
608
@@ -699,24 +695,6 @@ static void unlink_rr_item(const char *name)
695
rmdir(git_path("rr-cache/%s", name));
696
}
697
702
-struct rerere_gc_config_cb {
703
- int cutoff_noresolve;
704
- int cutoff_resolve;
705
-};
706
-
707
-static int git_rerere_gc_config(const char *var, const char *value, void *cb)
708
-{
709
- struct rerere_gc_config_cb *cf = cb;
710
-
711
- if (!strcmp(var, "gc.rerereresolved"))
712
- cf->cutoff_resolve = git_config_int(var, value);
713
- else if (!strcmp(var, "gc.rerereunresolved"))
714
- cf->cutoff_noresolve = git_config_int(var, value);
715
- else
716
- return git_default_config(var, value, cb);
717
- return 0;
718
-}
719
-
698
void rerere_gc(struct string_list *rr)
699
{
700
struct string_list to_remove = STRING_LIST_INIT_DUP;
@@ -724,9 +702,12 @@ void rerere_gc(struct string_list *rr)
702
struct dirent *e;
703
int i, cutoff;
704
time_t now = time(NULL), then;
727
- struct rerere_gc_config_cb cf = { 15, 60 };
705
+ int cutoff_noresolve = 15;
706
+ int cutoff_resolve = 60;
707
729
- git_config(git_rerere_gc_config, &cf);
708
+ git_config_get_int("gc.rerereresolved", &cutoff_resolve);
709
+ git_config_get_int("gc.rerereunresolved", &cutoff_noresolve);
710
+ git_config(git_default_config, NULL);
711
dir = opendir(git_path("rr-cache"));
712
if (!dir)
713
die_errno("unable to open rr-cache directory");
@@ -736,12 +717,12 @@ void rerere_gc(struct string_list *rr)
717
718
then = rerere_last_used_at(e->d_name);
719
if (then) {
739
- cutoff = cf.cutoff_resolve;
720
+ cutoff = cutoff_resolve;
721
} else {
722
then = rerere_created_at(e->d_name);
723
if (!then)
724
continue;
744
- cutoff = cf.cutoff_noresolve;
725
+ cutoff = cutoff_noresolve;
726
}
727
if (then < now - cutoff * 86400)
728
string_list_append(&to_remove, e->d_name);