Subject: Re: [PATCH v2 1/2] parse-options.h: add parse_opt_expiry_date helper

From: Junio C Hamano <[email-masked]>
Date: Mon, 03 Jan 2022 18:26:42 -0800

"John Cai via GitGitGadget" <[email-masked]> writes:

> From: John Cai <[email-masked]>
>
> 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" <[email-masked]>
> ---
>  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;
>  }

Does this even belong to parse-options-cb.c file, though?  It's
interface tells us that it is not limited to the parse-options
infrastructure (i.e. it does not even take "struct option" at all).

I am not sure how having this new function will be helpful to begin
with.  We'll see why it helps by looking at the next step, I
presume, but I wonder if the new caller of this function should just
call parse_expiry_date() itself (with "unset means 'never'").

> 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))