diff mbox series

[v2,08/11] commit-graph: stop using optname()

Message ID patch-v2-08.11-58683b3d89d-20211001T142631Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series fix bug, use existing enums | expand

Commit Message

Ævar Arnfjörð Bjarmason Oct. 1, 2021, 2:29 p.m. UTC
Stop using optname() in builtin/commit-graph.c to emit an error with
the --max-new-filters option. This changes code added in 809e0327f57
(builtin/commit-graph.c: introduce '--max-new-filters=<n>',
2020-09-18).

See 9440b831ad5 (parse-options: replace opterror() with optname(),
2018-11-10) for why using optname() like this is considered bad,
i.e. it's assembling human-readable output piecemeal, and the "option
`X'" at the start can't be translated.

It didn't matter in this case, but this code was also buggy in its use
of "opt->flags" to optname(), that function expects flags, but not
*those* flags.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/commit-graph.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

René Scharfe Oct. 1, 2021, 5:12 p.m. UTC | #1
Am 01.10.21 um 16:29 schrieb Ævar Arnfjörð Bjarmason:
> Stop using optname() in builtin/commit-graph.c to emit an error with
> the --max-new-filters option. This changes code added in 809e0327f57
> (builtin/commit-graph.c: introduce '--max-new-filters=<n>',
> 2020-09-18).
>
> See 9440b831ad5 (parse-options: replace opterror() with optname(),
> 2018-11-10) for why using optname() like this is considered bad,
> i.e. it's assembling human-readable output piecemeal, and the "option
> `X'" at the start can't be translated.
>
> It didn't matter in this case, but this code was also buggy in its use
> of "opt->flags" to optname(), that function expects flags, but not
> *those* flags.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/commit-graph.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
> index 0386f5c7755..36552db89fe 100644
> --- a/builtin/commit-graph.c
> +++ b/builtin/commit-graph.c
> @@ -172,8 +172,7 @@ static int write_option_max_new_filters(const struct option *opt,
>  		const char *s;
>  		*to = strtol(arg, (char **)&s, 10);
>  		if (*s)
> -			return error(_("%s expects a numerical value"),
> -				     optname(opt, opt->flags));
> +			return error(_("option `max-new-filters' expects a numerical value"));

The option name itself is untranslatable.  parse_opt_abbrev_cb() has code
like this:

			return error(_("option `%s' expects a numerical value"),
				     opt->long_name);

This would work here as well.  Advantage: One less string to translate.

>  	}
>  	return 0;
>  }
>
diff mbox series

Patch

diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 0386f5c7755..36552db89fe 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -172,8 +172,7 @@  static int write_option_max_new_filters(const struct option *opt,
 		const char *s;
 		*to = strtol(arg, (char **)&s, 10);
 		if (*s)
-			return error(_("%s expects a numerical value"),
-				     optname(opt, opt->flags));
+			return error(_("option `max-new-filters' expects a numerical value"));
 	}
 	return 0;
 }