@matheusbsbs / matheus-bagliano / commits / 3613f9b4c0
Fork 0

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>

Nicolas Pitre committed May 2, 2008 at 15:11 UTC 3613f9b4c02c3e3d35f4c6c06e40d5c176e7eb6d
1 file changed +13 -14
builtin-pack-objects.c
+13 -14
@@ -102,21 +102,24 @@ static uint32_t written, written_delta;
102 static uint32_t reused, reused_delta;
103
104
105 -static void *delta_against(void *buf, unsigned long size, struct object_entry *entry)
105 +static void *get_delta(struct object_entry *entry)
106 {
107 - unsigned long othersize, delta_size;
107 + unsigned long size, base_size, delta_size;
108 + void *buf, *base_buf, *delta_buf;
109 enum object_type type;
109 - void *otherbuf = read_sha1_file(entry->delta->idx.sha1, &type, &othersize);
110 - void *delta_buf;
110
112 - if (!otherbuf)
111 + buf = read_sha1_file(entry->idx.sha1, &type, &size);
112 + if (!buf)
113 + die("unable to read %s", sha1_to_hex(entry->idx.sha1));
114 + base_buf = read_sha1_file(entry->delta->idx.sha1, &type, &base_size);
115 + if (!base_buf)
116 die("unable to read %s", sha1_to_hex(entry->delta->idx.sha1));
114 - delta_buf = diff_delta(otherbuf, othersize,
117 + delta_buf = diff_delta(base_buf, base_size,
118 buf, size, &delta_size, 0);
116 - if (!delta_buf || delta_size != entry->delta_size)
119 + if (!delta_buf || delta_size != entry->delta_size)
120 die("delta size changed");
118 - free(buf);
119 - free(otherbuf);
121 + free(buf);
122 + free(base_buf);
123 return delta_buf;
124 }
125
@@ -223,7 +226,6 @@ static unsigned long write_object(struct sha1file *f,
226 off_t write_offset)
227 {
228 unsigned long size;
226 - enum object_type type;
229 void *buf;
230 unsigned char header[10];
231 unsigned char dheader[10];
@@ -281,10 +283,7 @@ static unsigned long write_object(struct sha1file *f,
283 obj_type = (allow_ofs_delta && entry->delta->idx.offset) ?
284 OBJ_OFS_DELTA : OBJ_REF_DELTA;
285 } else {
284 - buf = read_sha1_file(entry->idx.sha1, &type, &size);
285 - if (!buf)
286 - die("unable to read %s", sha1_to_hex(entry->idx.sha1));
287 - buf = delta_against(buf, size, entry);
286 + buf = get_delta(entry);
287 size = entry->delta_size;
288 obj_type = (allow_ofs_delta && entry->delta->idx.offset) ?
289 OBJ_OFS_DELTA : OBJ_REF_DELTA;