object: allow grow_object_hash to handle arbitrary repositories
Reviewed-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
dd5d9deb01
commit
346a817a72
16
object.c
16
object.c
@ -116,27 +116,27 @@ struct object *lookup_object(const unsigned char *sha1)
|
|||||||
* power of 2 (but at least 32). Copy the existing values to the new
|
* power of 2 (but at least 32). Copy the existing values to the new
|
||||||
* hash map.
|
* hash map.
|
||||||
*/
|
*/
|
||||||
#define grow_object_hash(r) grow_object_hash_##r()
|
static void grow_object_hash(struct repository *r)
|
||||||
static void grow_object_hash_the_repository(void)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
/*
|
/*
|
||||||
* Note that this size must always be power-of-2 to match hash_obj
|
* Note that this size must always be power-of-2 to match hash_obj
|
||||||
* above.
|
* above.
|
||||||
*/
|
*/
|
||||||
int new_hash_size = the_repository->parsed_objects->obj_hash_size < 32 ? 32 : 2 * the_repository->parsed_objects->obj_hash_size;
|
int new_hash_size = r->parsed_objects->obj_hash_size < 32 ? 32 : 2 * r->parsed_objects->obj_hash_size;
|
||||||
struct object **new_hash;
|
struct object **new_hash;
|
||||||
|
|
||||||
new_hash = xcalloc(new_hash_size, sizeof(struct object *));
|
new_hash = xcalloc(new_hash_size, sizeof(struct object *));
|
||||||
for (i = 0; i < the_repository->parsed_objects->obj_hash_size; i++) {
|
for (i = 0; i < r->parsed_objects->obj_hash_size; i++) {
|
||||||
struct object *obj = the_repository->parsed_objects->obj_hash[i];
|
struct object *obj = r->parsed_objects->obj_hash[i];
|
||||||
|
|
||||||
if (!obj)
|
if (!obj)
|
||||||
continue;
|
continue;
|
||||||
insert_obj_hash(obj, new_hash, new_hash_size);
|
insert_obj_hash(obj, new_hash, new_hash_size);
|
||||||
}
|
}
|
||||||
free(the_repository->parsed_objects->obj_hash);
|
free(r->parsed_objects->obj_hash);
|
||||||
the_repository->parsed_objects->obj_hash = new_hash;
|
r->parsed_objects->obj_hash = new_hash;
|
||||||
the_repository->parsed_objects->obj_hash_size = new_hash_size;
|
r->parsed_objects->obj_hash_size = new_hash_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *create_object_the_repository(const unsigned char *sha1, void *o)
|
void *create_object_the_repository(const unsigned char *sha1, void *o)
|
||||||
|
Reference in New Issue
Block a user