summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e5e3e0f)
raw | patch | inline | side by side (parent: e5e3e0f)
author | Nicolas Pitre <nico@cam.org> | |
Wed, 29 Jun 2005 06:49:56 +0000 (02:49 -0400) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Wed, 29 Jun 2005 16:11:38 +0000 (09:11 -0700) |
This is a wrap-up patch including all the cleanups I've done to the
delta code and its usage. The most important change is the
factorization of the delta header handling code.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
delta code and its usage. The most important change is the
factorization of the delta header handling code.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
count-delta.c | patch | blob | history | |
delta.h | patch | blob | history | |
diff-delta.c | patch | blob | history | |
pack-objects.c | patch | blob | history | |
patch-delta.c | patch | blob | history | |
sha1_file.c | patch | blob | history |
diff --git a/count-delta.c b/count-delta.c
index 8901034188c4d17be6676dd1fd532a23384cb5cb..7559ff68b10925154af3d52b8134f47fcf7c5233 100644 (file)
--- a/count-delta.c
+++ b/count-delta.c
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include "delta.h"
#include "count-delta.h"
-static unsigned long get_hdr_size(const unsigned char **datap)
-{
- const unsigned char *data = *datap;
- 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;
-}
-
/*
* NOTE. We do not _interpret_ delta fully. As an approximation, we
* just count the number of bytes that are copied from the source, and
unsigned char cmd;
unsigned long src_size, dst_size, out;
- /* the smallest delta size possible is 4 bytes */
- if (delta_size < 4)
+ if (delta_size < DELTA_SIZE_MIN)
return -1;
data = delta_buf;
top = delta_buf + delta_size;
- src_size = get_hdr_size(&data);
- dst_size = get_hdr_size(&data);
+ src_size = get_delta_hdr_size(&data);
+ dst_size = get_delta_hdr_size(&data);
added_literal = copied_from_source = out = 0;
while (data < top) {
index bc3a220179cefd0af169ab4f2e6aeeb5675f900a..31d1820f80f2887d51808170fc86585ada42d42e 100644 (file)
--- a/delta.h
+++ b/delta.h
void *delta_buf, unsigned long delta_size,
unsigned long *dst_size);
+/* the smallest possible delta size is 4 bytes */
+#define DELTA_SIZE_MIN 4
+
+/*
+ * This must be called twice on the delta data buffer, first to get the
+ * expected reference buffer size, and again to get the result buffer size.
+ */
+static inline unsigned long get_delta_hdr_size(const unsigned char **datap)
+{
+ const unsigned char *data = *datap;
+ 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;
+}
+
#endif
diff --git a/diff-delta.c b/diff-delta.c
index 67f60814b714493568add5a92df4a8acf8085a14..b2ae7b5e6c3b4aa409ccfa60f67d5c8eb1690504 100644 (file)
--- a/diff-delta.c
+++ b/diff-delta.c
*orig = i;
}
- /* next time around the largest possible output is 1 + 4 + 3 */
if (max_size && outpos > max_size) {
free(out);
delta_cleanup(&bdf);
return NULL;
}
+
+ /* next time around the largest possible output is 1 + 4 + 3 */
if (outpos > outsize - 8) {
void *tmp = out;
outsize = outsize * 3 / 2;
diff --git a/pack-objects.c b/pack-objects.c
index fc969e342a80c99a7455daf32696c828123ad1b9..d95f45ebfefc6f696d57b5273ea3f049d4f1ffd2 100644 (file)
--- a/pack-objects.c
+++ b/pack-objects.c
if (!otherbuf)
die("unable to read %s", sha1_to_hex(entry->delta->sha1));
delta_buf = diff_delta(otherbuf, othersize,
- buf, size, &delta_size, ~0UL);
+ buf, size, &delta_size, 0);
if (!delta_buf || delta_size != entry->delta_size)
die("delta size changed");
free(buf);
diff --git a/patch-delta.c b/patch-delta.c
index b68dd13c63be4a3834354916398b1ab4827334cc..26281ea1230f730931442bc0ed59966a6f4031be 100644 (file)
--- a/patch-delta.c
+++ b/patch-delta.c
const unsigned char *data, *top;
unsigned char *dst_buf, *out, cmd;
unsigned long size;
- int i;
- /* the smallest delta size possible is 4 bytes */
- if (delta_size < 4)
+ if (delta_size < DELTA_SIZE_MIN)
return NULL;
data = delta_buf;
top = delta_buf + delta_size;
/* make sure the orig file size matches what we expect */
- cmd = *data++;
- size = cmd & ~0x80;
- i = 7;
- while (cmd & 0x80) {
- cmd = *data++;
- size |= (cmd & ~0x80) << i;
- i += 7;
- }
+ size = get_delta_hdr_size(&data);
if (size != src_size)
return NULL;
/* now the result size */
- cmd = *data++;
- size = cmd & ~0x80;
- i = 7;
- while (cmd & 0x80) {
- cmd = *data++;
- size |= (cmd & ~0x80) << i;
- i += 7;
- }
+ size = get_delta_hdr_size(&data);
dst_buf = malloc(size);
if (!dst_buf)
return NULL;
diff --git a/sha1_file.c b/sha1_file.c
index f6cf180bd485bc7be78e2cd969c8cd3139f6ad6d..737ecb48002c873d43bafc99810feb00194b0d8c 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -592,22 +592,6 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned l
return unpack_sha1_rest(&stream, hdr, *size);
}
-static unsigned long parse_delta_size(unsigned char **p)
-{
- unsigned char c;
- unsigned long size = 0;
- unsigned shift = 0;
- unsigned char *data = *p;
-
- do {
- c = *data++;
- size += (c & 0x7f) << shift;
- shift += 7;
- } while (c & 0x80);
- *p = data;
- return size;
-}
-
static int packed_delta_info(unsigned char *base_sha1,
unsigned long delta_size,
unsigned long left,
* the result size. Verify the base size while we are at it.
*/
data = delta_head;
- verify_base_size = parse_delta_size(&data);
- result_size = parse_delta_size(&data);
+ verify_base_size = get_delta_hdr_size(&data);
if (verify_base_size != base_size)
die("delta base size mismatch");
+ /* Read the result size */
+ result_size = get_delta_hdr_size(&data);
*sizep = result_size;
return 0;
}