From: Alex Riesen <raa.lkml@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: martin f krafft <madduck@madduck.net>,
git discussion list <git@vger.kernel.org>,
439992-quiet@bugs.debian.org
Subject: Re: [PATCH] Remove duplicate pathspecs from ls-files command line
Date: Wed, 29 Aug 2007 23:15:19 +0200 [thread overview]
Message-ID: <20070829211519.GE11824@steel.home> (raw)
In-Reply-To: <7v4piioyu1.fsf@gitster.siamese.dyndns.org>
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
next prev parent reply other threads:[~2007-08-29 21:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-29 8:11 double occurrence of filenames on command lines martin f krafft
2007-08-29 19:44 ` [PATCH] Remove duplicate pathspecs from ls-files command line Alex Riesen
2007-08-29 20:44 ` Junio C Hamano
2007-08-29 21:04 ` martin f krafft
2007-08-29 21:15 ` Alex Riesen [this message]
2007-08-29 21:36 ` David Kastrup
2007-08-30 1:25 ` Junio C Hamano
2007-08-30 5:52 ` David Kastrup
2007-08-29 20:57 ` martin f krafft
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070829211519.GE11824@steel.home \
--to=raa.lkml@gmail.com \
--cc=439992-quiet@bugs.debian.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=madduck@madduck.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox