git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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
Previous: Junio C HamanoNext: Andrei Rybak
Message 5 of 7 in “C: use skip-prefix to avoid hardcoded string length”
  1. C: use skip-prefix to avoid hardcoded string lengthJunio C Hamano, Jan 27, 2020
  2. Jeff KingJan 27, 2020
  3. Junio C HamanoJan 28, 2020
  4. C: use skip-prefix to avoid hardcoded string lengthJunio C Hamano, Jan 30, 2020
  5. Jeff KingJan 31, 2020
  6. Andrei RybakJan 31, 2020
  7. Junio C HamanoJan 31, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.