From: Junio C Hamano Date: Thu, 25 Nov 2010 04:49:37 GMT Subject: Re: [PATCH] help: always suggest common-cmds if prefix of cmd Message-ID: <7vfwuqrori.fsf@alter.siamese.dyndns.org> In-Reply-To: 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;