Proper lock handling.
authorJelmer Vernooij <jelmer@jelmer.uk>
Thu, 24 May 2018 21:00:58 +0000 (22:00 +0100)
committerJelmer Vernooij <jelmer@jelmer.uk>
Thu, 24 May 2018 21:00:58 +0000 (22:00 +0100)
subvertpy/tests/test_wc.py
subvertpy/util.c
subvertpy/util.h
subvertpy/wc.c

index 6c4f6e622cb07004275b6c185a819e4bdc421610..3a608a7256a939962a674ab8addfdc1e0b15132f 100644 (file)
@@ -426,15 +426,19 @@ class ContextTests(SubversionTestCase):
             f.write("modified")
         self.client_add("checkout/bla.txt")
         context = wc.Context()
-        context.add_lock("checkout/bla.txt", ())
-        context.remove_lock("checkout/bla.txt")
+        self.assertEqual((False, False), context.locked("checkout"))
+        context.add_lock("checkout", ())
+        self.assertEqual((True, True), context.locked("checkout"))
+        context.remove_lock("checkout")
 
     def test_add_from_disk(self):
         self.make_client("repos", "checkout")
         with open('checkout/bla.txt', 'w') as f:
             f.write("modified")
         context = wc.Context()
+        context.add_lock("checkout", ())
         context.add_from_disk('checkout/bla.txt')
+        context.remove_lock("checkout")
 
     def test_get_prop_diffs(self):
         self.make_client("repos", "checkout")
index f928971890f2798bda66bd88bff2cf49af69118c..c0a9a18ea9c474d0b0b4adfd892327ed7d3feff3 100644 (file)
@@ -1212,14 +1212,6 @@ PyObject *dirent_hash_to_dict(apr_hash_t *dirents, unsigned int dirent_fields, a
        return py_dirents;
 }
 
-svn_lock_t *py_object_to_svn_lock(PyObject *py_lock, apr_pool_t *pool)
-{
-    svn_lock_t *ret = svn_lock_create(pool);
-
-    /* TODO */
-    return ret;
-}
-
 PyObject *propchanges_to_list(const apr_array_header_t *propchanges)
 {
     int i;
@@ -1247,5 +1239,3 @@ PyObject *propchanges_to_list(const apr_array_header_t *propchanges)
 
     return py_propchanges;
 }
-
-
index b2bd1d078edb7a003ade84d077f8eb81213a1e00..b58af9541938f5328260e5526e2d0e0860de6696 100644 (file)
@@ -160,7 +160,6 @@ const char *py_object_to_svn_relpath(PyObject *obj, apr_pool_t *pool);
 const char *py_object_to_svn_path_or_url(PyObject *obj, apr_pool_t *pool);
 char *py_object_to_svn_string(PyObject *obj, apr_pool_t *pool);
 const char *py_object_to_svn_abspath(PyObject *obj, apr_pool_t *pool);
-svn_lock_t *py_object_to_svn_lock(PyObject *py_lock, apr_pool_t *pool);
 #define py_object_from_svn_abspath PyUnicode_FromString
 PyObject *propchanges_to_list(const apr_array_header_t *propchanges);
 
index 500ed5dcd57e40e8a83aca001ee52c94e7c7dfcd..da6511d00706fded8b8737b49b6c7d7e510bf246 100644 (file)
 #define T_BOOL T_BYTE
 #endif
 
+typedef struct {
+    PyObject_HEAD
+    svn_lock_t *lock;
+    apr_pool_t *pool;
+} LockObject;
+extern PyTypeObject Lock_Type;
+
 #if ONLY_BEFORE_SVN(1, 5)
 struct svn_wc_committed_queue_t
 {
@@ -1598,6 +1605,12 @@ static PyObject *py_wc_walk_status(PyObject *self, PyObject *args, PyObject *kwa
     Py_RETURN_NONE;
 }
 
+static svn_lock_t *py_object_to_svn_lock(PyObject *py_lock, apr_pool_t *pool)
+{
+       LockObject* lockobj = (LockObject *)py_lock;
+       return lockobj->lock;
+}
+
 static PyObject *py_wc_add_lock(PyObject *self, PyObject *args, PyObject *kwargs)
 {
     ContextObject *context_obj = (ContextObject *)self;
@@ -1607,7 +1620,8 @@ static PyObject *py_wc_add_lock(PyObject *self, PyObject *args, PyObject *kwargs
     const char *path;
     apr_pool_t *scratch_pool;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO", kwnames, &py_path, &py_lock)) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO!", kwnames, &py_path, &Lock_Type,
+                                     &py_lock)) {
         return NULL;
     }
 
@@ -1679,6 +1693,9 @@ static PyObject *py_wc_add_from_disk(PyObject *self, PyObject *args, PyObject *k
     }
 
     pool = Pool(NULL);
+    if (pool == NULL) {
+        return NULL;
+    }
 
     path = py_object_to_svn_abspath(py_path, pool);
     if (path == NULL) {
@@ -1939,6 +1956,52 @@ static PyTypeObject Context_Type = {
 
 #endif
 
+static void lock_dealloc(PyObject *self)
+{
+       LockObject *lockself = (LockObject *)self;
+
+       apr_pool_destroy(lockself->pool);
+
+       PyObject_Del(self);
+}
+
+static PyObject *lock_init(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+       char *kwnames[] = { NULL };
+       LockObject *ret;
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "", kwnames))
+               return NULL;
+
+       ret = PyObject_New(LockObject, &Lock_Type);
+       if (ret == NULL)
+               return NULL;
+
+       ret->pool = Pool(NULL);
+       if (ret->pool == NULL)
+               return NULL;
+       ret->lock = svn_lock_create(ret->pool);
+
+       return (PyObject *)ret;
+}
+
+PyTypeObject Lock_Type = {
+       PyVarObject_HEAD_INIT(NULL, 0)
+       "wc.Lock", /*   const char *tp_name;  For printing, in format "<module>.<name>" */
+       sizeof(LockObject),
+       0,/*    Py_ssize_t tp_basicsize, tp_itemsize;  For allocation */
+
+       /* Methods to implement standard operations */
+
+       .tp_dealloc = lock_dealloc, /*  destructor tp_dealloc;  */
+
+       .tp_doc = "Lock", /*    const char *tp_doc;  Documentation string */
+
+       .tp_methods = NULL, /*  struct PyMethodDef *tp_methods; */
+
+       .tp_new = lock_init, /* tp_new tp_new */
+};
+
 static PyObject *
 moduleinit(void)
 {
@@ -1981,6 +2044,9 @@ moduleinit(void)
                return NULL;
 #endif
 
+       if (PyType_Ready(&Lock_Type) < 0)
+               return NULL;
+
        apr_initialize();
 
 #if PY_MAJOR_VERSION >= 3