Rev 1259: Merge use of C-based repos bindings. in http://people.samba.org/bzr/jelmer/bzr-svn/0.4

Jelmer Vernooij jelmer at samba.org
Sun Jun 22 09:00:45 BST 2008


At http://people.samba.org/bzr/jelmer/bzr-svn/0.4

------------------------------------------------------------
revno: 1259
revision-id: jelmer at samba.org-20080622080044-rhp1ksghhe0rg9iv
parent: jelmer at samba.org-20080622074304-a2bbhhxj8sskh0gj
parent: jelmer at samba.org-20080622080012-ei0y16lts2z3hcb6
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Sun 2008-06-22 10:00:44 +0200
message:
  Merge use of C-based repos bindings.
removed:
  repos.py                       repos.py-20080621160832-kvb89lus284oufuq-1
added:
  repos.c                        repos.pyx-20080314114432-g2b5lqe776tkbl4k-1
modified:
  setup.py                       setup.py-20060502115218-86950492da22353f
  tests/test_convert.py          test_convert.py-20060705203611-b1l0bapeku6foco0-1
  tests/test_repos.py            test_repos.py-20060508151940-ddc49a59257ca712
    ------------------------------------------------------------
    revno: 1244.2.5
    revision-id: jelmer at samba.org-20080622080012-ei0y16lts2z3hcb6
    parent: jelmer at samba.org-20080622074440-ag2v3unt934qpmej
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: 0.4-repos-cext
    timestamp: Sun 2008-06-22 10:00:12 +0200
    message:
      Fix build with C-based repos module.
    removed:
      repos.py                       repos.py-20080621160832-kvb89lus284oufuq-1
    modified:
      repos.c                        repos.pyx-20080314114432-g2b5lqe776tkbl4k-1
    ------------------------------------------------------------
    revno: 1244.2.4
    revision-id: jelmer at samba.org-20080622074440-ag2v3unt934qpmej
    parent: jelmer at samba.org-20080621162914-djsxs1ep4c0bmwad
    parent: jelmer at samba.org-20080622074304-a2bbhhxj8sskh0gj
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: 0.4-repos-cext
    timestamp: Sun 2008-06-22 09:44:40 +0200
    message:
      Merge 0.4.
    removed:
      delta.py                       delta.py-20080617225125-jeg43afui0czkuwk-1
      ra.py                          ra.py-20080615005305-t5221niknu8rm6bt-1
    added:
      client.c                       client.pyx-20080313235339-wbyjbw2namuiql8f-1
      delta.py                       delta.py-20080316001917-xyng7m3jlxvdc4c9-1
      ra.c                           ra.pyx-20080313140933-qybkqaxe3m4mcll7-1
      ra.h                           ra.h-20080621214350-wlaxxs087eiu02me-1
      wc.h                           wc.h-20080622050149-ir7xe34a497adbmp-1
    modified:
      Makefile                       makefile.other-20080311181537-5svhje3v1flh1n4f-1
      __init__.py                    __init__.py-20051008155114-eae558e6cf149e1d
      auth.py                        auth.py-20071209174622-w8d42k6nm5yhxvi8-1
      branch.py                      svnbranch.py-20051017135706-11c749eb0dab04a7
      commit.py                      commit.py-20060607190346-qvq128wgfubhhgm2-1
      core.py                        core.py-20080615010310-67lnibnp889hlarb-1
      editor.c                       editor.c-20080602191336-frj7az1sdk13o1tw-1
      fetch.py                       fetch.py-20060625004942-x2lfaib8ra707a8p-1
      format.py                      format.py-20070917005147-94kb7zysotf82kqw-1
      layout.py                      layout.py-20080323165407-y9qw8nx4oykvoe1k-1
      logwalker.py                   logwalker.py-20060621215743-c13fhfnyzh1xzwh2-1
      repos.py                       repos.py-20080621160832-kvb89lus284oufuq-1
      setup.py                       setup.py-20060502115218-86950492da22353f
      tests/__init__.py              __init__.py-20060508151940-e9f4d914801a2535
      tests/test_commit.py           test_commit.py-20060624213521-l5kcufywkh9mnilk-1
      tests/test_fetch.py            test_fetch.py-20070624210302-luvgwjmlfysk5qeq-1
      tests/test_push.py             test_push.py-20070201165715-g2ievcdfqi33wqsy-1
      tests/test_repos.py            test_repos.py-20060508151940-ddc49a59257ca712
      tests/test_workingtree.py      test_workingtree.py-20060622191524-0di7bc3q1ckdbybb-1
      transport.py                   transport.py-20060406231150-b3472d06b3a0818d
      tree.py                        tree.py-20060624222557-dudlwqcmkf22lt2s-1
      util.c                         util.c-20080531154025-s8ef6ej9tytsnkkw-1
      util.h                         util.h-20080531154025-s8ef6ej9tytsnkkw-2
      wc.c                           wc.pyx-20080313142018-10l8l23vha2j9e6b-1
      workingtree.py                 workingtree.py-20060306120941-b083cb0fdd4a69de
    ------------------------------------------------------------
    revno: 1244.2.3
    revision-id: jelmer at samba.org-20080621162914-djsxs1ep4c0bmwad
    parent: jelmer at samba.org-20080619172013-73xy4dzdrmin6lmw
    parent: jelmer at samba.org-20080621162146-wjwtgd6hijvoz406
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: 0.4-ra
    timestamp: Sat 2008-06-21 18:29:14 +0200
    message:
      Merge upstream.
    added:
      repos.py                       repos.py-20080621160832-kvb89lus284oufuq-1
    modified:
      auth.py                        auth.py-20071209174622-w8d42k6nm5yhxvi8-1
      convert.py                     svn2bzr.py-20051018015439-cb4563bff29e632d
      errors.py                      errors.py-20061226172623-w1sbj8ynpo0eojqp-1
      fetch.py                       fetch.py-20060625004942-x2lfaib8ra707a8p-1
      format.py                      format.py-20070917005147-94kb7zysotf82kqw-1
      ra.py                          ra.py-20080615005305-t5221niknu8rm6bt-1
    ------------------------------------------------------------
    revno: 1244.2.2
    revision-id: jelmer at samba.org-20080619172013-73xy4dzdrmin6lmw
    parent: jelmer at samba.org-20080619155742-cb10ki8v5ceflqyw
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: 0.4-ra
    timestamp: Thu 2008-06-19 19:20:13 +0200
    message:
      Cherrypick repository C bindings.
    modified:
      repos.c                        repos.pyx-20080314114432-g2b5lqe776tkbl4k-1
      tests/test_repos.py            test_repos.py-20060508151940-ddc49a59257ca712
    ------------------------------------------------------------
    revno: 1244.2.1
    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
=== added file 'repos.c'
--- a/repos.c	1970-01-01 00:00:00 +0000
+++ b/repos.c	2008-06-22 08:00:12 +0000
@@ -0,0 +1,248 @@
+/*
+ * 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(NULL);
+	if (pool == NULL)
+		return NULL;
+    hash_config = apr_hash_make(pool); /* FIXME */
+    hash_fs_config = apr_hash_make(pool); /* FIXME */
+    RUN_SVN_WITH_POOL(pool, svn_repos_create(&repos, path, NULL, NULL, 
+                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(NULL);
+	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);
+
+	if (fs == NULL) {
+		PyErr_SetString(PyExc_RuntimeError, "Unable to obtain fs handle");
+		return NULL;
+	}
+
+	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(NULL);
+	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(NULL);
+	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(NULL);
+	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);
+}

=== removed file 'repos.py'
--- a/repos.py	2008-06-22 07:43:04 +0000
+++ b/repos.py	1970-01-01 00:00:00 +0000
@@ -1,50 +0,0 @@
-# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer at samba.org>
- 
-# 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 3 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, see <http://www.gnu.org/licenses/>.
-
-import svn.repos
-
-LOAD_UUID_IGNORE = svn.repos.load_uuid_ignore
-LOAD_UUID_FORCE = svn.repos.load_uuid_force
-LOAD_UUID_DEFAULT = svn.repos.load_uuid_default
-
-def create(path):
-    r = svn.repos.create(path, '', '', None, None)
-    return Repository(path, r)
-
-class Fs(object):
-    def __init__(self, fs):
-        self.fs = fs
-
-    def get_uuid(self):
-        return svn.fs.get_uuid(self.fs)
-
-
-class Repository(object):
-    def __init__(self, local_path, _repos=None):
-        if _repos is not None:
-            self.repos = _repos
-        else:
-            self.repos = svn.repos.svn_repos_open(local_path)
-
-    def fs(self):
-        return Fs(svn.repos.fs(self.repos))
-
-    def load_fs(self, dumpstream, feedback_stream, uuid_action=LOAD_UUID_DEFAULT,
-                parent_dir="", use_pre_commit_hook=False, use_post_commit_hook=False, 
-                cancel_func=None):
-        return svn.repos.load_fs2(self.repos, dumpstream, feedback_stream, uuid_action,
-                parent_dir, use_pre_commit_hook, use_post_commit_hook, cancel_func)
-
-

=== modified file 'setup.py'
--- a/setup.py	2008-06-22 05:13:11 +0000
+++ b/setup.py	2008-06-22 07:44:40 +0000
@@ -46,6 +46,8 @@
                     include_dirs=[apr_include_dir(), svn_include_dir()]), 
           Extension("ra", ["ra.c", "util.c", "editor.c"], libraries=["svn_ra-1"], 
                     include_dirs=[apr_include_dir(), svn_include_dir()]), 
+          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/test_convert.py'
--- a/tests/test_convert.py	2008-06-22 07:43:04 +0000
+++ b/tests/test_convert.py	2008-06-22 07:44:40 +0000
@@ -25,6 +25,7 @@
 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

=== modified file 'tests/test_repos.py'
--- a/tests/test_repos.py	2008-06-22 07:38:16 +0000
+++ b/tests/test_repos.py	2008-06-22 07:44:40 +0000
@@ -511,7 +511,7 @@
         self.assertTrue(isinstance(bzrdir, BzrDir))
         repository = bzrdir._find_repository()
         fs = self.open_fs('c')
-        self.assertEqual(svn.fs.get_uuid(fs), repository.uuid)
+        self.assertEqual(fs.get_uuid(), repository.uuid)
 
     def test_get_inventory_weave(self):
         bzrdir = self.make_client_and_bzrdir('d', 'dc')




More information about the bazaar-commits mailing list