Skip to content

Commit 633e5ad

Browse files
tanayabhgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f44af51 commit 633e5ad

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

rerere.c

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,11 @@ static int do_plain_rerere(struct string_list *rr, int fd)
573573
return write_rr(rr, fd);
574574
}
575575

576-
static int git_rerere_config(const char *var, const char *value, void *cb)
576+
static void git_rerere_config(void)
577577
{
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);
585581
}
586582

587583
static int is_rerere_enabled(void)
@@ -606,7 +602,7 @@ int setup_rerere(struct string_list *merge_rr, int flags)
606602
{
607603
int fd;
608604

609-
git_config(git_rerere_config, NULL);
605+
git_rerere_config();
610606
if (!is_rerere_enabled())
611607
return -1;
612608

@@ -699,34 +695,19 @@ static void unlink_rr_item(const char *name)
699695
rmdir(git_path("rr-cache/%s", name));
700696
}
701697

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-
720698
void rerere_gc(struct string_list *rr)
721699
{
722700
struct string_list to_remove = STRING_LIST_INIT_DUP;
723701
DIR *dir;
724702
struct dirent *e;
725703
int i, cutoff;
726704
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;
728707

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);
730711
dir = opendir(git_path("rr-cache"));
731712
if (!dir)
732713
die_errno("unable to open rr-cache directory");
@@ -736,12 +717,12 @@ void rerere_gc(struct string_list *rr)
736717

737718
then = rerere_last_used_at(e->d_name);
738719
if (then) {
739-
cutoff = cf.cutoff_resolve;
720+
cutoff = cutoff_resolve;
740721
} else {
741722
then = rerere_created_at(e->d_name);
742723
if (!then)
743724
continue;
744-
cutoff = cf.cutoff_noresolve;
725+
cutoff = cutoff_noresolve;
745726
}
746727
if (then < now - cutoff * 86400)
747728
string_list_append(&to_remove, e->d_name);

0 commit comments

Comments
 (0)