diff mbox series

[63/76] diff.c: convert -O

Message ID 20190117130615.18732-64-pclouds@gmail.com (mailing list archive)
State New, archived
Headers show
Series Convert diff opt parser to parse_options() | expand

Commit Message

Duy Nguyen Jan. 17, 2019, 1:06 p.m. UTC
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Johannes Schindelin Jan. 21, 2019, 12:14 p.m. UTC | #1
Hi Duy,

On Thu, 17 Jan 2019, Nguyễn Thái Ngọc Duy wrote:

> diff --git a/diff.c b/diff.c
> index ae993f5551..4e004a2195 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -5401,6 +5401,8 @@ static void prep_parse_options(struct diff_options *options)
>  		OPT_BIT_F(0, "pickaxe-regex", &options->pickaxe_opts,
>  			  N_("treat <string> in -S as extended POSIX regular expression"),
>  			  DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),
> +		OPT_FILENAME('O', NULL, &options->orderfile,
> +			     N_("override diff.orderFile configuration variable")),
>  		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
>  		  N_("Output to a specific file"),
>  		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
> @@ -5453,10 +5455,7 @@ int diff_opt_parse(struct diff_options *options,
>  	}
>  
>  	/* misc options */
> -	else if ((argcount = short_opt('O', av, &optarg))) {
> -		options->orderfile = prefix_filename(prefix, optarg);
> -		return argcount;
> -	} else if (skip_prefix(arg, "--find-object=", &arg))
> +	else if (skip_prefix(arg, "--find-object=", &arg))

You probably used GCC and therefore missed that this patch removes the
last user of `short_opt()`, and therefore leaves `short_opt()` unused.
Apparently Clang v9.1.0 (which is used in Azure Pipelines' macOS builds)
is smart enough to notice that, though. So please squash this in when you
send another iteration of this patch (in a hopefully smaller package than
that six-and-a-half-dozen patch series):

-- snip --
diff --git a/diff.c b/diff.c
index 381259e987a5..5e1ab7daec44 100644
--- a/diff.c
+++ b/diff.c
@@ -4692,22 +4692,6 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va
 }
 #endif
 
-static inline int short_opt(char opt, const char **argv,
-			    const char **optarg)
-{
-	const char *arg = argv[0];
-	if (arg[0] != '-' || arg[1] != opt)
-		return 0;
-	if (arg[2] != '\0') {
-		*optarg = arg + 2;
-		return 1;
-	}
-	if (!argv[1])
-		die("Option '%c' requires a value", opt);
-	*optarg = argv[1];
-	return 2;
-}
-
 int parse_long_opt(const char *opt, const char **argv,
 		   const char **optarg)
 {
-- snap --

Ciao,
Johannes

>  		return parse_objfind_opt(options, arg);
>  	else if ((argcount = parse_long_opt("diff-filter", av, &optarg))) {
>  		int offending = parse_diff_filter_opt(optarg, options);
> -- 
> 2.20.0.482.g66447595a7
> 
> 
>
diff mbox series

Patch

diff --git a/diff.c b/diff.c
index ae993f5551..4e004a2195 100644
--- a/diff.c
+++ b/diff.c
@@ -5401,6 +5401,8 @@  static void prep_parse_options(struct diff_options *options)
 		OPT_BIT_F(0, "pickaxe-regex", &options->pickaxe_opts,
 			  N_("treat <string> in -S as extended POSIX regular expression"),
 			  DIFF_PICKAXE_REGEX, PARSE_OPT_NONEG),
+		OPT_FILENAME('O', NULL, &options->orderfile,
+			     N_("override diff.orderFile configuration variable")),
 		{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
 		  N_("Output to a specific file"),
 		  PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5453,10 +5455,7 @@  int diff_opt_parse(struct diff_options *options,
 	}
 
 	/* misc options */
-	else if ((argcount = short_opt('O', av, &optarg))) {
-		options->orderfile = prefix_filename(prefix, optarg);
-		return argcount;
-	} else if (skip_prefix(arg, "--find-object=", &arg))
+	else if (skip_prefix(arg, "--find-object=", &arg))
 		return parse_objfind_opt(options, arg);
 	else if ((argcount = parse_long_opt("diff-filter", av, &optarg))) {
 		int offending = parse_diff_filter_opt(optarg, options);