summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Nicolas Pitre <nico@cam.org>2005-06-29 00:27:45 -0400
committerLibravatar Linus Torvalds <torvalds@ppc970.osdl.org>2005-06-28 21:38:47 -0700
commit69a2d426f0d249bca2c6f754b3c1283c0fa72fd4 (patch)
treeb71e760d5a5da66dda5170b9c2ad6073c10f9814
parent[PATCH] Emit base objects of a delta chain when the delta is output. (diff)
downloadtgif-69a2d426f0d249bca2c6f754b3c1283c0fa72fd4.tar.xz
[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>
-rw-r--r--count-delta.c21
-rw-r--r--diff-delta.c34
-rw-r--r--patch-delta.c28
3 files changed, 37 insertions, 46 deletions
diff --git a/count-delta.c b/count-delta.c
index c7f3767880..8901034188 100644
--- a/count-delta.c
+++ b/count-delta.c
@@ -11,16 +11,13 @@
static unsigned long get_hdr_size(const unsigned char **datap)
{
const unsigned char *data = *datap;
- unsigned long size;
- unsigned char cmd;
- int i;
- size = i = 0;
- cmd = *data++;
- while (cmd) {
- if (cmd & 1)
- size |= *data++ << i;
- i += 8;
- cmd >>= 1;
+ unsigned char cmd = *data++;
+ unsigned long size = cmd & ~0x80;
+ int i = 7;
+ while (cmd & 0x80) {
+ cmd = *data++;
+ size |= (cmd & ~0x80) << i;
+ i += 7;
}
*datap = data;
return size;
@@ -47,8 +44,8 @@ int count_delta(void *delta_buf, unsigned long delta_size,
unsigned char cmd;
unsigned long src_size, dst_size, out;
- /* 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 -1;
data = delta_buf;
diff --git a/diff-delta.c b/diff-delta.c
index fd9b37f491..67f60814b7 100644
--- a/diff-delta.c
+++ b/diff-delta.c
@@ -228,28 +228,22 @@ void *diff_delta(void *from_buf, unsigned long from_size,
top = to_buf + to_size;
/* store reference buffer size */
- orig = out + outpos++;
- *orig = i = 0;
- do {
- if (from_size & 0xff) {
- *orig |= (1 << i);
- out[outpos++] = from_size;
- }
- i++;
- from_size >>= 8;
- } while (from_size);
+ out[outpos++] = from_size;
+ from_size >>= 7;
+ while (from_size) {
+ out[outpos - 1] |= 0x80;
+ out[outpos++] = from_size;
+ from_size >>= 7;
+ }
/* store target buffer size */
- orig = out + outpos++;
- *orig = i = 0;
- do {
- if (to_size & 0xff) {
- *orig |= (1 << i);
- out[outpos++] = to_size;
- }
- i++;
- to_size >>= 8;
- } while (to_size);
+ out[outpos++] = to_size;
+ to_size >>= 7;
+ while (to_size) {
+ out[outpos - 1] |= 0x80;
+ out[outpos++] = to_size;
+ to_size >>= 7;
+ }
inscnt = 0;
moff = 0;
diff --git a/patch-delta.c b/patch-delta.c
index a8d75ee1c8..b68dd13c63 100644
--- a/patch-delta.c
+++ b/patch-delta.c
@@ -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)