From: Junio C Hamano Date: Tue, 10 Mar 2026 20:16:39 GMT Subject: Re: [PATCH v3 6/8] parseopt: autocorrect mistyped subcommands Message-ID: In-Reply-To: Jiamu Sun <39@barroit.sh> writes: > +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. > +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)) {