sha1_file: freshen pack objects before loose
authorJeff King <peff@peff.net>
Mon, 20 Apr 2015 19:54:03 +0000 (15:54 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Apr 2015 20:09:38 +0000 (13:09 -0700)
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 <ssaasen@atlassian.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_file.c
index 9711ef817d7cee1c78ed82fa5f53c71eab235a23..cd6c102ccfdcc43e29ead7a07300d5ae18fca2ab 100644 (file)
@@ -3014,7 +3014,7 @@ int write_sha1_file(const void *buf, unsigned long len, const char *type, unsign
        write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
        if (returnsha1)
                hashcpy(returnsha1, sha1);
-       if (freshen_loose_object(sha1) || freshen_packed_object(sha1))
+       if (freshen_packed_object(sha1) || freshen_loose_object(sha1))
                return 0;
        return write_loose_object(sha1, hdr, hdrlen, buf, len, 0);
 }