git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Steven Grimm <koreth@midwinter.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Optimize sha1_object_info for loose objects, not concurrent repacks
Date: Tue, 5 Aug 2008 13:18:53 -0700	[thread overview]
Message-ID: <20080805201853.GG27207@spearce.org> (raw)
In-Reply-To: <20080805200841.GA23121@midwinter.com>

Steven Grimm <koreth@midwinter.com> wrote:
> When dealing with a repository with lots of loose objects, sha1_object_info
> would rescan the packs directory every time an unpacked object was referenced
> before finally giving up and looking for the loose object. This caused a lot
> of extra unnecessary system calls during git pack-objects; the code was
> rereading the entire pack directory once for each loose object file.
> 
> This patch looks for a loose object before falling back to rescanning the
> pack directory, rather than the other way around.
> 
> Signed-off-by: Steven Grimm <koreth@midwinter.com>

Heh.  Cute bug.

ACK.

> diff --git a/sha1_file.c b/sha1_file.c
> index e281c14..32e4664 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -1929,11 +1929,18 @@ static int sha1_loose_object_info(const unsigned char *sha1, unsigned long *size
>  int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
>  {
>  	struct pack_entry e;
> +	int status;
>  
>  	if (!find_pack_entry(sha1, &e, NULL)) {
> +		/* Most likely it's a loose object. */
> +		status = sha1_loose_object_info(sha1, sizep);
> +		if (status >= 0)
> +			return status;
> +
> +		/* Not a loose object; someone else may have just packed it. */
>  		reprepare_packed_git();
>  		if (!find_pack_entry(sha1, &e, NULL))
> -			return sha1_loose_object_info(sha1, sizep);
> +			return status;
>  	}
>  	return packed_object_info(e.p, e.offset, sizep);
>  }

-- 
Shawn.

      reply	other threads:[~2008-08-05 20:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-05 20:08 [PATCH] Optimize sha1_object_info for loose objects, not concurrent repacks Steven Grimm
2008-08-05 20:18 ` Shawn O. Pearce [this message]

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=20080805201853.GG27207@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=koreth@midwinter.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.
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).