Rev 53: Minor changes to get diff-delta.c and patch-delta.c to compile. in http://bzr.arbash-meinel.com/plugins/groupcompress_rabin
John Arbash Meinel
john at arbash-meinel.com
Fri Feb 27 17:32:04 GMT 2009
At http://bzr.arbash-meinel.com/plugins/groupcompress_rabin
------------------------------------------------------------
revno: 53
revision-id: john at arbash-meinel.com-20090227173204-ce7djs6xbflluut1
parent: john at arbash-meinel.com-20090227160746-1gt1m20vqk7i273c
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: groupcompress_rabin
timestamp: Fri 2009-02-27 11:32:04 -0600
message:
Minor changes to get diff-delta.c and patch-delta.c to compile.
This includes bringing in 'delta.h'
-------------- next part --------------
=== added file 'delta.h'
--- a/delta.h 1970-01-01 00:00:00 +0000
+++ b/delta.h 2009-02-27 17:32:04 +0000
@@ -0,0 +1,107 @@
+#ifndef DELTA_H
+#define DELTA_H
+
+#include <stdlib.h>
+#include <string.h>
+/* opaque object for delta index */
+struct delta_index;
+
+/*
+ * create_delta_index: compute index data from given buffer
+ *
+ * This returns a pointer to a struct delta_index that should be passed to
+ * subsequent create_delta() calls, or to free_delta_index(). A NULL pointer
+ * is returned on failure. The given buffer must not be freed nor altered
+ * before free_delta_index() is called. The returned pointer must be freed
+ * using free_delta_index().
+ */
+extern struct delta_index *
+create_delta_index(const void *buf, unsigned long bufsize);
+
+/*
+ * free_delta_index: free the index created by create_delta_index()
+ *
+ * Given pointer must be what create_delta_index() returned, or NULL.
+ */
+extern void free_delta_index(struct delta_index *index);
+
+/*
+ * sizeof_delta_index: returns memory usage of delta index
+ *
+ * Given pointer must be what create_delta_index() returned, or NULL.
+ */
+extern unsigned long sizeof_delta_index(struct delta_index *index);
+
+/*
+ * create_delta: create a delta from given index for the given buffer
+ *
+ * This function may be called multiple times with different buffers using
+ * the same delta_index pointer. If max_delta_size is non-zero and the
+ * resulting delta is to be larger than max_delta_size then NULL is returned.
+ * On success, a non-NULL pointer to the buffer with the delta data is
+ * returned and *delta_size is updated with its size. The returned buffer
+ * must be freed by the caller.
+ */
+extern void *
+create_delta(const struct delta_index *index,
+ const void *buf, unsigned long bufsize,
+ unsigned long *delta_size, unsigned long max_delta_size);
+
+/*
+ * diff_delta: create a delta from source buffer to target buffer
+ *
+ * If max_delta_size is non-zero and the resulting delta is to be larger
+ * than max_delta_size then NULL is returned. On success, a non-NULL
+ * pointer to the buffer with the delta data is returned and *delta_size is
+ * updated with its size. The returned buffer must be freed by the caller.
+ */
+static inline void *
+diff_delta(const void *src_buf, unsigned long src_bufsize,
+ const void *trg_buf, unsigned long trg_bufsize,
+ unsigned long *delta_size, unsigned long max_delta_size)
+{
+ struct delta_index *index = create_delta_index(src_buf, src_bufsize);
+ if (index) {
+ void *delta = create_delta(index, trg_buf, trg_bufsize,
+ delta_size, max_delta_size);
+ free_delta_index(index);
+ return delta;
+ }
+ return NULL;
+}
+
+/*
+ * patch_delta: recreate target buffer given source buffer and delta data
+ *
+ * On success, a non-NULL pointer to the target buffer is returned and
+ * *trg_bufsize is updated with its size. On failure a NULL pointer is
+ * returned. The returned buffer must be freed by the caller.
+ */
+extern void *patch_delta(const void *src_buf, unsigned long src_size,
+ const 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 source buffer size, and again to get the target 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
=== modified file 'diff-delta.c'
--- a/diff-delta.c 2009-02-26 04:22:29 +0000
+++ b/diff-delta.c 2009-02-27 17:32:04 +0000
@@ -11,8 +11,8 @@
* published by the Free Software Foundation.
*/
-#include "git-compat-util.h"
#include "delta.h"
+#include <assert.h>
/* maximum hash entry list for the same hash bucket */
#define HASH_LIMIT 64
@@ -127,7 +127,7 @@
const void *src_buf;
unsigned long src_size;
unsigned int hash_mask;
- struct index_entry *hash[FLEX_ARRAY];
+ struct index_entry *hash[];
};
struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
=== modified file 'patch-delta.c'
--- a/patch-delta.c 2009-02-26 04:22:29 +0000
+++ b/patch-delta.c 2009-02-27 17:32:04 +0000
@@ -9,7 +9,6 @@
* published by the Free Software Foundation.
*/
-#include "git-compat-util.h"
#include "delta.h"
void *patch_delta(const void *src_buf, unsigned long src_size,
@@ -33,7 +32,11 @@
/* now the result size */
size = get_delta_hdr_size(&data, top);
- dst_buf = xmalloc(size + 1);
+ dst_buf = malloc(size + 1);
+ if (dst_buf == NULL) {
+ /* XXX: Out of memory */
+ return NULL;
+ }
dst_buf[size] = 0;
out = dst_buf;
@@ -69,14 +72,14 @@
* extensions. In the mean time we must fail when
* encountering them (might be data corruption).
*/
- error("unexpected delta opcode 0");
+ /* XXX: error("unexpected delta opcode 0"); */
goto bad;
}
}
/* sanity check */
if (data != top || size != 0) {
- error("delta replay has gone wild");
+ /* XXX: error("delta replay has gone wild"); */
bad:
free(dst_buf);
return NULL;
More information about the bazaar-commits
mailing list