Junio C Hamano, Wed, Aug 29, 2007 22:44:22 +0200: > > That loop is plain old O(n^2) that penalizes everybody. > Maybe something in pathspec matching code could be reused to notice the duplications? It has to go through all of them anyway... > Please do not penalize sane callers when you try to improve > support of mistaken usage. Move expensive error recovery in the > error path when possible, and have _only_ mistaken users pay the > price. > > Like this perhaps. > I just would write it shorter (except for that ugly label before closing brace). diff --git a/builtin-ls-files.c b/builtin-ls-files.c index d36181a..258868e 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -511,11 +511,28 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) */ int num, errors = 0; for (num = 0; pathspec[num]; num++) { + int other; + if (ps_matched[num]) continue; + /* + * The caller might have fed identical pathspec + * twice. Do not barf on such a mistake. + */ + for (other = 0; pathspec[other]; other++) { + if (other == num || !ps_matched[other]) + continue; + if (!strcmp(pathspec[other], pathspec[num])) + /* + * Ok, we have a match already. + */ + goto found_dup; + } + error("pathspec '%s' did not match any file(s) known to git.", pathspec[num] + prefix_offset); errors++; + found_dup:; } if (errors) -- 1.5.3.rc7.26.g5f7e4 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html