[PATCH 02/24] config: repo_config_get_expiry()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Callers interested in parsing an approxidate from configuration
currently make use of the `git_config_get_expiry()` function via the
standard `git_config()` callback.

Introduce a `repo_config_get_expiry()` variant in the style of functions
introduced by 3b256228a6 (config: read config from a repository object,
2017-06-22) to read a single value without requiring the git_config()
callback-style approach.

This new function is similar to the existing implementation in
`git_config_get_expiry()`, however it differs in that it fills out a
`timestamp_t` value through a pointer, instead of merely checking and
discarding the result (and returning it as a string).

This function will gain its first caller in a subsequent commit to parse
a "threshold" parameter for excluding too-recent commits from
pseudo-merge groups.

Signed-off-by: Taylor Blau <me@xxxxxxxxxxxx>
---
 config.c | 18 ++++++++++++++++++
 config.h |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/config.c b/config.c
index 3cfeb3d8bd9..8512da92273 100644
--- a/config.c
+++ b/config.c
@@ -2627,6 +2627,24 @@ int repo_config_get_pathname(struct repository *repo,
 	return ret;
 }
 
+int repo_config_get_expiry(struct repository *repo,
+			   const char *key, const char **dest)
+{
+	int ret;
+
+	git_config_check_init(repo);
+
+	ret = repo_config_get_string(repo, key, (char **)dest);
+	if (ret)
+		return ret;
+	if (strcmp(*dest, "now")) {
+		timestamp_t now = approxidate("now");
+		if (approxidate(*dest) >= now)
+			git_die_config(key, _("Invalid %s: '%s'"), key, *dest);
+	}
+	return ret;
+}
+
 /* Read values into protected_config. */
 static void read_protected_config(void)
 {
diff --git a/config.h b/config.h
index 5dba984f770..619db01bc27 100644
--- a/config.h
+++ b/config.h
@@ -576,6 +576,8 @@ int repo_config_get_maybe_bool(struct repository *repo,
 			       const char *key, int *dest);
 int repo_config_get_pathname(struct repository *repo,
 			     const char *key, const char **dest);
+int repo_config_get_expiry(struct repository *repo,
+			   const char *key, const char **dest);
 
 /*
  * Functions for reading protected config. By definition, protected
-- 
2.44.0.303.g1dc5e5b124c





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux