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

[PATCH 28/53] Convert remaining callers of lookup_blob to object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Apr 23, 2017, 21:34 UTC
Message-ID
<20170423213453.253425-29-sandals@crustytoothpaste.net>
In-Reply-To
<20170423213453.253425-1-sandals@crustytoothpaste.net>

All but a few callers of lookup_blob have been converted to struct object_id. Introduce a temporary, which will be removed later, into parse_object to ease the transition, and convert the remaining callers so that we can update lookup_blob to take struct object_id *.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/index-pack.c | 28 ++++++++++++++--------------
 builtin/merge-tree.c | 10 +++++-----
 object.c             |  9 ++++++---
 3 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index fef0025e4..2241ee68e 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -785,7 +785,7 @@ static int check_collison(struct object_entry *entry)
 
 static void sha1_object(const void *data, struct object_entry *obj_entry,
 			unsigned long size, enum object_type type,
-			const unsigned char *sha1)
+			const struct object_id *oid)
 {
 	void *new_data = NULL;
 	int collision_test_needed = 0;
@@ -794,7 +794,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 
 	if (startup_info->have_repository) {
 		read_lock();
-		collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
+		collision_test_needed = has_sha1_file_with_flags(oid->hash, HAS_SHA1_QUICK);
 		read_unlock();
 	}
 
@@ -809,31 +809,31 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 		enum object_type has_type;
 		unsigned long has_size;
 		read_lock();
-		has_type = sha1_object_info(sha1, &has_size);
+		has_type = sha1_object_info(oid->hash, &has_size);
 		if (has_type < 0)
-			die(_("cannot read existing object info %s"), sha1_to_hex(sha1));
+			die(_("cannot read existing object info %s"), oid_to_hex(oid));
 		if (has_type != type || has_size != size)
-			die(_("SHA1 COLLISION FOUND WITH %s !"), sha1_to_hex(sha1));
-		has_data = read_sha1_file(sha1, &has_type, &has_size);
+			die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
+		has_data = read_sha1_file(oid->hash, &has_type, &has_size);
 		read_unlock();
 		if (!data)
 			data = new_data = get_data_from_pack(obj_entry);
 		if (!has_data)
-			die(_("cannot read existing object %s"), sha1_to_hex(sha1));
+			die(_("cannot read existing object %s"), oid_to_hex(oid));
 		if (size != has_size || type != has_type ||
 		    memcmp(data, has_data, size) != 0)
-			die(_("SHA1 COLLISION FOUND WITH %s !"), sha1_to_hex(sha1));
+			die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
 		free(has_data);
 	}
 
 	if (strict) {
 		read_lock();
 		if (type == OBJ_BLOB) {
-			struct blob *blob = lookup_blob(sha1);
+			struct blob *blob = lookup_blob(oid->hash);
 			if (blob)
 				blob->object.flags |= FLAG_CHECKED;
 			else
-				die(_("invalid blob object %s"), sha1_to_hex(sha1));
+				die(_("invalid blob object %s"), oid_to_hex(oid));
 		} else {
 			struct object *obj;
 			int eaten;
@@ -845,7 +845,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			 * we do not need to free the memory here, as the
 			 * buf is deleted by the caller.
 			 */
-			obj = parse_object_buffer(sha1, type, size, buf, &eaten);
+			obj = parse_object_buffer(oid->hash, type, size, buf, &eaten);
 			if (!obj)
 				die(_("invalid %s"), typename(type));
 			if (do_fsck_object &&
@@ -960,7 +960,7 @@ static void resolve_delta(struct object_entry *delta_obj,
 		       typename(delta_obj->real_type),
 		       delta_obj->idx.oid.hash);
 	sha1_object(result->data, NULL, result->size, delta_obj->real_type,
-		    delta_obj->idx.oid.hash);
+		    &delta_obj->idx.oid);
 	counter_lock();
 	nr_resolved_deltas++;
 	counter_unlock();
@@ -1149,7 +1149,7 @@ static void parse_pack_objects(unsigned char *sha1)
 			nr_delays++;
 		} else
 			sha1_object(data, NULL, obj->size, obj->type,
-				    obj->idx.oid.hash);
+				    &obj->idx.oid);
 		free(data);
 		display_progress(progress, i+1);
 	}
@@ -1176,7 +1176,7 @@ static void parse_pack_objects(unsigned char *sha1)
 			continue;
 		obj->real_type = obj->type;
 		sha1_object(NULL, obj, obj->size, obj->type,
-			    obj->idx.oid.hash);
+			    &obj->idx.oid);
 		nr_delays--;
 	}
 	if (nr_delays)
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 5b7ab9b96..cdeb6562d 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -161,14 +161,14 @@ static int both_empty(struct name_entry *a, struct name_entry *b)
 	return !(a->oid || b->oid);
 }
 
-static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)
+static struct merge_list *create_entry(unsigned stage, unsigned mode, const struct object_id *oid, const char *path)
 {
 	struct merge_list *res = xcalloc(1, sizeof(*res));
 
 	res->stage = stage;
 	res->path = path;
 	res->mode = mode;
-	res->blob = lookup_blob(sha1);
+	res->blob = lookup_blob(oid->hash);
 	return res;
 }
 
@@ -188,8 +188,8 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s
 		return;
 
 	path = traverse_path(info, result);
-	orig = create_entry(2, ours->mode, ours->oid->hash, path);
-	final = create_entry(0, result->mode, result->oid->hash, path);
+	orig = create_entry(2, ours->mode, ours->oid, path);
+	final = create_entry(0, result->mode, result->oid, path);
 
 	final->link = orig;
 
@@ -239,7 +239,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info
 		path = entry->path;
 	else
 		path = traverse_path(info, n);
-	link = create_entry(stage, n->mode, n->oid->hash, path);
+	link = create_entry(stage, n->mode, n->oid, path);
 	link->link = entry;
 	return link;
 }
diff --git a/object.c b/object.c
index fe2222356..0208c407a 100644
--- a/object.c
+++ b/object.c
@@ -190,7 +190,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
 
 	obj = NULL;
 	if (type == OBJ_BLOB) {
-		struct blob *blob = lookup_blob(sha1);
+		struct blob *blob = lookup_blob(oid.hash);
 		if (blob) {
 			if (parse_blob_buffer(blob, buffer, size))
 				return NULL;
@@ -251,8 +251,11 @@ struct object *parse_object(const unsigned char *sha1)
 	const unsigned char *repl = lookup_replace_object(sha1);
 	void *buffer;
 	struct object *obj;
+	struct object_id oid;
 
-	obj = lookup_object(sha1);
+	hashcpy(oid.hash, sha1);
+
+	obj = lookup_object(oid.hash);
 	if (obj && obj->parsed)
 		return obj;
 
@@ -263,7 +266,7 @@ struct object *parse_object(const unsigned char *sha1)
 			error("sha1 mismatch %s", sha1_to_hex(repl));
 			return NULL;
 		}
-		parse_blob_buffer(lookup_blob(sha1), NULL, 0);
+		parse_blob_buffer(lookup_blob(oid.hash), NULL, 0);
 		return lookup_object(sha1);
 	}
 
Previous: brian m. carlsonNext: Stefan Beller
Message 32 of 67 in “object_id part 8”
  1. 00/53 object_id part 8brian m. carlson, Apr 23, 2017
  2. 02/53 Clean up outstanding object_id transforms.brian m. carlson, Apr 23, 2017
  3. 01/53 fetch-pack: convert to struct object_idbrian m. carlson, Apr 23, 2017
  4. 03/53 Convert struct cache_tree to use struct object_idbrian m. carlson, Apr 23, 2017
  5. 04/53 builtin/name-rev: convert to struct object_idbrian m. carlson, Apr 23, 2017
  6. 05/53 builtin/prune: convert to struct object_idbrian m. carlson, Apr 23, 2017
  7. 06/53 bundle: convert to struct object_idbrian m. carlson, Apr 23, 2017
  8. 08/53 builtin/blame: convert static function to struct object_idbrian m. carlson, Apr 23, 2017
  9. 07/53 branch: convert to struct object_idbrian m. carlson, Apr 23, 2017
  10. 10/53 fast-import: convert internal structs to struct object_idbrian m. carlson, Apr 23, 2017
  11. 09/53 builtin/rev-parse: convert to struct object_idbrian m. carlson, Apr 23, 2017
  12. 12/53 submodule: convert merge_submodule to use struct object_idbrian m. carlson, Apr 23, 2017
  13. 13/53 notes-cache: convert to struct object_idbrian m. carlson, Apr 23, 2017
  14. Stefan BellerApr 24, 2017
  15. 11/53 fast-import: convert to struct object_idbrian m. carlson, Apr 23, 2017
  16. Stefan BellerApr 24, 2017
  17. brian m. carlsonApr 24, 2017
  18. 14/53 parse-options-cb: convert to struct object_idbrian m. carlson, Apr 23, 2017
  19. 17/53 tag: convert parse_tag_buffer to struct object_idbrian m. carlson, Apr 23, 2017
  20. 15/53 reflog_expire: convert to struct object_idbrian m. carlson, Apr 23, 2017
  21. 16/53 builtin/verify-commit: convert to struct object_idbrian m. carlson, Apr 23, 2017
  22. 19/53 notes-utils: convert internals to struct object_idbrian m. carlson, Apr 23, 2017
  23. 18/53 http-push: convert some static functions to struct object_idbrian m. carlson, Apr 23, 2017
  24. 22/53 sequencer: convert some functions to struct object_idbrian m. carlson, Apr 23, 2017
  25. 20/53 revision: convert prepare_show_merge to struct object_idbrian m. carlson, Apr 23, 2017
  26. 21/53 shallow: convert shallow registration functions to object_idbrian m. carlson, Apr 23, 2017
  27. 23/53 builtin/tag: convert to struct object_idbrian m. carlson, Apr 23, 2017
  28. 24/53 Convert remaining callers of lookup_commit_reference* to object_idbrian m. carlson, Apr 23, 2017
  29. 26/53 pack: convert struct pack_idx_entry to struct object_idbrian m. carlson, Apr 23, 2017
  30. 25/53 Convert lookup_commit* to struct object_idbrian m. carlson, Apr 23, 2017
  31. 27/53 builtin/unpack-objects: convert to struct object_idbrian m. carlson, Apr 23, 2017
  32. 28/53 Convert remaining callers of lookup_blob to object_idbrian m. carlson, Apr 23, 2017
  33. Stefan BellerApr 24, 2017
  34. 29/53 Convert lookup_blob to struct object_idbrian m. carlson, Apr 23, 2017
  35. 30/53 tree: convert read_tree_1 to use struct object_id internallybrian m. carlson, Apr 23, 2017
  36. 31/53 builtin/reflog: convert tree_is_complete to take struct object_idbrian m. carlson, Apr 23, 2017
  37. 34/53 Convert lookup_tag to struct object_idbrian m. carlson, Apr 23, 2017
  38. 32/53 Convert lookup_tree to struct object_idbrian m. carlson, Apr 23, 2017
  39. 33/53 log-tree: convert to struct object_idbrian m. carlson, Apr 23, 2017
  40. 35/53 Convert the verify_pack callback to struct object_idbrian m. carlson, Apr 23, 2017
  41. Stefan BellerApr 26, 2017
  42. Jeff KingApr 27, 2017
  43. brian m. carlsonApr 28, 2017
  44. Jeff KingApr 28, 2017
  45. 36/53 Convert struct ref_array_item to struct object_idbrian m. carlson, Apr 23, 2017
  46. 37/53 ref-filter: convert some static functions to struct object_idbrian m. carlson, Apr 23, 2017
  47. 38/53 refs: convert struct ref_update to use struct object_idbrian m. carlson, Apr 23, 2017
  48. Michael HaggertyApr 27, 2017
  49. 39/53 refs/files-backend: convert many internals to struct object_idbrian m. carlson, Apr 23, 2017
  50. Michael HaggertyApr 27, 2017
  51. 40/53 http-push: convert process_ls_object and descendants to object_idbrian m. carlson, Apr 23, 2017
  52. 41/53 revision: rename add_pending_sha1 to add_pending_oidbrian m. carlson, Apr 23, 2017
  53. 43/53 upload-pack: convert remaining parse_object callers to object_idbrian m. carlson, Apr 23, 2017
  54. 46/53 builtin/ls-files: convert overlay_tree_on_cache to object_idbrian m. carlson, Apr 23, 2017
  55. 45/53 builtin/read-tree: convert to struct object_idbrian m. carlson, Apr 23, 2017
  56. 47/53 sequencer: convert fast_forward_to to struct object_idbrian m. carlson, Apr 23, 2017
  57. 51/53 sequencer: convert do_recursive_merge to struct object_idbrian m. carlson, Apr 23, 2017
  58. 50/53 diff-lib: convert do_diff_cache to struct object_idbrian m. carlson, Apr 23, 2017
  59. 48/53 merge: convert checkout_fast_forward to struct object_idbrian m. carlson, Apr 23, 2017
  60. 49/53 builtin/ls-tree: convert to struct object_idbrian m. carlson, Apr 23, 2017
  61. 44/53 sha1_name: convert internals of peel_onion to object_idbrian m. carlson, Apr 23, 2017
  62. 42/53 revision: convert remaining parse_object callers to object_idbrian m. carlson, Apr 23, 2017
  63. 52/53 tree: convert parse_tree_indirect to struct object_idbrian m. carlson, Apr 23, 2017
  64. 53/53 object: convert parse_object* to take struct object_idbrian m. carlson, Apr 23, 2017
  65. Stefan BellerApr 27, 2017
  66. Junio C HamanoApr 24, 2017
  67. Brandon WilliamsApr 24, 2017

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.