#include "config.h"
static uint32_t locate_object_entry_hash(struct packing_data *pdata,
- const unsigned char *sha1,
+ const struct object_id *oid,
int *found)
{
uint32_t i, mask = (pdata->index_size - 1);
- i = sha1hash(sha1) & mask;
+ i = oidhash(oid) & mask;
while (pdata->index[i] > 0) {
uint32_t pos = pdata->index[i] - 1;
- if (hasheq(sha1, pdata->objects[pos].idx.oid.hash)) {
+ if (oideq(oid, &pdata->objects[pos].idx.oid)) {
*found = 1;
return i;
}
for (i = 0; i < pdata->nr_objects; i++) {
int found;
uint32_t ix = locate_object_entry_hash(pdata,
- entry->idx.oid.hash,
+ &entry->idx.oid,
&found);
if (found)
}
struct object_entry *packlist_find(struct packing_data *pdata,
- const unsigned char *sha1,
- uint32_t *index_pos)
+ const struct object_id *oid)
{
uint32_t i;
int found;
if (!pdata->index_size)
return NULL;
- i = locate_object_entry_hash(pdata, sha1, &found);
-
- if (index_pos)
- *index_pos = i;
+ i = locate_object_entry_hash(pdata, oid, &found);
if (!found)
return NULL;
}
struct object_entry *packlist_alloc(struct packing_data *pdata,
- const unsigned char *sha1,
- uint32_t index_pos)
+ const struct object_id *oid)
{
struct object_entry *new_entry;
new_entry = pdata->objects + pdata->nr_objects++;
memset(new_entry, 0, sizeof(*new_entry));
- hashcpy(new_entry->idx.oid.hash, sha1);
+ oidcpy(&new_entry->idx.oid, oid);
if (pdata->index_size * 3 <= pdata->nr_objects * 4)
rehash_objects(pdata);
- else
- pdata->index[index_pos] = pdata->nr_objects;
+ else {
+ int found;
+ uint32_t pos = locate_object_entry_hash(pdata,
+ &new_entry->idx.oid,
+ &found);
+ if (found)
+ BUG("duplicate object inserted into hash");
+ pdata->index[pos] = pdata->nr_objects;
+ }
if (pdata->in_pack)
pdata->in_pack[pdata->nr_objects - 1] = NULL;