[PATCH] denser delta header encoding

Since the delta data format is not tied to any actual git object
anymore, now is the time to add a small improvement to the delta data
header as it is been done for packed object header.  This patch allows
for reducing the delta header of about 2 bytes and makes for simpler
code.

Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Nicolas Pitre
2005-06-29 00:27:45 -04:00
committed by Linus Torvalds
parent 9d5ab9625d
commit 69a2d426f0
3 changed files with 37 additions and 46 deletions

View File

@@ -22,33 +22,33 @@ void *patch_delta(void *src_buf, unsigned long src_size,
unsigned long size;
int i;
/* the smallest delta size possible is 6 bytes */
if (delta_size < 6)
/* the smallest delta size possible is 4 bytes */
if (delta_size < 4)
return NULL;
data = delta_buf;
top = delta_buf + delta_size;
/* make sure the orig file size matches what we expect */
size = i = 0;
cmd = *data++;
while (cmd) {
if (cmd & 1)
size |= *data++ << i;
i += 8;
cmd >>= 1;
size = cmd & ~0x80;
i = 7;
while (cmd & 0x80) {
cmd = *data++;
size |= (cmd & ~0x80) << i;
i += 7;
}
if (size != src_size)
return NULL;
/* now the result size */
size = i = 0;
cmd = *data++;
while (cmd) {
if (cmd & 1)
size |= *data++ << i;
i += 8;
cmd >>= 1;
size = cmd & ~0x80;
i = 7;
while (cmd & 0x80) {
cmd = *data++;
size |= (cmd & ~0x80) << i;
i += 7;
}
dst_buf = malloc(size);
if (!dst_buf)