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

[PATCH 8/8] fast-import: cache objects while dereferencing

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

dereference() reads objects with read_sha1_file, and reads types of objects with sha1_object_info. But doesn't cache the result in struct object_entry.

Make these calls to read_sha1_file and sha1_object_info cached in struct object_entry.

Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
---
 fast-import.c |   31 +++++++++++++++++--------------
 1 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 3c4c998..43158c8 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2891,15 +2891,11 @@ static void parse_cat_blob(void)
 	cat_blob(oe);
 }
 
-static struct object_entry *dereference(struct object_entry *oe,
-					unsigned char sha1[20])
+static struct object_entry *dereference(struct object_entry *oe)
 {
+	unsigned char next_sha1[20];
 	unsigned long size;
 	char *buf = NULL;
-	if (!oe) {
-		oe = insert_object(sha1);
-		resolve_sha1_object(oe);
-	}
 	switch (oe->type) {
 	case OBJ_TREE:	/* easy case. */
 		return oe;
@@ -2914,26 +2910,31 @@ static struct object_entry *dereference(struct object_entry *oe,
 		buf = gfi_unpack_entry(oe, &size);
 	} else {
 		enum object_type unused;
-		buf = read_sha1_file(sha1, &unused, &size);
+		buf = read_sha1_file(oe->idx.sha1, &unused, &size);
 	}
 	if (!buf)
-		die("Can't load object %s", sha1_to_hex(sha1));
+		die("Can't load object %s", sha1_to_hex(oe->idx.sha1));
 
 	/* Peel one layer. */
 	switch (oe->type) {
 	case OBJ_TAG:
 		if (size < 40 + strlen("object ") ||
-		    get_sha1_hex(buf + strlen("object "), sha1))
+		    get_sha1_hex(buf + strlen("object "), next_sha1))
 			die("Invalid SHA1 in tag: %s", command_buf.buf);
 		break;
 	case OBJ_COMMIT:
 		if (size < 40 + strlen("tree ") ||
-		    get_sha1_hex(buf + strlen("tree "), sha1))
+		    get_sha1_hex(buf + strlen("tree "), next_sha1))
 			die("Invalid SHA1 in commit: %s", command_buf.buf);
 	}
 
 	free(buf);
-	return find_object(sha1);
+
+	oe = insert_object(next_sha1);
+	if (!oe->idx.offset)
+		resolve_sha1_object(oe);
+
+	return oe;
 }
 
 static struct object_entry *parse_treeish_dataref(const char **p)
@@ -2953,12 +2954,14 @@ static struct object_entry *parse_treeish_dataref(const char **p)
 	} else {	/* <sha1> */
 		if (get_sha1_hex(*p, sha1))
 			die("Invalid SHA1: %s", command_buf.buf);
-		e = find_object(sha1);
+		e = insert_object(sha1);
+		if (!e->idx.offset)
+			resolve_sha1_object(e);
 		*p += 40;
 	}
 
-	while (!e || e->type != OBJ_TREE)
-		e = dereference(e, sha1);
+	while (e->type != OBJ_TREE)
+		e = dereference(e);
 	return e;
 }
 
-- 
1.7.3.4
Previous: Dmitry IvankovNext: Junio C Hamano
Message 9 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.