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

[PATCH 2/6] pack-objects: use object_id in packlist_alloc()

From
Jeff King <peff@peff.net>
Date
Sep 5, 2019, 22:52 UTC
Message-ID
<20190905225224.GB25657@sigill.intra.peff.net>
In-Reply-To
<20190905224859.GA28660@sigill.intra.peff.net>

The only caller of packlist_alloc() already has a "struct object_id", and we immediately copy the hash they pass us into our own object_id. Let's avoid the unnecessary round-trip to a raw sha1 pointer.

Signed-off-by: Jeff King <peff@peff.net>
---
Just noticed since I was touching that function.

This is the second-to-last raw sha1 in pack-objects.c. The final one is slightly tricky to get rid of, because it comes from the raw base_ref pointer we parse out of the packfile's mmap. I left it out of this series, but I wouldn't mind if somebody wants to take a stab at it.

 builtin/pack-objects.c | 2 +-
 pack-objects.c         | 4 ++--
 pack-objects.h         | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 76ce906946..dc2a7e9ac0 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1147,7 +1147,7 @@ static void create_object_entry(const struct object_id *oid,
 {
 	struct object_entry *entry;
 
-	entry = packlist_alloc(&to_pack, oid->hash, index_pos);
+	entry = packlist_alloc(&to_pack, oid, index_pos);
 	entry->hash = hash;
 	oe_set_type(entry, type);
 	if (exclude)
diff --git a/pack-objects.c b/pack-objects.c
index 52560293b6..c1df08df1a 100644
--- a/pack-objects.c
+++ b/pack-objects.c
@@ -153,7 +153,7 @@ void prepare_packing_data(struct repository *r, struct packing_data *pdata)
 }
 
 struct object_entry *packlist_alloc(struct packing_data *pdata,
-				    const unsigned char *sha1,
+				    const struct object_id *oid,
 				    uint32_t index_pos)
 {
 	struct object_entry *new_entry;
@@ -177,7 +177,7 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
 	new_entry = pdata->objects + pdata->nr_objects++;
 
 	memset(new_entry, 0, sizeof(*new_entry));
-	hashcpy(new_entry->idx.oid.hash, sha1);
+	oidcpy(&new_entry->idx.oid, oid);
 
 	if (pdata->index_size * 3 <= pdata->nr_objects * 4)
 		rehash_objects(pdata);
diff --git a/pack-objects.h b/pack-objects.h
index 857d43850b..47bf7ebf86 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -183,7 +183,7 @@ static inline void packing_data_unlock(struct packing_data *pdata)
 }
 
 struct object_entry *packlist_alloc(struct packing_data *pdata,
-				    const unsigned char *sha1,
+				    const struct object_id *oid,
 				    uint32_t index_pos);
 
 struct object_entry *packlist_find(struct packing_data *pdata,
-- 
2.23.0.463.g883b23b1c5
Previous: Jeff KingNext: Jeff King
Message 14 of 23 in “Fix maybe-uninitialized warnings found by gcc 9 -flto”
  1. Fix maybe-uninitialized warnings found by gcc 9 -fltoStephan Beyer, Sep 5, 2019
  2. René ScharfeSep 5, 2019
  3. Jeff KingSep 5, 2019
  4. René ScharfeSep 5, 2019
  5. Junio C HamanoSep 5, 2019
  6. René ScharfeSep 5, 2019
  7. Junio C HamanoSep 5, 2019
  8. Junio C HamanoSep 5, 2019
  9. Junio C HamanoSep 5, 2019
  10. Jeff KingSep 5, 2019
  11. Junio C HamanoSep 5, 2019
  12. Jeff KingSep 5, 2019
  13. 1/6 git-am: handle missing "author" when parsing commitJeff King, Sep 5, 2019
  14. 2/6 pack-objects: use object_id in packlist_alloc()Jeff King, Sep 5, 2019
  15. 3/6 bulk-checkin: zero-initialize hashfile_checkpointJeff King, Sep 5, 2019
  16. 4/6 diff-delta: set size out-parameter to 0 for NULL deltaJeff King, Sep 5, 2019
  17. Stephan BeyerSep 5, 2019
  18. Jeff KingSep 5, 2019
  19. Stephan BeyerSep 5, 2019
  20. Jeff KingSep 6, 2019
  21. 6/6 pack-objects: drop packlist index_pos optimizationJeff King, Sep 6, 2019
  22. 5/6 test-read-cache: drop namelen variableJeff King, Sep 5, 2019
  23. 6/6 pack-objects: drop packlist index_pos optimizationJeff King, Sep 5, 2019

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.