git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 6/8] fast-import: cache oe in load_tree

From
Dmitry Ivankov <divanorama@gmail.com>
Date
Sep 19, 2011, 01:27 UTC
Message-ID
<1316395657-6991-7-git-send-email-divanorama@gmail.com>
In-Reply-To
<1316395657-6991-1-git-send-email-divanorama@gmail.com>

load_tree reads a tree object given it's sha1. If there was no struct object_entry allocated for this sha1, load_tree doesn't allocate it and thus doesn't cache it's struct object_entry.

Make this read_sha1_file cached in struct object_entry.
Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
---
 fast-import.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index dd3dcd5..1c0716b 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -599,6 +599,17 @@ static void resolve_sha1_object(struct object_entry *oe)
 	oe->idx.offset = 1; /* nonzero */
 }
 
+static void *resolve_sha1_object_read(struct object_entry *oe, enum object_type *type, unsigned long *size)
+{
+	void *ret = read_sha1_file(oe->idx.sha1, type, size);
+	if (!ret)
+		return ret;
+	oe->type = *type;
+	oe->pack_id = MAX_PACK_ID;
+	oe->idx.offset = 1; /* nonzero */
+	return ret;
+}
+
 static int try_resolve_sha1_pack_object(struct object_entry *e,
 						enum object_type type)
 {
@@ -1363,8 +1374,8 @@ static void load_tree(struct tree_entry *root)
 	if (is_null_sha1(sha1))
 		return;
 
-	myoe = find_object(sha1);
-	if (myoe && myoe->pack_id != MAX_PACK_ID) {
+	myoe = insert_object(sha1);
+	if (myoe->idx.offset && myoe->pack_id != MAX_PACK_ID) {
 		if (myoe->type != OBJ_TREE)
 			die("Not a tree: %s", sha1_to_hex(sha1));
 		t->delta_depth = myoe->depth;
@@ -1373,7 +1384,10 @@ static void load_tree(struct tree_entry *root)
 			die("Can't load tree %s", sha1_to_hex(sha1));
 	} else {
 		enum object_type type;
-		buf = read_sha1_file(sha1, &type, &size);
+		if (!myoe->idx.offset)
+			buf = resolve_sha1_object_read(myoe, &type, &size);
+		else
+			buf = read_sha1_file(sha1, &type, &size);
 		if (!buf || type != OBJ_TREE)
 			die("Can't load tree %s", sha1_to_hex(sha1));
 	}
-- 
1.7.3.4
Previous: Dmitry IvankovNext: Dmitry Ivankov
Message 7 of 13 in “fast-import: cache oe more often”
  1. 0/8 fast-import: cache oe more oftenDmitry Ivankov, Sep 19, 2011
  2. 1/8 fast-import: cache oe in file_change_mDmitry Ivankov, Sep 19, 2011
  3. 2/8 fast-import: cache oe in parse_new_tagDmitry Ivankov, Sep 19, 2011
  4. 3/8 fast-import: cache oe in note_change_nDmitry Ivankov, Sep 19, 2011
  5. 4/8 fast-import: extract common sha1_file access functionsDmitry Ivankov, Sep 19, 2011
  6. 5/8 fast-import: tiny optimization in read_marksDmitry Ivankov, Sep 19, 2011
  7. 6/8 fast-import: cache oe in load_treeDmitry Ivankov, Sep 19, 2011
  8. 7/8 fast-import: cache oe in cat_blobDmitry Ivankov, Sep 19, 2011
  9. 8/8 fast-import: cache objects while dereferencingDmitry Ivankov, Sep 19, 2011
  10. Junio C HamanoSep 20, 2011
  11. Jonathan NiederSep 20, 2011
  12. Dmitry IvankovSep 20, 2011
  13. Jonathan NiederSep 20, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.