Rev 998: Several more random fixes, add python implementation of svn delta apply algorithm. in file:///data/jelmer/bzr-svn/pyrex/

Jelmer Vernooij jelmer at samba.org
Sun Mar 16 17:57:37 GMT 2008


At file:///data/jelmer/bzr-svn/pyrex/

------------------------------------------------------------
revno: 998
revision-id:jelmer at samba.org-20080316175735-7mjfia3x76q7p63z
parent: jelmer at samba.org-20080316153905-sd6tt8i5o6y3sysa
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: pyrex
timestamp: Sun 2008-03-16 18:57:35 +0100
message:
  Several more random fixes, add python implementation of svn delta apply algorithm.
modified:
  client.pyx                     client.pyx-20080313235339-wbyjbw2namuiql8f-1
  constants.py                   constants.py-20080313210342-fuq3eruf2102bwml-1
  core.pxd                       core.pxd-20080314004625-ng663dn07ewpc26a-1
  core.pyx                       core.pyx-20080313210413-17k59slolpfe5kdq-1
  delta.py                       delta.py-20080316001917-xyng7m3jlxvdc4c9-1
  fetch.py                       fetch.py-20060625004942-x2lfaib8ra707a8p-1
  logwalker.py                   logwalker.py-20060621215743-c13fhfnyzh1xzwh2-1
  ra.pyx                         ra.pyx-20080313140933-qybkqaxe3m4mcll7-1
  tests/__init__.py              __init__.py-20060508151940-e9f4d914801a2535
  tests/test_commit.py           test_commit.py-20060624213521-l5kcufywkh9mnilk-1
  tests/test_errors.py           test_errors.py-20070129114605-ban03f32t6ja14ez-1
  tree.py                        tree.py-20060624222557-dudlwqcmkf22lt2s-1
  types.pxd                      types.pxi-20080313202425-vtt1ry64o98kgpg8-1
=== modified file 'client.pyx'
--- a/client.pyx	2008-03-16 14:17:23 +0000
+++ b/client.pyx	2008-03-16 17:57:35 +0000
@@ -104,7 +104,7 @@
                    svn_boolean_t recurse,
                    svn_boolean_t keep_locks,
                    svn_client_ctx_t *ctx,
-                   apr_pool_t *pool)
+                   apr_pool_t *pool) except *
 
     svn_error_t *svn_client_delete2(svn_commit_info_t **commit_info_p,
                    apr_array_header_t *paths,
@@ -169,7 +169,7 @@
                 svn_log_message_receiver_t receiver,
                 receiver_baton,
                 svn_client_ctx_t *ctx,
-                apr_pool_t *pool)
+                apr_pool_t *pool) except *
 
     svn_error_t *svn_client_propget2(apr_hash_t **props,
                     char *propname,

=== modified file 'constants.py'
--- a/constants.py	2008-03-16 05:24:21 +0000
+++ b/constants.py	2008-03-16 17:57:35 +0000
@@ -35,6 +35,7 @@
 ERR_WC_NOT_DIRECTORY = 155007
 ERR_ENTRY_EXISTS = 150002
 ERR_WC_PATH_NOT_FOUND = 155010
+ERR_CANCELLED = 200015
 
 AUTH_SSL_NOTYETVALID = 0x00000001
 AUTH_SSL_EXPIRED     = 0x00000002

=== modified file 'core.pxd'
--- a/core.pxd	2008-03-16 14:17:23 +0000
+++ b/core.pxd	2008-03-16 17:57:35 +0000
@@ -26,3 +26,4 @@
 cdef svn_stream_t *new_py_stream(apr_pool_t *pool, object py)
 cdef svn_stream_t *string_stream(apr_pool_t *pool, text)
 cdef prop_hash_to_dict(apr_hash_t *)
+cdef svn_error_t *py_svn_error(exc)

=== modified file 'core.pyx'
--- a/core.pyx	2008-03-16 14:17:23 +0000
+++ b/core.pyx	2008-03-16 17:57:35 +0000
@@ -19,6 +19,7 @@
 from apr cimport apr_pool_t, apr_pool_create, apr_pool_destroy
 from apr cimport apr_array_header_t, apr_array_make, apr_array_push
 from apr cimport apr_hash_index_t, apr_hash_this, apr_hash_first, apr_hash_next
+import constants
 from constants import PROP_REVISION_LOG, PROP_REVISION_AUTHOR, PROP_REVISION_DATE
 from types cimport svn_stream_set_read, svn_stream_set_write, svn_stream_set_close, svn_stream_from_stringbuf, svn_stream_create
 from types cimport svn_stringbuf_t, svn_stringbuf_ncreate, svn_string_t
@@ -28,17 +29,23 @@
     void Py_DECREF(object)
     object PyString_FromStringAndSize(char *, unsigned long)
     char *PyString_AS_STRING(object)
-	
+    
 cdef extern from "string.h":
     ctypedef unsigned long size_t 
     void *memcpy(void *dest, void *src, size_t len)
 
 apr_initialize()
 
+cdef svn_error_t *py_svn_error(exc):
+    cdef svn_error_t *ret
+    msg = "Python exception occurred: " + str(exc)
+    ret = svn_error_create(424242, NULL, msg)
+    return ret
+
 cdef svn_error_t *py_cancel_func(cancel_baton):
     if cancel_baton is not None:
         if cancel_baton():
-            return svn_error_create(200015, NULL, NULL) # cancelled
+            return svn_error_create(constants.ERR_CANCELLED, NULL, NULL)
     return NULL
 
 class SubversionException(Exception):
@@ -163,6 +170,7 @@
     if date != NULL:
         revprops[PROP_REVISION_DATE] = date
     baton(py_changed_paths, revision, revprops)
+    return NULL
 
 cdef svn_error_t *py_stream_read(void *baton, char *buffer, apr_size_t *length):
     self = <object>baton

=== modified file 'delta.py'
--- a/delta.py	2008-03-16 05:24:21 +0000
+++ b/delta.py	2008-03-16 17:57:35 +0000
@@ -15,11 +15,28 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """Subversion delta operations."""
 
-def apply_txdelta_handler(src_stream, target_stream):
-    assert hasattr(src_stream, 'read')
-    assert hasattr(target_stream, 'write')
-
-    def wrapper(*args):
-        print args
-
-    return wrapper
+def apply_txdelta_handler(sbuf, target_stream):
+    def apply_window(window):
+        (sview_offset, sview_len, tview_len, src_ops, ops, new_data) = window
+        sview = sbuf[sview_offset:sview_offset+sview_len]
+        tview = txdelta_apply_ops(src_ops, ops, new_data, sview)
+        assert len(tview) == tview_len
+        target_stream.write(tview)
+    return apply_window
+
+def txdelta_apply_ops(src_ops, ops, new_data, sview):
+    tview = ""
+    for (action, offset, length) in ops:
+        if action == 0:
+            # Copy from source area.
+            assert offset + length <= sview_len
+            tview += sview[offset:offset+length]
+        elif action == 1:
+            for i in xrange(length):
+                tview += tview[offset+i]
+        elif action == 2:
+            tview += new_data[offset:offset+length]
+        else:
+            raise Exception("Invalid delta instruction code")
+
+    return tview

=== modified file 'fetch.py'
--- a/fetch.py	2008-03-16 00:33:02 +0000
+++ b/fetch.py	2008-03-16 17:57:35 +0000
@@ -359,13 +359,12 @@
         self.file_stream = None
 
     def apply_textdelta(self, base_checksum=None):
-        actual_checksum = md5.new(self.file_data).hexdigest(),
+        actual_checksum = md5.new(self.file_data).hexdigest()
         assert (base_checksum is None or base_checksum == actual_checksum,
             "base checksum mismatch: %r != %r" % (base_checksum, 
                                                   actual_checksum))
         self.file_stream = StringIO()
-        return apply_txdelta_handler(StringIO(self.file_data), 
-                                     self.file_stream)
+        return apply_txdelta_handler(self.file_data, self.file_stream)
 
     def change_prop(self, name, value):
         if name == constants.PROP_EXECUTABLE: 

=== modified file 'logwalker.py'
--- a/logwalker.py	2008-03-16 14:51:30 +0000
+++ b/logwalker.py	2008-03-16 17:57:35 +0000
@@ -249,9 +249,9 @@
         assert ft == core.NODE_DIR
 
         class DirLister:
-            def __init__(self, path, files):
+            def __init__(self, base, files):
                 self.files = files
-                self.path = path
+                self.base = base
 
             def change_prop(self, name, value):
                 pass
@@ -259,13 +259,13 @@
             def add_directory(self, path):
                 """See Editor.add_directory()."""
                 self.files.append(urlutils.join(self.base, path))
-                return DirLister(path, self.files)
+                return DirLister(self.base, self.files)
 
             def add_file(self, path):
                 self.files.append(urlutils.join(self.base, path))
                 return FileLister()
 
-            def close(self, id):
+            def close(self):
                 pass
 
         class FileLister:
@@ -278,7 +278,7 @@
             def apply_textdelta(self, base_checksum=None):
                 pass
 
-            def close(self, checksum):
+            def close(self, checksum=None):
                 pass
 
         class TreeLister:
@@ -292,7 +292,7 @@
 
             def open_root(self, revnum):
                 """See Editor.open_root()."""
-                return DirLister(path, self.files)
+                return DirLister(self.base, self.files)
 
             def close(self, checksum=None):
                 pass
@@ -302,14 +302,11 @@
 
         editor = TreeLister(path)
         old_base = transport.base
-        try:
-            root_repos = transport.get_svn_repos_root()
-            transport.reparent(urlutils.join(root_repos, path))
-            reporter = transport.do_update(revnum, True, editor)
-            reporter.set_path("", revnum, True, None)
-            reporter.finish_report()
-        finally:
-            transport.reparent(old_base)
+        root_repos = transport.get_svn_repos_root()
+        reporter = transport.do_switch(revnum, True, 
+                urlutils.join(root_repos, path), editor)
+        reporter.set_path("", 0, True, None)
+        reporter.finish_report()
         return editor.files
 
     def get_previous(self, path, revnum):

=== modified file 'ra.pyx'
--- a/ra.pyx	2008-03-16 14:51:30 +0000
+++ b/ra.pyx	2008-03-16 17:57:35 +0000
@@ -600,10 +600,13 @@
         # Signals all delta windows have been received
         Py_DECREF(fn)
         return NULL
+    if fn is None:
+        # User doesn't care about deltas
+        return NULL
     ops = []
     for i in range(window.num_ops):
         ops.append((window.ops[i].action_code, window.ops[i].offset, window.ops[i].length))
-    fn(window.sview_offset, window.sview_len, window.tview_len, window.src_ops, ops, PyString_FromStringAndSize(window.new_data.data, window.new_data.len))
+    fn((window.sview_offset, window.sview_len, window.tview_len, window.src_ops, ops, PyString_FromStringAndSize(window.new_data.data, window.new_data.len)))
     return NULL
     
 

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2008-03-16 05:56:59 +0000
+++ b/tests/__init__.py	2008-03-16 17:57:35 +0000
@@ -26,6 +26,7 @@
 from bzrlib.urlutils import local_path_to_url
 from bzrlib.workingtree import WorkingTree
 
+import constants
 import repos, wc, client
 
 class TestCaseWithSubversionRepository(TestCaseInTempDir):
@@ -140,12 +141,16 @@
         """
         self.client_ctx.add(relpath, recursive, False, False)
 
-    def client_log(self, path, start_revnum=None, stop_revnum=None):
+    def client_log(self, path, start_revnum=0, stop_revnum="HEAD"):
         assert isinstance(path, str)
         ret = {}
-        def rcvr(orig_paths, rev, author, date, message, pool):
-            ret[rev] = (orig_paths, author, date, message)
-        self.client_ctx.log([path], start_revnum, stop_revnum, True, True, rcvr)
+        def rcvr(orig_paths, rev, revprops):
+            ret[rev] = (orig_paths, 
+                        revprops.get(constants.PROP_REVISION_AUTHOR),
+                        revprops.get(constants.PROP_REVISION_DATE),
+                        revprops.get(constants.PROP_REVISION_LOG))
+        self.client_ctx.log([path], rcvr, None, start_revnum, stop_revnum, 
+                            True, True)
         return ret
 
     def client_delete(self, relpath):

=== modified file 'tests/test_commit.py'
--- a/tests/test_commit.py	2008-03-16 06:11:05 +0000
+++ b/tests/test_commit.py	2008-03-16 17:57:35 +0000
@@ -569,6 +569,8 @@
         set_svn_revprops(transport, 1, {"svn:author": "Somebody", 
                                         "svn:date": time_to_cstring(1000000*473385600)})
 
+        import pdb
+        pdb.set_trace()
         self.assertEquals(("Somebody", "1985-01-01T00:00:00.000000Z", "My commit"), 
                           self.client_log("dc")[1][1:])
 

=== modified file 'tests/test_errors.py'
--- a/tests/test_errors.py	2008-03-16 04:31:39 +0000
+++ b/tests/test_errors.py	2008-03-16 17:57:35 +0000
@@ -21,7 +21,7 @@
 
 from errors import (convert_svn_error, convert_error, InvalidPropertyValue, 
                     InvalidSvnBranchPath, NotSvnBranchPath)
-from constants import ERR_UNKNOWN_HOSTNAME
+import constants
 
 from core import SubversionException
 
@@ -64,7 +64,7 @@
         self.assertIsInstance(convert_error(SubversionException("Unexpected end of stream", constants.ERR_INCOMPLETE_DATA)), UnexpectedEndOfContainerError)
 
     def test_convert_unknown_hostname(self):
-        self.assertIsInstance(convert_error(SubversionException("Unknown hostname 'bla'", SVN_ERR_UNKNOWN_HOSTNAME)), ConnectionError)
+        self.assertIsInstance(convert_error(SubversionException("Unknown hostname 'bla'", constants.ERR_UNKNOWN_HOSTNAME)), ConnectionError)
 
     def test_not_implemented(self):
         self.assertIsInstance(convert_error(SubversionException("Remote server doesn't support ...", constants.ERR_RA_NOT_IMPLEMENTED)), NotImplementedError)

=== modified file 'tree.py'
--- a/tree.py	2008-03-16 15:39:05 +0000
+++ b/tree.py	2008-03-16 17:57:35 +0000
@@ -88,7 +88,7 @@
         file_id, revision_id = self.tree.id_map[path]
         ie = self.tree._inventory.add_path(path, 'directory', file_id)
         ie.revision = revision_id
-        return DirectoryTreeEditor(self.editor, file_id)
+        return DirectoryTreeEditor(self.tree, file_id)
 
     def change_prop(self, name, value):
         from mapping import (SVN_PROP_BZR_ANCESTRY, 
@@ -108,11 +108,11 @@
             if self.file_id != self.tree._inventory.root.file_id:
                 mutter('%r set on non-root dir!' % name)
                 return
-        elif name in (SVN_PROP_ENTRY_COMMITTED_DATE,
-                      SVN_PROP_ENTRY_LAST_AUTHOR,
-                      SVN_PROP_ENTRY_LOCK_TOKEN,
-                      SVN_PROP_ENTRY_UUID,
-                      SVN_PROP_EXECUTABLE):
+        elif name in (constants.PROP_ENTRY_COMMITTED_DATE,
+                      constants.PROP_ENTRY_LAST_AUTHOR,
+                      constants.PROP_ENTRY_LOCK_TOKEN,
+                      constants.PROP_ENTRY_UUID,
+                      constants.PROP_EXECUTABLE):
             pass
         elif name.startswith(constants.PROP_WC_PREFIX):
             pass
@@ -198,7 +198,7 @@
 
     def apply_textdelta(self, base_checksum=None):
         self.file_stream = StringIO()
-        return apply_txdelta_handler(StringIO(""), self.file_stream)
+        return apply_txdelta_handler("", self.file_stream)
 
 
 class SvnBasisTree(RevisionTree):

=== modified file 'types.pxd'
--- a/types.pxd	2008-03-16 13:12:04 +0000
+++ b/types.pxd	2008-03-16 17:57:35 +0000
@@ -28,6 +28,7 @@
 cdef extern from "svn_error.h":
     ctypedef struct svn_error_t:
         apr_status_t apr_err
+        svn_error_t *child
         char *message
         char *file
         char *line




More information about the bazaar-commits mailing list