Re: [PATCH v4 07/10] parseopt: autocorrect mistyped subcommands
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 16, 2026, 19:41 UTC
- Message-ID
- <xmqqse9zo93p.fsf@gitster.g>
- In-Reply-To
- <SY0P300MB0801E3F75349DFDF98C221F6CE40A@SY0P300MB0801.AUSP300.PROD.OUTLOOK.COM>
Jiamu Sun <39@barroit.sh> writes:
Show 13 quoted lines
> Try to autocorrect the mistyped mandatory subcommand before showing an > error and exiting. Subcommands parsed with PARSE_OPT_SUBCOMMAND_OPTIONAL > are skipped. > > Use standard Damerau-Levenshtein distance (weights 1, 1, 1, 1) to > establish a predictable, mathematically sound baseline. > > Scale the allowed edit distance based on input length to prevent > false positives on short commands, following common practice for > fuzziness thresholds (e.g., Elasticsearch's AUTO fuzziness): > - Length 0-2: 0 edits allowed > - Length 3-5: 1 edit allowed > - Length 6+: 2 edits allowed
Is there a reason why this needs to differ from the settings for the typo detection/fixes for main commands? Would the same reasoning apply to both, and if not why not?
I would have expected that we would just emulate what we already do to the main commands, and later with experience with the subcommand typo detection/fixes, would tweak the parameters either only to the subcommand part or to the both with justifications.
Show 5 quoted lines
> + /* > + * Builtin subcommands are small enough that printing them all via > + * usage_with_options() is sufficient. Therefore, AUTOCORRECT_HINT > + * acts like AUTOCORRECT_NEVER. > + */
Sorry, but I am a bit confused with this reference to "Builtin subcommands". Are there subcommands that are not built-in?