summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2017-06-22 00:40:23 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-26 17:28:58 (GMT)
commitcd585e2a33841d725b821adbb9b48654fc7d0b61 (patch)
tree60982a4e7d9dfe0828792f326ed0a9684f4810df /sha1_file.c
parentdfdd4afcf97b0199f44231e726e373934da77717 (diff)
downloadgit-cd585e2a33841d725b821adbb9b48654fc7d0b61.zip
git-cd585e2a33841d725b821adbb9b48654fc7d0b61.tar.gz
git-cd585e2a33841d725b821adbb9b48654fc7d0b61.tar.bz2
sha1_file: do not access pack if unneeded
Currently, regardless of the contents of the "struct object_info" passed to sha1_object_info_extended(), that function always accesses the packfile whenever it returns information about a packed object, since it needs to populate "u.packed". Add the ability to pass NULL, and use NULL-ness of the argument to activate an optimization in which sha1_object_info_extended() does not needlessly access the packfile. A subsequent patch will make use of this optimization. A similar optimization is not made for the cached and loose cases as it would not cause a significant performance improvement. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index b6bc02f..bf6b64e 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2977,12 +2977,16 @@ static int sha1_loose_object_info(const unsigned char *sha1,
int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags)
{
+ static struct object_info blank_oi = OBJECT_INFO_INIT;
struct pack_entry e;
int rtype;
const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
lookup_replace_object(sha1) :
sha1;
+ if (!oi)
+ oi = &blank_oi;
+
if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
struct cached_object *co = find_cached_object(real);
if (co) {
@@ -3020,6 +3024,13 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
}
}
+ if (oi == &blank_oi)
+ /*
+ * We know that the caller doesn't actually need the
+ * information below, so return early.
+ */
+ return 0;
+
rtype = packed_object_info(e.p, e.offset, oi);
if (rtype < 0) {
mark_bad_packed_object(e.p, real);