Re: Bug Report: git add

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 07, 2011 at 12:28:26AM -0700, Junio C Hamano wrote:

> Jeff King <peff@xxxxxxxx> 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
--
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


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]