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

[PATCH 09/10] packed_object_info(): use object_id internally for delta base

From
Jeff King <peff@peff.net>
Date
Feb 24, 2020, 04:37 UTC
Message-ID
<20200224043731.GI1018190@coredump.intra.peff.net>
In-Reply-To
<20200224042625.GA1015553@coredump.intra.peff.net>

The previous commit changed the public interface of packed_object_info() to return a struct object_id rather than a bare hash. That enables us to convert our internal helper, as well. We can use nth_packed_object_id() directly for OFS_DELTA, but we'll still have to use oidread() to pull the hash for a REF_DELTA out of the packfile.

There should be no additional cost, since we're copying directly into the object_id the caller provided us (just as we did before; it's just happening now via nth_packed_object_id()).

Signed-off-by: Jeff King <peff@peff.net>
---
 packfile.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/packfile.c b/packfile.c
index ec7349bb86..90cb5a05ac 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1225,30 +1225,32 @@ off_t get_delta_base(struct packed_git *p,
  * the final object lookup), but more expensive for OFS deltas (we
  * have to load the revidx to convert the offset back into a sha1).
  */
-static const unsigned char *get_delta_base_sha1(struct packed_git *p,
-						struct pack_window **w_curs,
-						off_t curpos,
-						enum object_type type,
-						off_t delta_obj_offset)
+static int get_delta_base_oid(struct packed_git *p,
+			      struct pack_window **w_curs,
+			      off_t curpos,
+			      struct object_id *oid,
+			      enum object_type type,
+			      off_t delta_obj_offset)
 {
 	if (type == OBJ_REF_DELTA) {
 		unsigned char *base = use_pack(p, w_curs, curpos, NULL);
-		return base;
+		oidread(oid, base);
+		return 0;
 	} else if (type == OBJ_OFS_DELTA) {
 		struct revindex_entry *revidx;
 		off_t base_offset = get_delta_base(p, w_curs, &curpos,
 						   type, delta_obj_offset);
 
 		if (!base_offset)
-			return NULL;
+			return -1;
 
 		revidx = find_pack_revindex(p, base_offset);
 		if (!revidx)
-			return NULL;
+			return -1;
 
-		return nth_packed_object_sha1(p, revidx->nr);
+		return nth_packed_object_id(oid, p, revidx->nr);
 	} else
-		return NULL;
+		return -1;
 }
 
 static int retry_bad_packed_offset(struct repository *r,
@@ -1558,16 +1560,12 @@ int packed_object_info(struct repository *r, struct packed_git *p,
 
 	if (oi->delta_base_oid) {
 		if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
-			const unsigned char *base;
-
-			base = get_delta_base_sha1(p, &w_curs, curpos,
-						   type, obj_offset);
-			if (!base) {
+			if (get_delta_base_oid(p, &w_curs, curpos,
+					       oi->delta_base_oid,
+					       type, obj_offset) < 0) {
 				type = OBJ_BAD;
 				goto out;
 			}
-
-			hashcpy(oi->delta_base_oid->hash, base);
 		} else
 			oidclr(oi->delta_base_oid);
 	}
-- 
2.25.1.823.g95c5488cf7
Previous: Jeff KingNext: Jeff King
Message 12 of 14 in “removing nth_packed_object_sha1()”
  1. 0/10 removing nth_packed_object_sha1()Jeff King, Feb 24, 2020
  2. 01/10 nth_packed_object_oid(): use customary integer returnJeff King, Feb 24, 2020
  3. Jeff KingFeb 24, 2020
  4. 02/10 pack-objects: read delta base oid into object_id structJeff King, Feb 24, 2020
  5. brian m. carlsonFeb 25, 2020
  6. 03/10 pack-objects: convert oe_set_delta_ext() to use object_idJeff King, Feb 24, 2020
  7. 04/10 pack-objects: use object_id struct in pack-reuse codeJeff King, Feb 24, 2020
  8. 05/10 pack-bitmap: use object_id when loading on-disk bitmapsJeff King, Feb 24, 2020
  9. 06/10 pack-check: convert "internal error" die to a BUG()Jeff King, Feb 24, 2020
  10. 07/10 pack-check: push oid lookup into loopJeff King, Feb 24, 2020
  11. 08/10 packed_object_info(): use object_id for returning delta baseJeff King, Feb 24, 2020
  12. 09/10 packed_object_info(): use object_id internally for delta baseJeff King, Feb 24, 2020
  13. 10/10 packfile: drop nth_packed_object_sha1()Jeff King, Feb 24, 2020
  14. brian m. carlsonFeb 25, 2020

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.