[PATCH v2 1/2] parse-options.h: add parse_opt_expiry_date helper
- From
John Cai via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Jan 3, 2022, 15:20 UTC
- Message-ID
- <bcd74559c2474451687c81e97834b13a859d2191.1641223223.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1175.v2.git.git.1641223223.gitgitgadget@gmail.com>
From: John Cai <johncai86@gmail.com>
Extract the logic in parse_opt_expiry_date_cb into a helper parse_opt_expiry_date. This is to prepare for the following commit where we need to parse an expiry date that gets passed into a callback function in opt->value as part of a struct.
The next commit will utilize this helper in a callback function that aims to wrap the functionality in parse_opt_expiry_date_cb.
Signed-off-by: "John Cai" <johncai86@gmail.com> --- parse-options-cb.c | 7 ++++++- parse-options.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/parse-options-cb.c b/parse-options-cb.c index 3c811e1e4a7..3edb88a54d8 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -34,10 +34,15 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) int parse_opt_expiry_date_cb(const struct option *opt, const char *arg, int unset) +{ + return parse_opt_expiry_date((timestamp_t *)opt->value, arg, unset); +} + +int parse_opt_expiry_date(timestamp_t *t, const char *arg, int unset) { if (unset) arg = "never"; - if (parse_expiry_date(arg, (timestamp_t *)opt->value)) + if (parse_expiry_date(arg, t)) die(_("malformed expiration date '%s'"), arg); return 0; } diff --git a/parse-options.h b/parse-options.h index 275fb440818..0a15bac8619 100644 --- a/parse-options.h +++ b/parse-options.h @@ -301,6 +301,7 @@ enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const char *, int); int parse_opt_passthru(const struct option *, const char *, int); int parse_opt_passthru_argv(const struct option *, const char *, int); +int parse_opt_expiry_date(timestamp_t *, const char *, int); #define OPT__VERBOSE(var, h) OPT_COUNTUP('v', "verbose", (var), (h)) #define OPT__QUIET(var, h) OPT_COUNTUP('q', "quiet", (var), (h))
-- gitgitgadget