View | Details | Raw Unified | Return to bug 209063
Collapse All | Expand All

(-)../../home/pi/myp/misc/bdelta/Makefile (-2 / +9 lines)
Lines 2-16 Link Here
2
# $FreeBSD: head/misc/bdelta/Makefile 361099 2014-07-07 15:31:01Z olgeni $
2
# $FreeBSD: head/misc/bdelta/Makefile 361099 2014-07-07 15:31:01Z olgeni $
3
3
4
PORTNAME=	bdelta
4
PORTNAME=	bdelta
5
PORTVERSION=	0.1.0
5
PORTVERSION=	0.3.1
6
DISTVERSIONPREFIX=v
6
CATEGORIES=	misc devel
7
CATEGORIES=	misc devel
7
MASTER_SITES=	SF/deltup/${PORTNAME}/${PORTVERSION}
8
8
9
MAINTAINER=	novel@FreeBSD.org
9
MAINTAINER=	novel@FreeBSD.org
10
COMMENT=	Advanced delta creator, patcher, and library
10
COMMENT=	Advanced delta creator, patcher, and library
11
11
12
LICENSE=	MPL
13
14
WRKSRC=		${WRKDIR}/BDelta-${PORTVERSION}/src
15
12
USES=		gmake
16
USES=		gmake
13
USE_LDCONFIG=	yes
17
USE_LDCONFIG=	yes
18
USE_GITHUB=	yes
19
GH_ACCOUNT=	jjwhitney
20
GH_PROJECT=	BDelta
14
21
15
PLIST_FILES=	bin/bdelta bin/bpatch lib/libbdelta.so
22
PLIST_FILES=	bin/bdelta bin/bpatch lib/libbdelta.so
16
23
(-)../../home/pi/myp/misc/bdelta/distinfo (-2 / +2 lines)
Lines 1-2 Link Here
1
SHA256 (bdelta-0.1.0.tar.gz) = 7222011d8e3d2955f1ed094a0cc3edde6c681dd82bad5edb829ed68df32cd78d
1
SHA256 (jjwhitney-BDelta-v0.3.1_GH0.tar.gz) = 0ae5d6ede96d60efca2d142db7ed59af48d3044de5d329cfeaa48727171cd1bc
2
SIZE (bdelta-0.1.0.tar.gz) = 7418
2
SIZE (jjwhitney-BDelta-v0.3.1_GH0.tar.gz) = 14464
(-)../../home/pi/myp/misc/bdelta/files/patch-bdelta.cpp (+59 lines)
Line 0 Link Here
1
--- bdelta.cpp.orig	2013-01-30 20:16:01 UTC
2
+++ bdelta.cpp
3
@@ -10,6 +10,8 @@
4
 #include "file.h"
5
 #include "compatibility.h"
6
 
7
+#define FEFE
8
+
9
 const void *f_read(void *f, void *buf, unsigned place, unsigned num) {
10
 	fseek((FILE *)f, place, SEEK_SET);
11
 	fread_fixed((FILE *)f, buf, num);
12
@@ -103,9 +105,15 @@ int main(int argc, char **argv) {
13
 
14
 		nummatches = bdelta_numMatches(b);
15
 
16
+#ifdef FEFE
17
+		long long * copyloc1 = new long long[nummatches + 1];
18
+		long long * copyloc2 = new long long[nummatches + 1];
19
+		unsigned *  copynum = new unsigned[nummatches + 1];
20
+#else
21
 		unsigned * copyloc1 = new unsigned[nummatches + 1];
22
 		unsigned * copyloc2 = new unsigned[nummatches + 1];
23
 		unsigned *  copynum = new unsigned[nummatches + 1];
24
+#endif
25
 
26
 		FILE *fout = fopen(argv[3], "wb");
27
 		if (!fout) {
28
@@ -115,7 +123,7 @@ int main(int argc, char **argv) {
29
 
30
 		const char *magic = "BDT";
31
 		fwrite_fixed(fout, magic, 3);
32
-		unsigned short version = 1;
33
+		unsigned short version = 2;
34
 		write_word(fout, version);
35
 		unsigned char intsize = 4;
36
 		fwrite_fixed(fout, &intsize, 1);
37
@@ -129,12 +137,22 @@ int main(int argc, char **argv) {
38
 			unsigned p1, p2, num;
39
 			bdelta_getMatch(b, i, &p1, &p2, &num);
40
 			// printf("%*x, %*x, %*x, %*x\n", 10, p1, 10, p2, 10, num, 10, p2-lastp2);
41
+#ifdef FEFE
42
+			copyloc1[i] = (long long)p1 - lastp1;
43
+			copyloc2[i] = (long long)p2 - lastp2;
44
+			copynum[i] = num;
45
+			write_varint(fout, copyloc1[i]);
46
+			write_varint(fout, copyloc2[i]);
47
+			write_varint(fout, copynum[i]);
48
+//			printf("%u/%u: (%ld -> %u,%ld -> %u,%u)\n",i,nummatches,copyloc1[i],p1,copyloc2[i],p2,copynum[i]);
49
+#else
50
 			copyloc1[i] = p1 - lastp1;
51
 			write_dword(fout, copyloc1[i]);
52
 			copyloc2[i] = p2 - lastp2;
53
 			write_dword(fout, copyloc2[i]);
54
 			copynum[i] = num;
55
 			write_dword(fout, copynum[i]);
56
+#endif
57
 			lastp1 = p1 + num;
58
 			lastp2 = p2 + num;
59
 		}
(-)../../home/pi/myp/misc/bdelta/files/patch-bpatch.cpp (+87 lines)
Line 0 Link Here
1
--- bpatch.cpp.orig	2013-01-30 20:16:01 UTC
2
+++ bpatch.cpp
3
@@ -7,6 +7,8 @@
4
 #include "file.h"
5
 #include "compatibility.h"
6
 
7
+#define FEFE
8
+
9
 bool copy_bytes_to_file(FILE *infile, FILE *outfile, unsigned numleft) {
10
 	size_t numread;
11
 	do {
12
@@ -42,10 +44,17 @@ int main(int argc, char **argv) {
13
 			return 1;
14
 		}
15
 		unsigned short version = read_word(patchfile);
16
+#ifdef FEFE
17
+		if (version != 1 && version != 2) {
18
+			printf("unsupported patch version\n");
19
+			return 1;
20
+		}
21
+#else
22
 		if (version != 1) {
23
 			printf("unsupported patch version\n");
24
 			return 1;
25
 		}
26
+#endif
27
 		char intsize;
28
 		fread_fixed(patchfile, &intsize, 1);
29
 		if (intsize != 4) {
30
@@ -57,14 +66,32 @@ int main(int argc, char **argv) {
31
 
32
 		unsigned nummatches = read_dword(patchfile);
33
 
34
+#ifdef FEFE
35
+		long long * copyloc1 = new long long[nummatches + 1];
36
+		long long * copyloc2 = new long long[nummatches + 1];
37
+		unsigned *  copynum = new unsigned[nummatches + 1];
38
+#else
39
 		unsigned * copyloc1 = new unsigned[nummatches + 1];
40
 		unsigned * copyloc2 = new unsigned[nummatches + 1];
41
 		unsigned *  copynum = new unsigned[nummatches + 1];
42
+#endif
43
 
44
 		for (unsigned i = 0; i < nummatches; ++i) {
45
+#ifdef FEFE
46
+		  if (version==2) {
47
+			copyloc1[i] = read_varint(patchfile);
48
+			copyloc2[i] = read_varint(patchfile);
49
+			copynum[i] = read_varint(patchfile);
50
+		  } else {
51
 			copyloc1[i] = read_dword(patchfile);
52
 			copyloc2[i] = read_dword(patchfile);
53
 			copynum[i] = read_dword(patchfile);
54
+		  }
55
+#else
56
+			copyloc1[i] = read_dword(patchfile);
57
+			copyloc2[i] = read_dword(patchfile);
58
+			copynum[i] = read_dword(patchfile);
59
+#endif
60
 			size2 -= copyloc2[i] + copynum[i];
61
 		}
62
 		if (size2) {
63
@@ -77,16 +104,22 @@ int main(int argc, char **argv) {
64
 		FILE *outfile = fopen(argv[2], "wb");
65
 
66
 		for (unsigned i = 0; i < nummatches; ++i) {
67
+//			printf("%u/%u: copy %u bytes from patch file ofs %ld (dest ofs %u)\n",i,nummatches,copyloc2[i],ftell(patchfile),ftell(outfile));
68
 			if (!copy_bytes_to_file(patchfile, outfile, copyloc2[i])) {
69
 				printf("Error.  patchfile is truncated\n");
70
 				return -1;
71
 			}
72
 
73
-			int copyloc = copyloc1[i];
74
+			long long copyloc = copyloc1[i];
75
 			fseek(ref, copyloc, SEEK_CUR);
76
 
77
+			long curofs=ftell(ref);
78
+
79
+#ifdef FEFE
80
+//			printf("%u/%u: (%d -> %u,%d -> %u,%u)\n",i,nummatches-1,copyloc,ftell(ref),copyloc2[i],ftell(outfile),copynum[i]);
81
+#endif
82
 			if (!copy_bytes_to_file(ref, outfile, copynum[i])) {
83
-				printf("Error while copying from reference file\n");
84
+				printf("Error while copying from reference file (ofs %ld, %u bytes)\n", curofs, copynum[i]);
85
 				return -1;
86
 			}
87
 		}
(-)../../home/pi/myp/misc/bdelta/files/patch-file.h (+87 lines)
Line 0 Link Here
1
--- file.h.orig	2013-01-30 20:16:01 UTC
2
+++ file.h
3
@@ -3,6 +3,7 @@
4
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
 
6
 #include <stdio.h>
7
+#include <cstdlib>
8
 
9
 #define MAX_IO_BLOCK_SIZE (1024 * 1024)
10
 
11
@@ -58,6 +59,44 @@ unsigned read_dword(FILE *f) {
12
 	return (read_word(f) << 16) + low;
13
 }
14
 
15
+static size_t scan_varint(const char* in,size_t len, unsigned long long* n) {
16
+  size_t i;
17
+  unsigned long long l;
18
+  if (len==0) return 0;
19
+  for (l=0, i=0; i<len; ++i) {
20
+    l+=(unsigned long long)(in[i]&0x7f) << (i*7);
21
+    if (!(in[i]&0x80)) {
22
+      *n=l;
23
+      return i+1;
24
+    }
25
+  }
26
+  return 0;
27
+}
28
+
29
+size_t scan_pb_type0_sint(const char* in,size_t len,signed long long* l) {
30
+  unsigned long long m;
31
+  size_t n=scan_varint(in,len,&m);
32
+  if (!n) return 0;
33
+  *l=(-(m&1)) ^ (m>>1);
34
+  return n;
35
+}
36
+
37
+long long read_varint(FILE* f) {
38
+  char buf[20];
39
+  size_t i;
40
+  long long l;
41
+  for (i=0; i<sizeof(buf); ++i) {
42
+    fread_fixed(f,buf+i,1);
43
+    if (!(buf[i]&0x80)) {
44
+      if (scan_pb_type0_sint(buf,i+1,&l)!=i+1) break;
45
+      return l;
46
+    }
47
+  }
48
+  static char read_error_message[128];
49
+  strcpy(read_error_message, "parse error: read_varint() failed");
50
+  throw read_error_message;
51
+}
52
+
53
 void write_word(FILE *f, unsigned number) {
54
 	unsigned char b = number & 255,
55
 	              b2 = number >> 8;
56
@@ -70,6 +109,31 @@ void write_dword(FILE *f, unsigned numbe
57
 	write_word(f, number >> 16);
58
 }
59
 
60
+
61
+/* write int in least amount of bytes, return number of bytes */
62
+/* as used in varints from Google protocol buffers */
63
+static size_t fmt_varint(char* dest,unsigned long long l) {
64
+  /* high bit says if more bytes are coming, lower 7 bits are payload; little endian */
65
+  size_t i;
66
+  for (i=0; l; ++i, l>>=7) {
67
+    if (dest) dest[i]=(l&0x7f) | ((!!(l&~0x7f))<<7);
68
+  }
69
+  if (!i) {	/* l was 0 */
70
+    if (dest) dest[0]=0;
71
+    ++i;
72
+  }
73
+  return i;
74
+}
75
+
76
+static size_t fmt_pb_type0_sint(char* dest,signed long long l) {
77
+  return fmt_varint(dest,(l << 1) ^ (l >> (sizeof(l)*8-1)));
78
+}
79
+
80
+void write_varint(FILE* f, long long number) {
81
+  char tmp[20];
82
+  fwrite_fixed(f,tmp,fmt_pb_type0_sint(tmp,number));
83
+}
84
+
85
 bool fileExists(char *fname) {
86
 	FILE *f = fopen(fname, "rb");
87
 	bool exists = (f != NULL);
(-)../../home/pi/myp/misc/bdelta/files/patch-libbdelta.cpp (+20 lines)
Line 0 Link Here
1
--- libbdelta.cpp.orig	2016-04-26 04:19:52 UTC
2
+++ libbdelta.cpp
3
@@ -118,7 +118,7 @@ unsigned match_backward(BDelta_Instance 
4
 template <class T>
5
 inline T prior(T i) {return --i;}
6
 template <class T>
7
-inline T next(T i) {return ++i;}
8
+inline T bnext(T i) {return ++i;}
9
 
10
 
11
 struct UnusedRange {
12
@@ -421,7 +421,7 @@ void bdelta_pass(BDelta_Instance *b, uns
13
 			UnusedRange u1 = unused[i], u2 = unused2[i];
14
 			if (u1.num >= blocksize && u2.num >= blocksize)
15
 				if (! maxHoleSize || (u1.num <= maxHoleSize && u2.num <= maxHoleSize))
16
-					if (! (flags & BDELTA_SIDES_ORDERED) || (next(u1.ml) == u1.mr && next(u2.ml) == u2.mr))
17
+					if (! (flags & BDELTA_SIDES_ORDERED) || (bnext(u1.ml) == u1.mr && bnext(u2.ml) == u2.mr))
18
 						bdelta_pass_2(b, blocksize, minMatchSize, &u1, 1, &u2, 1);
19
 		}
20
 	}

Return to bug 209063