@ -277,6 +277,7 @@ static unsigned long write_object(struct sha1file *f,
*/
*/
if (!to_reuse) {
if (!to_reuse) {
no_reuse:
if (!usable_delta) {
if (!usable_delta) {
buf = read_sha1_file(entry->idx.sha1, &type, &size);
buf = read_sha1_file(entry->idx.sha1, &type, &size);
if (!buf)
if (!buf)
@ -358,20 +359,30 @@ static unsigned long write_object(struct sha1file *f,
struct revindex_entry *revidx;
struct revindex_entry *revidx;
off_t offset;
off_t offset;
if (entry->delta) {
if (entry->delta)
type = (allow_ofs_delta && entry->delta->idx.offset) ?
type = (allow_ofs_delta && entry->delta->idx.offset) ?
OBJ_OFS_DELTA : OBJ_REF_DELTA;
OBJ_OFS_DELTA : OBJ_REF_DELTA;
reused_delta++;
}
hdrlen = encode_header(type, entry->size, header);
hdrlen = encode_header(type, entry->size, header);
offset = entry->in_pack_offset;
offset = entry->in_pack_offset;
revidx = find_pack_revindex(p, offset);
revidx = find_pack_revindex(p, offset);
datalen = revidx[1].offset - offset;
datalen = revidx[1].offset - offset;
if (!pack_to_stdout && p->index_version > 1 &&
if (!pack_to_stdout && p->index_version > 1 &&
check_pack_crc(p, &w_curs, offset, datalen, revidx->nr))
check_pack_crc(p, &w_curs, offset, datalen, revidx->nr)) {
die("bad packed object CRC for %s", sha1_to_hex(entry->idx.sha1));
error("bad packed object CRC for %s", sha1_to_hex(entry->idx.sha1));
unuse_pack(&w_curs);
goto no_reuse;
}
offset += entry->in_pack_header_size;
offset += entry->in_pack_header_size;
datalen -= entry->in_pack_header_size;
datalen -= entry->in_pack_header_size;
if (!pack_to_stdout && p->index_version == 1 &&
check_pack_inflate(p, &w_curs, offset, datalen, entry->size)) {
error("corrupt packed object for %s", sha1_to_hex(entry->idx.sha1));
unuse_pack(&w_curs);
goto no_reuse;
}
if (type == OBJ_OFS_DELTA) {
if (type == OBJ_OFS_DELTA) {
off_t ofs = entry->idx.offset - entry->delta->idx.offset;
off_t ofs = entry->idx.offset - entry->delta->idx.offset;
unsigned pos = sizeof(dheader) - 1;
unsigned pos = sizeof(dheader) - 1;
@ -383,21 +394,19 @@ static unsigned long write_object(struct sha1file *f,
sha1write(f, header, hdrlen);
sha1write(f, header, hdrlen);
sha1write(f, dheader + pos, sizeof(dheader) - pos);
sha1write(f, dheader + pos, sizeof(dheader) - pos);
hdrlen += sizeof(dheader) - pos;
hdrlen += sizeof(dheader) - pos;
reused_delta++;
} else if (type == OBJ_REF_DELTA) {
} else if (type == OBJ_REF_DELTA) {
if (limit && hdrlen + 20 + datalen + 20 >= limit)
if (limit && hdrlen + 20 + datalen + 20 >= limit)
return 0;
return 0;
sha1write(f, header, hdrlen);
sha1write(f, header, hdrlen);
sha1write(f, entry->delta->idx.sha1, 20);
sha1write(f, entry->delta->idx.sha1, 20);
hdrlen += 20;
hdrlen += 20;
reused_delta++;
} else {
} else {
if (limit && hdrlen + datalen + 20 >= limit)
if (limit && hdrlen + datalen + 20 >= limit)
return 0;
return 0;
sha1write(f, header, hdrlen);
sha1write(f, header, hdrlen);
}
}
if (!pack_to_stdout && p->index_version == 1 &&
check_pack_inflate(p, &w_curs, offset, datalen, entry->size))
die("corrupt packed object for %s", sha1_to_hex(entry->idx.sha1));
copy_pack_data(f, p, &w_curs, offset, datalen);
copy_pack_data(f, p, &w_curs, offset, datalen);
unuse_pack(&w_curs);
unuse_pack(&w_curs);
reused++;
reused++;
@ -1074,6 +1083,7 @@ static void check_object(struct object_entry *entry)
*/
*/
entry->type = entry->in_pack_type;
entry->type = entry->in_pack_type;
entry->delta = base_entry;
entry->delta = base_entry;
entry->delta_size = entry->size;
entry->delta_sibling = base_entry->delta_child;
entry->delta_sibling = base_entry->delta_child;
base_entry->delta_child = entry;
base_entry->delta_child = entry;
unuse_pack(&w_curs);
unuse_pack(&w_curs);