Skip to content

Commit 77d6797

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d59ffb commit 77d6797

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

builtin/gc.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ static void report_pack_garbage(unsigned seen_bits, const char *path)
6262
string_list_append(&pack_garbage, path);
6363
}
6464

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-
7665
static void process_log_file(void)
7766
{
7867
struct stat st;
@@ -111,8 +100,8 @@ static void gc_config(void)
111100
git_config_get_int("gc.auto", &gc_auto_threshold);
112101
git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
113102
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);
116105
git_config(git_default_config, NULL);
117106
}
118107

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,9 @@ extern int git_config_get_untracked_cache(void);
18271827
extern int git_config_get_split_index(void);
18281828
extern int git_config_get_max_percent_split_change(void);
18291829

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+
18301833
/*
18311834
* This is a hack for test programs like test-dump-untracked-cache to
18321835
* ensure that they do not modify the untracked cache when reading it.

config.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,19 @@ int git_config_get_pathname(const char *key, const char **dest)
16851685
return ret;
16861686
}
16871687

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+
16881701
int git_config_get_untracked_cache(void)
16891702
{
16901703
int val = -1;

0 commit comments

Comments
 (0)