From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Darren Cook <darren@dcook.org>, git@vger.kernel.org
Subject: Re: Bug Report: git add
Date: Fri, 8 Apr 2011 15:15:54 -0400 [thread overview]
Message-ID: <20110408191554.GA6516@sigill.intra.peff.net> (raw)
In-Reply-To: <7vlizmfrl1.fsf@alter.siamese.dyndns.org>
On Thu, Apr 07, 2011 at 12:28:26AM -0700, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > @@ -139,8 +138,21 @@ static int lstat_cache_matchlen(struct cache_def *cache,
> > if (errno == ENOENT)
> > *ret_flags |= FL_NOENT;
> > } else if (S_ISDIR(st.st_mode)) {
> > - last_slash_dir = last_slash;
> > - continue;
> > + struct stat junk;
> > + struct strbuf gitdir = STRBUF_INIT;
> > + strbuf_add(&gitdir, cache->path, match_len);
> > + strbuf_addstr(&gitdir, "/.git");
> > + if (lstat(gitdir.buf, &junk) < 0) {
> > + if (errno == ENOENT) {
> > + last_slash_dir = last_slash;
> > + strbuf_release(&gitdir);
> > + continue;
> > + }
> > + *ret_flags = FL_LSTATERR;
> > + }
> > + else
> > + *ret_flags = FL_GITREPO;
>
> This only checks "does the directory have .git in it?".
Yeah. I was trying to keep the test as inexpensive as possible, since
this is a very frequently called codepath. But really, doing a more
elaborate test shouldn't matter. The common case will be that the stat
fails, and we do nothing else.
I do worry about adding an extra lstat for each directory having
noticeable overhead. Maybe it doesn't matter because of the stat
caching, but I didn't measure.
> It probably is sufficient, but setup.c:is_git_directory() may do a more
> appropriate check, I think. That ".git" thing could be a regular file
> (i.e. "gitdir: path"), so depending on the junk.st_mode, you may have to
> call read_gitfile_gently() on it before checking with is_git_directory().
I worry a little about the PATH_MAX check and die in is_git_directory. I
would hate for a deep hierarchy to start failing because of this extra
check. OTOH, it is only 5 extra characters to append ".git", so it is
unlikely that a path was that close to PATH_MAX but not exceeding it.
Similarly, read_gitfile_gently is anything but gentle. It die()s if we
can't open the '.git' file or it is in an invalid format, which would be
a regression here.
-Peff
next prev parent reply other threads:[~2011-04-08 19:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-05 23:18 Bug Report: git add Darren Cook
2011-04-06 5:52 ` Ramkumar Ramachandra
2011-04-10 7:48 ` Jakub Narebski
2011-04-10 8:29 ` Ramkumar Ramachandra
2011-04-11 17:55 ` Junio C Hamano
2011-04-11 18:20 ` Jeff King
2011-04-07 0:57 ` Jeff King
2011-04-07 1:09 ` Junio C Hamano
2011-04-07 1:12 ` Jeff King
2011-04-07 1:48 ` Jeff King
2011-04-07 7:28 ` Junio C Hamano
2011-04-08 19:15 ` Jeff King [this message]
2011-04-08 19:46 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110408191554.GA6516@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=darren@dcook.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).