Rev 957: Finish open call for ra. in file:///data/jelmer/bzr-svn/pyrex/

Jelmer Vernooij jelmer at samba.org
Thu Mar 13 15:13:16 GMT 2008


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

------------------------------------------------------------
revno: 957
revision-id:jelmer at samba.org-20080313151315-h299qawxzu1fiv4n
parent: jelmer at samba.org-20080313143553-dwpbwylaghuxl7h7
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: pyrex
timestamp: Thu 2008-03-13 16:13:15 +0100
message:
  Finish open call for ra.
modified:
  ra.pyx                         ra.pyx-20080313140933-qybkqaxe3m4mcll7-1
=== modified file 'ra.pyx'
--- a/ra.pyx	2008-03-13 14:35:53 +0000
+++ b/ra.pyx	2008-03-13 15:13:15 +0000
@@ -24,11 +24,28 @@
 cdef extern from "svn_error.h":
     ctypedef struct svn_error_t
 
+cdef extern from "apr_errno.h":
+    ctypedef int apr_status_t
+
 cdef extern from "apr_pools.h":
     ctypedef struct apr_pool_t
+    void apr_pool_destroy(apr_pool_t *)
+    apr_status_t apr_pool_create(apr_pool_t **newpool, apr_pool_t *parent)
+
+cdef apr_pool_t *Pool(apr_pool_t *parent):
+    cdef apr_status_t status
+    cdef apr_pool_t *ret
+    ret = NULL
+    status = apr_pool_create(&ret, parent)
+    if status != 0:
+        # FIXME: Clearer error
+        raise Exception("APR Error")
+    return ret
 
 cdef extern from "apr_hash.h":
     ctypedef struct apr_hash_t
+    apr_hash_t *apr_hash_make(apr_pool_t *pool)
+    void apr_hash_set(apr_hash_t *ht, char *key, long klen, char *val)
 
 cdef extern from "svn_ra.h":
     svn_version_t *svn_ra_version()
@@ -58,15 +75,26 @@
 
     ctypedef struct svn_ra_callbacks2_t
 
+    svn_error_t *svn_ra_create_callbacks(svn_ra_callbacks2_t **callbacks,
+                            apr_pool_t *pool)
+
     ctypedef struct svn_ra_session_t
 
     svn_error_t *svn_ra_open2(svn_ra_session_t **session_p,
                           char *repos_URL,
                           svn_ra_callbacks2_t *callbacks,
-                          void *callback_baton,
+                          callback_baton,
                           apr_hash_t *config,
                           apr_pool_t *pool)
 
+    svn_error_t *svn_ra_reparent(svn_ra_session_t *ra_session, char *url, 
+            apr_pool_t *pool)
+
+    svn_error_t *svn_ra_get_latest_revnum(svn_ra_session_t *session,
+                                      long *latest_revnum,
+                                      apr_pool_t *pool)
+
+
 
 def version():
     """Get libsvn_ra version information.
@@ -76,4 +104,45 @@
     return (svn_ra_version().major, svn_ra_version().minor, 
             svn_ra_version().minor, svn_ra_version().tag)
 
-
+cdef void _check_error(svn_error_t *error):
+    if error:
+        # FIXME
+        raise Exception("SVN error")
+
+cdef class RemoteAccess:
+    cdef svn_ra_session_t *ra
+    cdef apr_pool_t *pool
+    def __init__(self, url, callbacks, config={}):
+        """Connect to a remote Subversion repository. 
+
+        :param url: URL of the repository
+        :param callbacks: Object to report progress and errors to.
+        :param config: Optional configuration
+        """
+        cdef svn_error_t *error
+        cdef svn_ra_callbacks2_t *callbacks2
+        cdef apr_hash_t *config_hash
+        self.pool = Pool(NULL)
+        assert self.pool != NULL
+        _check_error(svn_ra_create_callbacks(&callbacks2, self.pool))
+        config_hash = apr_hash_make(self.pool)
+        for (key, val) in config.items():
+            apr_hash_set(config_hash, key, len(key), val)
+        _check_error(svn_ra_open2(&self.ra, url, callbacks2, None, config_hash, 
+                     self.pool))
+
+    def get_latest_revnum(self):
+        """Obtain the number of the latest committed revision in the 
+        connected repository.
+        """
+        cdef long latest_revnum
+        cdef apr_pool_t *temp_pool
+        temp_pool = Pool(self.pool)
+        _check_error(svn_ra_get_latest_revnum(self.ra, &latest_revnum, 
+                     temp_pool))
+        apr_pool_destroy(temp_pool)
+        return latest_revnum
+
+    def __dealloc__(self):
+        if self.pool != NULL:
+            apr_pool_destroy(self.pool)




More information about the bazaar-commits mailing list