Re: [PATCH v2] C: use skip-prefix to avoid hardcoded string length
- From
Jeff King <peff@peff.net>
- Date
- Jan 31, 2020, 00:19 UTC
- Message-ID
- <20200131001907.GD2394563@coredump.intra.peff.net>
- In-Reply-To
- <xmqqa764d9f1.fsf_-_@gitster-ct.c.googlers.com>
On Thu, Jan 30, 2020 at 11:35:46AM -0800, Junio C Hamano wrote:
> * v2 uses a simpler conversion that has a side effect of changing > the error message from "git reflog expire" in a better way.
Thanks, this all looks good to me.
Show 18 quoted lines
> diff --git a/builtin/reflog.c b/builtin/reflog.c
> index 4d3430900d..81dfd563c0 100644
> --- a/builtin/reflog.c
> +++ b/builtin/reflog.c
> @@ -560,15 +560,16 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
>
> for (i = 1; i < argc; i++) {
> const char *arg = argv[i];
> +
> if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
> flags |= EXPIRE_REFLOGS_DRY_RUN;
> - else if (starts_with(arg, "--expire=")) {
> - if (parse_expiry_date(arg + 9, &cb.cmd.expire_total))
> + else if (skip_prefix(arg, "--expire=", &arg)) {
> + if (parse_expiry_date(arg, &cb.cmd.expire_total))
> die(_("'%s' is not a valid timestamp"), arg);
> explicit_expiry |= EXPIRE_TOTAL;
> }I'm not sure if you meant to leave the blank-line addition, or if it was a leftover from when there was a variable added there in v1. I think the result is more readable, though, so I certainly don't mind it. ;)
-Peff