Rev 1245: Import own bindings for Subversion repos library. in file:///data/jelmer/bzr-svn/0.4-ra/

Jelmer Vernooij jelmer at samba.org
Thu Jun 19 16:57:43 BST 2008


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

------------------------------------------------------------
revno: 1245
revision-id: jelmer at samba.org-20080619155742-cb10ki8v5ceflqyw
parent: jelmer at samba.org-20080619153347-eysgz8ci9hvjr5r3
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4-ra
timestamp: Thu 2008-06-19 17:57:42 +0200
message:
  Import own bindings for Subversion repos library.
added:
  repos.c                        repos.pyx-20080314114432-g2b5lqe776tkbl4k-1
modified:
  convert.py                     svn2bzr.py-20051018015439-cb4563bff29e632d
  setup.py                       setup.py-20060502115218-86950492da22353f
  tests/__init__.py              __init__.py-20060508151940-e9f4d914801a2535
  tests/test_convert.py          test_convert.py-20060705203611-b1l0bapeku6foco0-1
=== modified file 'convert.py'
--- a/convert.py	2008-06-19 13:58:42 +0000
+++ b/convert.py	2008-06-19 15:57:42 +0000
@@ -23,11 +23,12 @@
 from bzrlib.revision import ensure_null
 from bzrlib.transport import get_transport
 
+from bzrlib.plugins.svn import repos
+from bzrlib.plugins.svn.core import SubversionException
 from bzrlib.plugins.svn.errors import ERR_STREAM_MALFORMED_DATA
 from bzrlib.plugins.svn.format import get_rich_root_format
 
-import svn.core, svn.repos
-from svn.core import SubversionException
+import svn.core
 
 def transport_makedirs(transport, location_url):
     """Create missing directories.
@@ -63,7 +64,7 @@
         created.
     """
     from cStringIO import StringIO
-    repos = svn.repos.svn_repos_create(outputdir, '', '', None, None)
+    r = repos.create(outputdir)
     if dumpfile.endswith(".gz"):
         import gzip
         file = gzip.GzipFile(dumpfile)
@@ -73,8 +74,7 @@
     else:
         file = open(dumpfile)
     try:
-        svn.repos.load_fs2(repos, file, StringIO(), 
-                svn.repos.load_uuid_default, '', 0, 0, None)
+        r.load_fs(file, StringIO(), repos.LOAD_UUID_DEFAULT)
     except SubversionException, (_, num):
         if num == ERR_STREAM_MALFORMED_DATA:
             raise NotDumpFile(dumpfile)

=== added file 'repos.c'
--- a/repos.c	1970-01-01 00:00:00 +0000
+++ b/repos.c	2008-06-19 15:57:42 +0000
@@ -0,0 +1,242 @@
+/*
+ * 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_fs.h>
+#include <svn_repos.h>
+
+#include "util.h"
+
+PyAPI_DATA(PyTypeObject) Repository_Type;
+PyAPI_DATA(PyTypeObject) FileSystem_Type;
+
+typedef struct { 
+	PyObject_HEAD
+    apr_pool_t *pool;
+    svn_repos_t *repos;
+} RepositoryObject;
+
+static PyObject *repos_create(PyObject *self, PyObject *args)
+{
+	char *path;
+	PyObject *config=Py_None, *fs_config=Py_None;
+    svn_repos_t *repos;
+    apr_pool_t *pool;
+    apr_hash_t *hash_config, *hash_fs_config;
+	RepositoryObject *ret;
+
+	if (!PyArg_ParseTuple(args, "s|OO", &path, &config, &fs_config))
+		return NULL;
+
+    pool = Pool();
+	if (pool == NULL)
+		return NULL;
+    hash_config = NULL; /* FIXME */
+    hash_fs_config = NULL; /* FIXME */
+    RUN_SVN_WITH_POOL(pool, svn_repos_create(&repos, path, "", "", 
+                hash_config, hash_fs_config, pool));
+
+	ret = PyObject_New(RepositoryObject, &Repository_Type);
+	if (ret == NULL)
+		return NULL;
+
+	ret->pool = pool;
+	ret->repos = repos;
+
+    return (PyObject *)ret;
+}
+
+static void repos_dealloc(PyObject *self)
+{
+	RepositoryObject *repos = (RepositoryObject *)self;
+
+	apr_pool_destroy(repos->pool);
+}
+
+static PyObject *repos_init(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+	char *path;
+	char *kwnames[] = { "path", NULL };
+	RepositoryObject *ret;
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwnames, &path))
+		return NULL;
+
+	ret = PyObject_New(RepositoryObject, &Repository_Type);
+	if (ret == NULL)
+		return NULL;
+
+	ret->pool = Pool();
+	if (ret->pool == NULL)
+		return NULL;
+    if (!check_error(svn_repos_open(&ret->repos, path, ret->pool))) {
+		apr_pool_destroy(ret->pool);
+		PyObject_Del(ret);
+		return NULL;
+	}
+
+	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();
+	if (temp_pool == NULL)
+		return NULL;
+	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 = "";
+	PyObject *dumpstream, *feedback_stream, *cancel_func = Py_None;
+	bool use_pre_commit_hook = false, use_post_commit_hook = false;
+	char *kwnames[] = { "dumpstream", "feedback_stream", "uuid_action",
+		                "parent_dir", "use_pre_commit_hook", 
+						"use_post_commit_hook", "cancel_func", NULL };
+	int uuid_action;
+	apr_pool_t *temp_pool;
+	RepositoryObject *reposobj = (RepositoryObject *)self;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOi|sbbO", kwnames,
+								&dumpstream, &feedback_stream, &uuid_action,
+								&parent_dir, &use_pre_commit_hook, 
+								&use_post_commit_hook,
+								&cancel_func))
+		return NULL;
+
+	temp_pool = Pool();
+	if (temp_pool == NULL)
+		return NULL;
+	RUN_SVN_WITH_POOL(temp_pool, svn_repos_load_fs2(reposobj->repos, 
+				new_py_stream(temp_pool, dumpstream), 
+				new_py_stream(temp_pool, feedback_stream),
+				uuid_action, parent_dir, use_pre_commit_hook, 
+				use_post_commit_hook, py_cancel_func, (void *)cancel_func,
+				reposobj->pool));
+	apr_pool_destroy(temp_pool);
+	Py_RETURN_NONE;
+}
+
+static PyMethodDef repos_module_methods[] = {
+	{ "create", repos_create, METH_VARARGS, NULL },
+	{ NULL, }
+};
+
+static PyMethodDef repos_methods[] = {
+	{ "load_fs", (PyCFunction)repos_load_fs, METH_VARARGS|METH_KEYWORDS, NULL },
+	{ "fs", (PyCFunction)repos_fs, METH_NOARGS, NULL },
+	{ NULL, }
+};
+
+PyTypeObject Repository_Type = {
+	PyObject_HEAD_INIT(&PyType_Type) 0,
+	.tp_name = "repos.Repository",
+	.tp_basicsize = sizeof(RepositoryObject),
+	.tp_dealloc = repos_dealloc,
+	.tp_methods = repos_methods,
+	.tp_new = repos_init,
+};
+
+void initrepos(void)
+{
+	static apr_pool_t *pool;
+	PyObject *mod;
+
+	if (PyType_Ready(&Repository_Type) < 0)
+		return;
+
+	if (PyType_Ready(&FileSystem_Type) < 0)
+		return;
+
+	apr_initialize();
+	pool = Pool();
+	if (pool == NULL)
+		return;
+	svn_fs_initialize(pool);
+
+	mod = Py_InitModule3("repos", repos_module_methods, "Local repository management");
+	if (mod == NULL)
+		return;
+
+	PyModule_AddObject(mod, "LOAD_UUID_DEFAULT", PyLong_FromLong(0));
+	PyModule_AddObject(mod, "LOAD_UUID_IGNORE", PyLong_FromLong(1));
+	PyModule_AddObject(mod, "LOAD_UUID_FORCE", PyLong_FromLong(2));
+
+	PyModule_AddObject(mod, "Repository", (PyObject *)&Repository_Type);
+	Py_INCREF(&Repository_Type);
+}

=== modified file 'setup.py'
--- a/setup.py	2008-06-19 15:33:26 +0000
+++ b/setup.py	2008-06-19 15:57:42 +0000
@@ -42,6 +42,8 @@
                 'bzrlib.plugins.svn.mapping3', 
                 'bzrlib.plugins.svn.tests'],
       ext_modules=[
+          Extension("repos", ["repos.c", "util.c"], libraries=["svn_repos-1"], 
+                    include_dirs=[apr_include_dir(), svn_include_dir()]), 
           Extension("wc", ["wc.c", "util.c", "editor.c"], libraries=["svn_wc-1"],
                      include_dirs=[apr_include_dir(), svn_include_dir()])],
       )

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2008-06-19 15:33:26 +0000
+++ b/tests/__init__.py	2008-06-19 15:57:42 +0000
@@ -29,7 +29,9 @@
 from bzrlib.urlutils import local_path_to_url
 from bzrlib.workingtree import WorkingTree
 
-import svn.core, svn.repos
+import svn.core
+
+from bzrlib.plugins.svn import repos
 from bzrlib.plugins.svn.ra import RemoteAccess
 
 class TestCaseWithSubversionRepository(TestCaseInTempDir):
@@ -52,7 +54,7 @@
         """
         abspath = os.path.join(self.test_dir, relpath)
 
-        svn.repos.create(abspath, '', '', None, None)
+        repos.create(abspath)
 
         if allow_revprop_changes:
             if sys.platform == 'win32':
@@ -260,9 +262,7 @@
 
         :return: FS.
         """
-        repos = svn.repos.open(relpath)
-
-        return svn.repos.fs(repos)
+        return repos.Repository(relpath).fs()
 
     def commit_editor(self, url, message="Test commit"):
         ra = RemoteAccess(url.encode('utf8'))

=== modified file 'tests/test_convert.py'
--- a/tests/test_convert.py	2008-06-05 10:21:04 +0000
+++ b/tests/test_convert.py	2008-06-19 15:57:42 +0000
@@ -25,14 +25,14 @@
 from bzrlib.trace import mutter
 
 import os, sys
+
+from bzrlib.plugins.svn import repos
 from bzrlib.plugins.svn.convert import convert_repository, NotDumpFile, load_dumpfile
 from bzrlib.plugins.svn.format import get_rich_root_format
 from bzrlib.plugins.svn.mapping3 import set_branching_scheme
 from bzrlib.plugins.svn.mapping3.scheme import TrunkBranchingScheme, NoBranchingScheme
 from bzrlib.plugins.svn.tests import TestCaseWithSubversionRepository
 
-import svn.repos
-
 class TestLoadDumpfile(TestCaseInTempDir):
     def test_loaddumpfile(self):
         dumpfile = os.path.join(self.test_dir, "dumpfile")
@@ -52,10 +52,9 @@
 PROPS-END
 """)
         load_dumpfile(dumpfile, "d")
-        repos = svn.repos.open("d")
-        fs = svn.repos.fs(repos)
+        fs = repos.Repository("d").fs()
         self.assertEqual("6987ef2d-cd6b-461f-9991-6f1abef3bd59", 
-                svn.fs.get_uuid(fs))
+                fs.get_uuid())
 
     def test_loaddumpfile_invalid(self):
         dumpfile = os.path.join(self.test_dir, "dumpfile")




More information about the bazaar-commits mailing list