git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.

Previous: Junio C HamanoNext: Erik Faye-Lund
Message 18 of 27 in “bug: unexpected output for "git st" + suggestion”
  1. Tarek ZiadéNov 23, 2010
  2. Nguyen Thai Ngoc DuyNov 23, 2010
  3. Tarek ZiadéNov 23, 2010
  4. Nguyen Thai Ngoc DuyNov 23, 2010
  5. Tarek ZiadéNov 23, 2010
  6. Nguyen Thai Ngoc DuyNov 23, 2010
  7. Andreas SchwabNov 23, 2010
  8. Sylvain RabotNov 23, 2010
  9. Erik Faye-LundNov 23, 2010
  10. Tarek ZiadéNov 23, 2010
  11. Erik Faye-LundNov 23, 2010
  12. Tarek ZiadéNov 23, 2010
  13. help: always suggest common-cmds if prefix of cmdErik Faye-Lund, Nov 23, 2010
  14. Junio C HamanoNov 24, 2010
  15. Erik Faye-LundNov 24, 2010
  16. help: always suggest common-cmds if prefix of cmdErik Faye-Lund, Nov 24, 2010
  17. Junio C HamanoNov 25, 2010
  18. Erik Faye-LundNov 25, 2010
  19. help: always suggest common-cmds if prefix of cmdErik Faye-Lund, Nov 26, 2010
  20. Junio C HamanoNov 27, 2010
  21. Erik Faye-LundNov 29, 2010
  22. Jonathan NiederNov 29, 2010
  23. Erik Faye-LundNov 29, 2010
  24. Junio C HamanoNov 29, 2010
  25. Erik Faye-LundDec 1, 2010
  26. help.autoCorrect prefix selection considered a bit dangerousÆvar Arnfjörð Bjarmason, Nov 19, 2018
  27. Junio C HamanoNov 20, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.