Merge branch 'jk/oidhash'

Code clean-up to remove hardcoded SHA-1 hash from many places.

* jk/oidhash:
  hashmap: convert sha1hash() to oidhash()
  hash.h: move object_id definition from cache.h
  khash: rename oid helper functions
  khash: drop sha1-specific map types
  pack-bitmap: convert khash_sha1 maps into kh_oid_map
  delta-islands: convert island_marks khash to use oids
  khash: rename kh_oid_t to kh_oid_set
  khash: drop broken oid_map typedef
  object: convert create_object() to use object_id
  object: convert internal hash_obj() to object_id
  object: convert lookup_object() to use object_id
  object: convert lookup_unknown_object() to use object_id
  pack-objects: convert locate_object_entry_hash() to object_id
  pack-objects: convert packlist_find() to use object_id
  pack-bitmap-write: convert some helpers to use object_id
  upload-pack: rename a "sha1" variable to "oid"
  describe: fix accidental oid/hash type-punning
This commit is contained in:
Junio C Hamano
2019-07-09 15:25:43 -07:00
37 changed files with 156 additions and 168 deletions

View File

@ -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 oidhash(oid) & (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++;
@ -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, 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)
@ -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);
@ -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);
if (!obj)
obj = create_object(the_repository, sha1,
obj = create_object(the_repository, oid,
alloc_object_node(the_repository));
return obj;
}
@ -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);