Rev 1042: Move some common helper functions into a separate file. in file:///data/jelmer/bzr-svn/cext/

Jelmer Vernooij jelmer at samba.org
Sat May 31 16:45:51 BST 2008


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

------------------------------------------------------------
revno: 1042
revision-id: jelmer at samba.org-20080531154551-twgnvrs7ybj38ry3
parent: jelmer at samba.org-20080531153255-fnypium32rvodn03
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: cext
timestamp: Sat 2008-05-31 17:45:51 +0200
message:
  Move some common helper functions into a separate file.
removed:
  apr.pxd                        apr.pxd-20080313192457-r08q1i1681oz4fqp-1
added:
  util.c                         util.c-20080531154025-s8ef6ej9tytsnkkw-1
  util.h                         util.h-20080531154025-s8ef6ej9tytsnkkw-2
modified:
  client.c                       client.pyx-20080313235339-wbyjbw2namuiql8f-1
  core.c                         core.pyx-20080313210413-17k59slolpfe5kdq-1
  ra.c                           ra.pyx-20080313140933-qybkqaxe3m4mcll7-1
  setup.py                       setup.py-20060502115218-86950492da22353f
=== removed file 'apr.pxd'
--- a/apr.pxd	2008-05-31 04:01:48 +0000
+++ b/apr.pxd	1970-01-01 00:00:00 +0000
@@ -1,65 +0,0 @@
-# Copyright © 2008 Jelmer Vernooij <jelmer at samba.org>
-# -*- coding: utf-8 -*-
-# vim: ft=pyrex
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-# APR stuff
-
-cdef extern from "apr_errno.h":
-    ctypedef int apr_status_t
-    ctypedef unsigned long apr_size_t
-    char * apr_strerror(apr_status_t statcode, char *buf, apr_size_t bufsize)
-
-cdef extern from "apr_general.h":
-    ctypedef unsigned long apr_uint32_t
-    apr_status_t apr_initialize()
-
-cdef extern from "apr_file_io.h":
-    ctypedef struct apr_file_t 
-    ctypedef long long apr_off_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)
-    void *apr_palloc(apr_pool_t *, apr_size_t)
-
-cdef extern from "apr_strings.h":
-    char *apr_pstrdup(apr_pool_t *p, char *s)
-
-cdef extern from "apr_tables.h":
-    ctypedef struct apr_array_header_t:
-        apr_pool_t *pool
-        int elt_size
-        int nelts
-        int nalloc
-        char *elts
-    apr_array_header_t *apr_array_make(apr_pool_t *p, int nelts, int elt_size)
-    void *apr_array_push(apr_array_header_t *arr)
-    void *apr_array_pop(apr_array_header_t *arr)
-
-cdef extern from "apr_hash.h":
-    ctypedef struct apr_hash_t
-    ctypedef struct apr_hash_index_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)
-    apr_hash_index_t *apr_hash_first(apr_pool_t *p, apr_hash_t *ht)
-    apr_hash_index_t * apr_hash_next(apr_hash_index_t *hi)
-    void apr_hash_this(apr_hash_index_t *hi, void **key, 
-                                long *klen, void **val)
-
-cdef extern from "apr_time.h":
-    ctypedef unsigned long long apr_time_t

=== modified file 'client.c'
--- a/client.c	2008-05-31 15:32:55 +0000
+++ b/client.c	2008-05-31 15:45:51 +0000
@@ -22,6 +22,8 @@
 #include <svn_opt.h>
 #include <svn_client.h>
 
+#include "util.h"
+
 static bool to_opt_revision(PyObject *arg, svn_opt_revision_t *ret)
 {
     if (PyInt_Check(arg)) {
@@ -49,7 +51,7 @@
     return false;
 }
      
-svn_error_t *py_log_msg_func2(const char **log_msg, const char **tmp_file, apr_array_header_t *commit_items, void *baton, apr_pool_t *pool)
+svn_error_t *py_log_msg_func2(const char **log_msg, const char **tmp_file, const apr_array_header_t *commit_items, void *baton, apr_pool_t *pool)
 {
     PyObject *py_commit_items, *ret, *py_log_msg, *py_tmp_file;
     if (baton == Py_None)
@@ -327,7 +329,7 @@
     PyObject *rev = Py_None;
     bool force = false;
     ClientObject *client = (ClientObject *)self;
-    char *propname, *propval, *url;
+    char *propname, *url;
     svn_revnum_t set_rev;
     svn_opt_revision_t c_rev;
     svn_string_t c_val;

=== modified file 'core.c'
--- a/core.c	2008-05-31 15:32:55 +0000
+++ b/core.c	2008-05-31 15:45:51 +0000
@@ -24,6 +24,8 @@
 #include <svn_config.h>
 #include <svn_io.h>
 
+#include "util.h"
+
 PyAPI_DATA(PyTypeObject) SubversionExceptionType;
  
 svn_error_t *py_cancel_func(void *cancel_baton)
@@ -46,7 +48,7 @@
 
 static PyObject *SubversionException_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
 {
-	const char *kwnames[] = { "msg", "num", NULL };
+	char *kwnames[] = { "msg", "num", NULL };
 	SubversionExceptionObject *ret;
 	/* FIXME */
 	ret = PyObject_New(SubversionExceptionObject, &SubversionExceptionType);
@@ -56,11 +58,6 @@
 	return (PyObject *)ret;
 }
 
-void PyErr_SetSubversionException(svn_error_t *error)
-{
-	/* FIXME */
-}
-
 PyTypeObject SubversionExceptionType = {
 	PyObject_HEAD_INIT(&PyExc_BaseException) 0,
 	.tp_name = "core.SubversionException",
@@ -69,37 +66,13 @@
 	.tp_new = SubversionException_new,
 };
 
-static PyObject *wrap_lock(svn_lock_t *lock)
+PyObject *wrap_lock(svn_lock_t *lock)
 {
     return Py_BuildValue("(zzzbzz)", lock->path, lock->token, lock->owner, 
 						 lock->comment, lock->is_dav_comment, 
 						 lock->creation_date, lock->expiration_date);
 }
 
-bool check_error(svn_error_t *error)
-{
-    if (error != NULL) {
-		PyErr_SetSubversionException(error);
-   		return false;
-	}
-	return true;
-}
-
-apr_pool_t *Pool(apr_pool_t *parent)
-{
-    apr_status_t status;
-    apr_pool_t *ret;
-    char errmsg[1024];
-    ret = NULL;
-    status = apr_pool_create(&ret, parent);
-    if (status != 0) {
-        PyErr_SetString(PyExc_Exception, 
-						apr_strerror(status, errmsg, sizeof(errmsg)));
-		return NULL;
-	}
-    return ret;
-}
-
 /** Convert a UNIX timestamp to a Subversion CString. */
 static PyObject *time_to_cstring(PyObject *self, PyObject *args)
 {
@@ -138,9 +111,9 @@
     apr_hash_t *cfg_hash;
     apr_hash_index_t *idx;
     char *c_config_dir;
-    char *key;
+    const char *key;
     char *val;
-    long klen;
+    apr_ssize_t klen;
 	PyObject *config_dir = Py_None, *ret;
 
 	if (!PyArg_ParseTuple(args, "z", &config_dir))
@@ -159,7 +132,7 @@
     ret = PyDict_New();
     for (idx = apr_hash_first(pool, cfg_hash); idx != NULL; 
 		 idx = apr_hash_next(idx)) {
-        apr_hash_this(idx, (void **)&key, &klen, (void **)&val);
+        apr_hash_this(idx, (const void **)&key, &klen, (void **)&val);
         PyDict_SetItemString(ret, key, PyString_FromString(val));
 	}
     apr_pool_destroy(pool);
@@ -185,60 +158,6 @@
     return ret;
 }
 
-apr_array_header_t *string_list_to_apr_array(apr_pool_t *pool, PyObject *l)
-{
-    apr_array_header_t *ret;
-	int i;
-    if (l == Py_None) {
-        return NULL;
-	}
-    ret = apr_array_make(pool, PyList_Size(l), 4);
-	for (i = 0; i < PyList_Size(l); i++) {
-		char **el = (char **)apr_array_push(ret);
-        *el = PyString_AsString(PyList_GetItem(l, i));
-	}
-    return ret;
-}
-
-svn_error_t *py_svn_log_wrapper(void *baton, apr_hash_t *changed_paths, long revision, char *author, char *date, char *message, apr_pool_t *pool)
-{
-    apr_hash_index_t *idx;
-    char *key;
-    long klen;
-    svn_log_changed_path_t *val;
-	PyObject *revprops, *py_changed_paths, *ret;
-
-    if (changed_paths == NULL) {
-        py_changed_paths = Py_None;
-	} else {
-        py_changed_paths = PyDict_New();
-        for (idx = apr_hash_first(pool, changed_paths); idx != NULL;
-             idx = apr_hash_next(idx)) {
-            apr_hash_this(idx, (void **)&key, &klen, (void **)&val);
-			PyDict_SetItemString(py_changed_paths, key, 
-					Py_BuildValue("(czi)", val->action, val->copyfrom_path, 
-                                         val->copyfrom_rev));
-		}
-	}
-    revprops = PyDict_New();
-    if (message != NULL) {
-        PyDict_SetItemString(revprops, SVN_PROP_REVISION_LOG, 
-							 PyString_FromString(message));
-	}
-    if (author != NULL) {
-        PyDict_SetItemString(revprops, SVN_PROP_REVISION_AUTHOR, 
-							 PyString_FromString(author));
-	}
-    if (date != NULL) {
-        PyDict_SetItemString(revprops, SVN_PROP_REVISION_DATE, 
-							 PyString_FromString(date));
-	}
-    ret = PyObject_CallFunction((PyObject *)baton, "OiO", py_changed_paths, 
-								 revision, revprops);
-	/* FIXME: Handle ret != NULL */
-	return NULL;
-}
-
 static svn_error_t *py_stream_read(void *baton, char *buffer, apr_size_t *length)
 {
     PyObject *self = (PyObject *)baton, *ret;
@@ -266,7 +185,7 @@
 	return NULL;
 }
 
-static svn_stream_t *string_stream(apr_pool_t *pool, PyObject *text)
+svn_stream_t *string_stream(apr_pool_t *pool, PyObject *text)
 {
     svn_stringbuf_t *buf;
     buf = svn_stringbuf_ncreate(PyString_AsString(text), 
@@ -285,32 +204,10 @@
     return stream;
 }
 
-PyObject *prop_hash_to_dict(apr_hash_t *props)
-{
-    char *key;
-    apr_hash_index_t *idx;
-    long klen;
-    svn_string_t *val;
-    apr_pool_t *pool;
-	PyObject *py_props;
-    if (props == NULL) {
-        return Py_None;
-	}
-    pool = Pool(NULL);
-    py_props = PyDict_New();
-    for (idx = apr_hash_first(pool, props); idx != NULL; 
-		 idx = apr_hash_next(idx)) {
-        apr_hash_this(idx, (void **)&key, &klen, (void **)&val);
-        PyDict_SetItemString(py_props, key, 
-							 PyString_FromStringAndSize(val->data, val->len));
-	}
-    apr_pool_destroy(pool);
-    return py_props;
-}
-
 static PyMethodDef core_methods[] = {
 	{ "get_config", get_config, METH_VARARGS, NULL },
 	{ "time_from_cstring", time_from_cstring, METH_VARARGS, NULL },
+	{ "time_to_cstring", time_to_cstring, METH_VARARGS, NULL },
 	{ NULL }
 };
 
@@ -318,6 +215,9 @@
 {
 	PyObject *mod;
 
+	if (PyType_Ready(&SubversionExceptionType) < 0)
+		return;
+
 	apr_initialize();
 
 	mod = Py_InitModule3("core", core_methods, "Core functions");
@@ -328,4 +228,7 @@
 	PyModule_AddObject(mod, "NODE_FILE", PyInt_FromLong(svn_node_file));
 	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);
 }

=== modified file 'ra.c'
--- a/ra.c	2008-05-31 15:32:55 +0000
+++ b/ra.c	2008-05-31 15:45:51 +0000
@@ -20,18 +20,6 @@
 #include <svn_types.h>
 #include <svn_ra.h>
  
-from apr cimport apr_pool_t, apr_pool_destroy, apr_palloc
-from apr cimport apr_hash_t, apr_hash_make, apr_hash_index_t, apr_hash_first, apr_hash_next, apr_hash_this, apr_hash_set
-from apr cimport apr_array_header_t, apr_array_make, apr_array_push
-from apr cimport apr_file_t, apr_off_t, apr_size_t, apr_uint32_t
-from apr cimport apr_initialize, apr_pstrdup
-from core cimport check_error, Pool, wrap_lock, string_list_to_apr_array, py_svn_log_wrapper, new_py_stream, prop_hash_to_dict, py_svn_error, revnum_list_to_apr_array
-from core import SubversionException
-from constants import PROP_REVISION_LOG, PROP_REVISION_AUTHOR, PROP_REVISION_DATE
-from types cimport svn_error_t, svn_revnum_t, svn_string_t, svn_version_t
-from types cimport svn_string_ncreate, svn_lock_t, svn_auth_baton_t, svn_auth_open, svn_auth_set_parameter, svn_auth_get_parameter, svn_node_kind_t, svn_commit_info_t, svn_filesize_t, svn_dirent_t, svn_log_message_receiver_t
-from types cimport svn_stream_t, svn_auth_get_simple_provider, svn_auth_provider_object_t, svn_auth_get_ssl_server_trust_file_provider, svn_auth_get_ssl_client_cert_file_provider, svn_auth_get_ssl_client_cert_pw_file_provider, svn_auth_get_username_provider, svn_auth_get_username_prompt_provider, svn_auth_cred_username_t, svn_auth_get_simple_prompt_provider, svn_auth_cred_simple_t, svn_auth_get_ssl_server_trust_prompt_provider, svn_auth_ssl_server_cert_info_t, svn_auth_cred_ssl_server_trust_t, svn_boolean_t, svn_auth_get_ssl_client_cert_pw_prompt_provider, svn_auth_cred_ssl_client_cert_pw_t 
-
 svn_error_t *py_commit_callback(svn_commit_info_t *commit_info, baton, apr_pool_t *pool)
 {
     baton(commit_info.revision, commit_info.date, commit_info.author);

=== modified file 'setup.py'
--- a/setup.py	2008-05-31 15:32:55 +0000
+++ b/setup.py	2008-05-31 15:45:51 +0000
@@ -42,9 +42,9 @@
                 'bzrlib.plugins.svn.mapping3', 
                 'bzrlib.plugins.svn.tests'],
       ext_modules=[
-          Extension("core", ["core.c"], libraries=["svn_subr-1"], 
+          Extension("core", ["core.c", "util.c"], libraries=["svn_subr-1"], 
                     include_dirs=[apr_include_dir(), svn_include_dir()]), 
-          Extension("client", ["client.c"], libraries=["svn_client-1"], 
+          Extension("client", ["client.c", "util.c"], libraries=["svn_client-1"], 
                     include_dirs=[apr_include_dir(), svn_include_dir()]), 
           Extension("ra", ["ra.c"], libraries=["svn_ra-1"], 
                     include_dirs=[apr_include_dir(), svn_include_dir()]), 

=== added file 'util.c'
--- a/util.c	1970-01-01 00:00:00 +0000
+++ b/util.c	2008-05-31 15:45:51 +0000
@@ -0,0 +1,130 @@
+/*
+ * Copyright © 2008 Jelmer Vernooij <jelmer at samba.org>
+ * -*- coding: utf-8 -*-
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include <stdbool.h>
+#include <Python.h>
+#include <apr_general.h>
+#include <svn_error.h>
+
+apr_pool_t *Pool(apr_pool_t *parent)
+{
+    apr_status_t status;
+    apr_pool_t *ret;
+    char errmsg[1024];
+    ret = NULL;
+    status = apr_pool_create(&ret, parent);
+    if (status != 0) {
+        PyErr_SetString(PyExc_Exception, 
+						apr_strerror(status, errmsg, sizeof(errmsg)));
+		return NULL;
+	}
+    return ret;
+}
+
+void PyErr_SetSubversionException(svn_error_t *error)
+{
+	/* FIXME */
+}
+
+bool check_error(svn_error_t *error)
+{
+    if (error != NULL) {
+		PyErr_SetSubversionException(error);
+   		return false;
+	}
+	return true;
+}
+
+apr_array_header_t *string_list_to_apr_array(apr_pool_t *pool, PyObject *l)
+{
+    apr_array_header_t *ret;
+	int i;
+    if (l == Py_None) {
+        return NULL;
+	}
+    ret = apr_array_make(pool, PyList_Size(l), 4);
+	for (i = 0; i < PyList_Size(l); i++) {
+		char **el = (char **)apr_array_push(ret);
+        *el = PyString_AsString(PyList_GetItem(l, i));
+	}
+    return ret;
+}
+
+PyObject *prop_hash_to_dict(apr_hash_t *props)
+{
+    const char *key;
+    apr_hash_index_t *idx;
+    apr_ssize_t klen;
+    svn_string_t *val;
+    apr_pool_t *pool;
+	PyObject *py_props;
+    if (props == NULL) {
+        return Py_None;
+	}
+    pool = Pool(NULL);
+    py_props = PyDict_New();
+    for (idx = apr_hash_first(pool, props); idx != NULL; 
+		 idx = apr_hash_next(idx)) {
+        apr_hash_this(idx, (const void **)&key, &klen, (void **)&val);
+        PyDict_SetItemString(py_props, key, 
+							 PyString_FromStringAndSize(val->data, val->len));
+	}
+    apr_pool_destroy(pool);
+    return py_props;
+}
+
+svn_error_t *py_svn_log_wrapper(void *baton, apr_hash_t *changed_paths, long revision, char *author, char *date, char *message, apr_pool_t *pool)
+{
+    apr_hash_index_t *idx;
+    const char *key;
+    apr_ssize_t klen;
+    svn_log_changed_path_t *val;
+	PyObject *revprops, *py_changed_paths, *ret;
+
+    if (changed_paths == NULL) {
+        py_changed_paths = Py_None;
+	} else {
+        py_changed_paths = PyDict_New();
+        for (idx = apr_hash_first(pool, changed_paths); idx != NULL;
+             idx = apr_hash_next(idx)) {
+            apr_hash_this(idx, (const void **)&key, &klen, (void **)&val);
+			PyDict_SetItemString(py_changed_paths, key, 
+					Py_BuildValue("(czi)", val->action, val->copyfrom_path, 
+                                         val->copyfrom_rev));
+		}
+	}
+    revprops = PyDict_New();
+    if (message != NULL) {
+        PyDict_SetItemString(revprops, SVN_PROP_REVISION_LOG, 
+							 PyString_FromString(message));
+	}
+    if (author != NULL) {
+        PyDict_SetItemString(revprops, SVN_PROP_REVISION_AUTHOR, 
+							 PyString_FromString(author));
+	}
+    if (date != NULL) {
+        PyDict_SetItemString(revprops, SVN_PROP_REVISION_DATE, 
+							 PyString_FromString(date));
+	}
+    ret = PyObject_CallFunction((PyObject *)baton, "OiO", py_changed_paths, 
+								 revision, revprops);
+	/* FIXME: Handle ret != NULL */
+	return NULL;
+}
+
+

=== added file 'util.h'
--- a/util.h	1970-01-01 00:00:00 +0000
+++ b/util.h	2008-05-31 15:45:51 +0000
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2008 Jelmer Vernooij <jelmer at samba.org>
+ * -*- coding: utf-8 -*-
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _BZR_SVN_UTIL_H_
+#define _BZR_SVN_UTIL_H_
+
+apr_pool_t *Pool(apr_pool_t *parent);
+bool check_error(svn_error_t *error);
+apr_array_header_t *string_list_to_apr_array(apr_pool_t *pool, PyObject *l);
+PyObject *prop_hash_to_dict(apr_hash_t *props);
+svn_error_t *py_svn_log_wrapper(void *baton, apr_hash_t *changed_paths, long revision, char *author, char *date, char *message, apr_pool_t *pool);
+
+#endif /* _BZR_SVN_UTIL_H_ */




More information about the bazaar-commits mailing list