]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: add git_config_get_expiry() from gc.c
authorChristian Couder <christian.couder@gmail.com>
Mon, 27 Feb 2017 18:00:13 +0000 (19:00 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Mar 2017 21:34:54 +0000 (13:34 -0800)
This function will be used in a following commit to get the expiration
time of the shared index files from the config, and it is generic
enough to be put in "config.c".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c
cache.h
config.c

index 069950d0b417f5eb97cd756ae32df7a2fb13abce..1e40d45aa2420a96acc3fb39b6dd00ac5e0cf370 100644 (file)
@@ -62,17 +62,6 @@ static void report_pack_garbage(unsigned seen_bits, const char *path)
                string_list_append(&pack_garbage, path);
 }
 
-static void git_config_date_string(const char *key, const char **output)
-{
-       if (git_config_get_string_const(key, output))
-               return;
-       if (strcmp(*output, "now")) {
-               unsigned long now = approxidate("now");
-               if (approxidate(*output) >= now)
-                       git_die_config(key, _("Invalid %s: '%s'"), key, *output);
-       }
-}
-
 static void process_log_file(void)
 {
        struct stat st;
@@ -111,8 +100,8 @@ static void gc_config(void)
        git_config_get_int("gc.auto", &gc_auto_threshold);
        git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
        git_config_get_bool("gc.autodetach", &detach_auto);
-       git_config_date_string("gc.pruneexpire", &prune_expire);
-       git_config_date_string("gc.worktreepruneexpire", &prune_worktrees_expire);
+       git_config_get_expiry("gc.pruneexpire", &prune_expire);
+       git_config_get_expiry("gc.worktreepruneexpire", &prune_worktrees_expire);
        git_config(git_default_config, NULL);
 }
 
diff --git a/cache.h b/cache.h
index f442f28189ef61da0ed15c5002f480391b22bf4f..279415afbd3bb9a6b965b85060a222030a7ee39c 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1827,6 +1827,9 @@ extern int git_config_get_untracked_cache(void);
 extern int git_config_get_split_index(void);
 extern int git_config_get_max_percent_split_change(void);
 
+/* This dies if the configured or default date is in the future */
+extern int git_config_get_expiry(const char *key, const char **output);
+
 /*
  * This is a hack for test programs like test-dump-untracked-cache to
  * ensure that they do not modify the untracked cache when reading it.
index cf212785bb762a2fd020040f6c0f460b540b4c92..d6c8f8f3ba73ce1e14e27a82ba15bd605e585c14 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1685,6 +1685,19 @@ int git_config_get_pathname(const char *key, const char **dest)
        return ret;
 }
 
+int git_config_get_expiry(const char *key, const char **output)
+{
+       int ret = git_config_get_string_const(key, output);
+       if (ret)
+               return ret;
+       if (strcmp(*output, "now")) {
+               unsigned long now = approxidate("now");
+               if (approxidate(*output) >= now)
+                       git_die_config(key, _("Invalid %s: '%s'"), key, *output);
+       }
+       return ret;
+}
+
 int git_config_get_untracked_cache(void)
 {
        int val = -1;