[PATCH 1/3] sha1_object_info(): pay attention to cached objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We have some hardcoded objects (e.g. "empty tree") and also an interface
to pretend we have objects in-core without ever writing them out to the
disk.  read_sha1_file() are aware of these cached objects.  However,
some codepaths use sha1_object_info() to find out the availability and
size of the object without reading the object data, without using
read_sha1_file().

This teaches sha1_object_info() about these cached objects.

Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
---
 sha1_file.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 2aff59b..d9e342e 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1926,10 +1926,25 @@ static int sha1_loose_object_info(const unsigned char *sha1, unsigned long *size
 	return status;
 }
 
+struct cached_object {
+	unsigned char sha1[20];
+	enum object_type type;
+	void *buf;
+	unsigned long size;
+};
+static struct cached_object *find_cached_object(const unsigned char *sha1);
+
 int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
 {
 	struct pack_entry e;
 	int status;
+	struct cached_object *co;
+
+	co = find_cached_object(sha1);
+	if (co) {
+		*sizep = co->size;
+		return co->type;
+	}
 
 	if (!find_pack_entry(sha1, &e, NULL)) {
 		/* Most likely it's a loose object. */
@@ -1975,12 +1990,7 @@ static void *read_packed_sha1(const unsigned char *sha1,
  * to write them into the object store (e.g. a browse-only
  * application).
  */
-static struct cached_object {
-	unsigned char sha1[20];
-	enum object_type type;
-	void *buf;
-	unsigned long size;
-} *cached_objects;
+static struct cached_object *cached_objects;
 static int cached_object_nr, cached_object_alloc;
 
 static struct cached_object empty_tree = {
-- 
1.6.0.51.g078ae

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux