Re: [PATCH v2] C: use skip-prefix to avoid hardcoded string length

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

> 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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux