git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: index-pack outside of repository?
Date: Fri, 16 Dec 2016 13:55:34 -0800	[thread overview]
Message-ID: <xmqqh963r12h.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20161216214322.xibllaw2iibhc5nv@sigill.intra.peff.net> (Jeff King's message of "Fri, 16 Dec 2016 16:43:22 -0500")

Jeff King <peff@peff.net> writes:

> Ah, I only checked that it did not do anything terrible like write into
> ".git". But it looks like it still looks at the git_dir value as part of
> the collision check.
>
> Here's a patch, on top of the rest of the series.

Thanks for a quick turnaround, as always.

> -- >8 --
> Subject: [PATCH] index-pack: skip collision check when not in repository
>
> You can run "git index-pack path/to/foo.pack" outside of a
> repository to generate an index file, or just to verify the
> contents. There's no point in doing a collision check, since
> we obviously do not have any objects to collide with.
>
> The current code will blindly look in .git/objects based on
> the result of setup_git_env(). That effectively gives us the
> right answer (since we won't find any objects), but it's a
> waste of time, and it conflicts with our desire to
> eventually get rid of the "fallback to .git" behavior of
> setup_git_env().
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> I didn't do a test, as this doesn't really have any user-visible
> behavior change.
>
> I guess technically if you had a non-repo with
> ".git/objects/12/3456..." in it we would erroneously read it, but that's
> kind of bizarre. The interesting test is that when merged with
> jk/no-looking-at-dotgit-outside-repo-final, the test in t5300 doesn't
> die.

Yes.

>
>  builtin/index-pack.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/builtin/index-pack.c b/builtin/index-pack.c
> index d450a6ada2..f4b87c6c9f 100644
> --- a/builtin/index-pack.c
> +++ b/builtin/index-pack.c
> @@ -787,13 +787,15 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
>  			const unsigned char *sha1)
>  {
>  	void *new_data = NULL;
> -	int collision_test_needed;
> +	int collision_test_needed = 0;
>  
>  	assert(data || obj_entry);
>  
> -	read_lock();
> -	collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
> -	read_unlock();
> +	if (startup_info->have_repository) {
> +		read_lock();
> +		collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
> +		read_unlock();
> +	}
>  
>  	if (collision_test_needed && !data) {
>  		read_lock();

  reply	other threads:[~2016-12-16 21:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-15 20:40 index-pack outside of repository? Jeff King
2016-12-16  0:13 ` Junio C Hamano
2016-12-16  1:37   ` Jeff King
2016-12-16  2:29     ` Jeff King
2016-12-16  2:30       ` [PATCH 1/3] t5000: extract nongit function to test-lib-functions.sh Jeff King
2016-12-16  2:30       ` [PATCH 2/3] index-pack: complain when --stdin is used outside of a repo Jeff King
2016-12-16  2:31       ` [PATCH 3/3] t: use nongit() function where applicable Jeff King
2016-12-16 17:52       ` index-pack outside of repository? Junio C Hamano
2016-12-16 17:59         ` Junio C Hamano
2016-12-16 18:01           ` Junio C Hamano
2016-12-16 21:43             ` Jeff King
2016-12-16 21:55               ` Junio C Hamano [this message]
2016-12-16 18:54   ` Junio C Hamano
2016-12-16 21:44     ` 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=xmqqh963r12h.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.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.
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).