commit - 950de2cd7ce881d3596a41afa88c20f21387c1e3
commit + 0fd91dafe0b852573e3a6f82e986d8bebdaa25db
blob - 3d5f3fce1a9671ed367ea1dc222cda6d19e7c3c0
blob + 214ec0ace43c96d050e3c6e610171a914b8671a2
--- libexec/got-index-pack/got-index-pack.c
+++ libexec/got-index-pack/got-index-pack.c
}
static void
-make_initial_packidx(struct got_packidx *packidx, int nobj,
+make_packidx(struct got_packidx *packidx, int nobj,
struct got_indexed_object **objects)
{
struct got_indexed_object *obj;
mergesort(objects, nobj, sizeof(struct got_indexed_object *),
indexed_obj_cmp);
+ memset(packidx->hdr.fanout_table, 0,
+ GOT_PACKIDX_V2_FANOUT_TABLE_ITEMS * sizeof(uint32_t));
+ packidx->nlargeobj = 0;
+
for (i = 0; i < nobj; i++) {
obj = objects[i];
- if (!obj->valid)
- continue;
- add_indexed_object(packidx, idx++, obj);
+ if (obj->valid)
+ add_indexed_object(packidx, idx++, obj);
}
}
SHA1_CTX ctx;
uint8_t packidx_hash[SHA1_DIGEST_LENGTH];
ssize_t r, w;
- int pass;
+ int pass, have_ref_deltas = 0;
/* Check pack file header. */
r = read(pack->fd, &hdr, sizeof(hdr));
obj->type == GOT_OBJ_TYPE_TAG) {
objects[i]->valid = 1;
nloose++;
- }
+ } else if (obj->type == GOT_OBJ_TYPE_REF_DELTA)
+ have_ref_deltas = 1;
}
nvalid = nloose;
- make_initial_packidx(&packidx, nobj, objects);
+ /* In order to resolve ref deltas we need an in-progress pack index. */
+ if (have_ref_deltas)
+ make_packidx(&packidx, nobj, objects);
/*
* Second pass: We can now resolve deltas to compute the IDs of
objects[i]->valid = 1;
n++;
- update_packidx(&packidx, nobj, obj);
+ if (have_ref_deltas)
+ update_packidx(&packidx, nobj, obj);
err = got_privsep_send_index_pack_progress(ibuf, nobj, nobj,
nloose, nresolved + n);
if (err)
goto done;
}
- /* We may have seen duplicates. Update our total object count. */
- nobj = betoh32(packidx.hdr.fanout_table[0xff]);
+ make_packidx(&packidx, nobj, objects);
SHA1Init(&ctx);
err = hwrite(idxfd, "\xfftOc\x00\x00\x00\x02", 8, &ctx);
nobj * SHA1_DIGEST_LENGTH, &ctx);
if (err)
goto done;
- mergesort(objects, nobj, sizeof(struct got_indexed_object *),
- indexed_obj_cmp);
for(i = 0; i < nobj; i++){
PUTBE32(buf, objects[i]->crc);
err = hwrite(idxfd, buf, 4, &ctx);