From: Adam Simpkins Date: Sat, 27 Feb 2010 03:50:04 GMT Subject: [PATCH 3/3] clean up parsing of expiration dates Message-ID: <1267242604-5215-3-git-send-email-simpkins@facebook.com> In-Reply-To: <1267242604-5215-2-git-send-email-simpkins@facebook.com> The gc, prune, and reflog command all take arguments that control expiring of old objects/log entries. This cleans up the parsing of these arguments, and centralizes the logic so the commands behave consistently. Two new functions have been added for parsing expiration dates: parse_expire_date() is similar to approxidate_careful(), but also accepts the value "false" as a synonym for "never". git_config_expire_date() calls parse_expire_date(), and prints an error message if the value is invalid. A new OPT_EXPIRE_DATE option type has also been added to parse-options.h for parsing expiration date command line arguments. Signed-off-by: Adam Simpkins --- builtin-gc.c | 9 ++++----- builtin-prune.c | 4 ++-- builtin-reflog.c | 27 +++++++++++---------------- cache.h | 2 ++ config.c | 12 ++++++++++++ date.c | 10 ++++++++++ parse-options.c | 17 +++++++++++++++++ parse-options.h | 4 ++++ t/t1410-reflog.sh | 11 +++++++++++ t/t5304-prune.sh | 36 +++++++++++++++++++++++++++++++++++- 10 files changed, 108 insertions(+), 24 deletions(-) diff --git a/builtin-gc.c b/builtin-gc.c index c304638..3921e6e 100644 --- a/builtin-gc.c +++ b/builtin-gc.c @@ -57,11 +57,10 @@ static int gc_config(const char *var, const char *value, void *cb) return 0; } if (!strcmp(var, "gc.pruneexpire")) { - if (value && strcmp(value, "now")) { - unsigned long now = approxidate("now"); - if (approxidate(value) >= now) - return error("Invalid %s: '%s'", var, value); - } + /* Make sure the value is valid */ + unsigned long expire_date; + if (git_config_expire_date(&expire_date, var, value)) + return -1; return git_config_string(&prune_expire, var, value); } return git_default_config(var, value, cb); diff --git a/builtin-prune.c b/builtin-prune.c index f22bcf6..e8d25a6 100644 --- a/builtin-prune.c +++ b/builtin-prune.c @@ -129,8 +129,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix) "do not remove, show only"), OPT_BOOLEAN('v', NULL, &verbose, "report pruned objects"), - OPT_DATE(0, "expire", &expire, - "expire objects older than