Rev 1266: Fix more tests. in file:///data/jelmer/bzr-svn/0.4-ra-cext/

Jelmer Vernooij jelmer at samba.org
Sun Jun 22 07:04:21 BST 2008


At file:///data/jelmer/bzr-svn/0.4-ra-cext/

------------------------------------------------------------
revno: 1266
revision-id: jelmer at samba.org-20080622060420-2642ifct4wqkibog
parent: jelmer at samba.org-20080622051311-ttn0kyz0hlxq6k4h
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4-ra-cext
timestamp: Sun 2008-06-22 08:04:20 +0200
message:
  Fix more tests.
modified:
  branch.py                      svnbranch.py-20051017135706-11c749eb0dab04a7
  client.c                       client.pyx-20080313235339-wbyjbw2namuiql8f-1
  ra.c                           ra.pyx-20080313140933-qybkqaxe3m4mcll7-1
  tests/__init__.py              __init__.py-20060508151940-e9f4d914801a2535
  util.c                         util.c-20080531154025-s8ef6ej9tytsnkkw-1
  util.h                         util.h-20080531154025-s8ef6ej9tytsnkkw-2
  workingtree.py                 workingtree.py-20060306120941-b083cb0fdd4a69de
=== modified file 'branch.py'
--- a/branch.py	2008-06-21 23:22:22 +0000
+++ b/branch.py	2008-06-22 06:04:20 +0000
@@ -28,7 +28,7 @@
 
 from bzrlib.plugins.svn import core
 from bzrlib.plugins.svn.auth import create_auth_baton
-from bzrlib.plugins.svn.client import Client
+from bzrlib.plugins.svn.client import Client, get_config
 from bzrlib.plugins.svn.commit import push
 from bzrlib.plugins.svn.config import BranchConfig
 from bzrlib.plugins.svn.core import SubversionException

=== modified file 'client.c'
--- a/client.c	2008-06-22 05:13:11 +0000
+++ b/client.c	2008-06-22 06:04:20 +0000
@@ -28,6 +28,8 @@
 #include "wc.h"
 
 PyAPI_DATA(PyTypeObject) Client_Type;
+PyAPI_DATA(PyTypeObject) Config_Type;
+PyAPI_DATA(PyTypeObject) ConfigItem_Type;
 
 typedef struct {
 	PyObject_HEAD
@@ -35,7 +37,14 @@
 	apr_pool_t *pool;
 } ConfigObject;
 
+typedef struct {
+	PyObject_HEAD
+	svn_config_t *item;
+	PyObject *parent;
+} ConfigItemObject;
+
 static int client_set_auth(PyObject *self, PyObject *auth, void *closure);
+static int client_set_config(PyObject *self, PyObject *auth, void *closure);
 
 static bool to_opt_revision(PyObject *arg, svn_opt_revision_t *ret)
 {
@@ -145,6 +154,7 @@
     apr_pool_t *pool;
     PyObject *callbacks;
 	PyObject *py_auth;
+	PyObject *py_config;
 } ClientObject;
 
 static PyObject *client_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
@@ -171,12 +181,9 @@
         return NULL;
 	}
 
-	if (config != Py_None) {
-		PyErr_SetString(PyExc_NotImplementedError, "custom config not supported yet");
-		return NULL;
-	}
-
 	ret->py_auth = NULL;
+	ret->py_config = NULL;
+	client_set_config((PyObject *)ret, config, NULL);
 	client_set_auth((PyObject *)ret, auth, NULL);
     return (PyObject *)ret;
 }
@@ -267,6 +274,20 @@
 	return 0;
 }
 
+static int client_set_config(PyObject *self, PyObject *config, void *closure)
+{
+	ClientObject *client = (ClientObject *)self;
+
+	Py_XDECREF(client->py_config);
+
+	client->client->config = config_hash_from_object(config, client->pool);
+
+	client->py_config = config;
+	Py_INCREF(config);
+
+	return 0;
+}
+
 
 static PyObject *client_add(PyObject *self, PyObject *args, PyObject *kwargs)
 {
@@ -628,6 +649,7 @@
 	{ "log_msg_func", client_get_log_msg_func, client_set_log_msg_func, NULL },
 	{ "notify_func", client_get_notify_func, client_set_notify_func, NULL },
 	{ "auth", NULL, client_set_auth, NULL },
+	{ "config", NULL, client_set_config, NULL },
 	{ NULL, }
 };
 
@@ -651,6 +673,38 @@
     return ret;
 }
 
+static PyObject *config_get_dict(PyObject *self, void *closure)
+{
+	ConfigObject *config = (ConfigObject *)self;
+	apr_pool_t *pool;
+	PyObject *ret;
+    apr_hash_index_t *idx;
+    const char *key;
+    svn_config_t *val;
+    apr_ssize_t klen;
+
+	pool = Pool(NULL);
+	if (pool == NULL)
+		return NULL;
+
+    ret = PyDict_New();
+    for (idx = apr_hash_first(pool, config->config); idx != NULL; 
+		 idx = apr_hash_next(idx)) {
+		ConfigItemObject *data;
+        apr_hash_this(idx, (const void **)&key, &klen, (void **)&val);
+		data = PyObject_New(ConfigItemObject, &ConfigItem_Type);
+		data->item = val;
+        PyDict_SetItemString(ret, key, (PyObject *)data);
+	}
+
+	return ret;
+}
+
+static PyGetSetDef config_getset[] = {
+	{ "__dict__", config_get_dict, NULL, NULL },
+	{ NULL }
+};
+
 static PyMethodDef config_methods[] = {
 	{ "get_default_ignores", (PyCFunction)get_default_ignores, METH_NOARGS, NULL },
 	{ NULL }
@@ -668,9 +722,26 @@
 	.tp_name = "client.Config",
 	.tp_basicsize = sizeof(ConfigObject),
 	.tp_methods = config_methods,
+	.tp_getset = config_getset,
 	.tp_dealloc = (destructor)config_dealloc,
 };
 
+static void configitem_dealloc(PyObject *self)
+{
+	ConfigItemObject *item = (ConfigItemObject *)self;
+
+	Py_XDECREF(item->parent);
+	PyObject_Del(item);
+}
+
+PyTypeObject ConfigItem_Type = {
+	PyObject_HEAD_INIT(NULL) 0,
+	.tp_name = "client.ConfigItem",
+	.tp_basicsize = sizeof(ConfigItemObject),
+	.tp_dealloc = (destructor)configitem_dealloc,
+};
+
+
 
 
 PyTypeObject Client_Type = {
@@ -720,6 +791,9 @@
     if (PyType_Ready(&Config_Type) < 0)
         return;
 
+	if (PyType_Ready(&ConfigItem_Type) < 0)
+        return;
+
 	/* Make sure APR is initialized */
 	apr_initialize();
 

=== modified file 'ra.c'
--- a/ra.c	2008-06-22 04:51:45 +0000
+++ b/ra.c	2008-06-22 06:04:20 +0000
@@ -525,8 +525,6 @@
 	RemoteAccessObject *ret;
 	apr_hash_t *config_hash;
 	svn_ra_callbacks2_t *callbacks2;
-	Py_ssize_t idx = 0;
-	PyObject *key, *value;
 	svn_auth_baton_t *auth_baton;
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO", kwnames, &url, &progress_cb, (PyObject **)&auth, &config))
@@ -561,14 +559,8 @@
 	callbacks2->open_tmp_file = py_open_tmp_file;
 	ret->progress_func = progress_cb;
 	callbacks2->progress_baton = (void *)ret->progress_func;
-	config_hash = apr_hash_make(ret->pool);
-	if (PyDict_Check(config)) {
-		while (PyDict_Next(config, &idx, &key, &value)) {
-			apr_hash_set(config_hash, apr_pstrdup(ret->pool, PyString_AsString(key)), 
-						 PyString_Size(key), apr_pstrdup(ret->pool, PyString_AsString(value)));
-		}
-	} else if (config != Py_None) {
-		PyErr_SetString(PyExc_TypeError, "Expected dictionary for config");
+	config_hash = config_hash_from_object(config, ret->pool);
+	if (config_hash == NULL) {
 		apr_pool_destroy(ret->pool);
 		PyObject_Del(ret);
 		return NULL;

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2008-06-22 05:13:11 +0000
+++ b/tests/__init__.py	2008-06-22 06:04:20 +0000
@@ -29,8 +29,6 @@
 from bzrlib.urlutils import local_path_to_url
 from bzrlib.workingtree import WorkingTree
 
-import svn.core
-
 from bzrlib.plugins.svn import properties, ra, repos
 from bzrlib.plugins.svn.client import Client
 from bzrlib.plugins.svn.ra import Auth, RemoteAccess, txdelta_send_stream

=== modified file 'util.c'
--- a/util.c	2008-06-22 04:51:45 +0000
+++ b/util.c	2008-06-22 06:04:20 +0000
@@ -23,6 +23,7 @@
 #include <svn_io.h>
 #include <apr_errno.h>
 #include <svn_error_codes.h>
+#include <svn_config.h>
 
 #include "util.h"
 
@@ -258,4 +259,37 @@
     return NULL;
 }
 
+apr_hash_t *config_hash_from_object(PyObject *config, apr_pool_t *pool)
+{
+	Py_ssize_t idx = 0;
+	PyObject *key, *value;
+	apr_hash_t *config_hash;
+	PyObject *dict;
+	if (config == Py_None) {
+		RUN_SVN_WITH_POOL(pool, 
+					  svn_config_get_config(&config_hash, NULL, pool));
+		return config_hash;
+	}
+
+	config_hash = apr_hash_make(pool);
+
+	if (PyDict_Check(config)) {
+		dict = config;
+	} else {
+		dict = PyObject_GetAttrString(config, "__dict__");
+	}
+	
+	if (!PyDict_Check(dict)) {
+		PyErr_Format(PyExc_TypeError, "Expected dictionary for config, got %s", dict->ob_type->tp_name);
+		return NULL;
+	}
+
+	while (PyDict_Next(dict, &idx, &key, &value)) {
+		apr_hash_set(config_hash, apr_pstrdup(pool, PyString_AsString(key)), 
+					 PyString_Size(key), apr_pstrdup(pool, PyString_AsString(value)));
+	}
+
+	return config_hash;
+}
+
 

=== modified file 'util.h'
--- a/util.h	2008-06-22 04:51:45 +0000
+++ b/util.h	2008-06-22 06:04:20 +0000
@@ -44,6 +44,7 @@
 svn_stream_t *new_py_stream(apr_pool_t *pool, PyObject *py);
 PyObject *PyErr_NewSubversionException(svn_error_t *error);
 svn_error_t *py_cancel_func(void *cancel_baton);
+apr_hash_t *config_hash_from_object(PyObject *config, apr_pool_t *pool);
 
 #pragma GCC visibility pop
 

=== modified file 'workingtree.py'
--- a/workingtree.py	2008-06-22 04:51:45 +0000
+++ b/workingtree.py	2008-06-22 06:04:20 +0000
@@ -32,11 +32,14 @@
 from bzrlib.workingtree import WorkingTree, WorkingTreeFormat
 
 from bzrlib.plugins.svn import core, properties
+from bzrlib.plugins.svn.auth import create_auth_baton
 from bzrlib.plugins.svn.branch import SvnBranch
+from bzrlib.plugins.svn.client import Client
 from bzrlib.plugins.svn.commit import _revision_id_to_svk_feature
 from bzrlib.plugins.svn.convert import SvnConverter
 from bzrlib.plugins.svn.core import SubversionException, time_to_cstring
 from bzrlib.plugins.svn.errors import LocalCommitsUnsupported, NoSvnRepositoryPresent, ERR_FS_TXN_OUT_OF_DATE, ERR_ENTRY_EXISTS, ERR_WC_PATH_NOT_FOUND, ERR_WC_NOT_DIRECTORY
+from bzrlib.plugins.svn.format import get_rich_root_format
 from bzrlib.plugins.svn.mapping import (SVN_PROP_BZR_ANCESTRY, SVN_PROP_BZR_FILEIDS, 
                      SVN_PROP_BZR_REVISION_ID, SVN_PROP_BZR_REVISION_INFO,
                      escape_svn_path, generate_revision_metadata)
@@ -51,12 +54,6 @@
 import os
 import urllib
 
-import svn.core
-
-from bzrlib.plugins.svn.auth import create_auth_baton
-from bzrlib.plugins.svn.client import Client
-from bzrlib.plugins.svn.format import get_rich_root_format
-
 def generate_ignore_list(ignore_map):
     """Create a list of ignores, ordered by directory.
     




More information about the bazaar-commits mailing list