Fix init function use in C modules for Python3.
[jelmer/subvertpy.git] / subvertpy / wc.c
1 /*
2  * Copyright © 2008 Jelmer Vernooij <jelmer@jelmer.uk>
3  * -*- coding: utf-8 -*-
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation; either version 2.1 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19 #include <Python.h>
20 #include <apr_general.h>
21 #include <svn_wc.h>
22 #include <svn_path.h>
23 #include <svn_props.h>
24 #include <structmember.h>
25 #include <stdbool.h>
26 #include <apr_md5.h>
27
28 #include "util.h"
29 #include "editor.h"
30 #include "wc.h"
31
32 #ifndef T_BOOL
33 #define T_BOOL T_BYTE
34 #endif
35
36 #if ONLY_SINCE_SVN(1, 5)
37 #define REPORTER_T svn_ra_reporter3_t
38 #else
39 #define REPORTER_T svn_ra_reporter2_t
40 #endif
41
42 static PyTypeObject Entry_Type;
43 static PyTypeObject Status_Type;
44 static PyTypeObject Adm_Type;
45
46 static PyObject *py_entry(const svn_wc_entry_t *entry);
47 static PyObject *py_status(const svn_wc_status2_t *status);
48
49 #if ONLY_BEFORE_SVN(1, 5)
50 struct svn_wc_committed_queue_t
51 {
52         apr_pool_t *pool;
53         apr_array_header_t *queue;
54         svn_boolean_t have_recursive;
55 };
56
57 #if SVN_VER_MINOR < 5
58 typedef struct svn_wc_committed_queue_t svn_wc_committed_queue_t;
59 #endif
60
61 typedef struct
62 {
63         const char *path;
64         svn_wc_adm_access_t *adm_access;
65         svn_boolean_t recurse;
66         svn_boolean_t remove_lock;
67         apr_array_header_t *wcprop_changes;
68         unsigned char *digest;
69 } committed_queue_item_t;
70
71 #if SVN_VER_MINOR < 5
72 static
73 #endif
74 svn_wc_committed_queue_t *svn_wc_committed_queue_create(apr_pool_t *pool)
75 {
76         svn_wc_committed_queue_t *q;
77
78         q = apr_palloc(pool, sizeof(*q));
79         q->pool = pool;
80         q->queue = apr_array_make(pool, 1, sizeof(committed_queue_item_t *));
81         q->have_recursive = FALSE;
82
83         return q;
84 }
85
86 #if SVN_VER_MINOR < 5
87 static
88 #endif
89 svn_error_t *svn_wc_queue_committed(svn_wc_committed_queue_t **queue,
90                         const char *path,
91                         svn_wc_adm_access_t *adm_access,
92                         svn_boolean_t recurse,
93                         apr_array_header_t *wcprop_changes,
94                         svn_boolean_t remove_lock,
95                         svn_boolean_t remove_changelist,
96                         const unsigned char *digest,
97                         apr_pool_t *scratch_pool)
98 {
99   committed_queue_item_t *cqi;
100
101   (*queue)->have_recursive |= recurse;
102
103   /* Use the same pool as the one QUEUE was allocated in,
104      to prevent lifetime issues.  Intermediate operations
105      should use SCRATCH_POOL. */
106
107   /* Add to the array with paths and options */
108   cqi = apr_palloc((*queue)->pool, sizeof(*cqi));
109   cqi->path = path;
110   cqi->adm_access = adm_access;
111   cqi->recurse = recurse;
112   cqi->remove_lock = remove_lock;
113   cqi->wcprop_changes = wcprop_changes;
114   cqi->digest = digest;
115
116   APR_ARRAY_PUSH((*queue)->queue, committed_queue_item_t *) = cqi;
117
118   return SVN_NO_ERROR;
119 }
120
121 #endif
122
123 typedef struct {
124         PyObject_HEAD
125         apr_pool_t *pool;
126         svn_wc_committed_queue_t *queue;
127 } CommittedQueueObject;
128 static PyTypeObject CommittedQueue_Type;
129
130 #if ONLY_SINCE_SVN(1, 5)
131 static svn_error_t *py_ra_report_set_path(void *baton, const char *path, svn_revnum_t revision, svn_depth_t depth, int start_empty, const char *lock_token, apr_pool_t *pool)
132 {
133         PyObject *self = (PyObject *)baton, *py_lock_token, *ret;
134         PyGILState_STATE state = PyGILState_Ensure();
135         if (lock_token == NULL) {
136                 py_lock_token = Py_None;
137                 Py_INCREF(py_lock_token);
138         } else {
139                 py_lock_token = PyString_FromString(lock_token);
140         }
141         ret = PyObject_CallMethod(self, "set_path", "slbOi", path, revision, start_empty, py_lock_token, depth);
142         Py_DECREF(py_lock_token);
143         CB_CHECK_PYRETVAL(ret);
144         Py_DECREF(ret);
145         PyGILState_Release(state);
146         return NULL;
147 }
148
149 static svn_error_t *py_ra_report_link_path(void *report_baton, const char *path, const char *url, svn_revnum_t revision, svn_depth_t depth, int start_empty, const char *lock_token, apr_pool_t *pool)
150 {
151         PyObject *self = (PyObject *)report_baton, *ret, *py_lock_token;
152         PyGILState_STATE state = PyGILState_Ensure();
153         if (lock_token == NULL) {
154                 py_lock_token = Py_None;
155                 Py_INCREF(py_lock_token);
156         } else { 
157                 py_lock_token = PyString_FromString(lock_token);
158         }
159         ret = PyObject_CallMethod(self, "link_path", "sslbOi", path, url, revision, start_empty, py_lock_token, depth);
160         Py_DECREF(py_lock_token);
161         CB_CHECK_PYRETVAL(ret);
162         Py_DECREF(ret);
163         PyGILState_Release(state);
164         return NULL;
165 }
166
167
168 #else
169 static svn_error_t *py_ra_report_set_path(void *baton, const char *path, svn_revnum_t revision, int start_empty, const char *lock_token, apr_pool_t *pool)
170 {
171         PyObject *self = (PyObject *)baton, *py_lock_token, *ret;
172         PyGILState_STATE state = PyGILState_Ensure();
173         if (lock_token == NULL) {
174                 py_lock_token = Py_None;
175                 Py_INCREF(py_lock_token);
176         } else {
177                 py_lock_token = PyString_FromString(lock_token);
178         }
179         ret = PyObject_CallMethod(self, "set_path", "slbOi", path, revision, start_empty, py_lock_token, svn_depth_infinity);
180         CB_CHECK_PYRETVAL(ret);
181         Py_DECREF(ret);
182         PyGILState_Release(state);
183         return NULL;
184 }
185
186 static svn_error_t *py_ra_report_link_path(void *report_baton, const char *path, const char *url, svn_revnum_t revision, int start_empty, const char *lock_token, apr_pool_t *pool)
187 {
188         PyObject *self = (PyObject *)report_baton, *ret, *py_lock_token;
189         PyGILState_STATE state = PyGILState_Ensure();
190         if (lock_token == NULL) {
191                 py_lock_token = Py_None;
192                 Py_INCREF(py_lock_token);
193         } else { 
194                 py_lock_token = PyString_FromString(lock_token);
195         }
196         ret = PyObject_CallMethod(self, "link_path", "sslbOi", path, url, revision, start_empty, py_lock_token, svn_depth_infinity);
197         CB_CHECK_PYRETVAL(ret);
198         Py_DECREF(ret);
199         PyGILState_Release(state);
200         return NULL;
201 }
202
203
204 #endif
205
206 static svn_error_t *py_ra_report_delete_path(void *baton, const char *path, apr_pool_t *pool)
207 {
208         PyObject *self = (PyObject *)baton, *ret;
209         PyGILState_STATE state = PyGILState_Ensure();
210         ret = PyObject_CallMethod(self, "delete_path", "s", path);
211         CB_CHECK_PYRETVAL(ret);
212         Py_DECREF(ret);
213         PyGILState_Release(state);
214         return NULL;
215 }
216
217 static svn_error_t *py_ra_report_finish(void *baton, apr_pool_t *pool)
218 {
219         PyObject *self = (PyObject *)baton, *ret;
220         PyGILState_STATE state = PyGILState_Ensure();
221         ret = PyObject_CallMethod(self, "finish", "");
222         CB_CHECK_PYRETVAL(ret);
223         Py_DECREF(ret);
224         PyGILState_Release(state);
225         return NULL;
226 }
227
228 static svn_error_t *py_ra_report_abort(void *baton, apr_pool_t *pool)
229 {
230         PyObject *self = (PyObject *)baton, *ret;
231         PyGILState_STATE state = PyGILState_Ensure();
232         ret = PyObject_CallMethod(self, "abort", "");
233         CB_CHECK_PYRETVAL(ret);
234         Py_DECREF(ret);
235         PyGILState_Release(state);
236         return NULL;
237 }
238
239 static const REPORTER_T py_ra_reporter = {
240         py_ra_report_set_path,
241         py_ra_report_delete_path,
242         py_ra_report_link_path,
243         py_ra_report_finish,
244         py_ra_report_abort,
245 };
246
247
248
249 /**
250  * Get runtime libsvn_wc version information.
251  *
252  * :return: tuple with major, minor, patch version number and tag.
253  */
254 static PyObject *version(PyObject *self)
255 {
256         const svn_version_t *ver = svn_wc_version();
257         return Py_BuildValue("(iiis)", ver->major, ver->minor, 
258                                                  ver->patch, ver->tag);
259 }
260
261 SVN_VERSION_DEFINE(svn_api_version);
262
263 /**
264  * Get compile-time libsvn_wc version information.
265  *
266  * :return: tuple with major, minor, patch version number and tag.
267  */
268 static PyObject *api_version(PyObject *self)
269 {
270         const svn_version_t *ver = &svn_api_version;
271         return Py_BuildValue("(iiis)", ver->major, ver->minor, 
272                                                  ver->patch, ver->tag);
273 }
274
275 static svn_error_t *py_wc_found_entry(const char *path, const svn_wc_entry_t *entry, void *walk_baton, apr_pool_t *pool)
276 {
277         PyObject *fn, *ret;
278         PyObject *callbacks = (PyObject *)walk_baton;
279         PyGILState_STATE state = PyGILState_Ensure();
280         if (PyTuple_Check(callbacks)) {
281                 fn = PyTuple_GET_ITEM(callbacks, 0);
282         } else {
283                 fn = (PyObject *)walk_baton;
284         }
285         ret = PyObject_CallFunction(fn, "sO", path, py_entry(entry));
286         CB_CHECK_PYRETVAL(ret);
287         Py_DECREF(ret);
288         PyGILState_Release(state);
289         return NULL;
290 }
291
292 #if ONLY_SINCE_SVN(1, 5)
293
294 svn_error_t *py_wc_handle_error(const char *path, svn_error_t *err, void *walk_baton, apr_pool_t *pool)
295 {
296         PyObject *fn, *ret;
297         PyObject *py_err;
298         PyGILState_STATE state;
299         PyObject *callbacks = (PyObject *)walk_baton;
300         if (PyTuple_Check(callbacks)) {
301                 fn = PyTuple_GET_ITEM(callbacks, 1);
302         } else {
303                 return err;
304         }
305         state = PyGILState_Ensure();
306         py_err = PyErr_NewSubversionException(err);
307         ret = PyObject_CallFunction(fn, "sO", path, py_err);
308         CB_CHECK_PYRETVAL(ret);
309         Py_DECREF(ret);
310         PyGILState_Release(state);
311         Py_DECREF(py_err);
312         return NULL;
313 }
314
315 static svn_wc_entry_callbacks2_t py_wc_entry_callbacks2 = {
316         py_wc_found_entry,
317         py_wc_handle_error,
318 };
319 #else
320 static svn_wc_entry_callbacks_t py_wc_entry_callbacks = {
321         py_wc_found_entry
322 };
323
324 #endif
325
326
327 void py_wc_notify_func(void *baton, const svn_wc_notify_t *notify, apr_pool_t *pool)
328 {
329         PyObject *func = baton, *ret;
330         if (func == Py_None)
331                 return;
332
333         if (notify->err != NULL) {
334                 PyObject *excval = PyErr_NewSubversionException(notify->err);
335                 ret = PyObject_CallFunction(func, "O", excval);
336                 Py_DECREF(excval);
337                 Py_XDECREF(ret);
338                 /* If ret was NULL, the cancel func should abort the operation. */
339         }
340 }
341
342 typedef struct {
343         PyObject_HEAD
344         apr_pool_t *pool;
345         svn_wc_entry_t entry;
346 } EntryObject;
347
348 static void entry_dealloc(PyObject *self)
349 {
350         apr_pool_destroy(((EntryObject *)self)->pool);
351         PyObject_Del(self);
352 }
353
354 static PyMemberDef entry_members[] = {
355         { "name", T_STRING, offsetof(EntryObject, entry.name), READONLY, 
356                 "Name of the file"},
357         { "copyfrom_url", T_STRING, offsetof(EntryObject, entry.copyfrom_url), READONLY, 
358                 "Copyfrom location" },
359         { "copyfrom_rev", T_LONG, offsetof(EntryObject, entry.copyfrom_rev), READONLY, 
360                 "Copyfrom revision" },
361         { "uuid", T_STRING, offsetof(EntryObject, entry.uuid), READONLY,
362                 "UUID of repository" },
363         { "url", T_STRING, offsetof(EntryObject, entry.url), READONLY, 
364                 "URL in repository" },
365         { "repos", T_STRING, offsetof(EntryObject, entry.repos), READONLY, 
366                 "Canonical repository URL" },
367         { "schedule", T_INT, offsetof(EntryObject, entry.schedule), READONLY, 
368                 "Scheduling (add, replace, delete, etc)" },
369         { "kind", T_INT, offsetof(EntryObject, entry.kind), READONLY, 
370                 "Kind of file (file, dir, etc)" },
371         { "revision", T_LONG, offsetof(EntryObject, entry.revision), READONLY, 
372                 "Base revision", },
373         { "cmt_rev", T_LONG, offsetof(EntryObject, entry.cmt_rev), READONLY, 
374                 "Last revision this was changed" },
375         { "checksum", T_STRING, offsetof(EntryObject, entry.checksum), READONLY, 
376                 "Hex MD5 checksum for the untranslated text base file" },
377         { "cmt_date", T_LONG, offsetof(EntryObject, entry.cmt_date), READONLY, 
378                 "Last date this was changed" },
379         { "cmt_author", T_STRING, offsetof(EntryObject, entry.cmt_author), READONLY, 
380                 "Last commit author of this item" },
381         { NULL, }
382 };
383
384 static PyTypeObject Entry_Type = {
385         PyObject_HEAD_INIT(NULL) 0,
386         "wc.Entry", /*  const char *tp_name;  For printing, in format "<module>.<name>" */
387         sizeof(EntryObject), 
388         0,/*    Py_ssize_t tp_basicsize, tp_itemsize;  For allocation */
389         
390         /* Methods to implement standard operations */
391         
392         entry_dealloc, /*       destructor tp_dealloc;  */
393         NULL, /*        printfunc tp_print;     */
394         NULL, /*        getattrfunc tp_getattr; */
395         NULL, /*        setattrfunc tp_setattr; */
396         NULL, /*        cmpfunc tp_compare;     */
397         NULL, /*        reprfunc tp_repr;       */
398         
399         /* Method suites for standard classes */
400         
401         NULL, /*        PyNumberMethods *tp_as_number;  */
402         NULL, /*        PySequenceMethods *tp_as_sequence;      */
403         NULL, /*        PyMappingMethods *tp_as_mapping;        */
404         
405         /* More standard operations (here for binary compatibility) */
406         
407         NULL, /*        hashfunc tp_hash;       */
408         NULL, /*        ternaryfunc tp_call;    */
409         NULL, /*        reprfunc tp_str;        */
410         NULL, /*        getattrofunc tp_getattro;       */
411         NULL, /*        setattrofunc tp_setattro;       */
412         
413         /* Functions to access object as input/output buffer */
414         NULL, /*        PyBufferProcs *tp_as_buffer;    */
415         
416         /* Flags to define presence of optional/expanded features */
417         0, /*   long tp_flags;  */
418         
419         NULL, /*        const char *tp_doc;  Documentation string */
420         
421         /* Assigned meaning in release 2.0 */
422         /* call function for all accessible objects */
423         NULL, /*        traverseproc tp_traverse;       */
424         
425         /* delete references to contained objects */
426         NULL, /*        inquiry tp_clear;       */
427         
428         /* Assigned meaning in release 2.1 */
429         /* rich comparisons */
430         NULL, /*        richcmpfunc tp_richcompare;     */
431         
432         /* weak reference enabler */
433         0, /*   Py_ssize_t tp_weaklistoffset;   */
434         
435         /* Added in release 2.2 */
436         /* Iterators */
437         NULL, /*        getiterfunc tp_iter;    */
438         NULL, /*        iternextfunc tp_iternext;       */
439         
440         /* Attribute descriptor and subclassing stuff */
441         NULL, /*        struct PyMethodDef *tp_methods; */
442         entry_members, /*       struct PyMemberDef *tp_members; */
443
444 };
445
446 static PyObject *py_entry(const svn_wc_entry_t *entry)
447 {
448         EntryObject *ret;
449
450         ret = PyObject_New(EntryObject, &Entry_Type);
451         if (ret == NULL)
452                 return NULL;
453
454         ret->pool = Pool(NULL);
455         if (ret->pool == NULL)
456                 return NULL;
457         ret->entry = *svn_wc_entry_dup(entry, ret->pool);
458         return (PyObject *)ret;
459 }
460
461 typedef struct {
462         PyObject_HEAD
463         apr_pool_t *pool;
464         svn_wc_status2_t status;
465         PyObject *entry;
466 } StatusObject;
467
468 static void status_dealloc(PyObject *self)
469 {
470         apr_pool_destroy(((StatusObject *)self)->pool);
471         Py_XDECREF(((StatusObject *)self)->entry);
472         PyObject_Del(self);
473 }
474
475 static PyMemberDef status_members[] = {
476         { "entry", T_OBJECT, offsetof(StatusObject, entry), READONLY, 
477                 "Can be NULL if not under version control." },
478         { "locked", T_BOOL, offsetof(StatusObject, status.locked), READONLY, 
479                 "a directory can be 'locked' if a working copy update was interrupted." },
480         { "copied", T_BOOL, offsetof(StatusObject, status.copied), READONLY, 
481                 "a file or directory can be 'copied' if it's scheduled for addition-with-history (or part of a subtree that is scheduled as such.)." },
482         { "switched", T_BOOL, offsetof(StatusObject, status.switched), READONLY, 
483                 "a file or directory can be 'switched' if the switch command has been used." },
484         { "url", T_STRING, offsetof(StatusObject, status.url), READONLY, 
485                 "URL (actual or expected) in repository" },
486         { "revision", T_LONG, offsetof(StatusObject, status.ood_last_cmt_rev), READONLY, 
487                 "Set to the youngest committed revision, or SVN_INVALID_REVNUM if not out of date.", },
488         { "kind", T_INT, offsetof(StatusObject, status.ood_kind), READONLY, 
489                 "Set to the node kind of the youngest commit, or svn_node_none if not out of date.", },
490         { "status", T_INT, offsetof(StatusObject, status.text_status), READONLY, 
491                 "The status of the entry.", },
492         { NULL, }
493 };
494
495 static PyTypeObject Status_Type = {
496         PyObject_HEAD_INIT(NULL) 0,
497         "wc.Status", /* const char *tp_name;  For printing, in format "<module>.<name>" */
498         sizeof(StatusObject), 
499         0,/*    Py_ssize_t tp_basicsize, tp_itemsize;  For allocation */
500         
501         /* Methods to implement standard operations */
502         
503         status_dealloc, /*      destructor tp_dealloc;  */
504         NULL, /*        printfunc tp_print;     */
505         NULL, /*        getattrfunc tp_getattr; */
506         NULL, /*        setattrfunc tp_setattr; */
507         NULL, /*        cmpfunc tp_compare;     */
508         NULL, /*        reprfunc tp_repr;       */
509         
510         /* Method suites for standard classes */
511         
512         NULL, /*        PyNumberMethods *tp_as_number;  */
513         NULL, /*        PySequenceMethods *tp_as_sequence;      */
514         NULL, /*        PyMappingMethods *tp_as_mapping;        */
515         
516         /* More standard operations (here for binary compatibility) */
517         
518         NULL, /*        hashfunc tp_hash;       */
519         NULL, /*        ternaryfunc tp_call;    */
520         NULL, /*        reprfunc tp_str;        */
521         NULL, /*        getattrofunc tp_getattro;       */
522         NULL, /*        setattrofunc tp_setattro;       */
523         
524         /* Functions to access object as input/output buffer */
525         NULL, /*        PyBufferProcs *tp_as_buffer;    */
526         
527         /* Flags to define presence of optional/expanded features */
528         0, /*   long tp_flags;  */
529         
530         "Working copy status object", /*        const char *tp_doc;  Documentation string */
531         
532         /* Assigned meaning in release 2.0 */
533         /* call function for all accessible objects */
534         NULL, /*        traverseproc tp_traverse;       */
535         
536         /* delete references to contained objects */
537         NULL, /*        inquiry tp_clear;       */
538         
539         /* Assigned meaning in release 2.1 */
540         /* rich comparisons */
541         NULL, /*        richcmpfunc tp_richcompare;     */
542         
543         /* weak reference enabler */
544         0, /*   Py_ssize_t tp_weaklistoffset;   */
545         
546         /* Added in release 2.2 */
547         /* Iterators */
548         NULL, /*        getiterfunc tp_iter;    */
549         NULL, /*        iternextfunc tp_iternext;       */
550         
551         /* Attribute descriptor and subclassing stuff */
552         NULL, /*        struct PyMethodDef *tp_methods; */
553         status_members, /*      struct PyMemberDef *tp_members; */
554
555 };
556
557 static PyObject *py_status(const svn_wc_status2_t *status)
558 {
559         StatusObject *ret;
560         svn_wc_status2_t *dup_status;
561
562         ret = PyObject_New(StatusObject, &Status_Type);
563         if (ret == NULL)
564                 return NULL;
565
566         ret->pool = Pool(NULL);
567         if (ret->pool == NULL) {
568                 PyObject_Del(ret);
569                 return NULL;
570         }
571
572         dup_status = svn_wc_dup_status2(status, ret->pool);
573         if (dup_status == NULL)
574         {
575                 PyErr_NoMemory();
576                 return NULL;
577         }
578         ret->status = *dup_status;
579
580         ret->entry = py_entry(ret->status.entry);
581         return (PyObject *)ret;
582 }
583
584 typedef struct {
585         PyObject_HEAD
586         svn_wc_adm_access_t *adm;
587         apr_pool_t *pool;
588 } AdmObject;
589
590 #define ADM_CHECK_CLOSED(adm_obj) \
591         if (adm_obj->adm == NULL) { \
592                 PyErr_SetString(PyExc_RuntimeError, "WorkingCopy instance already closed"); \
593                 return NULL; \
594         }
595
596 static PyObject *adm_init(PyTypeObject *self, PyObject *args, PyObject *kwargs)
597 {
598         PyObject *associated;
599         char *path;
600         bool write_lock=false;
601         int depth=0;
602         svn_wc_adm_access_t *parent_wc;
603         svn_error_t *err;
604         AdmObject *ret;
605         char *kwnames[] = { "associated", "path", "write_lock", "depth", NULL };
606
607         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|bi", kwnames,
608                         &associated, &path, &write_lock, &depth))
609                 return NULL;
610
611         ret = PyObject_New(AdmObject, &Adm_Type);
612         if (ret == NULL)
613                 return NULL;
614
615         ret->pool = Pool(NULL);
616         if (ret->pool == NULL)
617                 return NULL;
618         if (associated == Py_None) {
619                 parent_wc = NULL;
620         } else {
621                 parent_wc = ((AdmObject *)associated)->adm;
622         }
623         Py_BEGIN_ALLOW_THREADS
624         err = svn_wc_adm_open3(&ret->adm, parent_wc, 
625                                                    svn_path_canonicalize(path, ret->pool),
626                                                    write_lock, depth, py_cancel_check, NULL, 
627                                                    ret->pool);
628         Py_END_ALLOW_THREADS
629         
630         if (err != NULL) {
631                 handle_svn_error(err);
632                 svn_error_clear(err);
633                 Py_DECREF(ret);
634                 return NULL;
635         }
636
637         return (PyObject *)ret;
638 }
639
640 static PyObject *adm_access_path(PyObject *self)
641 {
642         AdmObject *admobj = (AdmObject *)self;
643         ADM_CHECK_CLOSED(admobj);
644         return PyString_FromString(svn_wc_adm_access_path(admobj->adm));
645 }
646
647 static PyObject *adm_locked(PyObject *self)
648 {
649         AdmObject *admobj = (AdmObject *)self;
650         ADM_CHECK_CLOSED(admobj);
651         return PyBool_FromLong(svn_wc_adm_locked(admobj->adm));
652 }
653
654 static PyObject *adm_prop_get(PyObject *self, PyObject *args)
655 {
656         char *name, *path;
657         AdmObject *admobj = (AdmObject *)self;
658         const svn_string_t *value;
659         apr_pool_t *temp_pool;
660         PyObject *ret;
661
662         if (!PyArg_ParseTuple(args, "ss", &name, &path))
663                 return NULL;
664
665         ADM_CHECK_CLOSED(admobj);
666
667         temp_pool = Pool(NULL);
668         if (temp_pool == NULL)
669                 return NULL;
670         RUN_SVN_WITH_POOL(temp_pool, svn_wc_prop_get(&value, name, path, admobj->adm, temp_pool));
671         if (value == NULL || value->data == NULL) {
672                 ret = Py_None;
673                 Py_INCREF(ret);
674         } else {
675                 ret = PyString_FromStringAndSize(value->data, value->len);
676         }
677         apr_pool_destroy(temp_pool);
678         return ret;
679 }
680
681 static PyObject *adm_prop_set(PyObject *self, PyObject *args)
682 {
683         char *name, *value, *path; 
684         AdmObject *admobj = (AdmObject *)self;
685         bool skip_checks=false;
686         apr_pool_t *temp_pool;
687         int vallen;
688         svn_string_t *cvalue;
689         PyObject *notify_func = Py_None;
690
691         if (!PyArg_ParseTuple(args, "sz#s|bO", &name, &value, &vallen, &path, &skip_checks,
692                                                   &notify_func))
693                 return NULL;
694
695         ADM_CHECK_CLOSED(admobj);
696
697         temp_pool = Pool(NULL);
698         if (temp_pool == NULL)
699                 return NULL;
700         if (value == NULL) {
701                 cvalue = NULL;
702         } else {
703                 cvalue = svn_string_ncreate(value, vallen, temp_pool);
704         }
705 #if ONLY_SINCE_SVN(1, 6)
706         RUN_SVN_WITH_POOL(temp_pool, svn_wc_prop_set3(name, cvalue, path, admobj->adm, 
707                                 skip_checks, py_wc_notify_func, (void *)notify_func, 
708                                 temp_pool));
709 #else
710         RUN_SVN_WITH_POOL(temp_pool, svn_wc_prop_set2(name, cvalue, path, admobj->adm, 
711                                 skip_checks, temp_pool));
712 #endif
713         apr_pool_destroy(temp_pool);
714
715         Py_RETURN_NONE;
716 }
717
718 static PyObject *adm_entries_read(PyObject *self, PyObject *args)
719 {
720         apr_hash_t *entries;
721         AdmObject *admobj = (AdmObject *)self;
722         apr_pool_t *temp_pool;
723         bool show_hidden=false;
724         apr_hash_index_t *idx;
725         const char *key;
726         apr_ssize_t klen;
727         svn_wc_entry_t *entry;
728         PyObject *py_entries, *obj;
729
730         if (!PyArg_ParseTuple(args, "|b", &show_hidden))
731                 return NULL;
732
733         ADM_CHECK_CLOSED(admobj);
734
735         temp_pool = Pool(NULL);
736         if (temp_pool == NULL)
737                 return NULL;
738         RUN_SVN_WITH_POOL(temp_pool, svn_wc_entries_read(&entries, admobj->adm, 
739                                  show_hidden, temp_pool));
740         py_entries = PyDict_New();
741         if (py_entries == NULL) {
742                 apr_pool_destroy(temp_pool);
743                 return NULL;
744         }
745         idx = apr_hash_first(temp_pool, entries);
746         while (idx != NULL) {
747                 apr_hash_this(idx, (const void **)&key, &klen, (void **)&entry);
748                 if (entry == NULL) {
749                         obj = Py_None;
750                         Py_INCREF(obj);
751                 } else {
752                         obj = py_entry(entry);
753                 }
754                 PyDict_SetItemString(py_entries, key, obj);
755                 Py_DECREF(obj);
756                 idx = apr_hash_next(idx);
757         }
758         apr_pool_destroy(temp_pool);
759         return py_entries;
760 }
761
762 static PyObject *adm_walk_entries(PyObject *self, PyObject *args)
763 {
764         char *path;
765         PyObject *callbacks; 
766         bool show_hidden=false;
767         apr_pool_t *temp_pool;
768         AdmObject *admobj = (AdmObject *)self;
769         svn_depth_t depth = svn_depth_infinity;
770
771         if (!PyArg_ParseTuple(args, "sO|bi", &path, &callbacks, &show_hidden, &depth))
772                 return NULL;
773
774         ADM_CHECK_CLOSED(admobj);
775
776         temp_pool = Pool(NULL);
777         if (temp_pool == NULL)
778                 return NULL;
779 #if ONLY_SINCE_SVN(1, 5)
780         RUN_SVN_WITH_POOL(temp_pool, svn_wc_walk_entries3(
781                           svn_path_canonicalize(path, temp_pool), admobj->adm, 
782                                 &py_wc_entry_callbacks2, (void *)callbacks,
783                                 depth, show_hidden, py_cancel_check, NULL,
784                                 temp_pool));
785 #else
786         if (depth != svn_depth_infinity) {
787                 PyErr_SetString(PyExc_NotImplementedError,
788                                                 "depth != infinity not supported for svn < 1.5");
789                 apr_pool_destroy(temp_pool);
790                 return NULL;
791         }
792         RUN_SVN_WITH_POOL(temp_pool, svn_wc_walk_entries2(
793                           svn_path_canonicalize(path, temp_pool), admobj->adm, 
794                                 &py_wc_entry_callbacks, (void *)callbacks,
795                                 show_hidden, py_cancel_check, NULL,
796                                 temp_pool));
797 #endif
798         apr_pool_destroy(temp_pool);
799
800         Py_RETURN_NONE;
801 }
802
803 static PyObject *adm_entry(PyObject *self, PyObject *args)
804 {
805         char *path;
806         bool show_hidden=false;
807         apr_pool_t *temp_pool;
808         AdmObject *admobj = (AdmObject *)self;
809         const svn_wc_entry_t *entry;
810         PyObject *ret;
811
812         if (!PyArg_ParseTuple(args, "s|b", &path, &show_hidden))
813                 return NULL;
814
815         ADM_CHECK_CLOSED(admobj);
816
817         temp_pool = Pool(NULL);
818         if (temp_pool == NULL)
819                 return NULL;
820         RUN_SVN_WITH_POOL(temp_pool, svn_wc_entry(&entry, svn_path_canonicalize(path, temp_pool), admobj->adm, show_hidden, temp_pool));
821
822         if (entry == NULL) {
823                 PyErr_Format(PyExc_KeyError, "No such entry '%s'", path);
824                 ret = NULL;
825         } else  {
826                 ret = py_entry(entry);
827         }
828
829         apr_pool_destroy(temp_pool);
830         return ret;
831 }
832
833 static PyObject *adm_get_prop_diffs(PyObject *self, PyObject *args)
834 {
835         char *path;
836         apr_pool_t *temp_pool;
837         apr_array_header_t *propchanges;
838         apr_hash_t *original_props;
839         AdmObject *admobj = (AdmObject *)self;
840         svn_prop_t el;
841         int i;
842         PyObject *py_propchanges, *py_orig_props, *pyval;
843
844         if (!PyArg_ParseTuple(args, "s", &path))
845                 return NULL;
846
847         ADM_CHECK_CLOSED(admobj);
848
849         temp_pool = Pool(NULL);
850         if (temp_pool == NULL)
851                 return NULL;
852         RUN_SVN_WITH_POOL(temp_pool, svn_wc_get_prop_diffs(&propchanges, &original_props,
853                                 svn_path_canonicalize(path, temp_pool), admobj->adm, temp_pool));
854         py_propchanges = PyList_New(propchanges->nelts);
855         if (py_propchanges == NULL) {
856                 apr_pool_destroy(temp_pool);
857                 return NULL;
858         }
859         for (i = 0; i < propchanges->nelts; i++) {
860                 el = APR_ARRAY_IDX(propchanges, i, svn_prop_t);
861                 if (el.value != NULL)
862                         pyval = Py_BuildValue("(sz#)", el.name, el.value->data, el.value->len);
863                 else
864                         pyval = Py_BuildValue("(sO)", el.name, Py_None);
865                 if (pyval == NULL) {
866                         apr_pool_destroy(temp_pool);
867                         Py_DECREF(py_propchanges);
868                         return NULL;
869                 }
870                 if (PyList_SetItem(py_propchanges, i, pyval) != 0) {
871                         Py_DECREF(py_propchanges);
872                         apr_pool_destroy(temp_pool);
873                         return NULL;
874                 }
875         }
876         py_orig_props = prop_hash_to_dict(original_props);
877         apr_pool_destroy(temp_pool);
878         if (py_orig_props == NULL) {
879                 Py_DECREF(py_propchanges);
880                 return NULL;
881         }
882         return Py_BuildValue("(NN)", py_propchanges, py_orig_props);
883 }
884
885 static PyObject *adm_add(PyObject *self, PyObject *args, PyObject *kwargs)
886 {
887         char *path, *copyfrom_url=NULL;
888         svn_revnum_t copyfrom_rev=-1; 
889         char *kwnames[] = { "path", "copyfrom_url", "copyfrom_rev", "notify_func", "depth", NULL };
890         PyObject *notify_func=Py_None;
891         AdmObject *admobj = (AdmObject *)self;
892         apr_pool_t *temp_pool;
893         svn_depth_t depth = svn_depth_infinity;
894
895         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zlOi", kwnames, &path,
896                         &copyfrom_url, &copyfrom_rev, &notify_func, &depth))
897                 return NULL;
898
899         ADM_CHECK_CLOSED(admobj);
900
901         temp_pool = Pool(NULL);
902         if (temp_pool == NULL)
903                 return NULL;
904
905 #if ONLY_SINCE_SVN(1, 6)
906         RUN_SVN_WITH_POOL(temp_pool, svn_wc_add3(
907                                                    svn_path_canonicalize(path, temp_pool), admobj->adm, depth, copyfrom_url, 
908                                                         copyfrom_rev, py_cancel_check, NULL,
909                                                         py_wc_notify_func, 
910                                                         (void *)notify_func, 
911                                                         temp_pool));
912 #else
913         if (depth != svn_depth_infinity) {
914                 PyErr_SetString(PyExc_NotImplementedError, "depth != infinity not supported on svn < 1.6");
915                 apr_pool_destroy(temp_pool);
916                 return NULL;
917         }
918         RUN_SVN_WITH_POOL(temp_pool, svn_wc_add2(
919                                                    svn_path_canonicalize(path, temp_pool), admobj->adm, copyfrom_url, 
920                                                         copyfrom_rev, py_cancel_check, 
921                                                         py_wc_notify_func, 
922                                                         (void *)notify_func, 
923                                                         temp_pool));
924 #endif
925         apr_pool_destroy(temp_pool);
926
927         Py_RETURN_NONE;
928 }
929
930 static PyObject *adm_copy(PyObject *self, PyObject *args)
931 {
932         AdmObject *admobj = (AdmObject *)self;
933         char *src, *dst; 
934         PyObject *notify_func=Py_None;
935         apr_pool_t *temp_pool;
936
937         if (!PyArg_ParseTuple(args, "ss|O", &src, &dst, &notify_func))
938                 return NULL;
939
940         ADM_CHECK_CLOSED(admobj);
941
942         temp_pool = Pool(NULL);
943         if (temp_pool == NULL)
944                 return NULL;
945         RUN_SVN_WITH_POOL(temp_pool, svn_wc_copy2(src, admobj->adm, dst,
946                                                         py_cancel_check, NULL,
947                                                         py_wc_notify_func, (void *)notify_func, 
948                                                         temp_pool));
949         apr_pool_destroy(temp_pool);
950
951         Py_RETURN_NONE;
952 }
953
954 static PyObject *adm_delete(PyObject *self, PyObject *args, PyObject *kwargs)
955 {
956         AdmObject *admobj = (AdmObject *)self;
957         apr_pool_t *temp_pool;
958         char *kwnames[] = { "path", "notify_func", "keep_local",
959                                 NULL };
960         char *path;
961         PyObject *notify_func=Py_None;
962         bool keep_local = false;
963
964         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|Ob:delete", kwnames, 
965                         &path, &notify_func, &keep_local))
966                 return NULL;
967
968         ADM_CHECK_CLOSED(admobj);
969
970         temp_pool = Pool(NULL);
971         if (temp_pool == NULL)
972                 return NULL;
973
974 #if ONLY_SINCE_SVN(1, 5)
975         RUN_SVN_WITH_POOL(temp_pool, svn_wc_delete3(path, admobj->adm, 
976                                                         py_cancel_check, NULL,
977                                                         py_wc_notify_func, (void *)notify_func, 
978                                                         keep_local,
979                                                         temp_pool));
980 #else
981         if (keep_local) {
982                 PyErr_SetString(PyExc_NotImplementedError, 
983                                                 "keep_local not supported on Subversion < 1.5");
984                 return NULL;
985         }
986
987         RUN_SVN_WITH_POOL(temp_pool, svn_wc_delete2(path, admobj->adm, 
988                                                         py_cancel_check, NULL,
989                                                         py_wc_notify_func, (void *)notify_func, 
990                                                         temp_pool));
991 #endif
992         apr_pool_destroy(temp_pool);
993
994         Py_RETURN_NONE;
995 }
996
997 static PyObject *adm_crawl_revisions(PyObject *self, PyObject *args, PyObject *kwargs)
998 {
999         char *path;
1000         PyObject *reporter;
1001         bool restore_files=true, recurse=true, use_commit_times=true;
1002         PyObject *notify_func=Py_None;
1003         apr_pool_t *temp_pool;
1004         AdmObject *admobj = (AdmObject *)self;
1005         svn_wc_traversal_info_t *traversal_info;
1006         svn_boolean_t depth_compatibility_trick = FALSE;
1007         svn_boolean_t honor_depth_exclude = FALSE;
1008         char *kwnames[] = { "path", "reporter", "restore_files", "recurse", "use_commit_times", "notify_func", "depth_compatibility_trick", "honor_depth_exclude,", NULL };
1009
1010         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|bbbObb", kwnames, &path,
1011                         &reporter, &restore_files, &recurse, &use_commit_times,
1012                         &notify_func, &depth_compatibility_trick, &honor_depth_exclude))
1013                 return NULL;
1014
1015         ADM_CHECK_CLOSED(admobj);
1016
1017         temp_pool = Pool(NULL);
1018         if (temp_pool == NULL)
1019                 return NULL;
1020         traversal_info = svn_wc_init_traversal_info(temp_pool);
1021 #if ONLY_SINCE_SVN(1, 6)
1022         RUN_SVN_WITH_POOL(temp_pool, svn_wc_crawl_revisions4(svn_path_canonicalize(path, temp_pool), admobj->adm, 
1023                                 &py_ra_reporter, (void *)reporter, 
1024                                 restore_files, recurse?svn_depth_infinity:svn_depth_files,
1025                                 honor_depth_exclude,
1026                                 depth_compatibility_trick, use_commit_times, 
1027                                 py_wc_notify_func, (void *)notify_func,
1028                                 traversal_info, temp_pool));
1029 #elif ONLY_SINCE_SVN(1, 5)
1030         RUN_SVN_WITH_POOL(temp_pool, svn_wc_crawl_revisions3(svn_path_canonicalize(path, temp_pool), admobj->adm, 
1031                                 &py_ra_reporter, (void *)reporter, 
1032                                 restore_files, recurse?svn_depth_infinity:svn_depth_files, 
1033                                 depth_compatibility_trick, use_commit_times, 
1034                                 py_wc_notify_func, (void *)notify_func,
1035                                 traversal_info, temp_pool));
1036 #else
1037         RUN_SVN_WITH_POOL(temp_pool, svn_wc_crawl_revisions2(svn_path_canonicalize(path, temp_pool), admobj->adm, 
1038                                 &py_ra_reporter, (void *)reporter, 
1039                                 restore_files, recurse, use_commit_times, 
1040                                 py_wc_notify_func, (void *)notify_func,
1041                                 traversal_info, temp_pool));
1042 #endif
1043         apr_pool_destroy(temp_pool);
1044
1045         Py_RETURN_NONE;
1046 }
1047
1048 static void wc_done_handler(void *self)
1049 {
1050         AdmObject *admobj = (AdmObject *)self;
1051
1052         Py_DECREF(admobj);
1053 }
1054
1055 static PyObject *adm_get_update_editor(PyObject *self, PyObject *args)
1056 {
1057         char *target;
1058         bool use_commit_times=true, recurse=true;
1059         PyObject * notify_func=Py_None;
1060         char *diff3_cmd=NULL;
1061         const svn_delta_editor_t *editor;
1062         AdmObject *admobj = (AdmObject *)self;
1063         void *edit_baton;
1064         apr_pool_t *pool;
1065         svn_revnum_t *latest_revnum;
1066         svn_error_t *err;
1067         svn_boolean_t allow_unver_obstructions = FALSE;
1068         svn_boolean_t depth_is_sticky = FALSE;
1069
1070         if (!PyArg_ParseTuple(args, "s|bbOzbb", &target, &use_commit_times,
1071                         &recurse, &notify_func, &diff3_cmd, &depth_is_sticky,
1072                         &allow_unver_obstructions))
1073                 return NULL;
1074
1075         ADM_CHECK_CLOSED(admobj);
1076
1077         pool = Pool(NULL);
1078         if (pool == NULL)
1079                 return NULL;
1080         latest_revnum = (svn_revnum_t *)apr_palloc(pool, sizeof(svn_revnum_t));
1081         Py_BEGIN_ALLOW_THREADS
1082 #if ONLY_SINCE_SVN(1, 5)
1083         /* FIXME: Support all values of depth */
1084         /* FIXME: Support fetch_func */
1085         /* FIXME: Support conflict func */
1086         err = svn_wc_get_update_editor3(latest_revnum, admobj->adm, target, 
1087                                 use_commit_times, recurse?svn_depth_infinity:svn_depth_files,
1088                                 depth_is_sticky, allow_unver_obstructions, 
1089                                 py_wc_notify_func, (void *)notify_func, 
1090                                 py_cancel_check, NULL,
1091                                 NULL, NULL, NULL, NULL,
1092                                 diff3_cmd, NULL, &editor, &edit_baton, 
1093                                 NULL, pool);
1094 #else
1095         if (allow_unver_obstructions) {
1096                 PyErr_SetString(PyExc_NotImplementedError, 
1097                                                 "allow_unver_obstructions is not supported in svn < 1.5");
1098                 apr_pool_destroy(pool);
1099                 PyEval_RestoreThread(_save);
1100                 return NULL;
1101         }
1102         if (depth_is_sticky) {
1103                 PyErr_SetString(PyExc_NotImplementedError, 
1104                                                 "depth_is_sticky is not supported in svn < 1.5");
1105                 apr_pool_destroy(pool);
1106                 PyEval_RestoreThread(_save);
1107                 return NULL;
1108         }
1109         err = svn_wc_get_update_editor2(latest_revnum, admobj->adm, target, 
1110                                 use_commit_times, recurse, py_wc_notify_func, (void *)notify_func, 
1111                                 py_cancel_check, NULL, diff3_cmd, &editor, &edit_baton, 
1112                                 NULL, pool);
1113 #endif
1114         Py_END_ALLOW_THREADS
1115         if (err != NULL) {
1116                 handle_svn_error(err);
1117                 svn_error_clear(err);
1118                 apr_pool_destroy(pool);
1119                 return NULL;
1120         }
1121         Py_INCREF(admobj);
1122         return new_editor_object(NULL, editor, edit_baton, pool, &Editor_Type,
1123                 wc_done_handler, admobj, NULL);
1124 }
1125
1126 static bool py_dict_to_wcprop_changes(PyObject *dict, apr_pool_t *pool, apr_array_header_t **ret)
1127 {
1128         PyObject *key, *val;
1129         Py_ssize_t idx;
1130
1131         if (dict == Py_None) {
1132                 *ret = NULL;
1133                 return true;
1134         }
1135
1136         if (!PyDict_Check(dict)) {
1137                 PyErr_SetString(PyExc_TypeError, "Expected dictionary with property changes");
1138                 return false;
1139         }
1140
1141         *ret = apr_array_make(pool, PyDict_Size(dict), sizeof(char *));
1142
1143         while (PyDict_Next(dict, &idx, &key, &val)) {
1144                    svn_prop_t *prop = apr_palloc(pool, sizeof(svn_prop_t));
1145                    prop->name = PyString_AsString(key);
1146                    if (val == Py_None) {
1147                            prop->value = NULL;
1148                    } else {
1149                            prop->value = svn_string_ncreate(PyString_AsString(val), PyString_Size(val), pool);
1150                    }
1151                    APR_ARRAY_PUSH(*ret, svn_prop_t *) = prop;
1152         }
1153
1154         return true;
1155 }
1156
1157 static PyObject *adm_has_binary_prop(PyObject *self, PyObject *args)
1158 {
1159         char *path;
1160         svn_boolean_t binary;
1161         AdmObject *admobj = (AdmObject *)self;
1162         apr_pool_t *temp_pool;
1163
1164         if (!PyArg_ParseTuple(args, "s", &path))
1165                 return NULL;
1166
1167         ADM_CHECK_CLOSED(admobj);
1168
1169         temp_pool = Pool(NULL);
1170         if (temp_pool == NULL)
1171                 return NULL;
1172
1173         RUN_SVN_WITH_POOL(temp_pool, svn_wc_has_binary_prop(&binary, path, admobj->adm, temp_pool));
1174
1175         apr_pool_destroy(temp_pool);
1176
1177         return PyBool_FromLong(binary);
1178 }
1179
1180 static PyObject *adm_process_committed(PyObject *self, PyObject *args, PyObject *kwargs)
1181 {
1182         char *path, *rev_date = NULL, *rev_author = NULL;
1183         bool recurse, remove_lock = false;
1184         unsigned char *digest = NULL;
1185         svn_revnum_t new_revnum;
1186         PyObject *py_wcprop_changes = Py_None;
1187         apr_array_header_t *wcprop_changes = NULL;
1188         AdmObject *admobj = (AdmObject *)self;
1189         apr_pool_t *temp_pool;
1190         int digest_len;
1191         svn_boolean_t remove_changelist = FALSE;
1192         char *kwnames[] = { "path", "recurse", "new_revnum", "rev_date", "rev_author", 
1193                                                 "wcprop_changes", "remove_lock", "digest", "remove_changelist", NULL };
1194
1195         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sblzz|Obz#b", kwnames, 
1196                                                                          &path, &recurse, &new_revnum, &rev_date,
1197                                                                          &rev_author, &py_wcprop_changes, 
1198                                                                          &remove_lock, &digest, &digest_len, &remove_changelist))
1199                 return NULL;
1200
1201         PyErr_WarnEx(PyExc_DeprecationWarning, "process_committed is deprecated. Use process_committed_queue instead.", 2);
1202
1203
1204         ADM_CHECK_CLOSED(admobj);
1205
1206         temp_pool = Pool(NULL);
1207         if (temp_pool == NULL)
1208                 return NULL;
1209
1210         if (!py_dict_to_wcprop_changes(py_wcprop_changes, temp_pool, &wcprop_changes)) {
1211                 apr_pool_destroy(temp_pool);
1212                 return NULL;
1213         }
1214
1215 #if ONLY_SINCE_SVN(1, 6)
1216         RUN_SVN_WITH_POOL(temp_pool, svn_wc_process_committed4(
1217                 svn_path_canonicalize(path, temp_pool), admobj->adm, recurse, new_revnum, 
1218                         rev_date, rev_author, wcprop_changes, 
1219                         remove_lock, remove_changelist, digest, temp_pool));
1220 #else
1221         if (remove_changelist) {
1222                 PyErr_SetString(PyExc_NotImplementedError, "remove_changelist only supported in svn < 1.6");
1223                 apr_pool_destroy(temp_pool);
1224                 return NULL;
1225         }
1226         RUN_SVN_WITH_POOL(temp_pool, svn_wc_process_committed3(svn_path_canonicalize(path, temp_pool), admobj->adm, recurse, new_revnum, 
1227                                                                                                                    rev_date, rev_author, wcprop_changes, 
1228                                                                                                                    remove_lock, digest, temp_pool));
1229 #endif
1230
1231         apr_pool_destroy(temp_pool);
1232
1233         Py_RETURN_NONE;
1234 }
1235
1236 static PyObject *adm_close(PyObject *self)
1237 {
1238         AdmObject *admobj = (AdmObject *)self;
1239         if (admobj->adm != NULL) {
1240 #if ONLY_SINCE_SVN(1, 6)
1241                 apr_pool_t *temp_pool = Pool(NULL);
1242                 Py_BEGIN_ALLOW_THREADS
1243                 svn_wc_adm_close2(admobj->adm, temp_pool);
1244                 apr_pool_destroy(temp_pool);
1245 #else
1246                 Py_BEGIN_ALLOW_THREADS
1247                 svn_wc_adm_close(admobj->adm);
1248 #endif
1249                 Py_END_ALLOW_THREADS
1250                 admobj->adm = NULL;
1251         }
1252
1253         Py_RETURN_NONE;
1254 }
1255
1256 static void adm_dealloc(PyObject *self)
1257 {
1258         apr_pool_destroy(((AdmObject *)self)->pool);
1259         PyObject_Del(self);
1260 }
1261
1262 static PyObject *adm_repr(PyObject *self)
1263 {
1264         AdmObject *admobj = (AdmObject *)self;
1265
1266         if (admobj->adm == NULL) {
1267                 return PyString_FromFormat("<wc.WorkingCopy (closed) at 0x%p>", admobj);
1268         } else {
1269                 return PyString_FromFormat("<wc.WorkingCopy at '%s'>", 
1270                                                                    svn_wc_adm_access_path(admobj->adm));
1271         }
1272 }
1273
1274 static PyObject *adm_remove_lock(PyObject *self, PyObject *args)
1275 {
1276         char *path;
1277         AdmObject *admobj = (AdmObject *)self;
1278         apr_pool_t *temp_pool;
1279
1280         if (!PyArg_ParseTuple(args, "s", &path))
1281                 return NULL;
1282
1283         ADM_CHECK_CLOSED(admobj);
1284
1285         temp_pool = Pool(NULL);
1286         if (temp_pool == NULL)
1287                 return NULL;
1288
1289         RUN_SVN_WITH_POOL(temp_pool, svn_wc_remove_lock(path, admobj->adm, temp_pool))
1290
1291         apr_pool_destroy(temp_pool);
1292
1293         Py_RETURN_NONE;
1294 }
1295
1296 static PyObject *get_ancestry(PyObject *self, PyObject *args)
1297 {
1298         char *path;
1299         char *url;
1300         svn_revnum_t rev;
1301         apr_pool_t *temp_pool;
1302         AdmObject *admobj = (AdmObject *)self;
1303
1304         if (!PyArg_ParseTuple(args, "s", &path))
1305                 return NULL;
1306
1307         ADM_CHECK_CLOSED(admobj);
1308
1309         temp_pool = Pool(NULL);
1310         if (temp_pool == NULL)
1311                 return NULL;
1312
1313         RUN_SVN_WITH_POOL(temp_pool, svn_wc_get_ancestry(&url, &rev, path, admobj->adm, temp_pool));
1314
1315         apr_pool_destroy(temp_pool);
1316
1317         return Py_BuildValue("(si)", url, rev);
1318 }
1319
1320 static PyObject *maybe_set_repos_root(PyObject *self, PyObject *args)
1321 {
1322         char *path, *repos;
1323         apr_pool_t *temp_pool;
1324         AdmObject *admobj = (AdmObject *)self;
1325
1326         if (!PyArg_ParseTuple(args, "ss", &path, &repos))
1327                 return NULL;
1328
1329         ADM_CHECK_CLOSED(admobj);
1330
1331         temp_pool = Pool(NULL);
1332         if (temp_pool == NULL)
1333                 return NULL;
1334
1335         RUN_SVN_WITH_POOL(temp_pool, svn_wc_maybe_set_repos_root(admobj->adm, path, repos, temp_pool));
1336
1337         Py_RETURN_NONE;
1338 }
1339
1340 static PyObject *add_repos_file(PyObject *self, PyObject *args, PyObject *kwargs)
1341 {
1342         char *kwnames[] = { "dst_path", "new_base_contents", "new_contents",
1343                 "new_base_props", "new_props", "copyfrom_url", "copyfrom_rev",
1344                 "notify", NULL };
1345         AdmObject *admobj = (AdmObject *)self;
1346         apr_pool_t *temp_pool;
1347         char *dst_path, *copyfrom_url = NULL;
1348         svn_revnum_t copyfrom_rev = -1;
1349         PyObject *py_new_base_contents, *py_new_contents, *py_new_base_props,
1350                          *py_new_props, *notify = Py_None;
1351         svn_stream_t *new_contents, *new_base_contents;
1352         apr_hash_t *new_props, *new_base_props;
1353
1354         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sOOOO|zlO", kwnames,
1355                         &dst_path, &py_new_base_contents, &py_new_contents, &py_new_base_props, 
1356                         &py_new_props, &copyfrom_url, &copyfrom_rev, &notify))
1357                 return NULL;
1358
1359         ADM_CHECK_CLOSED(admobj);
1360
1361         temp_pool = Pool(NULL);
1362         if (temp_pool == NULL)
1363                 return NULL;
1364
1365         new_base_props = prop_dict_to_hash(temp_pool, py_new_base_props);
1366
1367         new_props = prop_dict_to_hash(temp_pool, py_new_props);
1368
1369         new_base_contents = new_py_stream(temp_pool, py_new_base_contents);
1370
1371         new_contents = new_py_stream(temp_pool, py_new_contents);
1372
1373 #if ONLY_SINCE_SVN(1, 6)
1374         RUN_SVN_WITH_POOL(temp_pool, svn_wc_add_repos_file3(dst_path, admobj->adm,
1375                                                    new_base_contents,
1376                                                    new_contents,
1377                                                    new_base_props,
1378                                                    new_props,
1379                                                    copyfrom_url, copyfrom_rev,
1380                                                    py_cancel_check, NULL,
1381                                                    py_wc_notify_func, notify, temp_pool));
1382 #else
1383         PyErr_SetString(PyExc_NotImplementedError,
1384                                         "add_repos_file3 not supported on svn < 1.6");
1385         apr_pool_destroy(temp_pool);
1386 #endif
1387
1388         apr_pool_destroy(temp_pool);
1389
1390         Py_RETURN_NONE;
1391 }
1392
1393 static PyObject *mark_missing_deleted(PyObject *self, PyObject *args)
1394 {
1395         char *path;
1396         AdmObject *admobj = (AdmObject *)self;
1397         apr_pool_t *temp_pool;
1398
1399         if (!PyArg_ParseTuple(args, "s", &path))
1400                 return NULL;
1401
1402         ADM_CHECK_CLOSED(admobj);
1403
1404         temp_pool = Pool(NULL);
1405         if (temp_pool == NULL)
1406                 return NULL;
1407
1408         RUN_SVN_WITH_POOL(temp_pool, svn_wc_mark_missing_deleted(path, admobj->adm, temp_pool));
1409
1410         apr_pool_destroy(temp_pool);
1411
1412         Py_RETURN_NONE;
1413 }
1414
1415 static PyObject *remove_from_revision_control(PyObject *self, PyObject *args)
1416 {
1417         char *name;
1418         svn_boolean_t destroy_wf = FALSE, instant_error = FALSE;
1419         AdmObject *admobj = (AdmObject *)self;
1420         apr_pool_t *temp_pool;
1421
1422         if (!PyArg_ParseTuple(args, "s|bb", &name, &destroy_wf, &instant_error))
1423                 return NULL;
1424
1425         ADM_CHECK_CLOSED(admobj);
1426
1427         temp_pool = Pool(NULL);
1428         if (temp_pool == NULL)
1429                 return NULL;
1430
1431         RUN_SVN_WITH_POOL(temp_pool,
1432                 svn_wc_remove_from_revision_control(admobj->adm, name,
1433                         destroy_wf, instant_error, py_cancel_check, NULL, temp_pool));
1434
1435         apr_pool_destroy(temp_pool);
1436
1437         Py_RETURN_NONE;
1438 }
1439
1440 #if ONLY_SINCE_SVN(1, 6)
1441 static svn_error_t *wc_validator3(void *baton, const char *uuid, const char *url, const char *root_url, apr_pool_t *pool)
1442 {
1443         PyObject *py_validator = baton, *ret;
1444
1445         if (py_validator == Py_None) {
1446                 return NULL;
1447         }
1448
1449         ret = PyObject_CallFunction(py_validator, "sss", uuid, url, root_url);
1450         if (ret == NULL) {
1451                 return py_svn_error();
1452         }
1453
1454         Py_DECREF(ret);
1455
1456         return NULL;
1457 }
1458
1459 #else
1460
1461 static svn_error_t *wc_validator2(void *baton, const char *uuid, const char *url, svn_boolean_t root, apr_pool_t *pool)
1462 {
1463         PyObject *py_validator = baton, *ret;
1464
1465         if (py_validator == Py_None) {
1466                 return NULL;
1467         }
1468
1469         ret = PyObject_CallFunction(py_validator, "ssO", uuid, url, Py_None);
1470         if (ret == NULL) {
1471                 return py_svn_error();
1472         }
1473
1474         Py_DECREF(ret);
1475
1476         return NULL;
1477 }
1478
1479 #endif
1480
1481 static PyObject *relocate(PyObject *self, PyObject *args)
1482 {
1483         char *path, *from, *to;
1484         AdmObject *admobj = (AdmObject *)self;
1485         apr_pool_t *temp_pool;
1486         svn_boolean_t recurse = TRUE;
1487         PyObject *py_validator = Py_None;
1488
1489         if (!PyArg_ParseTuple(args, "sss|bO:relocate", &path, &from, &to, &recurse,
1490                         &py_validator))
1491                 return NULL;
1492
1493         ADM_CHECK_CLOSED(admobj);
1494
1495         temp_pool = Pool(NULL);
1496         if (temp_pool == NULL)
1497                 return NULL;
1498
1499 #if ONLY_SINCE_SVN(1, 6)
1500         RUN_SVN_WITH_POOL(temp_pool, svn_wc_relocate3(path, admobj->adm, from, to, recurse, wc_validator3, py_validator, temp_pool));
1501 #else
1502         RUN_SVN_WITH_POOL(temp_pool, svn_wc_relocate2(path, admobj->adm, from, to, recurse, wc_validator2, py_validator, temp_pool));
1503 #endif
1504
1505         apr_pool_destroy(temp_pool);
1506
1507         Py_RETURN_NONE;
1508 }
1509
1510 static PyObject *crop_tree(PyObject *self, PyObject *args)
1511 {
1512         char *target;
1513         svn_depth_t depth;
1514         PyObject *notify;
1515         apr_pool_t *temp_pool;
1516         AdmObject *admobj = (AdmObject *)self;
1517
1518         if (!PyArg_ParseTuple(args, "si|O", &target, &depth, &notify))
1519                 return NULL;
1520
1521         ADM_CHECK_CLOSED(admobj);
1522
1523 #if ONLY_SINCE_SVN(1, 6)
1524         temp_pool = Pool(NULL);
1525         if (temp_pool == NULL)
1526                 return NULL;
1527
1528         RUN_SVN_WITH_POOL(temp_pool, svn_wc_crop_tree(admobj->adm, 
1529                 target, depth, py_wc_notify_func, notify,
1530                 py_cancel_check, NULL, temp_pool));
1531
1532         apr_pool_destroy(temp_pool);
1533
1534         Py_RETURN_NONE;
1535 #else
1536         PyErr_SetString(PyExc_NotImplementedError, 
1537                                         "crop_tree only available on subversion < 1.6");
1538         return NULL;
1539 #endif
1540 }
1541
1542 static PyObject *translated_stream(PyObject *self, PyObject *args)
1543 {
1544         char *path, *versioned_file;
1545         StreamObject *ret;
1546         svn_stream_t *stream;
1547         AdmObject *admobj = (AdmObject *)self;
1548         apr_pool_t *stream_pool;
1549         int flags;
1550
1551         if (!PyArg_ParseTuple(args, "ssi", &path, &versioned_file, &flags))
1552                 return NULL;
1553
1554         ADM_CHECK_CLOSED(admobj);
1555
1556 #if ONLY_SINCE_SVN(1, 5)
1557         stream_pool = Pool(NULL);
1558         if (stream_pool == NULL)
1559                 return NULL;
1560
1561         RUN_SVN_WITH_POOL(stream_pool,
1562                 svn_wc_translated_stream(&stream, path, versioned_file, admobj->adm, 
1563                         flags, stream_pool));
1564
1565         ret = PyObject_New(StreamObject, &Stream_Type);
1566         if (ret == NULL)
1567                 return NULL;
1568
1569         ret->pool = stream_pool;
1570         ret->closed = FALSE;
1571         ret->stream = stream;
1572
1573         return (PyObject *)ret;
1574 #else
1575         PyErr_SetString(PyExc_NotImplementedError,
1576                 "translated_stream() is only available on Subversion >= 1.5");
1577         return NULL;
1578 #endif
1579 }
1580
1581 static PyObject *adm_text_modified(PyObject *self, PyObject *args)
1582 {
1583         char *path;
1584         svn_boolean_t force_comparison = FALSE;
1585         apr_pool_t *temp_pool;
1586         svn_boolean_t ret;
1587         AdmObject *admobj = (AdmObject *)self;
1588
1589         if (!PyArg_ParseTuple(args, "s|b", &path, &force_comparison))
1590                 return NULL;
1591
1592         ADM_CHECK_CLOSED(admobj);
1593
1594         temp_pool = Pool(NULL);
1595         if (temp_pool == NULL)
1596                 return NULL;
1597
1598         RUN_SVN_WITH_POOL(temp_pool,
1599                   svn_wc_text_modified_p(&ret, path, force_comparison, admobj->adm, 
1600                         temp_pool));
1601
1602         apr_pool_destroy(temp_pool);
1603
1604         return PyBool_FromLong(ret);
1605 }
1606
1607 static PyObject *adm_props_modified(PyObject *self, PyObject *args)
1608 {
1609         char *path;
1610         apr_pool_t *temp_pool;
1611         svn_boolean_t ret;
1612         AdmObject *admobj = (AdmObject *)self;
1613
1614         if (!PyArg_ParseTuple(args, "s", &path))
1615                 return NULL;
1616
1617         ADM_CHECK_CLOSED(admobj);
1618
1619         temp_pool = Pool(NULL);
1620         if (temp_pool == NULL)
1621                 return NULL;
1622
1623         RUN_SVN_WITH_POOL(temp_pool,
1624                   svn_wc_props_modified_p(&ret, path, admobj->adm, temp_pool));
1625
1626         apr_pool_destroy(temp_pool);
1627
1628         return PyBool_FromLong(ret);
1629 }
1630
1631 static PyObject *adm_process_committed_queue(PyObject *self, PyObject *args)
1632 {
1633         apr_pool_t *temp_pool;
1634         AdmObject *admobj = (AdmObject *)self;
1635         svn_revnum_t revnum;
1636         char *date, *author;
1637         CommittedQueueObject *py_queue;
1638
1639         if (!PyArg_ParseTuple(args, "O!lss", &CommittedQueue_Type, &py_queue,
1640                         &revnum, &date, &author))
1641                 return NULL;
1642
1643         ADM_CHECK_CLOSED(admobj);
1644
1645         temp_pool = Pool(NULL);
1646         if (temp_pool == NULL)
1647                 return NULL;
1648
1649 #if ONLY_SINCE_SVN(1, 5)
1650         RUN_SVN_WITH_POOL(temp_pool, svn_wc_process_committed_queue(py_queue->queue, admobj->adm, revnum, date, author, temp_pool));
1651 #else
1652         {
1653                 int i;
1654                 for (i = 0; i < py_queue->queue->queue->nelts; i++) {
1655                         committed_queue_item_t *cqi = APR_ARRAY_IDX(py_queue->queue->queue, i,
1656                                                                                                                 committed_queue_item_t *);
1657
1658                         RUN_SVN_WITH_POOL(temp_pool, svn_wc_process_committed3(cqi->path, admobj->adm,
1659                                    cqi->recurse, revnum, date, author, cqi->wcprop_changes,
1660                                    cqi->remove_lock, cqi->digest, temp_pool));
1661                 }
1662         }
1663 #endif
1664         apr_pool_destroy(temp_pool);
1665
1666         Py_RETURN_NONE;
1667 }
1668
1669 static PyObject *get_actual_target(PyObject *self, PyObject *args)
1670 {
1671         char *path;
1672         const char *anchor = NULL, *target = NULL;
1673         apr_pool_t *temp_pool;
1674         PyObject *ret;
1675
1676         if (!PyArg_ParseTuple(args, "s", &path))
1677                 return NULL;
1678
1679         temp_pool = Pool(NULL);
1680         if (temp_pool == NULL)
1681                 return NULL;
1682
1683         RUN_SVN_WITH_POOL(temp_pool,
1684                   svn_wc_get_actual_target(svn_path_canonicalize(path, temp_pool),
1685                                                                    &anchor, &target, temp_pool));
1686
1687         ret = Py_BuildValue("(ss)", anchor, target);
1688
1689         apr_pool_destroy(temp_pool);
1690
1691         return ret;
1692 }
1693
1694 static PyObject *is_wc_root(PyObject *self, PyObject *args)
1695 {
1696         char *path;
1697         svn_boolean_t wc_root;
1698         apr_pool_t *temp_pool;
1699         AdmObject *admobj = (AdmObject *)self;
1700
1701         if (!PyArg_ParseTuple(args, "s", &path))
1702                 return NULL;
1703
1704         ADM_CHECK_CLOSED(admobj);
1705
1706         temp_pool = Pool(NULL);
1707         if (temp_pool == NULL)
1708                 return NULL;
1709
1710         RUN_SVN_WITH_POOL(temp_pool,
1711                   svn_wc_is_wc_root(&wc_root, path, admobj->adm, temp_pool));
1712
1713         apr_pool_destroy(temp_pool);
1714
1715         return PyBool_FromLong(wc_root);
1716 }
1717
1718 static PyObject *transmit_text_deltas(PyObject *self, PyObject *args)
1719 {
1720         char *path;
1721         const char *tempfile;
1722         svn_boolean_t fulltext;
1723         PyObject *editor_obj, *py_digest;
1724         unsigned char digest[APR_MD5_DIGESTSIZE];
1725         apr_pool_t *temp_pool;
1726         AdmObject *admobj = (AdmObject *)self;
1727         PyObject *ret;
1728
1729         if (!PyArg_ParseTuple(args, "sbO", &path, &fulltext, &editor_obj))
1730                 return NULL;
1731
1732         ADM_CHECK_CLOSED(admobj);
1733
1734         temp_pool = Pool(NULL);
1735         if (temp_pool == NULL)
1736                 return NULL;
1737
1738         Py_INCREF(editor_obj);
1739
1740         RUN_SVN_WITH_POOL(temp_pool,
1741                 svn_wc_transmit_text_deltas2(&tempfile, digest,
1742                         svn_path_canonicalize(path, temp_pool), admobj->adm, fulltext,
1743                         &py_editor, editor_obj, temp_pool));
1744
1745         py_digest = PyString_FromStringAndSize((char *)digest, APR_MD5_DIGESTSIZE);
1746         if (py_digest == NULL) {
1747                 apr_pool_destroy(temp_pool);
1748                 return NULL;
1749         }
1750
1751         ret = Py_BuildValue("sN", tempfile, py_digest);
1752         if (ret == NULL) {
1753                 apr_pool_destroy(temp_pool);
1754                 return NULL;
1755         }
1756
1757         apr_pool_destroy(temp_pool);
1758
1759         return ret;
1760 }
1761
1762 static PyObject *transmit_prop_deltas(PyObject *self, PyObject *args)
1763 {
1764         char *path;
1765         PyObject *editor_obj;
1766         apr_pool_t *temp_pool;
1767         AdmObject *admobj = (AdmObject *)self;
1768         EntryObject *py_entry;
1769
1770         if (!PyArg_ParseTuple(args, "sO!O", &path, &Entry_Type, &py_entry, &editor_obj))
1771                 return NULL;
1772
1773         ADM_CHECK_CLOSED(admobj);
1774
1775         temp_pool = Pool(NULL);
1776         if (temp_pool == NULL)
1777                 return NULL;
1778
1779         Py_INCREF(editor_obj);
1780
1781         RUN_SVN_WITH_POOL(temp_pool,
1782                 svn_wc_transmit_prop_deltas(svn_path_canonicalize(path, temp_pool),
1783                         admobj->adm, &(py_entry->entry), &py_editor, editor_obj, NULL, temp_pool));
1784
1785         apr_pool_destroy(temp_pool);
1786
1787         Py_RETURN_NONE;
1788 }
1789
1790 static PyObject *retrieve(PyObject *self, PyObject *args)
1791 {
1792         char *path;
1793         svn_wc_adm_access_t *result;
1794         AdmObject *admobj = (AdmObject *)self, *ret;
1795         apr_pool_t *pool;
1796
1797         if (!PyArg_ParseTuple(args, "s", &path))
1798                 return NULL;
1799
1800         ADM_CHECK_CLOSED(admobj);
1801
1802         pool = Pool(NULL);
1803         if (pool == NULL)
1804                 return NULL;
1805
1806         RUN_SVN_WITH_POOL(pool, svn_wc_adm_retrieve(&result, admobj->adm, 
1807                 svn_path_canonicalize(path, pool), pool));
1808
1809         ret = PyObject_New(AdmObject, &Adm_Type);
1810         if (ret == NULL)
1811                 return NULL;
1812
1813         ret->pool = pool;
1814         ret->adm = result;
1815
1816         return (PyObject *)ret;
1817 }
1818
1819 static PyObject *probe_retrieve(PyObject *self, PyObject *args)
1820 {
1821         char *path;
1822         svn_wc_adm_access_t *result;
1823         AdmObject *admobj = (AdmObject *)self, *ret;
1824         apr_pool_t *pool;
1825
1826         if (!PyArg_ParseTuple(args, "s", &path))
1827                 return NULL;
1828
1829         ADM_CHECK_CLOSED(admobj);
1830
1831         pool = Pool(NULL);
1832         if (pool == NULL)
1833                 return NULL;
1834
1835         RUN_SVN_WITH_POOL(pool, svn_wc_adm_probe_retrieve(&result, admobj->adm, 
1836                 svn_path_canonicalize(path, pool), pool));
1837
1838         ret = PyObject_New(AdmObject, &Adm_Type);
1839         if (ret == NULL)
1840                 return NULL;
1841
1842         ret->pool = pool;
1843         ret->adm = result;
1844
1845         return (PyObject *)ret;
1846 }
1847
1848 static PyObject *probe_try(PyObject *self, PyObject *args)
1849 {
1850         char *path;
1851         svn_wc_adm_access_t *result = NULL;
1852         AdmObject *admobj = (AdmObject *)self, *ret;
1853         apr_pool_t *pool;
1854         int levels_to_lock = -1;
1855         svn_boolean_t writelock = FALSE;
1856
1857         if (!PyArg_ParseTuple(args, "s|bi", &path, &writelock, &levels_to_lock))
1858                 return NULL;
1859
1860         ADM_CHECK_CLOSED(admobj);
1861
1862         pool = Pool(NULL);
1863         if (pool == NULL)
1864                 return NULL;
1865
1866         RUN_SVN_WITH_POOL(pool, svn_wc_adm_probe_try3(&result, admobj->adm, 
1867                 svn_path_canonicalize(path, pool), writelock, levels_to_lock,
1868                 py_cancel_check, NULL, pool));
1869
1870         if (result == NULL) {
1871                 apr_pool_destroy(pool);
1872                 Py_RETURN_NONE;
1873         }
1874
1875         ret = PyObject_New(AdmObject, &Adm_Type);
1876         if (ret == NULL)
1877                 return NULL;
1878
1879         ret->pool = pool;
1880         ret->adm = result;
1881
1882         return (PyObject *)ret;
1883 }
1884
1885 static PyObject *resolved_conflict(PyObject *self, PyObject *args)
1886 {
1887         AdmObject *admobj = (AdmObject *)self;
1888         apr_pool_t *temp_pool;
1889         svn_boolean_t resolve_props, resolve_tree, resolve_text;
1890         int depth;
1891 #if ONLY_SINCE_SVN(1, 5)
1892         svn_wc_conflict_choice_t conflict_choice;
1893 #else
1894         int conflict_choice;
1895 #endif
1896         PyObject *notify_func = Py_None;
1897         char *path;
1898
1899         if (!PyArg_ParseTuple(args, "sbbbii|O", &path, &resolve_text,
1900                                                   &resolve_props, &resolve_tree, &depth,
1901                                                   &conflict_choice, &notify_func))
1902                 return NULL;
1903
1904         ADM_CHECK_CLOSED(admobj);
1905
1906         temp_pool = Pool(NULL);
1907         if (temp_pool == NULL)
1908                 return NULL;
1909
1910 #if ONLY_SINCE_SVN(1, 6)
1911         RUN_SVN_WITH_POOL(temp_pool,
1912                   svn_wc_resolved_conflict4(path, admobj->adm, resolve_text, 
1913                                                                                 resolve_props, resolve_tree, depth,
1914                                                                                 conflict_choice, py_wc_notify_func,
1915                                                                            (void *)notify_func, py_cancel_check,
1916                                                                            NULL, temp_pool));
1917 #elif ONLY_SINCE_SVN(1, 5)
1918         if (resolve_tree) {
1919                 PyErr_SetString(PyExc_NotImplementedError,
1920                                                 "resolve_tree not supported with svn < 1.6");
1921                 apr_pool_destroy(temp_pool);
1922                 return NULL;
1923         } else {
1924                 RUN_SVN_WITH_POOL(temp_pool,
1925                           svn_wc_resolved_conflict3(path, admobj->adm, resolve_text, 
1926                                                                                         resolve_props, depth,
1927                                                                                         conflict_choice, py_wc_notify_func,
1928                                                                                    (void *)notify_func, py_cancel_check,
1929                                                                                    NULL, temp_pool));
1930         }
1931 #else
1932         if (resolve_tree) {
1933                 PyErr_SetString(PyExc_NotImplementedError,
1934                                                 "resolve_tree not supported with svn < 1.6");
1935                 apr_pool_destroy(temp_pool);
1936                 return NULL;
1937         } else if (depth != svn_depth_infinity && depth != svn_depth_files) {
1938                 PyErr_SetString(PyExc_NotImplementedError,
1939                                                 "only infinity and files values for depth are supported");
1940                 apr_pool_destroy(temp_pool);
1941                 return NULL;
1942         } else if (conflict_choice != 0) {
1943                 PyErr_SetString(PyExc_NotImplementedError,
1944                                                 "conflict choice not supported with svn < 1.5");
1945                 apr_pool_destroy(temp_pool);
1946                 return NULL;
1947         } else {
1948                 RUN_SVN_WITH_POOL(temp_pool,
1949                           svn_wc_resolved_conflict2(path, admobj->adm, resolve_text,
1950                                                                                         resolve_props,
1951                                                                                         (depth == svn_depth_infinity),
1952                                                                                         py_wc_notify_func,
1953                                                                                    (void *)notify_func, py_cancel_check,
1954                                                                                    NULL,
1955                                                                                    temp_pool));
1956         }
1957 #endif
1958
1959         apr_pool_destroy(temp_pool);
1960
1961         Py_RETURN_NONE;
1962 }
1963
1964 static PyObject *conflicted(PyObject *self, PyObject *args)
1965 {
1966         char *path;
1967         apr_pool_t *temp_pool;
1968         PyObject *ret;
1969         AdmObject *admobj = (AdmObject *)self;
1970         svn_boolean_t text_conflicted, prop_conflicted, tree_conflicted;
1971
1972         if (!PyArg_ParseTuple(args, "s", &path))
1973                 return NULL;
1974
1975         ADM_CHECK_CLOSED(admobj);
1976
1977         temp_pool = Pool(NULL);
1978         if (temp_pool == NULL)
1979                 return NULL;
1980
1981 #if ONLY_SINCE_SVN(1, 6)
1982         RUN_SVN_WITH_POOL(temp_pool, svn_wc_conflicted_p2(&text_conflicted,
1983                 &prop_conflicted, &tree_conflicted, path, admobj->adm, temp_pool));
1984
1985         ret = Py_BuildValue("(bbb)", text_conflicted, prop_conflicted, tree_conflicted);
1986 #else
1987         RUN_SVN_WITH_POOL(temp_pool, svn_wc_conflicted_p(&text_conflicted,
1988                 &prop_conflicted, path, admobj->adm, temp_pool));
1989
1990         ret = Py_BuildValue("(bbO)", text_conflicted, prop_conflicted, Py_None);
1991 #endif
1992
1993         apr_pool_destroy(temp_pool);
1994
1995         return ret;
1996 }
1997
1998 /**
1999  * Determine the status of a file in the specified working copy.
2000  *
2001  * :return: A status object.
2002  */
2003 static PyObject *ra_status(PyObject *self, PyObject *args)
2004 {
2005         char *path;
2006         svn_wc_status2_t *st;
2007         apr_pool_t *temp_pool;
2008         PyObject *ret;
2009         AdmObject *admobj = (AdmObject *)self;
2010
2011         if (!PyArg_ParseTuple(args, "s", &path))
2012                 return NULL;
2013
2014         ADM_CHECK_CLOSED(admobj);
2015
2016         temp_pool = Pool(NULL);
2017         if (temp_pool == NULL)
2018                 return NULL;
2019
2020         RUN_SVN_WITH_POOL(temp_pool, 
2021                         svn_wc_status2(
2022                                 &st,
2023                                 svn_path_canonicalize(svn_path_join(svn_wc_adm_access_path(admobj->adm), path, temp_pool), temp_pool),
2024                                 admobj->adm,
2025                                 temp_pool));
2026
2027         ret = py_status(st);
2028
2029         apr_pool_destroy(temp_pool);
2030
2031         return (PyObject*)ret;
2032 }
2033
2034 static PyMethodDef adm_methods[] = { 
2035         { "prop_set", adm_prop_set, METH_VARARGS, "S.prop_set(name, value, path, skip_checks=False)" },
2036         { "access_path", (PyCFunction)adm_access_path, METH_NOARGS, 
2037                 "S.access_path() -> path\n"
2038                 "Returns the base path for this working copy handle." },
2039         { "prop_get", adm_prop_get, METH_VARARGS, "S.prop_get(name, path) -> value" },
2040         { "entries_read", adm_entries_read, METH_VARARGS, "S.entries_read(include_hidden=False) -> dict" },
2041         { "walk_entries", adm_walk_entries, METH_VARARGS, 
2042                 "S.walk_entries(path, callback, show_hidden=False)\n"
2043                 "callback should be a function that takes a path and a wc entry" },
2044         { "locked", (PyCFunction)adm_locked, METH_NOARGS, 
2045                 "S.locked() -> bool" },
2046         { "get_prop_diffs", adm_get_prop_diffs, METH_VARARGS, 
2047                 "S.get_prop_diffs(path) -> (propchanges, originalprops)" },
2048         { "add", (PyCFunction)adm_add, METH_VARARGS|METH_KEYWORDS, "S.add(path, copyfrom_url=None, copyfrom_rev=-1, notify_func=None)" },
2049         { "copy", adm_copy, METH_VARARGS, "S.copy(src_path, dest_path, notify_func=None)" },
2050         { "delete", (PyCFunction)adm_delete, METH_VARARGS|METH_KEYWORDS, "S.delete(path, notify_func=None, keep_local=False)" },
2051         { "crawl_revisions", (PyCFunction)adm_crawl_revisions, METH_VARARGS|METH_KEYWORDS, 
2052                 "S.crawl_revisions(path, reporter, restore_files=True, recurse=True, use_commit_times=True, notify_func=None) -> None" },
2053         { "get_update_editor", adm_get_update_editor, METH_VARARGS, NULL },
2054         { "close", (PyCFunction)adm_close, METH_NOARGS, 
2055                 "S.close()" },
2056         { "entry", (PyCFunction)adm_entry, METH_VARARGS, 
2057                 "s.entry(path, show_hidden=False) -> entry" },
2058         { "process_committed", (PyCFunction)adm_process_committed, METH_VARARGS|METH_KEYWORDS, "S.process_committed(path, recurse, new_revnum, rev_date, rev_author, wcprop_changes=None, remove_lock=False, digest=None)" },
2059         { "process_committed_queue", (PyCFunction)adm_process_committed_queue, METH_VARARGS, "S.process_committed_queue(queue, new_revnum, rev_date, rev_author)" },
2060         { "remove_lock", (PyCFunction)adm_remove_lock, METH_VARARGS, "S.remove_lock(path)" }, 
2061         { "has_binary_prop", (PyCFunction)adm_has_binary_prop, METH_VARARGS, "S.has_binary_prop(path) -> bool" },
2062         { "text_modified", (PyCFunction)adm_text_modified, METH_VARARGS, "S.text_modified(filename, force_comparison=False) -> bool" },
2063         { "props_modified", (PyCFunction)adm_props_modified, METH_VARARGS, "S.props_modified(filename) -> bool" },
2064         { "get_ancestry", (PyCFunction)get_ancestry, METH_VARARGS,
2065                 "S.get_ancestry(path) -> (url, rev)" },
2066         { "maybe_set_repos_root", (PyCFunction)maybe_set_repos_root, METH_VARARGS, "S.maybe_set_repos_root(path, repos)" },
2067         { "add_repos_file", (PyCFunction)add_repos_file, METH_KEYWORDS, 
2068                 "S.add_repos_file(dst_path, new_base_contents, new_contents, new_base_props, new_props, copyfrom_url=None, copyfrom_rev=-1, notify_func=None)" },
2069         { "mark_missing_deleted", (PyCFunction)mark_missing_deleted, METH_VARARGS,
2070                 "S.mark_missing_deleted(path)" },
2071         { "remove_from_revision_control", (PyCFunction)remove_from_revision_control, METH_VARARGS,
2072                 "S.remove_from_revision_control(name, destroy_wf=False, instant_error=False)" },
2073         { "relocate", (PyCFunction)relocate, METH_VARARGS,
2074                 "S.relocate(path, from, to, recurse=TRUE, validator=None)" },
2075         { "crop_tree", (PyCFunction)crop_tree, METH_VARARGS,
2076                 "S.crop_tree(target, depth, notify_func=None, cancel=None)" },
2077         { "translated_stream", (PyCFunction)translated_stream, METH_VARARGS,
2078                 "S.translated_stream(path, versioned_file, flags) -> stream" },
2079         { "is_wc_root", (PyCFunction)is_wc_root, METH_VARARGS,
2080                 "S.is_wc_root(path) -> wc_root" },
2081         { "transmit_text_deltas", (PyCFunction)transmit_text_deltas, METH_VARARGS,
2082                 "S.transmit_text_deltas(fulltext, editor) -> (tempfile, digest)" },
2083         { "transmit_prop_deltas", (PyCFunction)transmit_prop_deltas, METH_VARARGS,
2084                 "S.transmit_prop_deltas(path, entry, editor)" },
2085         { "probe_retrieve", (PyCFunction)probe_retrieve, METH_VARARGS,
2086                 "S.probe_retrieve(path) -> WorkingCopy" },
2087         { "retrieve", (PyCFunction)retrieve, METH_VARARGS,
2088                 "S.retrieve(path) -> WorkingCopy" },
2089         { "probe_try", (PyCFunction)probe_try, METH_VARARGS,
2090                 "S.probe_try(path, write_lock=False, levels_to_lock=-1)" },
2091         { "conflicted", (PyCFunction)conflicted, METH_VARARGS,
2092                 "S.conflicted(path) -> (text_conflicted, prop_conflicted, tree_conflicted)" },
2093         { "resolved_conflict", (PyCFunction)resolved_conflict, METH_VARARGS,
2094                 "S.resolved_conflict(path, resolve_text, resolve_props, resolve_tree, depth, conflict_choice, notify_func=None, cancel=None)" },
2095         { "status", (PyCFunction)ra_status, METH_VARARGS, "status(wc_path) -> Status" },
2096         { NULL, }
2097 };
2098
2099 static PyTypeObject Adm_Type = {
2100         PyObject_HEAD_INIT(NULL) 0,
2101         "wc.WorkingCopy", /*    const char *tp_name;  For printing, in format "<module>.<name>" */
2102         sizeof(AdmObject), 
2103         0,/*    Py_ssize_t tp_basicsize, tp_itemsize;  For allocation */
2104         
2105         /* Methods to implement standard operations */
2106         
2107         adm_dealloc, /* destructor tp_dealloc;  */
2108         NULL, /*        printfunc tp_print;     */
2109         NULL, /*        getattrfunc tp_getattr; */
2110         NULL, /*        setattrfunc tp_setattr; */
2111         NULL, /*        cmpfunc tp_compare;     */
2112         adm_repr, /*    reprfunc tp_repr;       */
2113         
2114         /* Method suites for standard classes */
2115         
2116         NULL, /*        PyNumberMethods *tp_as_number;  */
2117         NULL, /*        PySequenceMethods *tp_as_sequence;      */
2118         NULL, /*        PyMappingMethods *tp_as_mapping;        */
2119         
2120         /* More standard operations (here for binary compatibility) */
2121         
2122         NULL, /*        hashfunc tp_hash;       */
2123         NULL, /*        ternaryfunc tp_call;    */
2124         adm_repr, /*    reprfunc tp_repr;       */
2125         NULL, /*        getattrofunc tp_getattro;       */
2126         NULL, /*        setattrofunc tp_setattro;       */
2127         
2128         /* Functions to access object as input/output buffer */
2129         NULL, /*        PyBufferProcs *tp_as_buffer;    */
2130         
2131         /* Flags to define presence of optional/expanded features */
2132         0, /*   long tp_flags;  */
2133         
2134         "Local working copy", /*        const char *tp_doc;  Documentation string */
2135         
2136         /* Assigned meaning in release 2.0 */
2137         /* call function for all accessible objects */
2138         NULL, /*        traverseproc tp_traverse;       */
2139         
2140         /* delete references to contained objects */
2141         NULL, /*        inquiry tp_clear;       */
2142         
2143         /* Assigned meaning in release 2.1 */
2144         /* rich comparisons */
2145         NULL, /*        richcmpfunc tp_richcompare;     */
2146         
2147         /* weak reference enabler */
2148         0, /*   Py_ssize_t tp_weaklistoffset;   */
2149         
2150         /* Added in release 2.2 */
2151         /* Iterators */
2152         NULL, /*        getiterfunc tp_iter;    */
2153         NULL, /*        iternextfunc tp_iternext;       */
2154         
2155         /* Attribute descriptor and subclassing stuff */
2156         adm_methods, /* struct PyMethodDef *tp_methods; */
2157         NULL, /*        struct PyMemberDef *tp_members; */
2158         NULL, /*        struct PyGetSetDef *tp_getset;  */
2159         NULL, /*        struct _typeobject *tp_base;    */
2160         NULL, /*        PyObject *tp_dict;      */
2161         NULL, /*        descrgetfunc tp_descr_get;      */
2162         NULL, /*        descrsetfunc tp_descr_set;      */
2163         0, /*   Py_ssize_t tp_dictoffset;       */
2164         NULL, /*        initproc tp_init;       */
2165         NULL, /*        allocfunc tp_alloc;     */
2166         adm_init, /*    newfunc tp_new; */
2167 };
2168
2169 static void committed_queue_dealloc(PyObject *self)
2170 {
2171         apr_pool_destroy(((CommittedQueueObject *)self)->pool);
2172         PyObject_Del(self);
2173 }
2174
2175 static PyObject *committed_queue_repr(PyObject *self)
2176 {
2177         CommittedQueueObject *cqobj = (CommittedQueueObject *)self;
2178
2179         return PyString_FromFormat("<wc.CommittedQueue at 0x%p>", cqobj->queue);
2180 }
2181
2182 static PyObject *committed_queue_init(PyTypeObject *self, PyObject *args, PyObject *kwargs)
2183 {
2184         CommittedQueueObject *ret;
2185         char *kwnames[] = { NULL };
2186
2187         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "", kwnames))
2188                 return NULL;
2189
2190         ret = PyObject_New(CommittedQueueObject, &CommittedQueue_Type);
2191         if (ret == NULL)
2192                 return NULL;
2193
2194         ret->pool = Pool(NULL);
2195         if (ret->pool == NULL)
2196                 return NULL;
2197         ret->queue = svn_wc_committed_queue_create(ret->pool);
2198         if (ret->queue == NULL) {
2199                 PyObject_Del(ret);
2200                 PyErr_NoMemory();
2201                 return NULL;
2202         }
2203
2204         return (PyObject *)ret;
2205 }
2206
2207 static PyObject *committed_queue_queue(CommittedQueueObject *self, PyObject *args)
2208 {
2209         char *path;
2210         AdmObject *admobj;
2211         PyObject *py_wcprop_changes = Py_None;
2212         svn_boolean_t remove_lock = FALSE, remove_changelist = FALSE;
2213         char *digest = NULL;
2214         svn_boolean_t recurse = FALSE;
2215         apr_pool_t *temp_pool;
2216         apr_array_header_t *wcprop_changes;
2217         int digest_len;
2218
2219         if (!PyArg_ParseTuple(args, "sO!|bObbz#", &path, &Adm_Type, &admobj,
2220                                                   &recurse, &py_wcprop_changes, &remove_lock,
2221                                                   &remove_changelist, &digest, &digest_len))
2222                 return NULL;
2223
2224         temp_pool = Pool(NULL);
2225         if (temp_pool == NULL)
2226                 return NULL;
2227
2228         if (!py_dict_to_wcprop_changes(py_wcprop_changes, self->pool, &wcprop_changes)) {
2229                 apr_pool_destroy(temp_pool);
2230                 return NULL;
2231         }
2232
2233         path = apr_pstrdup(self->pool, path);
2234         if (path == NULL) {
2235                 PyErr_NoMemory();
2236                 return NULL;
2237         }
2238
2239         if (digest != NULL) {
2240                 if (digest_len != APR_MD5_DIGESTSIZE) {
2241                         PyErr_SetString(PyExc_ValueError, "Invalid size for md5 digest");
2242                         apr_pool_destroy(temp_pool);
2243                         return NULL;
2244                 }
2245                 digest = apr_pstrdup(self->pool, digest);
2246                 if (digest == NULL) {
2247                         PyErr_NoMemory();
2248                         return NULL;
2249                 }
2250         }
2251
2252         RUN_SVN_WITH_POOL(temp_pool, 
2253                 svn_wc_queue_committed(&self->queue, path, admobj->adm, recurse,
2254                                                            wcprop_changes, remove_lock, remove_changelist,
2255                                                            (unsigned char *)digest, temp_pool));
2256
2257         apr_pool_destroy(temp_pool);
2258
2259         Py_RETURN_NONE;
2260 }
2261
2262 static PyMethodDef committed_queue_methods[] = {
2263         { "queue", (PyCFunction)committed_queue_queue, METH_VARARGS,
2264                 "S.queue(path, adm, recurse, wcprop_changes, remove_lock, remove_changelist, digest)" },
2265         { NULL }
2266 };
2267
2268 static PyTypeObject CommittedQueue_Type = {
2269         PyObject_HEAD_INIT(NULL) 0,
2270         "wc.CommittedQueue", /* const char *tp_name;  For printing, in format "<module>.<name>" */
2271         sizeof(CommittedQueueObject), 
2272         0,/*    Py_ssize_t tp_basicsize, tp_itemsize;  For allocation */
2273         
2274         /* Methods to implement standard operations */
2275         
2276         committed_queue_dealloc, /*     destructor tp_dealloc;  */
2277         NULL, /*        printfunc tp_print;     */
2278         NULL, /*        getattrfunc tp_getattr; */
2279         NULL, /*        setattrfunc tp_setattr; */
2280         NULL, /*        cmpfunc tp_compare;     */
2281         committed_queue_repr, /*        reprfunc tp_repr;       */
2282         
2283         /* Method suites for standard classes */
2284         
2285         NULL, /*        PyNumberMethods *tp_as_number;  */
2286         NULL, /*        PySequenceMethods *tp_as_sequence;      */
2287         NULL, /*        PyMappingMethods *tp_as_mapping;        */
2288         
2289         /* More standard operations (here for binary compatibility) */
2290         
2291         NULL, /*        hashfunc tp_hash;       */
2292         NULL, /*        ternaryfunc tp_call;    */
2293         NULL, /*        reprfunc tp_str;        */
2294         NULL, /*        getattrofunc tp_getattro;       */
2295         NULL, /*        setattrofunc tp_setattro;       */
2296         
2297         /* Functions to access object as input/output buffer */
2298         NULL, /*        PyBufferProcs *tp_as_buffer;    */
2299         
2300         /* Flags to define presence of optional/expanded features */
2301         0, /*   long tp_flags;  */
2302         
2303         "Committed queue", /*   const char *tp_doc;  Documentation string */
2304         
2305         /* Assigned meaning in release 2.0 */
2306         /* call function for all accessible objects */
2307         NULL, /*        traverseproc tp_traverse;       */
2308         
2309         /* delete references to contained objects */
2310         NULL, /*        inquiry tp_clear;       */
2311         
2312         /* Assigned meaning in release 2.1 */
2313         /* rich comparisons */
2314         NULL, /*        richcmpfunc tp_richcompare;     */
2315         
2316         /* weak reference enabler */
2317         0, /*   Py_ssize_t tp_weaklistoffset;   */
2318         
2319         /* Added in release 2.2 */
2320         /* Iterators */
2321         NULL, /*        getiterfunc tp_iter;    */
2322         NULL, /*        iternextfunc tp_iternext;       */
2323         
2324         /* Attribute descriptor and subclassing stuff */
2325         committed_queue_methods, /*     struct PyMethodDef *tp_methods; */
2326         NULL, /*        struct PyMemberDef *tp_members; */
2327         NULL, /*        struct PyGetSetDef *tp_getset;  */
2328         NULL, /*        struct _typeobject *tp_base;    */
2329         NULL, /*        PyObject *tp_dict;      */
2330         NULL, /*        descrgetfunc tp_descr_get;      */
2331         NULL, /*        descrsetfunc tp_descr_set;      */
2332         0, /*   Py_ssize_t tp_dictoffset;       */
2333         NULL, /*        initproc tp_init;       */
2334         NULL, /*        allocfunc tp_alloc;     */
2335         committed_queue_init, /*        newfunc tp_new; */
2336 };
2337
2338 /** 
2339  * Determine the revision status of a specified working copy.
2340  *
2341  * :return: Tuple with minimum and maximum revnums found, whether the 
2342  * working copy was switched and whether it was modified.
2343  */
2344 static PyObject *revision_status(PyObject *self, PyObject *args, PyObject *kwargs)
2345 {
2346         char *kwnames[] = { "wc_path", "trail_url", "committed",  NULL };
2347         char *wc_path, *trail_url=NULL;
2348         bool committed=false;
2349         PyObject *ret;
2350          svn_wc_revision_status_t *revstatus;
2351         apr_pool_t *temp_pool;
2352
2353         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zb", kwnames, &wc_path,
2354                                                                          &trail_url, &committed))
2355                 return NULL;
2356
2357         temp_pool = Pool(NULL);
2358         if (temp_pool == NULL)
2359                 return NULL;
2360         RUN_SVN_WITH_POOL(temp_pool, 
2361                         svn_wc_revision_status(
2362                                 &revstatus, 
2363                                 svn_path_canonicalize(wc_path, temp_pool),
2364                                 trail_url,
2365                                  committed, py_cancel_check, NULL, temp_pool));
2366         ret = Py_BuildValue("(llbb)", revstatus->min_rev, revstatus->max_rev, 
2367                         revstatus->switched, revstatus->modified);
2368         apr_pool_destroy(temp_pool);
2369         return ret;
2370 }
2371
2372 static PyObject *is_normal_prop(PyObject *self, PyObject *args)
2373 {
2374         char *name;
2375
2376         if (!PyArg_ParseTuple(args, "s", &name))
2377                 return NULL;
2378
2379         return PyBool_FromLong(svn_wc_is_normal_prop(name));
2380 }
2381
2382 static PyObject *is_adm_dir(PyObject *self, PyObject *args)
2383 {
2384         char *name;
2385         apr_pool_t *pool;
2386         svn_boolean_t ret;
2387
2388         if (!PyArg_ParseTuple(args, "s", &name))
2389                 return NULL;
2390
2391         pool = Pool(NULL);
2392         if (pool == NULL)
2393                 return NULL;
2394
2395         ret = svn_wc_is_adm_dir(name, pool);
2396
2397         apr_pool_destroy(pool);
2398
2399         return PyBool_FromLong(ret);
2400 }
2401
2402 static PyObject *is_wc_prop(PyObject *self, PyObject *args)
2403 {
2404         char *name;
2405
2406         if (!PyArg_ParseTuple(args, "s", &name))
2407                 return NULL;
2408
2409         return PyBool_FromLong(svn_wc_is_wc_prop(name));
2410 }
2411
2412 static PyObject *is_entry_prop(PyObject *self, PyObject *args)
2413 {
2414         char *name;
2415
2416         if (!PyArg_ParseTuple(args, "s", &name))
2417                 return NULL;
2418
2419         return PyBool_FromLong(svn_wc_is_entry_prop(name));
2420 }
2421
2422 static PyObject *get_adm_dir(PyObject *self)
2423 {
2424         apr_pool_t *pool;
2425         PyObject *ret;
2426         const char *dir;
2427         pool = Pool(NULL);
2428         if (pool == NULL)
2429                 return NULL;
2430         dir = svn_wc_get_adm_dir(pool);
2431         ret = PyString_FromString(dir);
2432         apr_pool_destroy(pool);
2433         return ret;
2434 }
2435
2436 static PyObject *set_adm_dir(PyObject *self, PyObject *args)
2437 {
2438         apr_pool_t *temp_pool;
2439         char *name;
2440
2441         if (!PyArg_ParseTuple(args, "s", &name))
2442                 return NULL;
2443
2444         temp_pool = Pool(NULL);
2445         if (temp_pool == NULL)
2446                 return NULL;
2447         RUN_SVN_WITH_POOL(temp_pool, svn_wc_set_adm_dir(name, temp_pool));
2448         apr_pool_destroy(temp_pool);
2449         Py_RETURN_NONE;
2450 }
2451
2452 static PyObject *get_pristine_copy_path(PyObject *self, PyObject *args)
2453 {
2454         apr_pool_t *pool;
2455         const char *pristine_path;
2456         char *path;
2457         PyObject *ret;
2458
2459         if (!PyArg_ParseTuple(args, "s", &path))
2460                 return NULL;
2461
2462         pool = Pool(NULL);
2463         if (pool == NULL)
2464                 return NULL;
2465         PyErr_WarnEx(PyExc_DeprecationWarning, "get_pristine_copy_path is deprecated. Use get_pristine_contents instead.", 2);
2466         RUN_SVN_WITH_POOL(pool,
2467                   svn_wc_get_pristine_copy_path(svn_path_canonicalize(path, pool),
2468                                                                                 &pristine_path, pool));
2469         ret = PyString_FromString(pristine_path);
2470         apr_pool_destroy(pool);
2471         return ret;
2472 }
2473
2474 static PyObject *get_pristine_contents(PyObject *self, PyObject *args)
2475 {
2476         char *path;
2477         apr_pool_t *temp_pool;
2478 #if ONLY_SINCE_SVN(1, 6)
2479         apr_pool_t *stream_pool;
2480         StreamObject *ret;
2481         svn_stream_t *stream;
2482 #else
2483         PyObject *ret;
2484         const char *pristine_path;
2485 #endif
2486
2487         if (!PyArg_ParseTuple(args, "s", &path))
2488                 return NULL;
2489
2490 #if ONLY_SINCE_SVN(1, 6)
2491         stream_pool = Pool(NULL);
2492         if (stream_pool == NULL)
2493                 return NULL;
2494
2495         temp_pool = Pool(stream_pool);
2496         if (temp_pool == NULL) {
2497                 apr_pool_destroy(stream_pool);
2498                 return NULL;
2499         }
2500
2501         RUN_SVN_WITH_POOL(stream_pool, svn_wc_get_pristine_contents(&stream, svn_path_canonicalize(path, temp_pool), stream_pool, temp_pool));
2502         apr_pool_destroy(temp_pool);
2503
2504         if (stream == NULL) {
2505                 apr_pool_destroy(stream_pool);
2506                 Py_RETURN_NONE;
2507         }
2508
2509         ret = PyObject_New(StreamObject, &Stream_Type);
2510         if (ret == NULL)
2511                 return NULL;
2512
2513         ret->pool = stream_pool;
2514         ret->closed = FALSE;
2515         ret->stream = stream;
2516
2517         return (PyObject *)ret;
2518 #else
2519         temp_pool = Pool(NULL);
2520         if (temp_pool == NULL)
2521                 return NULL;
2522         RUN_SVN_WITH_POOL(temp_pool, svn_wc_get_pristine_copy_path(svn_path_canonicalize(path, temp_pool), &pristine_path, temp_pool));
2523         ret = PyFile_FromString((char *)pristine_path, "rb");
2524         apr_pool_destroy(temp_pool);
2525         return ret;
2526 #endif
2527 }
2528
2529 static PyObject *ensure_adm(PyObject *self, PyObject *args, PyObject *kwargs)
2530 {
2531         char *path, *uuid, *url;
2532         char *repos=NULL; 
2533         svn_revnum_t rev=-1;
2534         apr_pool_t *pool;
2535         char *kwnames[] = { "path", "uuid", "url", "repos", "rev", "depth", NULL };
2536         svn_depth_t depth = svn_depth_infinity;
2537
2538         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss|sli", kwnames, 
2539                                                                          &path, &uuid, &url, &repos, &rev, &depth))
2540                 return NULL;
2541
2542         pool = Pool(NULL);
2543         if (pool == NULL)
2544                 return NULL;
2545 #if ONLY_SINCE_SVN(1, 5)
2546         RUN_SVN_WITH_POOL(pool, 
2547                                           svn_wc_ensure_adm3(svn_path_canonicalize(path, pool),
2548                                                                                  uuid, url, repos, rev, depth, pool));
2549 #else
2550         if (depth != svn_depth_infinity) {
2551                 PyErr_SetString(PyExc_NotImplementedError, 
2552                                                 "depth != infinity not supported with svn < 1.5");
2553                 apr_pool_destroy(pool);
2554                 return NULL;
2555         }
2556         RUN_SVN_WITH_POOL(pool, 
2557                                           svn_wc_ensure_adm2(svn_path_canonicalize(path, pool),
2558                                                                                  uuid, url, repos, rev, pool));
2559 #endif
2560         apr_pool_destroy(pool);
2561         Py_RETURN_NONE;
2562 }
2563
2564 static PyObject *check_wc(PyObject *self, PyObject *args)
2565 {
2566         char *path;
2567         apr_pool_t *pool;
2568         int wc_format;
2569
2570         if (!PyArg_ParseTuple(args, "s", &path))
2571                 return NULL;
2572
2573         pool = Pool(NULL);
2574         if (pool == NULL)
2575                 return NULL;
2576         RUN_SVN_WITH_POOL(pool, svn_wc_check_wc(svn_path_canonicalize(path, pool), &wc_format, pool));
2577         apr_pool_destroy(pool);
2578         return PyLong_FromLong(wc_format);
2579 }
2580
2581 static PyObject *cleanup_wc(PyObject *self, PyObject *args, PyObject *kwargs)
2582 {
2583         char *path;
2584         char *diff3_cmd = NULL;
2585         char *kwnames[] = { "path", "diff3_cmd", NULL };
2586         apr_pool_t *temp_pool;
2587
2588         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|z", kwnames, 
2589                                                                          &path, &diff3_cmd)) 
2590                 return NULL;
2591
2592         temp_pool = Pool(NULL);
2593         if (temp_pool == NULL)
2594                 return NULL;
2595         RUN_SVN_WITH_POOL(temp_pool, 
2596                                 svn_wc_cleanup2(path, diff3_cmd, py_cancel_check, NULL,
2597                                                                 temp_pool));
2598         apr_pool_destroy(temp_pool);
2599
2600         Py_RETURN_NONE;
2601 }
2602
2603 static PyObject *match_ignore_list(PyObject *self, PyObject *args)
2604 {
2605 #if ONLY_SINCE_SVN(1, 5)
2606         char *str;
2607         PyObject *py_list;
2608         apr_array_header_t *list;
2609         apr_pool_t *temp_pool;
2610         svn_boolean_t ret;
2611
2612         if (!PyArg_ParseTuple(args, "sO", &str, &py_list))
2613                 return NULL;
2614
2615         temp_pool = Pool(NULL);
2616
2617         if (!string_list_to_apr_array(temp_pool, py_list, &list)) {
2618                 apr_pool_destroy(temp_pool);
2619                 return NULL;
2620         }
2621
2622         ret = svn_wc_match_ignore_list(str, list, temp_pool);
2623
2624         apr_pool_destroy(temp_pool);
2625
2626         return PyBool_FromLong(ret);
2627 #else
2628         PyErr_SetNone(PyExc_NotImplementedError);
2629         return NULL;
2630 #endif
2631 }
2632
2633 static PyMethodDef wc_methods[] = {
2634         { "check_wc", check_wc, METH_VARARGS, "check_wc(path) -> version\n"
2635                 "Check whether path contains a Subversion working copy\n"
2636                 "return the workdir version"},
2637         { "cleanup", (PyCFunction)cleanup_wc, METH_VARARGS|METH_KEYWORDS, "cleanup(path, diff3_cmd=None)\n" },
2638         { "ensure_adm", (PyCFunction)ensure_adm, METH_KEYWORDS|METH_VARARGS, 
2639                 "ensure_adm(path, uuid, url, repos=None, rev=None)" },
2640         { "get_adm_dir", (PyCFunction)get_adm_dir, METH_NOARGS, 
2641                 "get_adm_dir() -> name" },
2642         { "set_adm_dir", (PyCFunction)set_adm_dir, METH_VARARGS,
2643                 "set_adm_dir(name)" },
2644         { "get_pristine_copy_path", get_pristine_copy_path, METH_VARARGS, 
2645                 "get_pristine_copy_path(path) -> path" },
2646         { "get_pristine_contents", get_pristine_contents, METH_VARARGS,
2647                 "get_pristine_contents(path) -> stream" },
2648         { "is_adm_dir", is_adm_dir, METH_VARARGS, 
2649                 "is_adm_dir(name) -> bool" },
2650         { "is_normal_prop", is_normal_prop, METH_VARARGS, 
2651                 "is_normal_prop(name) -> bool" },
2652         { "is_entry_prop", is_entry_prop, METH_VARARGS, 
2653                 "is_entry_prop(name) -> bool" },
2654         { "is_wc_prop", is_wc_prop, METH_VARARGS, 
2655                 "is_wc_prop(name) -> bool" },
2656         { "revision_status", (PyCFunction)revision_status, METH_KEYWORDS|METH_VARARGS, "revision_status(wc_path, trail_url=None, committed=False) -> (min_rev, max_rev, switched, modified)" },
2657         { "version", (PyCFunction)version, METH_NOARGS,
2658                 "version() -> (major, minor, patch, tag)\n\n"
2659                 "Version of libsvn_wc currently used."
2660         },
2661         { "api_version", (PyCFunction)api_version, METH_NOARGS,
2662                 "api_version() -> (major, minor, patch, tag)\n\n"
2663                 "Version of libsvn_wc Subvertpy was compiled against."
2664         },
2665         { "match_ignore_list", (PyCFunction)match_ignore_list, METH_VARARGS,
2666                 "match_ignore_list(str, patterns) -> bool" },
2667         { "get_actual_target", (PyCFunction)get_actual_target, METH_VARARGS,
2668                 "get_actual_target(path) -> (anchor, target)" },
2669         { NULL, }
2670 };
2671
2672 static PyObject *
2673 moduleinit(void)
2674 {
2675         PyObject *mod;
2676
2677         if (PyType_Ready(&Entry_Type) < 0)
2678                 return NULL;
2679
2680         if (PyType_Ready(&Status_Type) < 0)
2681                 return NULL;
2682
2683         if (PyType_Ready(&Adm_Type) < 0)
2684                 return NULL;
2685
2686         if (PyType_Ready(&Editor_Type) < 0)
2687                 return NULL;
2688
2689         if (PyType_Ready(&FileEditor_Type) < 0)
2690                 return NULL;
2691
2692         if (PyType_Ready(&DirectoryEditor_Type) < 0)
2693                 return NULL;
2694
2695         if (PyType_Ready(&TxDeltaWindowHandler_Type) < 0)
2696                 return NULL;
2697
2698         if (PyType_Ready(&Stream_Type) < 0)
2699                 return NULL;
2700
2701         if (PyType_Ready(&CommittedQueue_Type) < 0)
2702                 return NULL;
2703
2704         apr_initialize();
2705
2706 #if PY_MAJOR_VERSION >= 3
2707         static struct PyModuleDef moduledef = {
2708           PyModuleDef_HEAD_INIT,
2709           "wc",         /* m_name */
2710           "Working Copies", /* m_doc */
2711           -1,              /* m_size */
2712           wc_methods, /* m_methods */
2713           NULL,            /* m_reload */
2714           NULL,            /* m_traverse */
2715           NULL,            /* m_clear*/
2716           NULL,            /* m_free */
2717         };
2718         mod = PyModule_Create(&moduledef);
2719 #else
2720         mod = Py_InitModule3("wc", wc_methods, "Working Copies");
2721 #endif
2722         if (mod == NULL)
2723                 return NULL;
2724
2725         PyModule_AddIntConstant(mod, "SCHEDULE_NORMAL", 0);
2726         PyModule_AddIntConstant(mod, "SCHEDULE_ADD", 1);
2727         PyModule_AddIntConstant(mod, "SCHEDULE_DELETE", 2);
2728         PyModule_AddIntConstant(mod, "SCHEDULE_REPLACE", 3);
2729
2730 #if ONLY_SINCE_SVN(1, 5)
2731         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_POSTPONE",
2732                                                         svn_wc_conflict_choose_postpone);
2733         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_BASE",
2734                                                         svn_wc_conflict_choose_base);
2735         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_THEIRS_FULL",
2736                                                         svn_wc_conflict_choose_theirs_full);
2737         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MINE_FULL",
2738                                                         svn_wc_conflict_choose_mine_full);
2739         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_THEIRS_CONFLICT",
2740                                                         svn_wc_conflict_choose_theirs_conflict);
2741         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MINE_CONFLICT",
2742                                                         svn_wc_conflict_choose_mine_conflict);
2743         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MERGED",
2744                                                         svn_wc_conflict_choose_merged);
2745 #endif
2746
2747         PyModule_AddIntConstant(mod, "STATUS_NONE", svn_wc_status_none);
2748         PyModule_AddIntConstant(mod, "STATUS_UNVERSIONED", svn_wc_status_unversioned);
2749         PyModule_AddIntConstant(mod, "STATUS_NORMAL", svn_wc_status_normal);
2750         PyModule_AddIntConstant(mod, "STATUS_ADDED", svn_wc_status_added);
2751         PyModule_AddIntConstant(mod, "STATUS_MISSING", svn_wc_status_missing);
2752         PyModule_AddIntConstant(mod, "STATUS_DELETED", svn_wc_status_deleted);
2753         PyModule_AddIntConstant(mod, "STATUS_REPLACED", svn_wc_status_replaced);
2754         PyModule_AddIntConstant(mod, "STATUS_MODIFIED", svn_wc_status_modified);
2755         PyModule_AddIntConstant(mod, "STATUS_MERGED", svn_wc_status_merged);
2756         PyModule_AddIntConstant(mod, "STATUS_CONFLICTED", svn_wc_status_conflicted);
2757         PyModule_AddIntConstant(mod, "STATUS_IGNORED", svn_wc_status_ignored);
2758         PyModule_AddIntConstant(mod, "STATUS_OBSTRUCTED", svn_wc_status_obstructed);
2759         PyModule_AddIntConstant(mod, "STATUS_EXTERNAL", svn_wc_status_external);
2760         PyModule_AddIntConstant(mod, "STATUS_INCOMPLETE", svn_wc_status_incomplete);
2761
2762         PyModule_AddIntConstant(mod, "TRANSLATE_FROM_NF", SVN_WC_TRANSLATE_FROM_NF);
2763         PyModule_AddIntConstant(mod, "TRANSLATE_TO_NF", SVN_WC_TRANSLATE_TO_NF);
2764         PyModule_AddIntConstant(mod, "TRANSLATE_FORCE_EOL_REPAIR", SVN_WC_TRANSLATE_FORCE_EOL_REPAIR);
2765         PyModule_AddIntConstant(mod, "TRANSLATE_NO_OUTPUT_CLEANUP", SVN_WC_TRANSLATE_NO_OUTPUT_CLEANUP);
2766         PyModule_AddIntConstant(mod, "TRANSLATE_FORCE_COPY", SVN_WC_TRANSLATE_FORCE_COPY);
2767         PyModule_AddIntConstant(mod, "TRANSLATE_USE_GLOBAL_TMP", SVN_WC_TRANSLATE_USE_GLOBAL_TMP);
2768
2769 #if ONLY_SINCE_SVN(1, 5)
2770         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_POSTPONE", svn_wc_conflict_choose_postpone);
2771         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_BASE", svn_wc_conflict_choose_base);
2772         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_THEIRS_FULL", svn_wc_conflict_choose_theirs_full);
2773         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MINE_FULL", svn_wc_conflict_choose_mine_full);
2774         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_THEIRS_CONFLICT", svn_wc_conflict_choose_theirs_conflict);
2775         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MINE_CONFLICT", svn_wc_conflict_choose_mine_conflict);
2776         PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MERGED", svn_wc_conflict_choose_merged);
2777 #endif
2778
2779 #if ONLY_BEFORE_SVN(1, 7)
2780         /* Subversion 1.7 has a couple of significant behaviour changes that break subvertpy.
2781          * We haven't updated the code to deal with these changes in behaviour yet.
2782          * */
2783         PyModule_AddObject(mod, "WorkingCopy", (PyObject *)&Adm_Type);
2784         Py_INCREF(&Adm_Type);
2785
2786         PyModule_AddObject(mod, "CommittedQueue", (PyObject *)&CommittedQueue_Type);
2787         Py_INCREF(&CommittedQueue_Type);
2788 #endif
2789
2790         return mod;
2791 }
2792
2793 #if PY_MAJOR_VERSION >= 3
2794 PyMODINIT_FUNC
2795 PyInit_wc(void)
2796 {
2797         return moduleinit();
2798 }
2799 #else
2800 PyMODINIT_FUNC
2801 initwc(void)
2802 {
2803         moduleinit();
2804 }
2805 #endif