Rev 55: Add a apply_delta2 function, just in case it matters. in http://bzr.arbash-meinel.com/plugins/groupcompress_rabin

John Arbash Meinel john at arbash-meinel.com
Fri Feb 27 18:21:04 GMT 2009


At http://bzr.arbash-meinel.com/plugins/groupcompress_rabin

------------------------------------------------------------
revno: 55
revision-id: john at arbash-meinel.com-20090227182104-ogr8fu5548ewpzx3
parent: john at arbash-meinel.com-20090227173623-wbwvxgznqacu6u48
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: groupcompress_rabin
timestamp: Fri 2009-02-27 12:21:04 -0600
message:
  Add a apply_delta2 function, just in case it matters.
-------------- next part --------------
=== modified file '_groupcompress_c.pyx'
--- a/_groupcompress_c.pyx	2009-02-27 17:36:23 +0000
+++ b/_groupcompress_c.pyx	2009-02-27 18:21:04 +0000
@@ -41,6 +41,9 @@
     unsigned long get_delta_hdr_size(unsigned char **datap,
                                      unsigned char *top)
     Py_ssize_t DELTA_SIZE_MIN
+    void *patch_delta(void *src_buf, unsigned long src_size,
+                      void *delta_buf, unsigned long delta_size,
+                      unsigned long *dst_size)
 
 cdef extern from "Python.h":
     int PyString_CheckExact(object)
@@ -213,3 +216,32 @@
     # *dst_size = out - dst_buf;
     assert (out - dst_buf) == PyString_GET_SIZE(result)
     return result
+
+
+def apply_delta2(source_bytes, delta_bytes):
+    """Apply a delta generated by make_delta to source_bytes."""
+    # This defers to the patch-delta code rather than implementing it here
+    # If this is faster, we can bring the memory allocation and error handling
+    # into apply_delta(), and leave the primary loop in a separate C func.
+    cdef char *source, *delta, *target
+    cdef Py_ssize_t source_size, delta_size
+    cdef unsigned long target_size
+
+    if not PyString_CheckExact(source_bytes):
+        raise TypeError('source is not a str')
+    if not PyString_CheckExact(delta_bytes):
+        raise TypeError('delta is not a str')
+
+    source = PyString_AS_STRING(source_bytes)
+    source_size = PyString_GET_SIZE(source_bytes)
+    delta = PyString_AS_STRING(delta_bytes)
+    delta_size = PyString_GET_SIZE(delta_bytes)
+
+    target = <char *>patch_delta(source, source_size,
+                                 delta, delta_size,
+                                 &target_size)
+    if target == NULL:
+        return None
+    result = PyString_FromStringAndSize(target, target_size)
+    free(target)
+    return result



More information about the bazaar-commits mailing list