* Look up the record for the given sha1 in the hash map stored in * obj_hash. Return NULL if it was not found. */
| 90 | * obj_hash. Return NULL if it was not found. |
| 91 | */ |
| 92 | struct object *lookup_object(struct repository *r, const struct object_id *oid) |
| 93 | { |
| 94 | unsigned int i, first; |
| 95 | struct object *obj; |
| 96 | |
| 97 | if (!r->parsed_objects->obj_hash) |
| 98 | return NULL; |
| 99 | |
| 100 | first = i = hash_obj(oid, r->parsed_objects->obj_hash_size); |
| 101 | while ((obj = r->parsed_objects->obj_hash[i]) != NULL) { |
| 102 | if (oideq(oid, &obj->oid)) |
| 103 | break; |
| 104 | i++; |
| 105 | if (i == r->parsed_objects->obj_hash_size) |
| 106 | i = 0; |
| 107 | } |
| 108 | if (obj && i != first) { |
| 109 | /* |
| 110 | * Move object to where we started to look for it so |
| 111 | * that we do not need to walk the hash table the next |
| 112 | * time we look for it. |
| 113 | */ |
| 114 | SWAP(r->parsed_objects->obj_hash[i], |
| 115 | r->parsed_objects->obj_hash[first]); |
| 116 | } |
| 117 | return obj; |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | * Increase the size of the hash map stored in obj_hash to the next |
no test coverage detected