config: add git_config_get_expiry() from gc.c

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>

Christian Couder committed Feb 27, 2017 at 19:00 UTC 77d67977cac46aa6c07c66ce9e2470f00feb9d20
3 files changed +18 -13
builtin/gc.c
+2 -13
@@ -62,17 +62,6 @@ static void report_pack_garbage(unsigned seen_bits, const char *path)
62 string_list_append(&pack_garbage, path);
63 }
64
65 -static void git_config_date_string(const char *key, const char **output)
66 -{
67 - if (git_config_get_string_const(key, output))
68 - return;
69 - if (strcmp(*output, "now")) {
70 - unsigned long now = approxidate("now");
71 - if (approxidate(*output) >= now)
72 - git_die_config(key, _("Invalid %s: '%s'"), key, *output);
73 - }
74 -}
75 -
65 static void process_log_file(void)
66 {
67 struct stat st;
@@ -111,8 +100,8 @@ static void gc_config(void)
100 git_config_get_int("gc.auto", &gc_auto_threshold);
101 git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
102 git_config_get_bool("gc.autodetach", &detach_auto);
114 - git_config_date_string("gc.pruneexpire", &prune_expire);
115 - git_config_date_string("gc.worktreepruneexpire", &prune_worktrees_expire);
103 + git_config_get_expiry("gc.pruneexpire", &prune_expire);
104 + git_config_get_expiry("gc.worktreepruneexpire", &prune_worktrees_expire);
105 git_config(git_default_config, NULL);
106 }
107
cache.h
+3
@@ -1827,6 +1827,9 @@ extern int git_config_get_untracked_cache(void);
1827 extern int git_config_get_split_index(void);
1828 extern int git_config_get_max_percent_split_change(void);
1829
1830 +/* This dies if the configured or default date is in the future */
1831 +extern int git_config_get_expiry(const char *key, const char **output);
1832 +
1833 /*
1834 * This is a hack for test programs like test-dump-untracked-cache to
1835 * ensure that they do not modify the untracked cache when reading it.
config.c
+13
@@ -1685,6 +1685,19 @@ int git_config_get_pathname(const char *key, const char **dest)
1685 return ret;
1686 }
1687
1688 +int git_config_get_expiry(const char *key, const char **output)
1689 +{
1690 + int ret = git_config_get_string_const(key, output);
1691 + if (ret)
1692 + return ret;
1693 + if (strcmp(*output, "now")) {
1694 + unsigned long now = approxidate("now");
1695 + if (approxidate(*output) >= now)
1696 + git_die_config(key, _("Invalid %s: '%s'"), key, *output);
1697 + }
1698 + return ret;
1699 +}
1700 +
1701 int git_config_get_untracked_cache(void)
1702 {
1703 int val = -1;