Optimize sha1_object_info for loose objects, not concurrent repacks
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> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Steven Grimm committed
Aug 5, 2008 at 13:08 UTC
ddd63e64e4ac7e455dff3e807bf6a6977bb61456
1 file changed
+8
-1
sha1_file.c
+8
-1
@@ -1929,11 +1929,18 @@ static int sha1_loose_object_info(const unsigned char *sha1, unsigned long *size
1929
int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
1930
{
1931
struct pack_entry e;
1932
+ int status;
1933
1934
if (!find_pack_entry(sha1, &e, NULL)) {
1935
+ /* Most likely it's a loose object. */
1936
+ status = sha1_loose_object_info(sha1, sizep);
1937
+ if (status >= 0)
1938
+ return status;
1939
+
1940
+ /* Not a loose object; someone else may have just packed it. */
1941
reprepare_packed_git();
1942
if (!find_pack_entry(sha1, &e, NULL))
1936
- return sha1_loose_object_info(sha1, sizep);
1943
+ return status;
1944
}
1945
return packed_object_info(e.p, e.offset, sizep);
1946
}