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>
This commit is contained in:
parent
f44af51d13
commit
633e5ad326
43
rerere.c
43
rerere.c
@ -573,15 +573,11 @@ static int do_plain_rerere(struct string_list *rr, int fd)
|
|||||||
return write_rr(rr, fd);
|
return write_rr(rr, fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int git_rerere_config(const char *var, const char *value, void *cb)
|
static void git_rerere_config(void)
|
||||||
{
|
{
|
||||||
if (!strcmp(var, "rerere.enabled"))
|
git_config_get_bool("rerere.enabled", &rerere_enabled);
|
||||||
rerere_enabled = git_config_bool(var, value);
|
git_config_get_bool("rerere.autoupdate", &rerere_autoupdate);
|
||||||
else if (!strcmp(var, "rerere.autoupdate"))
|
git_config(git_default_config, NULL);
|
||||||
rerere_autoupdate = git_config_bool(var, value);
|
|
||||||
else
|
|
||||||
return git_default_config(var, value, cb);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_rerere_enabled(void)
|
static int is_rerere_enabled(void)
|
||||||
@ -606,7 +602,7 @@ int setup_rerere(struct string_list *merge_rr, int flags)
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
git_config(git_rerere_config, NULL);
|
git_rerere_config();
|
||||||
if (!is_rerere_enabled())
|
if (!is_rerere_enabled())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -699,24 +695,6 @@ static void unlink_rr_item(const char *name)
|
|||||||
rmdir(git_path("rr-cache/%s", name));
|
rmdir(git_path("rr-cache/%s", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct rerere_gc_config_cb {
|
|
||||||
int cutoff_noresolve;
|
|
||||||
int cutoff_resolve;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int git_rerere_gc_config(const char *var, const char *value, void *cb)
|
|
||||||
{
|
|
||||||
struct rerere_gc_config_cb *cf = cb;
|
|
||||||
|
|
||||||
if (!strcmp(var, "gc.rerereresolved"))
|
|
||||||
cf->cutoff_resolve = git_config_int(var, value);
|
|
||||||
else if (!strcmp(var, "gc.rerereunresolved"))
|
|
||||||
cf->cutoff_noresolve = git_config_int(var, value);
|
|
||||||
else
|
|
||||||
return git_default_config(var, value, cb);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void rerere_gc(struct string_list *rr)
|
void rerere_gc(struct string_list *rr)
|
||||||
{
|
{
|
||||||
struct string_list to_remove = STRING_LIST_INIT_DUP;
|
struct string_list to_remove = STRING_LIST_INIT_DUP;
|
||||||
@ -724,9 +702,12 @@ void rerere_gc(struct string_list *rr)
|
|||||||
struct dirent *e;
|
struct dirent *e;
|
||||||
int i, cutoff;
|
int i, cutoff;
|
||||||
time_t now = time(NULL), then;
|
time_t now = time(NULL), then;
|
||||||
struct rerere_gc_config_cb cf = { 15, 60 };
|
int cutoff_noresolve = 15;
|
||||||
|
int cutoff_resolve = 60;
|
||||||
|
|
||||||
git_config(git_rerere_gc_config, &cf);
|
git_config_get_int("gc.rerereresolved", &cutoff_resolve);
|
||||||
|
git_config_get_int("gc.rerereunresolved", &cutoff_noresolve);
|
||||||
|
git_config(git_default_config, NULL);
|
||||||
dir = opendir(git_path("rr-cache"));
|
dir = opendir(git_path("rr-cache"));
|
||||||
if (!dir)
|
if (!dir)
|
||||||
die_errno("unable to open rr-cache directory");
|
die_errno("unable to open rr-cache directory");
|
||||||
@ -736,12 +717,12 @@ void rerere_gc(struct string_list *rr)
|
|||||||
|
|
||||||
then = rerere_last_used_at(e->d_name);
|
then = rerere_last_used_at(e->d_name);
|
||||||
if (then) {
|
if (then) {
|
||||||
cutoff = cf.cutoff_resolve;
|
cutoff = cutoff_resolve;
|
||||||
} else {
|
} else {
|
||||||
then = rerere_created_at(e->d_name);
|
then = rerere_created_at(e->d_name);
|
||||||
if (!then)
|
if (!then)
|
||||||
continue;
|
continue;
|
||||||
cutoff = cf.cutoff_noresolve;
|
cutoff = cutoff_noresolve;
|
||||||
}
|
}
|
||||||
if (then < now - cutoff * 86400)
|
if (then < now - cutoff * 86400)
|
||||||
string_list_append(&to_remove, e->d_name);
|
string_list_append(&to_remove, e->d_name);
|
||||||
|
Loading…
Reference in New Issue
Block a user