From 0ebbcf70e672ef9ad46eb4975a34d3639190aeb2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Jun 2019 03:41:10 -0400 Subject: object: convert lookup_unknown_object() to use object_id There are no callers left of lookup_unknown_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. It also matches the existing conversions of lookup_blob(), etc. The conversions of callers were done by hand, but they're all mechanical one-liners. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- object.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index e81d47a79c..d5b1d8daaf 100644 --- a/object.c +++ b/object.c @@ -178,11 +178,11 @@ void *object_as_type(struct repository *r, struct object *obj, enum object_type } } -struct object *lookup_unknown_object(const unsigned char *sha1) +struct object *lookup_unknown_object(const struct object_id *oid) { - struct object *obj = lookup_object(the_repository, sha1); + struct object *obj = lookup_object(the_repository, oid->hash); if (!obj) - obj = create_object(the_repository, sha1, + obj = create_object(the_repository, oid->hash, alloc_object_node(the_repository)); return obj; } -- cgit v1.2.3 From d0229abd93e1115d935b0e55067e29bcc9815ce8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Jun 2019 03:41:14 -0400 Subject: object: convert lookup_object() to use object_id 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. It also matches the existing conversions of lookup_blob(), etc. The conversions of callers were done by hand, but they're all mechanical one-liners. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- object.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index d5b1d8daaf..34c1d0dc8f 100644 --- a/object.c +++ b/object.c @@ -85,7 +85,7 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i * Look up the record for the given sha1 in the hash map stored in * obj_hash. Return NULL if it was not found. */ -struct object *lookup_object(struct repository *r, const unsigned char *sha1) +struct object *lookup_object(struct repository *r, const struct object_id *oid) { unsigned int i, first; struct object *obj; @@ -93,9 +93,9 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1) if (!r->parsed_objects->obj_hash) return NULL; - first = i = hash_obj(sha1, r->parsed_objects->obj_hash_size); + first = i = hash_obj(oid->hash, r->parsed_objects->obj_hash_size); while ((obj = r->parsed_objects->obj_hash[i]) != NULL) { - if (hasheq(sha1, obj->oid.hash)) + if (oideq(oid, &obj->oid)) break; i++; if (i == r->parsed_objects->obj_hash_size) @@ -180,7 +180,7 @@ void *object_as_type(struct repository *r, struct object *obj, enum object_type struct object *lookup_unknown_object(const struct object_id *oid) { - struct object *obj = lookup_object(the_repository, oid->hash); + struct object *obj = lookup_object(the_repository, oid); if (!obj) obj = create_object(the_repository, oid->hash, alloc_object_node(the_repository)); @@ -256,7 +256,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid) void *buffer; struct object *obj; - obj = lookup_object(r, oid->hash); + obj = lookup_object(r, oid); if (obj && obj->parsed) return obj; @@ -268,7 +268,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid) return NULL; } parse_blob_buffer(lookup_blob(r, oid), NULL, 0); - return lookup_object(r, oid->hash); + return lookup_object(r, oid); } buffer = repo_read_object_file(r, oid, &type, &size); -- cgit v1.2.3 From 46931d39389f2886e6c159674923345f024e1c64 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Jun 2019 03:41:17 -0400 Subject: object: convert internal hash_obj() to object_id Now that lookup_object() has an object_id, we can consistently pass that around instead of a raw sha1. We still convert to a hash to pass to sha1hash(), but the goal is for that to go away shortly. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- object.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 34c1d0dc8f..dbfdbe504d 100644 --- a/object.c +++ b/object.c @@ -59,9 +59,9 @@ int type_from_string_gently(const char *str, ssize_t len, int gentle) * the specified sha1. n must be a power of 2. Please note that the * return value is *not* consistent across computer architectures. */ -static unsigned int hash_obj(const unsigned char *sha1, unsigned int n) +static unsigned int hash_obj(const struct object_id *oid, unsigned int n) { - return sha1hash(sha1) & (n - 1); + return sha1hash(oid->hash) & (n - 1); } /* @@ -71,7 +71,7 @@ static unsigned int hash_obj(const unsigned char *sha1, unsigned int n) */ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size) { - unsigned int j = hash_obj(obj->oid.hash, size); + unsigned int j = hash_obj(&obj->oid, size); while (hash[j]) { j++; @@ -93,7 +93,7 @@ struct object *lookup_object(struct repository *r, const struct object_id *oid) if (!r->parsed_objects->obj_hash) return NULL; - first = i = hash_obj(oid->hash, r->parsed_objects->obj_hash_size); + first = i = hash_obj(oid, r->parsed_objects->obj_hash_size); while ((obj = r->parsed_objects->obj_hash[i]) != NULL) { if (oideq(oid, &obj->oid)) break; -- cgit v1.2.3 From a378509e1c8d817b3abe42bd8b3c8aa2a6f9af8a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Jun 2019 03:41:21 -0400 Subject: object: convert create_object() to use object_id There are no callers left of create_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 Signed-off-by: Junio C Hamano --- object.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'object.c') 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; } -- cgit v1.2.3 From d40abc8e95f75b529feb140178b69a3783c2d108 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Jun 2019 03:41:49 -0400 Subject: hashmap: convert sha1hash() to oidhash() There are no callers left of sha1hash() that do not simply pass the "hash" member of a "struct object_id". Let's get rid of the outdated sha1-specific function and provide one that operates on the whole struct (even though the technique, taking the first few bytes of the hash, will remain the same). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'object.c') diff --git a/object.c b/object.c index 317647da3e..94db02214a 100644 --- a/object.c +++ b/object.c @@ -61,7 +61,7 @@ int type_from_string_gently(const char *str, ssize_t len, int gentle) */ static unsigned int hash_obj(const struct object_id *oid, unsigned int n) { - return sha1hash(oid->hash) & (n - 1); + return oidhash(oid) & (n - 1); } /* -- cgit v1.2.3