Skip to content

Commit b5f52f3

Browse files
peffgitster
authored andcommitted
sha1_file: freshen pack objects before loose
When writing out an object file, we first check whether it already exists and if so optimize out the write. Prior to 33d4221, we did this by calling has_sha1_file(), which will check for packed objects followed by loose. Since that commit, we check loose objects first. For the common case of a repository whose objects are mostly packed, this means we will make a lot of extra access() system calls checking for loose objects. We should follow the same packed-then-loose order that all of our other lookups use. Reported-by: Stefan Saasen <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1385bb7 commit b5f52f3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sha1_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3014,7 +3014,7 @@ int write_sha1_file(const void *buf, unsigned long len, const char *type, unsign
30143014
write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
30153015
if (returnsha1)
30163016
hashcpy(returnsha1, sha1);
3017-
if (freshen_loose_object(sha1) || freshen_packed_object(sha1))
3017+
if (freshen_packed_object(sha1) || freshen_loose_object(sha1))
30183018
return 0;
30193019
return write_loose_object(sha1, hdr, hdrlen, buf, len, 0);
30203020
}

0 commit comments

Comments
 (0)