Rev 1051: Provide access to the fs associated with a repos. in file:///data/jelmer/bzr-svn/cext/
Jelmer Vernooij
jelmer at samba.org
Mon Jun 2 21:15:48 BST 2008
At file:///data/jelmer/bzr-svn/cext/
------------------------------------------------------------
revno: 1051
revision-id: jelmer at samba.org-20080602201547-1s9prjrm5x6hgp0h
parent: jelmer at samba.org-20080602191337-661krsid8e2bu8xq
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: cext
timestamp: Mon 2008-06-02 22:15:47 +0200
message:
Provide access to the fs associated with a repos.
modified:
client.c client.pyx-20080313235339-wbyjbw2namuiql8f-1
core.c core.pyx-20080313210413-17k59slolpfe5kdq-1
repos.c repos.pyx-20080314114432-g2b5lqe776tkbl4k-1
tests/__init__.py __init__.py-20060508151940-e9f4d914801a2535
transport.py transport.py-20060406231150-b3472d06b3a0818d
util.c util.c-20080531154025-s8ef6ej9tytsnkkw-1
=== modified file 'client.c'
--- a/client.c 2008-06-02 18:58:48 +0000
+++ b/client.c 2008-06-02 20:15:47 +0000
@@ -112,21 +112,32 @@
static void client_dealloc(PyObject *self)
{
ClientObject *client = (ClientObject *)self;
+ if (client->client->log_msg_baton2 != NULL) {
+ Py_DECREF((PyObject *)client->client->log_msg_baton2);
+ }
apr_pool_destroy(client->pool);
client->pool = NULL;
}
-static PyObject *client_set_log_msg_func(PyObject *self, PyObject *args)
+static PyObject *client_get_log_msg_func(PyObject *self, void *closure)
{
- PyObject *func;
ClientObject *client = (ClientObject *)self;
- if (!PyArg_ParseTuple(args, "O", &func))
- return NULL;
+ client->client->log_msg_func2 = py_log_msg_func2;
+ if (client->client->log_msg_baton2 == NULL)
+ return Py_None;
+ return client->client->log_msg_baton2;
+}
+static int client_set_log_msg_func(PyObject *self, PyObject *func, void *closure)
+{
+ ClientObject *client = (ClientObject *)self;
client->client->log_msg_func2 = py_log_msg_func2;
+ if (client->client->log_msg_baton2 != NULL) {
+ Py_DECREF((PyObject *)client->client->log_msg_baton2);
+ }
client->client->log_msg_baton2 = (void *)func;
Py_INCREF(func);
- return Py_None;
+ return 0;
}
static PyObject *client_add(PyObject *self, PyObject *args, PyObject *kwargs)
@@ -374,7 +385,6 @@
}
static PyMethodDef client_methods[] = {
- { "set_log_msg_func", client_set_log_msg_func, METH_VARARGS, NULL },
{ "add", (PyCFunction)client_add, METH_VARARGS|METH_KEYWORDS, NULL },
{ "checkout", (PyCFunction)client_checkout, METH_VARARGS|METH_KEYWORDS, NULL },
{ "commit", (PyCFunction)client_commit, METH_VARARGS|METH_KEYWORDS, NULL },
@@ -390,6 +400,11 @@
{ NULL }
};
+static PyGetSetDef client_getset[] = {
+ { "log_msg_func", client_get_log_msg_func, client_set_log_msg_func, NULL },
+ { NULL }
+};
+
PyTypeObject Client_Type = {
PyObject_HEAD_INIT(&PyType_Type) 0,
.tp_name = "client.Client",
@@ -397,6 +412,7 @@
.tp_methods = client_methods,
.tp_dealloc = client_dealloc,
.tp_new = client_new,
+ .tp_getset = client_getset,
};
void initclient(void)
=== modified file 'core.c'
--- a/core.c 2008-06-02 19:13:37 +0000
+++ b/core.c 2008-06-02 20:15:47 +0000
@@ -26,33 +26,6 @@
#include "util.h"
-PyAPI_DATA(PyTypeObject) SubversionExceptionType;
-
-typedef struct {
- PyObject_HEAD
- char *msg;
- int num;
-} SubversionExceptionObject;
-
-static PyObject *SubversionException_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-{
- char *kwnames[] = { "msg", "num", NULL };
- SubversionExceptionObject *ret;
- /* FIXME */
- ret = PyObject_New(SubversionExceptionObject, &SubversionExceptionType);
- if (ret == NULL)
- return NULL;
-
- return (PyObject *)ret;
-}
-
-PyTypeObject SubversionExceptionType = {
- PyObject_HEAD_INIT(&PyType_Type) 0,
- .tp_name = "core.SubversionException",
- .tp_basicsize = sizeof(SubversionExceptionObject),
- .tp_new = SubversionException_new,
-};
-
/** Convert a UNIX timestamp to a Subversion CString. */
static PyObject *time_to_cstring(PyObject *self, PyObject *args)
{
@@ -90,7 +63,6 @@
apr_pool_t *pool;
apr_hash_t *cfg_hash;
apr_hash_index_t *idx;
- char *c_config_dir;
const char *key;
char *val;
apr_ssize_t klen;
@@ -101,10 +73,8 @@
return NULL;
pool = Pool(NULL);
- if (check_error(svn_config_get_config(&cfg_hash, c_config_dir, pool))) {
- apr_pool_destroy(pool);
- return NULL;
- }
+ RUN_SVN_WITH_POOL(pool,
+ svn_config_get_config(&cfg_hash, config_dir, pool));
ret = PyDict_New();
for (idx = apr_hash_first(pool, cfg_hash); idx != NULL;
idx = apr_hash_next(idx)) {
@@ -127,9 +97,6 @@
{
PyObject *mod;
- if (PyType_Ready(&SubversionExceptionType) < 0)
- return;
-
apr_initialize();
mod = Py_InitModule3("core", core_methods, "Core functions");
@@ -141,6 +108,6 @@
PyModule_AddObject(mod, "NODE_UNKNOWN", PyInt_FromLong(svn_node_unknown));
PyModule_AddObject(mod, "NODE_NONE", PyInt_FromLong(svn_node_none));
- PyModule_AddObject(mod, "SubversionException", (PyObject *)&SubversionExceptionType);
- Py_INCREF(&SubversionExceptionType);
+ PyModule_AddObject(mod, "SubversionException",
+ PyErr_NewException("core.SubversionException", NULL, NULL));
}
=== modified file 'repos.c'
--- a/repos.c 2008-06-02 18:58:48 +0000
+++ b/repos.c 2008-06-02 20:15:47 +0000
@@ -25,6 +25,7 @@
#include "util.h"
PyAPI_DATA(PyTypeObject) Repository_Type;
+PyAPI_DATA(PyTypeObject) FileSystem_Type;
typedef struct {
PyObject_HEAD
@@ -90,6 +91,69 @@
return (PyObject *)ret;
}
+typedef struct {
+ PyObject_HEAD
+ RepositoryObject *repos;
+ apr_pool_t *pool;
+ svn_fs_t *fs;
+} FileSystemObject;
+
+static PyObject *repos_fs(PyObject *self)
+{
+ RepositoryObject *reposobj = (RepositoryObject *)self;
+ FileSystemObject *ret;
+ svn_fs_t *fs;
+
+ fs = svn_repos_fs(reposobj->repos);
+
+ ret = PyObject_New(FileSystemObject, &FileSystem_Type);
+ if (ret == NULL)
+ return NULL;
+
+ ret->fs = fs;
+ ret->repos = reposobj;
+ ret->pool = reposobj->pool;
+ Py_INCREF(reposobj);
+
+ return (PyObject *)ret;
+}
+
+static PyObject *fs_get_uuid(PyObject *self)
+{
+ FileSystemObject *fsobj = (FileSystemObject *)self;
+ const char *uuid;
+ PyObject *ret;
+ apr_pool_t *temp_pool;
+
+ temp_pool = Pool(fsobj->pool);
+ RUN_SVN_WITH_POOL(temp_pool, svn_fs_get_uuid(fsobj->fs, &uuid, temp_pool));
+ ret = PyString_FromString(uuid);
+ apr_pool_destroy(temp_pool);
+
+ return ret;
+}
+
+static PyMethodDef fs_methods[] = {
+ { "get_uuid", (PyCFunction)fs_get_uuid, METH_NOARGS, NULL },
+ { NULL }
+};
+
+static void fs_dealloc(PyObject *self)
+{
+ FileSystemObject *fsobj = (FileSystemObject *)self;
+
+ Py_DECREF(fsobj->repos);
+ apr_pool_destroy(fsobj->pool);
+}
+
+PyTypeObject FileSystem_Type = {
+ PyObject_HEAD_INIT(NULL) 0,
+ .tp_name = "repos.FileSystem",
+ .tp_basicsize = sizeof(FileSystemObject),
+ .tp_dealloc = fs_dealloc,
+ .tp_methods = fs_methods,
+};
+
static PyObject *repos_load_fs(PyObject *self, PyObject *args, PyObject *kwargs)
{
const char *parent_dir = "";
@@ -127,6 +191,7 @@
static PyMethodDef repos_methods[] = {
{ "load_fs", (PyCFunction)repos_load_fs, METH_VARARGS|METH_KEYWORDS, NULL },
+ { "fs", (PyCFunction)repos_fs, METH_NOARGS, NULL },
{ NULL }
};
@@ -145,6 +210,9 @@
if (PyType_Ready(&Repository_Type) < 0)
return;
+ if (PyType_Ready(&FileSystem_Type) < 0)
+ return;
+
apr_initialize();
mod = Py_InitModule3("repos", repos_module_methods, "Local repository management");
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2008-05-30 02:38:27 +0000
+++ b/tests/__init__.py 2008-06-02 20:15:47 +0000
@@ -36,7 +36,7 @@
def setUp(self):
super(TestCaseWithSubversionRepository, self).setUp()
self.client_ctx = client.Client()
- self.client_ctx.set_log_msg_func(self.log_message_func)
+ self.client_ctx.log_msg_func = self.log_message_func
def log_message_func(self, items):
return (self.next_message, None)
=== modified file 'transport.py'
--- a/transport.py 2008-05-31 04:01:48 +0000
+++ b/transport.py 2008-06-02 20:15:47 +0000
@@ -31,7 +31,7 @@
import urlparse
import urllib
-svn_config = core.get_config(None)
+svn_config = core.get_config()
def get_client_string():
"""Return a string that can be send as part of the User Agent string."""
=== modified file 'util.c'
--- a/util.c 2008-06-02 17:12:25 +0000
+++ b/util.c 2008-06-02 20:15:47 +0000
@@ -39,12 +39,18 @@
PyObject *PyErr_NewSubversionException(svn_error_t *error)
{
+
return NULL; /* FIXME */
}
void PyErr_SetSubversionException(svn_error_t *error)
{
- /* FIXME */
+ PyObject *excobj = PyImport_ImportModule("core.SubversionException");
+
+ if (excobj == NULL)
+ abort();
+
+ PyErr_SetObject(excobj, Py_BuildValue("(si)", error->message, error->apr_err));
}
bool check_error(svn_error_t *error)
More information about the bazaar-commits
mailing list