Re: [PATCH 7/8] reflog: convert to parse_options() API

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

 



Ævar Arnfjörð Bjarmason  <avarab@xxxxxxxxx> writes:

>  int cmd_reflog(int argc, const char **argv, const char *prefix)
>  {
> -	if (argc > 1 && !strcmp(argv[1], "-h"))
> -		usage(_(reflog_usage));
> +	struct option options[] = {
> +		OPT_END()
> +	};
>  
> -	/* With no command, we default to showing it. */
> -	if (argc < 2 || *argv[1] == '-')
> -		return cmd_log_reflog(argc, argv, prefix);
> +	argc = parse_options(argc, argv, prefix, options, reflog_usage,
> +			     PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 |
> +			     PARSE_OPT_KEEP_UNKNOWN |
> +			     PARSE_OPT_NO_INTERNAL_HELP);
> +
> +	/*
> +	  * With "git reflog" we default to showing it. !argc is
> +	  * impossible with PARSE_OPT_KEEP_ARGV0.
> +	  */

Funny indentation?

> +	if (argc == 1)
> +		goto log_reflog;
> +
> +	if (!strcmp(argv[1], "-h"))
> +		usage_with_options(reflog_usage, options);
> +	else if (*argv[1] == '-')
> +		goto log_reflog;

Unfortunate.  KEEP_UNKNOWN is unwieldy, but it is no worse than the
original.  We do not have options that are common to all "git reflog"
subcommands, so the first token after "git reflog" being anything
that begins with "-" is a sign that the default "show" command is
being asked for.

> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 0f439c99d61..1d004744589 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -329,7 +329,7 @@ test_commit () {
>  	else
>  		$echo "${3-$1}" >"$indir$file"
>  	fi &&
> -	git ${indir:+ -C "$indir"} add "$file" &&
> +	git ${indir:+ -C "$indir"} add -- "$file" &&

OK.

Looking good.




[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