Commits

Anonymous committed 7623d48

Added support for multiple windows.

  • Participants
  • Parent commits 3eaa2a6

Comments (0)

Files changed (2)

heechee/svndiff.py

 OP_SOURCE_COPY = 0
 OP_TARGET_COPY = 1
 OP_NEW_DATA = 2
+MAX_WINDOW_SIZE = 1024 * 100
 
 
 def read_integer(handle):
     return target.getvalue()
 
 
-def make_cheap_diff(text):
-    "Makes a completely uncompressed svndiff of the given text."
-    
-    if text == "":
+def make_cheap_diff(text, data_size=MAX_WINDOW_SIZE - 200):
+    """Makes a completely uncompressed svndiff of the given text.
+    Returns a generator that yields windows.
+
+    :param data_size: the size of the data for onc slice.  This
+                      does not include the headers.
+    """
+    pos = 0
+    while 1:
+        slice = text[pos:pos + data_size]
+        if not slice:
+            break
+        yield make_cheap_window(slice)
+        pos += len(slice)
+
+
+def make_cheap_window(slice):
+    """Creates a window for the slice."""
+    if not slice:
         instructions = ""
     else:
-        instructions = chr(OP_NEW_DATA << 6) + make_integer(len(text))
+        instructions = chr(OP_NEW_DATA << 6) + make_integer(len(slice))
     
-    return ("SVN\0" +
+    result = ("SVN\0" +
            "\0" + # Source offset
            "\0" + # Source length
-           make_integer(len(text)) + # Target length
+           make_integer(len(slice)) + # Target length
            make_integer(len(instructions)) + # Instructions length
-           make_integer(len(text)) + # New data length
+           make_integer(len(slice)) + # New data length
            instructions +
-           text)
+           slice)
+    assert len(result) < MAX_WINDOW_SIZE, 'window too large'
+    return result

heechee/webdav.py

             response = self._propstat_response(request, {
                 DAV_NS+"version-controlled-configuration": self._href("/!svn/vcc/default"),
                 DAV_NS+"resourcetype": Element(DAV_NS+"collection"),
-                SVN_NS+"baseline-relative-path": None,
                 SVN_NS+"repository-uuid": self.repo.uuid,
             })
         
                 dir_ch_in.append(self._href("/!svn/ver/%s%s" % (rev, item.get_path())))
                 rev_elem = SubElement(file, SVN_NS+"set-prop", name="svn:entry:committed-rev")
                 rev_elem.text = str(rev)
-                txdelta = SubElement(file, SVN_NS+"txdelta")
-                txdelta.text = make_cheap_diff(item.contents).encode("base64")
+                for window in make_cheap_diff(item.contents):
+                    txdelta = SubElement(file, SVN_NS+"txdelta")
+                    txdelta.text = window.encode("base64")
         
         return Response(tostring(up_rep))