Re: [PATCH v3 6/8] parseopt: autocorrect mistyped subcommands
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 10, 2026, 20:16 UTC
- Message-ID
- <xmqq7brjtp7c.fsf@gitster.g>
- In-Reply-To
- <SY0P300MB08011B31B360FC14F05418C1CE46A@SY0P300MB0801.AUSP300.PROD.OUTLOOK.COM>
Jiamu Sun <39@barroit.sh> writes:
Show 7 quoted lines
> +static int similar_enough(const char *cmd, unsigned int dist)
> +{
> + size_t len = strlen(cmd);
> + unsigned int threshold = len < 3 ? 1 : len < 6 ? 3 : 6;
> +
> + return dist < threshold;
> +}There should be some explanation on the reason why this is very different from SIMILAR_ENOUGH used in help.c for main commands, especially given that the levenshtein() call here uses identical weight parameters (0,2,1,3) as used by the call there.
Show 15 quoted lines
> +static const char *autocorrect_subcommand(const char *cmd,
> + ...
> + for_each_string_list_item(cand, cmds) {
> + unsigned int dist = levenshtein(cmd, cand->string, 0, 2, 1, 3);
> +
> + if (dist < min) {
> + min = dist;
> + best = cand;
> + ties = 0;
> + } else if (dist == min) {
> + ties++;
> + }
> + }
> +
> + if (!ties && similar_enough(cmd, min)) {