[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] svn_client_ctx_t callback fixes, mark 2

From: Walter Mundt <emage_at_spamcop.net>
Date: 2006-05-28 12:53:30 CEST

After some discussion with maxb on IRC and a bit more work, here is a
new-and-hopefully-improved patch. Main changes are a warning about the
dangers of the PY_AS_VOID typemap, using #ifdef's around that typemap to
match with Jelmer's patch, and a new test of the client.log3() function.

[[[
Provide direct access to certain libsvn_swig_py "thunk" function
pointers to Python so that Python code can properly set fields in
svn_client_ctx_t structures.

[ In subversion/bindings/swig ]

* include/svn_types.swg:
   (PY_AS_VOID): New typemap for converting PyObjects into void* batons.
* svn_client.i:
   Mark svn_client_ctx_t baton members as PY_AS_VOID
   (svn_swig_py_cancel_func): new opaque pointer constant
   (svn_swig_py_get_commit_log_func): new opaque pointer constant
* python/tests/client.py:
   Fixed up doc comments throughout.
   (SubversionRepositoryTestCase): Renamed test case class to
   SubversionClientTestCase (original name is a probable typo)
   (test_mkdir_url, test_log3_url): New tests.
]]]

Index: subversion/bindings/swig/python/tests/client.py
===================================================================
--- subversion/bindings/swig/python/tests/client.py (revision 19841)
+++ subversion/bindings/swig/python/tests/client.py (working copy)
@@ -5,13 +5,33 @@
 from trac.versioncontrol.tests.svn_fs import SubversionRepositoryTestSetup, \
   REPOS_PATH
 from urllib import pathname2url
+from urlparse import urljoin
 
-class SubversionRepositoryTestCase(unittest.TestCase):
- """Test cases for the Subversion repository layer"""
+class SubversionClientTestCase(unittest.TestCase):
+ """Test cases for the basic SWIG Subversion client layer"""
 
+ def log_message_func(self, items, pool):
+ """ Simple log message provider for unit tests. """
+ self.log_message_func_calls += 1
+ return "Test log message"
+
+ def log_receiver(self, changed_paths, revision, author, date, message, pool):
+ """ Function to recieve log messages retrieved by client.log3(). """
+ self.log_message = message
+ self.change_author = author
+ self.changed_paths = changed_paths
+
   def setUp(self):
- """Load a Subversion repository"""
+ """Set up authentication and client context"""
     self.client_ctx = client.svn_client_create_context()
+ self.client_ctx.log_msg_func2 = client.svn_swig_py_get_commit_log_func
+ # nasty refcount issue -- to be fixed in higher-level bindings
+ self.boundLogMsgFunc = self.log_message_func
+ self.client_ctx.log_msg_baton2 = self.boundLogMsgFunc
+ self.log_message_func_calls = 0
+ self.log_message = None
+ self.changed_paths = None
+ self.change_auther = None
 
     providers = [
        client.svn_client_get_simple_provider(),
@@ -19,6 +39,7 @@
     ]
 
     self.client_ctx.auth_baton = core.svn_auth_open(providers)
+ self.repos_url = "file://" + pathname2url(REPOS_PATH)
 
   def info_receiver(self, path, info, pool):
     """Squirrel away the output from 'svn info' so that the unit tests
@@ -27,27 +48,50 @@
     self.info = info
 
   def test_info(self):
- """Test scope of get_logs callbacks"""
+ """Test svn_client_info on an empty repository"""
 
     # Run info
     revt = core.svn_opt_revision_t()
     revt.kind = core.svn_opt_revision_head
- repos_url = "file://" + pathname2url(REPOS_PATH)
- client.info(repos_url, revt, revt, self.info_receiver,
+ client.info(self.repos_url, revt, revt, self.info_receiver,
                 False, self.client_ctx)
 
     # Check output from running info. This also serves to verify that
     # the internal 'info' object is still valid
     self.assertEqual(self.path, os.path.basename(REPOS_PATH))
     self.info.assert_valid()
- self.assertEqual(self.info.URL, repos_url)
- self.assertEqual(self.info.repos_root_URL, repos_url)
+ self.assertEqual(self.info.URL, self.repos_url)
+ self.assertEqual(self.info.repos_root_URL, self.repos_url)
 
+ def test_mkdir_url(self):
+ """Test svn_client_mkdir2 on a file:// URL"""
+ dir = urljoin(self.repos_url+"/", "dir1")
+
+ commit_info = client.mkdir2((dir,), self.client_ctx)
+ self.assertEqual(commit_info.revision, 13)
+ self.assertEqual(self.log_message_func_calls, 1)
 
+ def test_log3_url(self):
+ """Test svn_client_log3 on a file:// URL"""
+ dir = urljoin(self.repos_url+"/", "trunk/dir1")
+
+ start = core.svn_opt_revision_t()
+ end = core.svn_opt_revision_t()
+ core.svn_opt_parse_revision(start, end, "4:0")
+ client.log3((dir,), start, start, end, 1, True, False, self.log_receiver,
+ self.client_ctx)
+ self.assertEqual(self.change_author, "john")
+ self.assertEqual(self.log_message, "More directories.")
+ self.assertEqual(len(self.changed_paths), 3)
+ for dir in ('/trunk/dir1', '/trunk/dir2', '/trunk/dir3'):
+ self.assertTrue(self.changed_paths.has_key(dir))
+ self.assertEqual(self.changed_paths[dir].action, 'A')
+
 def suite():
- return unittest.makeSuite(SubversionRepositoryTestCase, 'test',
+ return unittest.makeSuite(SubversionClientTestCase, 'test',
                               suiteClass=SubversionRepositoryTestSetup)
 
 if __name__ == '__main__':
     runner = unittest.TextTestRunner()
     runner.run(suite())
+
Index: subversion/bindings/swig/include/svn_types.swg
===================================================================
--- subversion/bindings/swig/include/svn_types.swg (revision 19841)
+++ subversion/bindings/swig/include/svn_types.swg (working copy)
@@ -526,6 +526,23 @@
 }
 
 /* -----------------------------------------------------------------------
+ Mapper to automatically turn Python objects into void* batons on assignment
+*/
+
+#ifdef SWIGPYTHON
+/* NOTE: Use of this typemap can be dangerous, because it doesn't INCREF
+ the object. All objects passed via this template MUST have a
+ reference kept alive elsewhere in Python code. */
+%typemap(in) void *PY_AS_VOID {
+ if ($input == Py_None) {
+ $1 = NULL;
+ } else {
+ $1 = (void *)$input;
+ }
+}
+#endif
+
+/* -----------------------------------------------------------------------
    Wrap the digest output for functions populating digests.
 */
 
Index: subversion/bindings/swig/svn_client.i
===================================================================
--- subversion/bindings/swig/svn_client.i (revision 19841)
+++ subversion/bindings/swig/svn_client.i (working copy)
@@ -71,6 +71,16 @@
 
 #ifdef SWIGPYTHON
 %apply svn_stream_t *WRAPPED_STREAM { svn_stream_t * };
+
+/* members of svn_client_ctx_t */
+%apply void *PY_AS_VOID {
+ void *notify_baton,
+ void *log_msg_baton,
+ void *cancel_baton,
+ void *notify_baton2,
+ void *log_msg_baton2,
+ void *progress_baton
+};
 #endif
 
 /* -----------------------------------------------------------------------
@@ -498,6 +508,14 @@
 %include svn_time_h.swg
 %include svn_client_h.swg
 
+#ifdef SWIGPYTHON
+
+/* provide Python with access to some thunks. */
+%constant svn_cancel_func_t svn_swig_py_cancel_func;
+%constant svn_client_get_commit_log2_t svn_swig_py_get_commit_log_func;
+
+#endif
+
 #ifdef SWIGRUBY
 %inline %{
 static VALUE

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun May 28 12:54:25 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.