pack-objects: abstract away hash algorithm
Instead of using hard-coded instances of the constant 20, use the_hash_algo to look up the correct constant. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
37fec86a83
commit
411791009b
@ -264,6 +264,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
|
|||||||
enum object_type type;
|
enum object_type type;
|
||||||
void *buf;
|
void *buf;
|
||||||
struct git_istream *st = NULL;
|
struct git_istream *st = NULL;
|
||||||
|
const unsigned hashsz = the_hash_algo->rawsz;
|
||||||
|
|
||||||
if (!usable_delta) {
|
if (!usable_delta) {
|
||||||
if (entry->type == OBJ_BLOB &&
|
if (entry->type == OBJ_BLOB &&
|
||||||
@ -320,7 +321,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
|
|||||||
dheader[pos] = ofs & 127;
|
dheader[pos] = ofs & 127;
|
||||||
while (ofs >>= 7)
|
while (ofs >>= 7)
|
||||||
dheader[--pos] = 128 | (--ofs & 127);
|
dheader[--pos] = 128 | (--ofs & 127);
|
||||||
if (limit && hdrlen + sizeof(dheader) - pos + datalen + 20 >= limit) {
|
if (limit && hdrlen + sizeof(dheader) - pos + datalen + hashsz >= limit) {
|
||||||
if (st)
|
if (st)
|
||||||
close_istream(st);
|
close_istream(st);
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -332,19 +333,19 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
|
|||||||
} else if (type == OBJ_REF_DELTA) {
|
} else if (type == OBJ_REF_DELTA) {
|
||||||
/*
|
/*
|
||||||
* Deltas with a base reference contain
|
* Deltas with a base reference contain
|
||||||
* an additional 20 bytes for the base sha1.
|
* additional bytes for the base object ID.
|
||||||
*/
|
*/
|
||||||
if (limit && hdrlen + 20 + datalen + 20 >= limit) {
|
if (limit && hdrlen + hashsz + datalen + hashsz >= limit) {
|
||||||
if (st)
|
if (st)
|
||||||
close_istream(st);
|
close_istream(st);
|
||||||
free(buf);
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
hashwrite(f, header, hdrlen);
|
hashwrite(f, header, hdrlen);
|
||||||
hashwrite(f, entry->delta->idx.oid.hash, 20);
|
hashwrite(f, entry->delta->idx.oid.hash, hashsz);
|
||||||
hdrlen += 20;
|
hdrlen += hashsz;
|
||||||
} else {
|
} else {
|
||||||
if (limit && hdrlen + datalen + 20 >= limit) {
|
if (limit && hdrlen + datalen + hashsz >= limit) {
|
||||||
if (st)
|
if (st)
|
||||||
close_istream(st);
|
close_istream(st);
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -376,6 +377,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
|
|||||||
unsigned char header[MAX_PACK_OBJECT_HEADER],
|
unsigned char header[MAX_PACK_OBJECT_HEADER],
|
||||||
dheader[MAX_PACK_OBJECT_HEADER];
|
dheader[MAX_PACK_OBJECT_HEADER];
|
||||||
unsigned hdrlen;
|
unsigned hdrlen;
|
||||||
|
const unsigned hashsz = the_hash_algo->rawsz;
|
||||||
|
|
||||||
if (entry->delta)
|
if (entry->delta)
|
||||||
type = (allow_ofs_delta && entry->delta->idx.offset) ?
|
type = (allow_ofs_delta && entry->delta->idx.offset) ?
|
||||||
@ -411,7 +413,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
|
|||||||
dheader[pos] = ofs & 127;
|
dheader[pos] = ofs & 127;
|
||||||
while (ofs >>= 7)
|
while (ofs >>= 7)
|
||||||
dheader[--pos] = 128 | (--ofs & 127);
|
dheader[--pos] = 128 | (--ofs & 127);
|
||||||
if (limit && hdrlen + sizeof(dheader) - pos + datalen + 20 >= limit) {
|
if (limit && hdrlen + sizeof(dheader) - pos + datalen + hashsz >= limit) {
|
||||||
unuse_pack(&w_curs);
|
unuse_pack(&w_curs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -420,16 +422,16 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
|
|||||||
hdrlen += sizeof(dheader) - pos;
|
hdrlen += sizeof(dheader) - pos;
|
||||||
reused_delta++;
|
reused_delta++;
|
||||||
} else if (type == OBJ_REF_DELTA) {
|
} else if (type == OBJ_REF_DELTA) {
|
||||||
if (limit && hdrlen + 20 + datalen + 20 >= limit) {
|
if (limit && hdrlen + hashsz + datalen + hashsz >= limit) {
|
||||||
unuse_pack(&w_curs);
|
unuse_pack(&w_curs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
hashwrite(f, header, hdrlen);
|
hashwrite(f, header, hdrlen);
|
||||||
hashwrite(f, entry->delta->idx.oid.hash, 20);
|
hashwrite(f, entry->delta->idx.oid.hash, hashsz);
|
||||||
hdrlen += 20;
|
hdrlen += hashsz;
|
||||||
reused_delta++;
|
reused_delta++;
|
||||||
} else {
|
} else {
|
||||||
if (limit && hdrlen + datalen + 20 >= limit) {
|
if (limit && hdrlen + datalen + hashsz >= limit) {
|
||||||
unuse_pack(&w_curs);
|
unuse_pack(&w_curs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -752,7 +754,7 @@ static off_t write_reused_pack(struct hashfile *f)
|
|||||||
die_errno("unable to seek in reused packfile");
|
die_errno("unable to seek in reused packfile");
|
||||||
|
|
||||||
if (reuse_packfile_offset < 0)
|
if (reuse_packfile_offset < 0)
|
||||||
reuse_packfile_offset = reuse_packfile->pack_size - 20;
|
reuse_packfile_offset = reuse_packfile->pack_size - the_hash_algo->rawsz;
|
||||||
|
|
||||||
total = to_write = reuse_packfile_offset - sizeof(struct pack_header);
|
total = to_write = reuse_packfile_offset - sizeof(struct pack_header);
|
||||||
|
|
||||||
@ -1438,7 +1440,7 @@ static void check_object(struct object_entry *entry)
|
|||||||
if (reuse_delta && !entry->preferred_base)
|
if (reuse_delta && !entry->preferred_base)
|
||||||
base_ref = use_pack(p, &w_curs,
|
base_ref = use_pack(p, &w_curs,
|
||||||
entry->in_pack_offset + used, NULL);
|
entry->in_pack_offset + used, NULL);
|
||||||
entry->in_pack_header_size = used + 20;
|
entry->in_pack_header_size = used + the_hash_algo->rawsz;
|
||||||
break;
|
break;
|
||||||
case OBJ_OFS_DELTA:
|
case OBJ_OFS_DELTA:
|
||||||
buf = use_pack(p, &w_curs,
|
buf = use_pack(p, &w_curs,
|
||||||
@ -1850,7 +1852,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
|
|||||||
/* Now some size filtering heuristics. */
|
/* Now some size filtering heuristics. */
|
||||||
trg_size = trg_entry->size;
|
trg_size = trg_entry->size;
|
||||||
if (!trg_entry->delta) {
|
if (!trg_entry->delta) {
|
||||||
max_size = trg_size/2 - 20;
|
max_size = trg_size/2 - the_hash_algo->rawsz;
|
||||||
ref_depth = 1;
|
ref_depth = 1;
|
||||||
} else {
|
} else {
|
||||||
max_size = trg_entry->delta_size;
|
max_size = trg_entry->delta_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user