pack-objects: small cleanup
Better encapsulate delta creation for writing. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e4b9c36ca4
commit
3613f9b4c0
@ -102,21 +102,24 @@ static uint32_t written, written_delta;
|
|||||||
static uint32_t reused, reused_delta;
|
static uint32_t reused, reused_delta;
|
||||||
|
|
||||||
|
|
||||||
static void *delta_against(void *buf, unsigned long size, struct object_entry *entry)
|
static void *get_delta(struct object_entry *entry)
|
||||||
{
|
{
|
||||||
unsigned long othersize, delta_size;
|
unsigned long size, base_size, delta_size;
|
||||||
|
void *buf, *base_buf, *delta_buf;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
void *otherbuf = read_sha1_file(entry->delta->idx.sha1, &type, &othersize);
|
|
||||||
void *delta_buf;
|
|
||||||
|
|
||||||
if (!otherbuf)
|
buf = read_sha1_file(entry->idx.sha1, &type, &size);
|
||||||
|
if (!buf)
|
||||||
|
die("unable to read %s", sha1_to_hex(entry->idx.sha1));
|
||||||
|
base_buf = read_sha1_file(entry->delta->idx.sha1, &type, &base_size);
|
||||||
|
if (!base_buf)
|
||||||
die("unable to read %s", sha1_to_hex(entry->delta->idx.sha1));
|
die("unable to read %s", sha1_to_hex(entry->delta->idx.sha1));
|
||||||
delta_buf = diff_delta(otherbuf, othersize,
|
delta_buf = diff_delta(base_buf, base_size,
|
||||||
buf, size, &delta_size, 0);
|
buf, size, &delta_size, 0);
|
||||||
if (!delta_buf || delta_size != entry->delta_size)
|
if (!delta_buf || delta_size != entry->delta_size)
|
||||||
die("delta size changed");
|
die("delta size changed");
|
||||||
free(buf);
|
free(buf);
|
||||||
free(otherbuf);
|
free(base_buf);
|
||||||
return delta_buf;
|
return delta_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +226,6 @@ static unsigned long write_object(struct sha1file *f,
|
|||||||
off_t write_offset)
|
off_t write_offset)
|
||||||
{
|
{
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
enum object_type type;
|
|
||||||
void *buf;
|
void *buf;
|
||||||
unsigned char header[10];
|
unsigned char header[10];
|
||||||
unsigned char dheader[10];
|
unsigned char dheader[10];
|
||||||
@ -281,10 +283,7 @@ static unsigned long write_object(struct sha1file *f,
|
|||||||
obj_type = (allow_ofs_delta && entry->delta->idx.offset) ?
|
obj_type = (allow_ofs_delta && entry->delta->idx.offset) ?
|
||||||
OBJ_OFS_DELTA : OBJ_REF_DELTA;
|
OBJ_OFS_DELTA : OBJ_REF_DELTA;
|
||||||
} else {
|
} else {
|
||||||
buf = read_sha1_file(entry->idx.sha1, &type, &size);
|
buf = get_delta(entry);
|
||||||
if (!buf)
|
|
||||||
die("unable to read %s", sha1_to_hex(entry->idx.sha1));
|
|
||||||
buf = delta_against(buf, size, entry);
|
|
||||||
size = entry->delta_size;
|
size = entry->delta_size;
|
||||||
obj_type = (allow_ofs_delta && entry->delta->idx.offset) ?
|
obj_type = (allow_ofs_delta && entry->delta->idx.offset) ?
|
||||||
OBJ_OFS_DELTA : OBJ_REF_DELTA;
|
OBJ_OFS_DELTA : OBJ_REF_DELTA;
|
||||||
|
Loading…
Reference in New Issue
Block a user