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

[PATCH 09/17] object: convert create_object() to use object_id

From
Jeff King <peff@peff.net>
Date
Jun 20, 2019, 07:41 UTC
Message-ID
<20190620074121.GI3713@sigill.intra.peff.net>
In-Reply-To
<20190620073952.GA1539@sigill.intra.peff.net>

There are no callers left of lookup_object() that aren't just passing us the "hash" member of a "struct object_id". Let's take the whole struct, which gets us closer to removing all raw sha1 variables.

Signed-off-by: Jeff King <peff@peff.net>
---
 blob.c         | 3 +--
 commit-graph.c | 2 +-
 commit.c       | 3 +--
 object.c       | 6 +++---
 object.h       | 2 +-
 tag.c          | 3 +--
 tree.c         | 3 +--
 7 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/blob.c b/blob.c
index b9c7180b7c..36f9abda19 100644
--- a/blob.c
+++ b/blob.c
@@ -9,8 +9,7 @@ struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
 {
 	struct object *obj = lookup_object(r, oid);
 	if (!obj)
-		return create_object(r, oid->hash,
-				     alloc_blob_node(r));
+		return create_object(r, oid, alloc_blob_node(r));
 	return object_as_type(r, obj, OBJ_BLOB, 0);
 }
 
diff --git a/commit-graph.c b/commit-graph.c
index 7c5e54875f..5a62131d68 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1214,7 +1214,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
 		hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
 
 		graph_commit = lookup_commit(r, &cur_oid);
-		odb_commit = (struct commit *)create_object(r, cur_oid.hash, alloc_commit_node(r));
+		odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
 		if (parse_commit_internal(odb_commit, 0, 0)) {
 			graph_report(_("failed to parse commit %s from object database for commit-graph"),
 				     oid_to_hex(&cur_oid));
diff --git a/commit.c b/commit.c
index f47c75afae..b71ac195d4 100644
--- a/commit.c
+++ b/commit.c
@@ -59,8 +59,7 @@ struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
 {
 	struct object *obj = lookup_object(r, oid);
 	if (!obj)
-		return create_object(r, oid->hash,
-				     alloc_commit_node(r));
+		return create_object(r, oid, alloc_commit_node(r));
 	return object_as_type(r, obj, OBJ_COMMIT, 0);
 }
 
diff --git a/object.c b/object.c
index dbfdbe504d..317647da3e 100644
--- a/object.c
+++ b/object.c
@@ -141,13 +141,13 @@ static void grow_object_hash(struct repository *r)
 	r->parsed_objects->obj_hash_size = new_hash_size;
 }
 
-void *create_object(struct repository *r, const unsigned char *sha1, void *o)
+void *create_object(struct repository *r, const struct object_id *oid, void *o)
 {
 	struct object *obj = o;
 
 	obj->parsed = 0;
 	obj->flags = 0;
-	hashcpy(obj->oid.hash, sha1);
+	oidcpy(&obj->oid, oid);
 
 	if (r->parsed_objects->obj_hash_size - 1 <= r->parsed_objects->nr_objs * 2)
 		grow_object_hash(r);
@@ -182,7 +182,7 @@ struct object *lookup_unknown_object(const struct object_id *oid)
 {
 	struct object *obj = lookup_object(the_repository, oid);
 	if (!obj)
-		obj = create_object(the_repository, oid->hash,
+		obj = create_object(the_repository, oid,
 				    alloc_object_node(the_repository));
 	return obj;
 }
diff --git a/object.h b/object.h
index 47301186a4..0120892bbd 100644
--- a/object.h
+++ b/object.h
@@ -118,7 +118,7 @@ struct object *get_indexed_object(unsigned int);
  */
 struct object *lookup_object(struct repository *r, const struct object_id *oid);
 
-void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
+void *create_object(struct repository *r, const struct object_id *oid, void *obj);
 
 void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet);
 
diff --git a/tag.c b/tag.c
index 3ae00ba1ab..5db870edb9 100644
--- a/tag.c
+++ b/tag.c
@@ -102,8 +102,7 @@ struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
 {
 	struct object *obj = lookup_object(r, oid);
 	if (!obj)
-		return create_object(r, oid->hash,
-				     alloc_tag_node(r));
+		return create_object(r, oid, alloc_tag_node(r));
 	return object_as_type(r, obj, OBJ_TAG, 0);
 }
 
diff --git a/tree.c b/tree.c
index 0ebb8c5b02..4720945e6a 100644
--- a/tree.c
+++ b/tree.c
@@ -199,8 +199,7 @@ struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
 {
 	struct object *obj = lookup_object(r, oid);
 	if (!obj)
-		return create_object(r, oid->hash,
-				     alloc_tree_node(r));
+		return create_object(r, oid, alloc_tree_node(r));
 	return object_as_type(r, obj, OBJ_TREE, 0);
 }
 
-- 
2.22.0.732.g5402924b4b
Previous: Jeff KingNext: Ramsay Jones
Message 20 of 37 in “Test oidmap”
  1. 0/4 Test oidmapChristian Couder, Jun 15, 2019
  2. 1/4 t/helper: add test-oidmap.cChristian Couder, Jun 15, 2019
  3. 3/4 oidmap: use sha1hash() instead of static hash() functionChristian Couder, Jun 15, 2019
  4. 2/4 t: add t0016-oidmap.shChristian Couder, Jun 15, 2019
  5. 4/4 test-hashmap: remove 'hash' commandChristian Couder, Jun 15, 2019
  6. Jeff KingJun 19, 2019
  7. Jeff KingJun 19, 2019
  8. Christian CouderJun 19, 2019
  9. 0/17 drop non-object_id hashingJeff King, Jun 20, 2019
  10. 01/17 describe: fix accidental oid/hash type-punningJeff King, Jun 20, 2019
  11. Junio C HamanoJun 20, 2019
  12. Jeff KingJun 20, 2019
  13. 02/17 upload-pack: rename a "sha1" variable to "oid"Jeff King, Jun 20, 2019
  14. 03/17 pack-bitmap-write: convert some helpers to use object_idJeff King, Jun 20, 2019
  15. 04/17 pack-objects: convert packlist_find() to use object_idJeff King, Jun 20, 2019
  16. 05/17 pack-objects: convert locate_object_entry_hash() to object_idJeff King, Jun 20, 2019
  17. 06/17 object: convert lookup_unknown_object() to use object_idJeff King, Jun 20, 2019
  18. 07/17 object: convert lookup_object() to use object_idJeff King, Jun 20, 2019
  19. 08/17 object: convert internal hash_obj() to object_idJeff King, Jun 20, 2019
  20. 09/17 object: convert create_object() to use object_idJeff King, Jun 20, 2019
  21. Ramsay JonesJun 20, 2019
  22. Jeff KingJun 20, 2019
  23. 10/17 khash: drop broken oid_map typedefJeff King, Jun 20, 2019
  24. 11/17 khash: rename kh_oid_t to kh_oid_setJeff King, Jun 20, 2019
  25. 12/17 delta-islands: convert island_marks khash to use oidsJeff King, Jun 20, 2019
  26. Jonathan TanJun 20, 2019
  27. Jeff KingJun 20, 2019
  28. 13/17 pack-bitmap: convert khash_sha1 maps into kh_oid_mapJeff King, Jun 20, 2019
  29. 14/17 khash: drop sha1-specific map typesJeff King, Jun 20, 2019
  30. 15/17 khash: rename oid helper functionsJeff King, Jun 20, 2019
  31. Junio C HamanoJun 20, 2019
  32. Jeff KingJun 20, 2019
  33. René ScharfeJun 23, 2019
  34. Jeff KingJun 23, 2019
  35. 16/17 hash.h: move object_id definition from cache.hJeff King, Jun 20, 2019
  36. Junio C HamanoJun 20, 2019
  37. 17/17 hashmap: convert sha1hash() to oidhash()Jeff King, Jun 20, 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.