git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tanay Abhra <tanayabh@gmail.com>
To: git@vger.kernel.org
Cc: Tanay Abhra <tanayabh@gmail.com>,
	Ramkumar Ramachandra <artagnon@gmail.com>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: [PATCH 06/11] rerere.c: replace `git_config()` with `git_config_get_*()` family
Date: Mon,  4 Aug 2014 11:33:44 -0700	[thread overview]
Message-ID: <1407177229-30081-7-git-send-email-tanayabh@gmail.com> (raw)
In-Reply-To: <1407177229-30081-1-git-send-email-tanayabh@gmail.com>

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>
---
 rerere.c | 43 ++++++++++++-------------------------------
 1 file changed, 12 insertions(+), 31 deletions(-)

diff --git a/rerere.c b/rerere.c
index d84b495..20b18ad 100644
--- a/rerere.c
+++ b/rerere.c
@@ -573,15 +573,11 @@ static int do_plain_rerere(struct string_list *rr, int 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"))
-		rerere_enabled = git_config_bool(var, value);
-	else if (!strcmp(var, "rerere.autoupdate"))
-		rerere_autoupdate = git_config_bool(var, value);
-	else
-		return git_default_config(var, value, cb);
-	return 0;
+	git_config_get_bool("rerere.enabled", &rerere_enabled);
+	git_config_get_bool("rerere.autoupdate", &rerere_autoupdate);
+	git_config(git_default_config, NULL);
 }
 
 static int is_rerere_enabled(void)
@@ -606,7 +602,7 @@ int setup_rerere(struct string_list *merge_rr, int flags)
 {
 	int fd;
 
-	git_config(git_rerere_config, NULL);
+	git_rerere_config();
 	if (!is_rerere_enabled())
 		return -1;
 
@@ -699,24 +695,6 @@ static void unlink_rr_item(const char *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)
 {
 	struct string_list to_remove = STRING_LIST_INIT_DUP;
@@ -724,9 +702,12 @@ void rerere_gc(struct string_list *rr)
 	struct dirent *e;
 	int i, cutoff;
 	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"));
 	if (!dir)
 		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);
 		if (then) {
-			cutoff = cf.cutoff_resolve;
+			cutoff = cutoff_resolve;
 		} else {
 			then = rerere_created_at(e->d_name);
 			if (!then)
 				continue;
-			cutoff = cf.cutoff_noresolve;
+			cutoff = cutoff_noresolve;
 		}
 		if (then < now - cutoff * 86400)
 			string_list_append(&to_remove, e->d_name);
-- 
1.9.0.GIT

  parent reply	other threads:[~2014-08-04 18:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-04 18:33 [PATCH 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
2014-08-04 18:33 ` [PATCH 01/11] daemon.c: replace `git_config()` with `git_config_get_bool()` family Tanay Abhra
2014-08-04 20:23   ` Matthieu Moy
2014-08-04 18:33 ` [PATCH 02/11] http-backend.c: " Tanay Abhra
2014-08-04 18:59   ` Eric Sunshine
2014-08-06 15:18     ` Tanay Abhra
2014-08-06 15:44       ` Matthieu Moy
2014-08-06 20:04         ` Eric Sunshine
2014-08-04 18:33 ` [PATCH 03/11] read-cache.c: replace `git_config()` with `git_config_get_*()` family Tanay Abhra
2014-08-04 18:33 ` [PATCH 04/11] archive.c: replace `git_config()` with `git_config_get_bool()` family Tanay Abhra
2014-08-04 18:33 ` [PATCH 05/11] fetchpack.c: replace `git_config()` with `git_config_get_*()` family Tanay Abhra
2014-08-04 18:33 ` Tanay Abhra [this message]
2014-08-04 18:33 ` [PATCH 07/11] builtin/gc.c: " Tanay Abhra
2014-08-04 20:41   ` Matthieu Moy
2014-08-04 18:33 ` [PATCH 08/11] pager.c: replace `git_config()` with `git_config_get_value()` Tanay Abhra
2014-08-04 20:36   ` Matthieu Moy
2014-08-04 18:33 ` [PATCH 09/11] imap-send.c: replace `git_config()` with `git_config_get_*()` family Tanay Abhra
2014-08-04 18:33 ` [PATCH 10/11] alias.c: replace `git_config()` with `git_config_get_string()` Tanay Abhra
2014-08-04 18:33 ` [PATCH 11/11] branch.c: replace `git_config()` with `git_config_get_string() Tanay Abhra
2014-08-04 20:42 ` [PATCH 00/11] git_config callers rewritten with the new config-set API Matthieu Moy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1407177229-30081-7-git-send-email-tanayabh@gmail.com \
    --to=tanayabh@gmail.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).