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

[PATCH 3/5] packfile: convert mark_bad_packed_object() to object_id

From
René Scharfe <l.s.r@web.de>
Date
Sep 11, 2021, 20:40 UTC
Message-ID
<a6d7114f-08c1-567a-d8d4-40becd2384f6@web.de>
In-Reply-To
<e50c1465-59de-7fe1-de01-800404c7640e@web.de>

All callers have full object IDs, so pass them on instead of just their hash member.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 object-file.c |  2 +-
 packfile.c    | 12 ++++++------
 packfile.h    |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/object-file.c b/object-file.c
index a8be899481..fb5a385a06 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1616,7 +1616,7 @@ static int do_oid_object_info_extended(struct repository *r,
 		return 0;
 	rtype = packed_object_info(r, e.p, e.offset, oi);
 	if (rtype < 0) {
-		mark_bad_packed_object(e.p, real->hash);
+		mark_bad_packed_object(e.p, real);
 		return do_oid_object_info_extended(r, real, oi, 0);
 	} else if (oi->whence == OI_PACKED) {
 		oi->u.packed.offset = e.offset;
diff --git a/packfile.c b/packfile.c
index 4d0d625238..fb15fc5b49 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1161,17 +1161,17 @@ int unpack_object_header(struct packed_git *p,
 	return type;
 }

-void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)
+void mark_bad_packed_object(struct packed_git *p, const struct object_id *oid)
 {
 	unsigned i;
 	const unsigned hashsz = the_hash_algo->rawsz;
 	for (i = 0; i < p->num_bad_objects; i++)
-		if (hasheq(sha1, p->bad_object_sha1 + hashsz * i))
+		if (hasheq(oid->hash, p->bad_object_sha1 + hashsz * i))
 			return;
 	p->bad_object_sha1 = xrealloc(p->bad_object_sha1,
 				      st_mult(GIT_MAX_RAWSZ,
 					      st_add(p->num_bad_objects, 1)));
-	hashcpy(p->bad_object_sha1 + hashsz * p->num_bad_objects, sha1);
+	hashcpy(p->bad_object_sha1 + hashsz * p->num_bad_objects, oid->hash);
 	p->num_bad_objects++;
 }

@@ -1272,7 +1272,7 @@ static int retry_bad_packed_offset(struct repository *r,
 	if (offset_to_pack_pos(p, obj_offset, &pos) < 0)
 		return OBJ_BAD;
 	nth_packed_object_id(&oid, p, pack_pos_to_index(p, pos));
-	mark_bad_packed_object(p, oid.hash);
+	mark_bad_packed_object(p, &oid);
 	type = oid_object_info(r, &oid, NULL);
 	if (type <= OBJ_NONE)
 		return OBJ_BAD;
@@ -1722,7 +1722,7 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
 				nth_packed_object_id(&oid, p, index_pos);
 				error("bad packed object CRC for %s",
 				      oid_to_hex(&oid));
-				mark_bad_packed_object(p, oid.hash);
+				mark_bad_packed_object(p, &oid);
 				data = NULL;
 				goto out;
 			}
@@ -1811,7 +1811,7 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
 				      " at offset %"PRIuMAX" from %s",
 				      oid_to_hex(&base_oid), (uintmax_t)obj_offset,
 				      p->pack_name);
-				mark_bad_packed_object(p, base_oid.hash);
+				mark_bad_packed_object(p, &base_oid);
 				base = read_object(r, &base_oid, &type, &base_size);
 				external_base = base;
 			}
diff --git a/packfile.h b/packfile.h
index 3ae117a8ae..a982ed9994 100644
--- a/packfile.h
+++ b/packfile.h
@@ -159,7 +159,7 @@ int packed_object_info(struct repository *r,
 		       struct packed_git *pack,
 		       off_t offset, struct object_info *);

-void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
+void mark_bad_packed_object(struct packed_git *, const struct object_id *);
 const struct packed_git *has_packed_and_bad(struct repository *r, const unsigned char *sha1);

 #define ON_DISK_KEEP_PACKS 1
--
2.33.0
Previous: René ScharfeNext: René Scharfe
Message 19 of 28 in “packfile: use oidset for bad objects”
  1. 0/3 packfile: use oidset for bad objectsRené Scharfe, Sep 11, 2021
  2. 1/3 packfile: convert mark_bad_packed_object() to object_idRené Scharfe, Sep 11, 2021
  3. 2/3 packfile: convert has_packed_and_bad() to object_idRené Scharfe, Sep 11, 2021
  4. 3/3 packfile: use oidset for bad objectsRené Scharfe, Sep 11, 2021
  5. Jeff KingSep 11, 2021
  6. René ScharfeSep 11, 2021
  7. Jeff KingSep 11, 2021
  8. René ScharfeSep 11, 2021
  9. Jeff KingSep 11, 2021
  10. 4/3 midx: inline nth_midxed_pack_entry()René Scharfe, Sep 11, 2021
  11. René ScharfeSep 11, 2021
  12. Jeff KingSep 11, 2021
  13. René ScharfeSep 11, 2021
  14. Jeff KingSep 11, 2021
  15. René ScharfeSep 11, 2021
  16. 0/5 packfile: use oidset for bad objectsRené Scharfe, Sep 11, 2021
  17. 1/5 oidset: make oidset_size() an inline functionRené Scharfe, Sep 11, 2021
  18. 2/5 midx: inline nth_midxed_pack_entry()René Scharfe, Sep 11, 2021
  19. 3/5 packfile: convert mark_bad_packed_object() to object_idRené Scharfe, Sep 11, 2021
  20. 4/5 packfile: convert has_packed_and_bad() to object_idRené Scharfe, Sep 11, 2021
  21. 5/5 packfile: use oidset for bad objectsRené Scharfe, Sep 11, 2021
  22. René ScharfeSep 11, 2021
  23. Jeff KingSep 11, 2021
  24. Derrick StoleeSep 11, 2021
  25. Taylor BlauSep 12, 2021
  26. Taylor BlauSep 12, 2021
  27. Derrick StoleeSep 12, 2021
  28. Taylor BlauSep 12, 2021

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.