X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=delta.h;h=9464f3e9b08b959d11305688ce194867a4017817;hb=dafc88b136b508c1c08129b756b6ba23b7c9d341;hp=bc3a220179cefd0af169ab4f2e6aeeb5675f900a;hpb=85c1f337be49eaa9a22e42a1c9958deef5ab57c3;p=git.git diff --git a/delta.h b/delta.h index bc3a2201..9464f3e9 100644 --- a/delta.h +++ b/delta.h @@ -9,4 +9,27 @@ extern void *patch_delta(void *src_buf, unsigned long src_size, 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 *top) +{ + const unsigned char *data = *datap; + unsigned char cmd; + unsigned long size = 0; + int i = 0; + do { + cmd = *data++; + size |= (cmd & ~0x80) << i; + i += 7; + } while (cmd & 0x80 && data < top); + *datap = data; + return size; +} + #endif