Merge branch 'jk/alloc-commit-id'
Make sure all in-core commit objects are assigned a unique number so that they can be annotated using the commit-slab API. * jk/alloc-commit-id: diff-tree: avoid lookup_unknown_object object_as_type: set commit index alloc: factor out commit index add object_as_type helper for casting objects parse_object_buffer: do not set object type move setting of object->type to alloc_* functions alloc: write out allocator definitions alloc.c: remove the alloc_raw_commit_node() function
This commit is contained in:
		
							
								
								
									
										26
									
								
								object.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								object.c
									
									
									
									
									
								
							| @ -130,13 +130,12 @@ static void grow_object_hash(void) | ||||
| 	obj_hash_size = new_hash_size; | ||||
| } | ||||
|  | ||||
| void *create_object(const unsigned char *sha1, int type, void *o) | ||||
| void *create_object(const unsigned char *sha1, void *o) | ||||
| { | ||||
| 	struct object *obj = o; | ||||
|  | ||||
| 	obj->parsed = 0; | ||||
| 	obj->used = 0; | ||||
| 	obj->type = type; | ||||
| 	obj->flags = 0; | ||||
| 	hashcpy(obj->sha1, sha1); | ||||
|  | ||||
| @ -148,11 +147,30 @@ void *create_object(const unsigned char *sha1, int type, void *o) | ||||
| 	return obj; | ||||
| } | ||||
|  | ||||
| void *object_as_type(struct object *obj, enum object_type type, int quiet) | ||||
| { | ||||
| 	if (obj->type == type) | ||||
| 		return obj; | ||||
| 	else if (obj->type == OBJ_NONE) { | ||||
| 		if (type == OBJ_COMMIT) | ||||
| 			((struct commit *)obj)->index = alloc_commit_index(); | ||||
| 		obj->type = type; | ||||
| 		return obj; | ||||
| 	} | ||||
| 	else { | ||||
| 		if (!quiet) | ||||
| 			error("object %s is a %s, not a %s", | ||||
| 			      sha1_to_hex(obj->sha1), | ||||
| 			      typename(obj->type), typename(type)); | ||||
| 		return NULL; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| struct object *lookup_unknown_object(const unsigned char *sha1) | ||||
| { | ||||
| 	struct object *obj = lookup_object(sha1); | ||||
| 	if (!obj) | ||||
| 		obj = create_object(sha1, OBJ_NONE, alloc_object_node()); | ||||
| 		obj = create_object(sha1, alloc_object_node()); | ||||
| 	return obj; | ||||
| } | ||||
|  | ||||
| @ -203,8 +221,6 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t | ||||
| 		warning("object %s has unknown type id %d", sha1_to_hex(sha1), type); | ||||
| 		obj = NULL; | ||||
| 	} | ||||
| 	if (obj && obj->type == OBJ_NONE) | ||||
| 		obj->type = type; | ||||
| 	return obj; | ||||
| } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Junio C Hamano
					Junio C Hamano