From: Jeff King <peff@peff.net>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Junio C Hamano <gitster@pobox.com>,
Michael J Gruber <git@drmicha.warpmail.net>,
Jon Schewe <jpschewe@mtu.net>,
spearce@spearce.org, git@vger.kernel.org
Subject: Re: [PATCH] ls-files: fix overeager pathspec optimization
Date: Sat, 9 Jan 2010 00:42:40 -0500 [thread overview]
Message-ID: <20100109054240.GA13321@coredump.intra.peff.net> (raw)
In-Reply-To: <alpine.LFD.2.00.1001081701570.7821@localhost.localdomain>
On Fri, Jan 08, 2010 at 05:07:46PM -0800, Linus Torvalds wrote:
> > But I am starting to wonder if we might be better off restructuring
> > read_directory_recursive(). Currently it assumes that the path it was
> > given _must_ be of interest (i.e. not ignored) and runs excluded() on
> > subdirectories it finds to make that same decision before recursing into
> > them or skipping them. It might make more sense if it first checked if
> > the path given by the caller should be ignored and act accordingly.
>
> Hmm. I can't make myself care one way or the other, I have to admit. I
> assume you mean basically taking the path and using the first component of
> it _instead_ of doing a readdir() - and getting rid of the simplification
> up front?
>
> I agree that that should work. Would it be simpler and cleaner? Perhaps.
> I'd have to see both patches to be able to tell. I do admit that while I
> acked your patch, it sure ain't _pretty_ to do that special odd
> "has_leading_ignored_dir()" thing.
It would look something like this:
diff --git a/dir.c b/dir.c
index 3a8d3e6..306d354 100644
--- a/dir.c
+++ b/dir.c
@@ -811,12 +811,19 @@ static void free_simplify(struct path_simplify *simplify)
int read_directory(struct dir_struct *dir, const char *path, int len, const char **pathspec)
{
struct path_simplify *simplify;
+ int d_type = DT_DIR;
+ int exclude;
if (has_symlink_leading_path(path, len))
return dir->nr;
simplify = create_simplify(pathspec);
- read_directory_recursive(dir, path, len, 0, simplify);
+ exclude = excluded(dir, path, &d_type);
+ if (exclude && (dir->flags & DIR_COLLECT_IGNORED) &&
+ in_pathspec(path, len, simplify))
+ dir_add_ignored(dir, path, len);
+ if (!exclude || (dir->flags & DIR_SHOW_IGNORED))
+ read_directory_recursive(dir, path, len, 0, simplify);
free_simplify(simplify);
qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name);
qsort(dir->ignored, dir->ignored_nr, sizeof(struct dir_entry *), cmp_name);
But unfortunately excluded() is not happy with the trailing slash on the
path given to read_directory, so we also need on top:
diff --git a/dir.c b/dir.c
index 306d354..6045a84 100644
--- a/dir.c
+++ b/dir.c
@@ -813,12 +813,17 @@ int read_directory(struct dir_struct *dir, const char *path, int len, const char
struct path_simplify *simplify;
int d_type = DT_DIR;
int exclude;
+ char *path_without_slash;
if (has_symlink_leading_path(path, len))
return dir->nr;
simplify = create_simplify(pathspec);
- exclude = excluded(dir, path, &d_type);
+ path_without_slash = xstrdup(path);
+ if (path_without_slash[strlen(path_without_slash)-1] == '/')
+ path_without_slash[strlen(path_without_slash)-1] = '\0';
+ exclude = excluded(dir, path_without_slash, &d_type);
+ free(path_without_slash);
if (exclude && (dir->flags & DIR_COLLECT_IGNORED) &&
in_pathspec(path, len, simplify))
dir_add_ignored(dir, path, len);
And that does fix the case that triggered this whole discussion, but I
haven't tested thoroughly to make sure we are not adversely affecting
other cases.
-Peff
next prev parent reply other threads:[~2010-01-09 5:43 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-08 15:17 Possible bug in git-completion.sh Jon Schewe
2010-01-08 15:40 ` Michael J Gruber
2010-01-08 16:24 ` Jeff King
2010-01-08 16:38 ` Junio C Hamano
2010-01-08 16:41 ` Jeff King
2010-01-08 16:45 ` Junio C Hamano
2010-01-08 16:56 ` Junio C Hamano
2010-01-08 17:24 ` Jeff King
2010-01-08 17:21 ` Jeff King
2010-01-08 18:21 ` Junio C Hamano
2010-01-08 19:58 ` Junio C Hamano
2010-01-08 23:01 ` [PATCH] ls-files: fix overeager pathspec optimization Junio C Hamano
2010-01-08 23:24 ` Linus Torvalds
2010-01-08 23:31 ` Junio C Hamano
2010-01-09 0:06 ` Junio C Hamano
2010-01-09 0:24 ` Linus Torvalds
2010-01-09 0:54 ` Junio C Hamano
2010-01-09 1:07 ` Linus Torvalds
2010-01-09 5:42 ` Jeff King [this message]
2010-01-09 7:16 ` Junio C Hamano
2010-01-09 7:35 ` [PATCH 1/4] t3001: test ls-files -o ignored/dir Junio C Hamano
2010-01-09 7:35 ` [PATCH 2/4] read_directory_recursive(): refactor handling of a single path into a separate function Junio C Hamano
2010-01-09 7:35 ` [PATCH 3/4] read_directory(): further split treat_path() Junio C Hamano
2010-01-09 7:35 ` [PATCH 4/4] ls-files: fix overeager pathspec optimization Junio C Hamano
2010-01-12 16:33 ` Jeff King
2010-01-09 8:07 ` [PATCH] " Junio C Hamano
2010-01-09 18:05 ` Linus Torvalds
2010-01-10 6:31 ` Junio C Hamano
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=20100109054240.GA13321@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jpschewe@mtu.net \
--cc=spearce@spearce.org \
--cc=torvalds@linux-foundation.org \
/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;
as well as URLs for NNTP newsgroup(s).