git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jonathan Nieder <jrnieder@gmail.com>,
	Richard Purdie <richard.purdie@linuxfoundation.org>,
	GIT Mailing-list <git@vger.kernel.org>,
	"Hart, Darren" <darren.hart@intel.com>,
	"Ashfield, Bruce" <Bruce.Ashfield@windriver.com>
Subject: Re: Alternates corruption issue
Date: Fri, 3 Feb 2012 07:02:15 -0500	[thread overview]
Message-ID: <20120203120215.GA31441@sigill.intra.peff.net> (raw)
In-Reply-To: <7vzkd0u4ik.fsf@alter.siamese.dyndns.org>

On Thu, Feb 02, 2012 at 04:47:31PM -0800, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > @@ -324,8 +324,11 @@ const char *enter_repo(const char *path, int strict)
> >  			return NULL;
> >  		len = strlen(used_path);
> >  		for (i = 0; suffix[i]; i++) {
> > +			struct stat st;
> >  			strcpy(used_path + len, suffix[i]);
> > -			if (!access(used_path, F_OK)) {
> > +			if (!stat(used_path, &st) &&
> > +			    (S_ISREG(st.st_mode) ||
> > +			    (S_ISDIR(st.st_mode) && is_git_directory(used_path)))) {
> 
> Hmm, how would this change interact with
> 
> >  				strcat(validated_path, suffix[i]);
> >  				break;
> >  			}
> 
> 	gitfile = read_gitfile(used_path);
> 
> that appear after the context in the patch?

It assumes that any file named ".git" is worth reading and selecting.
And then later we actually read_gitfile to find out if it's worth-while.
There is no change of behavior from before the patch, as we would
similarly notice the file (without checking if it's a real gitfile) and
then later read it and possibly fail.

However, with the ordering change, there is a technically a regression
in one case: a random file "foo" next to a repo "foo.git". Saying "git
ls-remote foo" used to prefer "foo.git", and will now select the file
"foo" only to fail.

The code-path in clone's get_repo_path handles this properly (it checks
that the path is really a valid gitfile before finishing the loop). The
gitfile-reading from later in enter_repo could be hoisted into the loop.
If was trying to make a less-invasive change; if we're going to do that
much rewriting, it probably makes sense to factor out the logic from
get_repo_path and have them share the code.

Thanks for noticing. I saw this issue when I was writing the original
version of the patch, and meant to revisit it and at least document it
in the commit message, but I ended up forgetting.

-Peff

  reply	other threads:[~2012-02-03 12:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-31 14:05 Alternates corruption issue Richard Purdie
2012-01-31 19:39 ` Jeff King
2012-01-31 20:25   ` Junio C Hamano
2012-01-31 20:44     ` Jeff King
2012-01-31 21:40       ` Jonathan Nieder
2012-01-31 21:47         ` Jeff King
2012-01-31 21:55           ` Jonathan Nieder
2012-01-31 22:05             ` Jeff King
2012-01-31 22:22               ` Jonathan Nieder
2012-01-31 22:42                 ` Jeff King
2012-01-31 22:59                   ` Jonathan Nieder
2012-02-02 21:59                 ` Jeff King
2012-02-03  0:47                   ` Junio C Hamano
2012-02-03 12:02                     ` Jeff King [this message]
2012-02-03 17:38                       ` Junio C Hamano
2012-02-03 21:29                         ` Jeff King
2012-02-03 21:51                           ` Junio C Hamano
2012-02-03 21:53                             ` Jeff King
2012-02-03 14:40                   ` Richard Purdie

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=20120203120215.GA31441@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Bruce.Ashfield@windriver.com \
    --cc=darren.hart@intel.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=richard.purdie@linuxfoundation.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).