commit - c5621f1ccb44ea1d23cb07ba3c4429145e969570
commit + 8bb2b40c0fb2116f6e878aa78960309ecf7740f6
blob - 0418b2da4cb3006d9ee541182e187be7ff6f5683
blob + ddea7438fde35927dd8f8d638e8af637251095e6
--- libexec/got-index-pack/got-index-pack.c
+++ libexec/got-index-pack/got-index-pack.c
size_t n;
ssize_t r;
- obj->crc = 0;
- if (lseek(packfd, obj->off + obj->tslen, SEEK_SET) == -1)
+ if (lseek(packfd, obj->off, SEEK_SET) == -1)
return got_error_from_errno("lseek");
obj->crc = crc32(0L, NULL, 0);
- for (n = obj->len; n > 0; n -= r){
+ for (n = obj->tslen + obj->len; n > 0; n -= r){
r = read(packfd, buf, n > sizeof(buf) ? sizeof(buf) : n);
if (r == -1)
return got_error_from_errno("read");
}
}
+static int
+indexed_obj_cmp(const void *pa, const void *pb)
+{
+ struct got_indexed_object *a, *b;
+
+ a = *(struct got_indexed_object **)pa;
+ b = *(struct got_indexed_object **)pb;
+ return got_object_id_cmp(&a->id, &b->id);
+}
+
static const struct got_error *
index_pack(struct got_pack *pack, int idxfd, uint8_t *pack_hash,
struct imsgbuf *ibuf)
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);