diff mbox series

[v2,12/16] parse-options: replace opterror() with optname()

Message ID 20181105192059.20303-13-pclouds@gmail.com (mailing list archive)
State New, archived
Headers show
Series Mark more strings for translation | expand

Commit Message

Duy Nguyen Nov. 5, 2018, 7:20 p.m. UTC
There are a few issues with opterror()

- it tries to assemble an English sentence from pieces. This is not
  great for translators because we give them pieces instead of a full
  sentence.

- It's a wrapper around error() and needs some hack to let the
  compiler know it always returns -1.

- Since it takes a string instead of printf format, one call site has
  to assemble the string manually before passing to it.

Kill it and produce the option name with optname(). The user will use
error() directly. This solves the second and third problems.

It kind helps the first problem as well because "%s does foo" does
give a translator a full sentence in a sense and let them reorder if
needed. But it has limitations, if the subject part has to change
based on the rest of the sentence, that language is screwed. This is
also why I try to avoid calling optname() when 'flags' is known in
advance.

Mark of these strings for translation as well while at there.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/merge.c     |  2 +-
 builtin/revert.c    |  3 ++-
 parse-options-cb.c  |  7 ++++---
 parse-options.c     | 46 +++++++++++++++++++++++++--------------------
 parse-options.h     |  5 +----
 ref-filter.c        |  8 +++++---
 t/t4211-line-log.sh |  2 +-
 7 files changed, 40 insertions(+), 33 deletions(-)

Comments

Junio C Hamano Nov. 6, 2018, 2:33 a.m. UTC | #1
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> There are a few issues with opterror()
>
> - it tries to assemble an English sentence from pieces. This is not
>   great for translators because we give them pieces instead of a full
>   sentence.
>
> - It's a wrapper around error() and needs some hack to let the
>   compiler know it always returns -1.
>
> - Since it takes a string instead of printf format, one call site has
>   to assemble the string manually before passing to it.
>
> Kill it and produce the option name with optname(). The user will use
> error() directly. This solves the second and third problems.

The proposed log message is not very friendly to reviewers, as there
is no hint what optname() does nor where it came from; it turns out
that this patch introduces it.

    Introduce optname() that does the early half of original
    opterror() to come up with the name of the option reported back
    to the user, and use it to kill opterror().  The callers of
    opterror() now directly call error() using the string returned
    by opterror() instead.

or something like that perhaps.

Theoretically not very friendly to topics in flight, but I do not
expect there would be any right now that wants to add new callers of
opterror().

I do agree with the reasoning behind this change.  Thanks for
working on it.

>
> It kind helps the first problem as well because "%s does foo" does
> give a translator a full sentence in a sense and let them reorder if
> needed. But it has limitations, if the subject part has to change
> based on the rest of the sentence, that language is screwed. This is
> also why I try to avoid calling optname() when 'flags' is known in
> advance.
>
> Mark of these strings for translation as well while at there.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/merge.c     |  2 +-
>  builtin/revert.c    |  3 ++-
>  parse-options-cb.c  |  7 ++++---
>  parse-options.c     | 46 +++++++++++++++++++++++++--------------------
>  parse-options.h     |  5 +----
>  ref-filter.c        |  8 +++++---
>  t/t4211-line-log.sh |  2 +-
>  7 files changed, 40 insertions(+), 33 deletions(-)
>
> diff --git a/builtin/merge.c b/builtin/merge.c
> index 92ba7e1c6d..82248d43c3 100644
> --- a/builtin/merge.c
> +++ b/builtin/merge.c
> @@ -128,7 +128,7 @@ static int option_read_message(struct parse_opt_ctx_t *ctx,
>  		ctx->argc--;
>  		arg = *++ctx->argv;
>  	} else
> -		return opterror(opt, "requires a value", 0);
> +		return error(_("option `%s' requires a value"), opt->long_name);
>  
>  	if (buf->len)
>  		strbuf_addch(buf, '\n');
> diff --git a/builtin/revert.c b/builtin/revert.c
> index c93393c89b..11190d2ab4 100644
> --- a/builtin/revert.c
> +++ b/builtin/revert.c
> @@ -69,7 +69,8 @@ static int option_parse_m(const struct option *opt,
>  
>  	replay->mainline = strtol(arg, &end, 10);
>  	if (*end || replay->mainline <= 0)
> -		return opterror(opt, "expects a number greater than zero", 0);
> +		return error(_("option `%s' expects a number greater than zero"),
> +			     opt->long_name);
>  
>  	return 0;
>  }
> diff --git a/parse-options-cb.c b/parse-options-cb.c
> index e8236534ac..813eb6301b 100644
> --- a/parse-options-cb.c
> +++ b/parse-options-cb.c
> @@ -18,7 +18,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
>  	} else {
>  		v = strtol(arg, (char **)&arg, 10);
>  		if (*arg)
> -			return opterror(opt, "expects a numerical value", 0);
> +			return error(_("option `%s' expects a numerical value"),
> +				     opt->long_name);
>  		if (v && v < MINIMUM_ABBREV)
>  			v = MINIMUM_ABBREV;
>  		else if (v > 40)
> @@ -54,8 +55,8 @@ int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
>  		arg = unset ? "never" : (const char *)opt->defval;
>  	value = git_config_colorbool(NULL, arg);
>  	if (value < 0)
> -		return opterror(opt,
> -			"expects \"always\", \"auto\", or \"never\"", 0);
> +		return error(_("option `%s' expects \"always\", \"auto\", or \"never\""),
> +			     opt->long_name);
>  	*(int *)opt->value = value;
>  	return 0;
>  }
> diff --git a/parse-options.c b/parse-options.c
> index 3b874a83a0..0bf817193d 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -32,7 +32,7 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
>  		p->argc--;
>  		*arg = *++p->argv;
>  	} else
> -		return opterror(opt, "requires a value", flags);
> +		return error(_("%s requires a value"), optname(opt, flags));
>  	return 0;
>  }
>  
> @@ -49,7 +49,6 @@ static int opt_command_mode_error(const struct option *opt,
>  				  int flags)
>  {
>  	const struct option *that;
> -	struct strbuf message = STRBUF_INIT;
>  	struct strbuf that_name = STRBUF_INIT;
>  
>  	/*
> @@ -67,13 +66,13 @@ static int opt_command_mode_error(const struct option *opt,
>  			strbuf_addf(&that_name, "--%s", that->long_name);
>  		else
>  			strbuf_addf(&that_name, "-%c", that->short_name);
> -		strbuf_addf(&message, ": incompatible with %s", that_name.buf);
> +		error(_("%s is incompatible with %s"),
> +		      optname(opt, flags), that_name.buf);
>  		strbuf_release(&that_name);
> -		opterror(opt, message.buf, flags);
> -		strbuf_release(&message);
>  		return -1;
>  	}
> -	return opterror(opt, ": incompatible with something else", flags);
> +	return error(_("%s : incompatible with something else"),
> +		     optname(opt, flags));
>  }
>  
>  static int get_value(struct parse_opt_ctx_t *p,
> @@ -86,11 +85,11 @@ static int get_value(struct parse_opt_ctx_t *p,
>  	int err;
>  
>  	if (unset && p->opt)
> -		return opterror(opt, "takes no value", flags);
> +		return error(_("%s takes no value"), optname(opt, flags));
>  	if (unset && (opt->flags & PARSE_OPT_NONEG))
> -		return opterror(opt, "isn't available", flags);
> +		return error(_("%s isn't available"), optname(opt, flags));
>  	if (!(flags & OPT_SHORT) && p->opt && (opt->flags & PARSE_OPT_NOARG))
> -		return opterror(opt, "takes no value", flags);
> +		return error(_("%s takes no value"), optname(opt, flags));
>  
>  	switch (opt->type) {
>  	case OPTION_LOWLEVEL_CALLBACK:
> @@ -176,7 +175,8 @@ static int get_value(struct parse_opt_ctx_t *p,
>  			return -1;
>  		*(int *)opt->value = strtol(arg, (char **)&s, 10);
>  		if (*s)
> -			return opterror(opt, "expects a numerical value", flags);
> +			return error(_("%s expects a numerical value"),
> +				     optname(opt, flags));
>  		return 0;
>  
>  	case OPTION_MAGNITUDE:
> @@ -191,9 +191,9 @@ static int get_value(struct parse_opt_ctx_t *p,
>  		if (get_arg(p, opt, flags, &arg))
>  			return -1;
>  		if (!git_parse_ulong(arg, opt->value))
> -			return opterror(opt,
> -				"expects a non-negative integer value with an optional k/m/g suffix",
> -				flags);
> +			return error(_("%s expects a non-negative integer value"
> +				       " with an optional k/m/g suffix"),
> +				     optname(opt, flags));
>  		return 0;
>  
>  	default:
> @@ -257,7 +257,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
>  			if (!rest)
>  				continue;
>  			if (*rest == '=')
> -				return opterror(options, "takes no value", flags);
> +				return error(_("%s takes no value"),
> +					     optname(options, flags));
>  			if (*rest)
>  				continue;
>  			p->out[p->cpidx++] = arg - 2;
> @@ -773,12 +774,17 @@ void NORETURN usage_msg_opt(const char *msg,
>  	usage_with_options(usagestr, options);
>  }
>  
> -#undef opterror
> -int opterror(const struct option *opt, const char *reason, int flags)
> +const char *optname(const struct option *opt, int flags)
>  {
> +	static struct strbuf sb = STRBUF_INIT;
> +
> +	strbuf_reset(&sb);
>  	if (flags & OPT_SHORT)
> -		return error("switch `%c' %s", opt->short_name, reason);
> -	if (flags & OPT_UNSET)
> -		return error("option `no-%s' %s", opt->long_name, reason);
> -	return error("option `%s' %s", opt->long_name, reason);
> +		strbuf_addf(&sb, "switch `%c'", opt->short_name);
> +	else if (flags & OPT_UNSET)
> +		strbuf_addf(&sb, "option `no-%s'", opt->long_name);
> +	else
> +		strbuf_addf(&sb, "option `%s'", opt->long_name);
> +
> +	return sb.buf;
>  }
> diff --git a/parse-options.h b/parse-options.h
> index dd14911a29..2e146aa6fa 100644
> --- a/parse-options.h
> +++ b/parse-options.h
> @@ -189,10 +189,7 @@ extern NORETURN void usage_msg_opt(const char *msg,
>  				   const struct option *options);
>  
>  extern int optbug(const struct option *opt, const char *reason);
> -extern int opterror(const struct option *opt, const char *reason, int flags);
> -#if defined(__GNUC__)
> -#define opterror(o,r,f) (opterror((o),(r),(f)), const_error())
> -#endif
> +const char *optname(const struct option *opt, int flags);
>  
>  /*----- incremental advanced APIs -----*/
>  
> diff --git a/ref-filter.c b/ref-filter.c
> index 2a05619211..0681359100 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -2302,9 +2302,11 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
>  
>  	if (rf->merge) {
>  		if (no_merged) {
> -			return opterror(opt, "is incompatible with --merged", 0);
> +			return error(_("option `%s' is incompatible with --merged"),
> +				     opt->long_name);
>  		} else {
> -			return opterror(opt, "is incompatible with --no-merged", 0);
> +			return error(_("option `%s' is incompatible with --no-merged"),
> +				     opt->long_name);
>  		}
>  	}
>  
> @@ -2318,7 +2320,7 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
>  	rf->merge_commit = lookup_commit_reference_gently(the_repository,
>  							  &oid, 0);
>  	if (!rf->merge_commit)
> -		return opterror(opt, "must point to a commit", 0);
> +		return error(_("option `%s' must point to a commit"), opt->long_name);
>  
>  	return 0;
>  }
> diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
> index ef1322148e..bd5fe4d148 100755
> --- a/t/t4211-line-log.sh
> +++ b/t/t4211-line-log.sh
> @@ -25,7 +25,7 @@ canned_test_failure () {
>  test_bad_opts () {
>  	test_expect_success "invalid args: $1" "
>  		test_must_fail git log $1 2>errors &&
> -		grep '$2' errors
> +		test_i18ngrep '$2' errors
>  	"
>  }
Ramsay Jones Nov. 6, 2018, 2:02 p.m. UTC | #2
On 06/11/2018 02:33, Junio C Hamano wrote:
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> 
>> There are a few issues with opterror()
>>
>> - it tries to assemble an English sentence from pieces. This is not
>>   great for translators because we give them pieces instead of a full
>>   sentence.
>>
>> - It's a wrapper around error() and needs some hack to let the
>>   compiler know it always returns -1.
>>
>> - Since it takes a string instead of printf format, one call site has
>>   to assemble the string manually before passing to it.
>>
>> Kill it and produce the option name with optname(). The user will use
>> error() directly. This solves the second and third problems.
> 
> The proposed log message is not very friendly to reviewers, as there
> is no hint what optname() does nor where it came from; it turns out
> that this patch introduces it.
> 
>     Introduce optname() that does the early half of original
>     opterror() to come up with the name of the option reported back
>     to the user, and use it to kill opterror().  The callers of
>     opterror() now directly call error() using the string returned
>     by opterror() instead.
> 
> or something like that perhaps.
> 
> Theoretically not very friendly to topics in flight, but I do not
> expect there would be any right now that wants to add new callers of
> opterror().
> 
> I do agree with the reasoning behind this change.  Thanks for
> working on it.
> 

Also, this patch does not replace opterror() calls outside of
the 'parse-options.c' file with optname(). This tickles my
static-check.pl script, since optname() is an external function
which is only called from 'parse-options.c'.

So, at present, optname() could be marked as a local 'static'
symbol. However, I could also imagine it being used by new callers
outside of 'parse-options.c' in the future. (maybe) Your call. ;-)

ATB,
Ramsay Jones
Jeff King Nov. 6, 2018, 7:08 p.m. UTC | #3
On Tue, Nov 06, 2018 at 02:02:42PM +0000, Ramsay Jones wrote:

> Also, this patch does not replace opterror() calls outside of
> the 'parse-options.c' file with optname(). This tickles my
> static-check.pl script, since optname() is an external function
> which is only called from 'parse-options.c'.
> 
> So, at present, optname() could be marked as a local 'static'
> symbol. However, I could also imagine it being used by new callers
> outside of 'parse-options.c' in the future. (maybe) Your call. ;-)

One potential caller is the BUG() cases I added in:

  https://public-inbox.org/git/20181105064542.GM25864@sigill.intra.peff.net/

I actually thought about factoring out an optname() there, but saw that
it involved memory ownership issues and punted (since those messages are
just BUG()s anyway, and unlikely to be triggered). But if we have it, we
could use it.

-Peff
Duy Nguyen Nov. 10, 2018, 4:55 a.m. UTC | #4
On Tue, Nov 6, 2018 at 3:07 PM Ramsay Jones <ramsay@ramsayjones.plus.com> wrote:
> Also, this patch does not replace opterror() calls outside of
> the 'parse-options.c' file with optname(). This tickles my
> static-check.pl script, since optname() is an external function
> which is only called from 'parse-options.c'.
>
> So, at present, optname() could be marked as a local 'static'
> symbol. However, I could also imagine it being used by new callers
> outside of 'parse-options.c' in the future. (maybe) Your call. ;-)

I was making it static, but the compiler complained about undefined
function and I would need to either move optname() up in
parse-options.c or add a forward declaration (but I was going to
_remove_ the declaration!)

Since it could be potentially used by Jeff's series (and I think it
does have potential in parse-options-cb.c), I'll just leave it
exported and caress your static-check.pl script (how did it not catch
optbug() not being used outside parse-options.c either)?
Ramsay Jones Nov. 10, 2018, 2:59 p.m. UTC | #5
On 10/11/2018 04:55, Duy Nguyen wrote:
> On Tue, Nov 6, 2018 at 3:07 PM Ramsay Jones <ramsay@ramsayjones.plus.com> wrote:
>> Also, this patch does not replace opterror() calls outside of
>> the 'parse-options.c' file with optname(). This tickles my
>> static-check.pl script, since optname() is an external function
>> which is only called from 'parse-options.c'.
>>
>> So, at present, optname() could be marked as a local 'static'
>> symbol. However, I could also imagine it being used by new callers
>> outside of 'parse-options.c' in the future. (maybe) Your call. ;-)
> 
> I was making it static, but the compiler complained about undefined
> function and I would need to either move optname() up in
> parse-options.c or add a forward declaration (but I was going to
> _remove_ the declaration!)
> 
> Since it could be potentially used by Jeff's series (and I think it
> does have potential in parse-options-cb.c), I'll just leave it
> exported and caress your static-check.pl script

Fair enough.

>                                                (how did it not catch
> optbug() not being used outside parse-options.c either)?

It did, some time ago (presumably, I haven't checked). Which is to
say: the output from the master branch notes it:

    $ grep parse-options sc
    parse-options.o	- optbug
    $ 

... but if it gets to the master branch I tend to forget it. (I have
been meaning to go through the 'sc' file and clean out some of the
'easy' cases).

So, if optname() doesn't get any new callers, I will watch it go
from 'pu' to 'next' and then to 'master' and ... ;-)

ATB,
Ramsay Jones
diff mbox series

Patch

diff --git a/builtin/merge.c b/builtin/merge.c
index 92ba7e1c6d..82248d43c3 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -128,7 +128,7 @@  static int option_read_message(struct parse_opt_ctx_t *ctx,
 		ctx->argc--;
 		arg = *++ctx->argv;
 	} else
-		return opterror(opt, "requires a value", 0);
+		return error(_("option `%s' requires a value"), opt->long_name);
 
 	if (buf->len)
 		strbuf_addch(buf, '\n');
diff --git a/builtin/revert.c b/builtin/revert.c
index c93393c89b..11190d2ab4 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -69,7 +69,8 @@  static int option_parse_m(const struct option *opt,
 
 	replay->mainline = strtol(arg, &end, 10);
 	if (*end || replay->mainline <= 0)
-		return opterror(opt, "expects a number greater than zero", 0);
+		return error(_("option `%s' expects a number greater than zero"),
+			     opt->long_name);
 
 	return 0;
 }
diff --git a/parse-options-cb.c b/parse-options-cb.c
index e8236534ac..813eb6301b 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -18,7 +18,8 @@  int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
 	} else {
 		v = strtol(arg, (char **)&arg, 10);
 		if (*arg)
-			return opterror(opt, "expects a numerical value", 0);
+			return error(_("option `%s' expects a numerical value"),
+				     opt->long_name);
 		if (v && v < MINIMUM_ABBREV)
 			v = MINIMUM_ABBREV;
 		else if (v > 40)
@@ -54,8 +55,8 @@  int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
 		arg = unset ? "never" : (const char *)opt->defval;
 	value = git_config_colorbool(NULL, arg);
 	if (value < 0)
-		return opterror(opt,
-			"expects \"always\", \"auto\", or \"never\"", 0);
+		return error(_("option `%s' expects \"always\", \"auto\", or \"never\""),
+			     opt->long_name);
 	*(int *)opt->value = value;
 	return 0;
 }
diff --git a/parse-options.c b/parse-options.c
index 3b874a83a0..0bf817193d 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -32,7 +32,7 @@  static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
 		p->argc--;
 		*arg = *++p->argv;
 	} else
-		return opterror(opt, "requires a value", flags);
+		return error(_("%s requires a value"), optname(opt, flags));
 	return 0;
 }
 
@@ -49,7 +49,6 @@  static int opt_command_mode_error(const struct option *opt,
 				  int flags)
 {
 	const struct option *that;
-	struct strbuf message = STRBUF_INIT;
 	struct strbuf that_name = STRBUF_INIT;
 
 	/*
@@ -67,13 +66,13 @@  static int opt_command_mode_error(const struct option *opt,
 			strbuf_addf(&that_name, "--%s", that->long_name);
 		else
 			strbuf_addf(&that_name, "-%c", that->short_name);
-		strbuf_addf(&message, ": incompatible with %s", that_name.buf);
+		error(_("%s is incompatible with %s"),
+		      optname(opt, flags), that_name.buf);
 		strbuf_release(&that_name);
-		opterror(opt, message.buf, flags);
-		strbuf_release(&message);
 		return -1;
 	}
-	return opterror(opt, ": incompatible with something else", flags);
+	return error(_("%s : incompatible with something else"),
+		     optname(opt, flags));
 }
 
 static int get_value(struct parse_opt_ctx_t *p,
@@ -86,11 +85,11 @@  static int get_value(struct parse_opt_ctx_t *p,
 	int err;
 
 	if (unset && p->opt)
-		return opterror(opt, "takes no value", flags);
+		return error(_("%s takes no value"), optname(opt, flags));
 	if (unset && (opt->flags & PARSE_OPT_NONEG))
-		return opterror(opt, "isn't available", flags);
+		return error(_("%s isn't available"), optname(opt, flags));
 	if (!(flags & OPT_SHORT) && p->opt && (opt->flags & PARSE_OPT_NOARG))
-		return opterror(opt, "takes no value", flags);
+		return error(_("%s takes no value"), optname(opt, flags));
 
 	switch (opt->type) {
 	case OPTION_LOWLEVEL_CALLBACK:
@@ -176,7 +175,8 @@  static int get_value(struct parse_opt_ctx_t *p,
 			return -1;
 		*(int *)opt->value = strtol(arg, (char **)&s, 10);
 		if (*s)
-			return opterror(opt, "expects a numerical value", flags);
+			return error(_("%s expects a numerical value"),
+				     optname(opt, flags));
 		return 0;
 
 	case OPTION_MAGNITUDE:
@@ -191,9 +191,9 @@  static int get_value(struct parse_opt_ctx_t *p,
 		if (get_arg(p, opt, flags, &arg))
 			return -1;
 		if (!git_parse_ulong(arg, opt->value))
-			return opterror(opt,
-				"expects a non-negative integer value with an optional k/m/g suffix",
-				flags);
+			return error(_("%s expects a non-negative integer value"
+				       " with an optional k/m/g suffix"),
+				     optname(opt, flags));
 		return 0;
 
 	default:
@@ -257,7 +257,8 @@  static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
 			if (!rest)
 				continue;
 			if (*rest == '=')
-				return opterror(options, "takes no value", flags);
+				return error(_("%s takes no value"),
+					     optname(options, flags));
 			if (*rest)
 				continue;
 			p->out[p->cpidx++] = arg - 2;
@@ -773,12 +774,17 @@  void NORETURN usage_msg_opt(const char *msg,
 	usage_with_options(usagestr, options);
 }
 
-#undef opterror
-int opterror(const struct option *opt, const char *reason, int flags)
+const char *optname(const struct option *opt, int flags)
 {
+	static struct strbuf sb = STRBUF_INIT;
+
+	strbuf_reset(&sb);
 	if (flags & OPT_SHORT)
-		return error("switch `%c' %s", opt->short_name, reason);
-	if (flags & OPT_UNSET)
-		return error("option `no-%s' %s", opt->long_name, reason);
-	return error("option `%s' %s", opt->long_name, reason);
+		strbuf_addf(&sb, "switch `%c'", opt->short_name);
+	else if (flags & OPT_UNSET)
+		strbuf_addf(&sb, "option `no-%s'", opt->long_name);
+	else
+		strbuf_addf(&sb, "option `%s'", opt->long_name);
+
+	return sb.buf;
 }
diff --git a/parse-options.h b/parse-options.h
index dd14911a29..2e146aa6fa 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -189,10 +189,7 @@  extern NORETURN void usage_msg_opt(const char *msg,
 				   const struct option *options);
 
 extern int optbug(const struct option *opt, const char *reason);
-extern int opterror(const struct option *opt, const char *reason, int flags);
-#if defined(__GNUC__)
-#define opterror(o,r,f) (opterror((o),(r),(f)), const_error())
-#endif
+const char *optname(const struct option *opt, int flags);
 
 /*----- incremental advanced APIs -----*/
 
diff --git a/ref-filter.c b/ref-filter.c
index 2a05619211..0681359100 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2302,9 +2302,11 @@  int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
 
 	if (rf->merge) {
 		if (no_merged) {
-			return opterror(opt, "is incompatible with --merged", 0);
+			return error(_("option `%s' is incompatible with --merged"),
+				     opt->long_name);
 		} else {
-			return opterror(opt, "is incompatible with --no-merged", 0);
+			return error(_("option `%s' is incompatible with --no-merged"),
+				     opt->long_name);
 		}
 	}
 
@@ -2318,7 +2320,7 @@  int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
 	rf->merge_commit = lookup_commit_reference_gently(the_repository,
 							  &oid, 0);
 	if (!rf->merge_commit)
-		return opterror(opt, "must point to a commit", 0);
+		return error(_("option `%s' must point to a commit"), opt->long_name);
 
 	return 0;
 }
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index ef1322148e..bd5fe4d148 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -25,7 +25,7 @@  canned_test_failure () {
 test_bad_opts () {
 	test_expect_success "invalid args: $1" "
 		test_must_fail git log $1 2>errors &&
-		grep '$2' errors
+		test_i18ngrep '$2' errors
 	"
 }