Re: [PATCH] help: always suggest common-cmds if prefix of cmd
- From
Erik Faye-Lund <kusmabite@gmail.com>
- Date
- Nov 25, 2010, 10:39 UTC
- Message-ID
- <AANLkTinKDqykfuV5=oHav9PRehDtJZct_q=zm7p8PAeo@mail.gmail.com>
- In-Reply-To
- <7vfwuqrori.fsf@alter.siamese.dyndns.org>
On Thu, Nov 25, 2010 at 5:49 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 35 quoted lines
> Erik Faye-Lund <kusmabite@gmail.com> writes:
>
>> Indeed. What about this intra-diff? Hopefully it's a bit clearer, as
>> it's closer to the original, just reusing the same logic for the new
>> similar loop... Also makes the final diff smaller, which is nice.
>>
>> diff --git a/help.c b/help.c
>> index dc76a62..d02a019 100644
>> --- a/help.c
>> +++ b/help.c
>> @@ -339,11 +339,10 @@ const char *help_unknown_cmd(const char *cmd)
>> die ("Uh oh. Your system reports no Git commands at all.");
>>
>> n = 0;
>> - do {
>> - best_similarity = main_cmds.names[n++]->len;
>> - } while (!best_similarity);
>> - n++;
>> - while (n < main_cmds.cnt && best_similarity >= main_cmds.names[n]->len)
>> + while (n < main_cmds.cnt && !main_cmds.names[n]->len)
>> + ++n;
>> + best_similarity = main_cmds.names[n++]->len;
>> + while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
>> ++n;
>
> Perhaps, but it is probably more conventional to write this kind of loop with:
>
> for (n = 0; ...; n++)
> ...
>
> no?
>
>> if (autocorrect && n == 1 && SIMILAR_ENOUGH(best_similarity)) {
>> const char *assumed = main_cmds.names[0]->name;
>Sure. I was just trying to match the existing code. But sure, I can change that if you prefer. I think it makes the end-result slightly nicer.