git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Optimize sha1_object_info for loose objects, not concurrent repacks

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 5, 2008, 20:18 UTC
Message-ID
<20080805201853.GG27207@spearce.org>
In-Reply-To
<20080805200841.GA23121@midwinter.com>
Steven Grimm <koreth@midwinter.com> wrote:
Show 10 quoted lines
> 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.
Show 24 quoted lines
> 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.
Previous: Steven Grimm
Message 2 of 2 in “Optimize sha1_object_info for loose objects, not concurrent repacks”
  1. Optimize sha1_object_info for loose objects, not concurrent repacksSteven Grimm, Aug 5, 2008
  2. Shawn O. PearceAug 5, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.