From: Erik Faye-Lund Date: Thu, 25 Nov 2010 10:39:27 GMT Subject: Re: [PATCH] help: always suggest common-cmds if prefix of cmd Message-ID: In-Reply-To: <7vfwuqrori.fsf@alter.siamese.dyndns.org> On Thu, Nov 25, 2010 at 5:49 AM, Junio C Hamano wrote: > Erik Faye-Lund 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.