2 * Copyright © 2008 Jelmer Vernooij <jelmer@samba.org>
3 * -*- coding: utf-8 -*-
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <apr_general.h>
23 #include <svn_props.h>
24 #include <structmember.h>
31 #if ONLY_SINCE_SVN(1, 5)
32 #define REPORTER_T svn_ra_reporter3_t
34 #define REPORTER_T svn_ra_reporter2_t
37 staticforward PyTypeObject Entry_Type;
38 staticforward PyTypeObject Adm_Type;
40 static PyObject *py_entry(const svn_wc_entry_t *entry);
42 #if ONLY_BEFORE_SVN(1, 5)
43 struct svn_wc_committed_queue_t
46 apr_array_header_t *queue;
47 svn_boolean_t have_recursive;
51 typedef struct svn_wc_committed_queue_t svn_wc_committed_queue_t;
57 svn_wc_adm_access_t *adm_access;
58 svn_boolean_t recurse;
59 svn_boolean_t remove_lock;
60 apr_array_header_t *wcprop_changes;
61 unsigned char *digest;
62 } committed_queue_item_t;
67 svn_wc_committed_queue_t *svn_wc_committed_queue_create(apr_pool_t *pool)
69 svn_wc_committed_queue_t *q;
71 q = apr_palloc(pool, sizeof(*q));
73 q->queue = apr_array_make(pool, 1, sizeof(committed_queue_item_t *));
74 q->have_recursive = FALSE;
82 svn_error_t *svn_wc_queue_committed(svn_wc_committed_queue_t **queue,
84 svn_wc_adm_access_t *adm_access,
85 svn_boolean_t recurse,
86 apr_array_header_t *wcprop_changes,
87 svn_boolean_t remove_lock,
88 svn_boolean_t remove_changelist,
89 const unsigned char *digest,
90 apr_pool_t *scratch_pool)
92 committed_queue_item_t *cqi;
94 (*queue)->have_recursive |= recurse;
96 /* Use the same pool as the one QUEUE was allocated in,
97 to prevent lifetime issues. Intermediate operations
98 should use SCRATCH_POOL. */
100 /* Add to the array with paths and options */
101 cqi = apr_palloc((*queue)->pool, sizeof(*cqi));
103 cqi->adm_access = adm_access;
104 cqi->recurse = recurse;
105 cqi->remove_lock = remove_lock;
106 cqi->wcprop_changes = wcprop_changes;
107 cqi->digest = digest;
109 APR_ARRAY_PUSH((*queue)->queue, committed_queue_item_t *) = cqi;
119 svn_wc_committed_queue_t *queue;
120 } CommittedQueueObject;
121 staticforward PyTypeObject CommittedQueue_Type;
123 #if ONLY_SINCE_SVN(1, 5)
124 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)
126 PyObject *self = (PyObject *)baton, *py_lock_token, *ret;
127 PyGILState_STATE state = PyGILState_Ensure();
128 if (lock_token == NULL) {
129 py_lock_token = Py_None;
130 Py_INCREF(py_lock_token);
132 py_lock_token = PyString_FromString(lock_token);
134 ret = PyObject_CallMethod(self, "set_path", "slbOi", path, revision, start_empty, py_lock_token, depth);
135 Py_DECREF(py_lock_token);
136 CB_CHECK_PYRETVAL(ret);
138 PyGILState_Release(state);
142 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)
144 PyObject *self = (PyObject *)report_baton, *ret, *py_lock_token;
145 PyGILState_STATE state = PyGILState_Ensure();
146 if (lock_token == NULL) {
147 py_lock_token = Py_None;
148 Py_INCREF(py_lock_token);
150 py_lock_token = PyString_FromString(lock_token);
152 ret = PyObject_CallMethod(self, "link_path", "sslbOi", path, url, revision, start_empty, py_lock_token, depth);
153 Py_DECREF(py_lock_token);
154 CB_CHECK_PYRETVAL(ret);
156 PyGILState_Release(state);
162 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)
164 PyObject *self = (PyObject *)baton, *py_lock_token, *ret;
165 PyGILState_STATE state = PyGILState_Ensure();
166 if (lock_token == NULL) {
167 py_lock_token = Py_None;
168 Py_INCREF(py_lock_token);
170 py_lock_token = PyString_FromString(lock_token);
172 ret = PyObject_CallMethod(self, "set_path", "slbOi", path, revision, start_empty, py_lock_token, svn_depth_infinity);
173 CB_CHECK_PYRETVAL(ret);
175 PyGILState_Release(state);
179 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)
181 PyObject *self = (PyObject *)report_baton, *ret, *py_lock_token;
182 PyGILState_STATE state = PyGILState_Ensure();
183 if (lock_token == NULL) {
184 py_lock_token = Py_None;
185 Py_INCREF(py_lock_token);
187 py_lock_token = PyString_FromString(lock_token);
189 ret = PyObject_CallMethod(self, "link_path", "sslbOi", path, url, revision, start_empty, py_lock_token, svn_depth_infinity);
190 CB_CHECK_PYRETVAL(ret);
192 PyGILState_Release(state);
199 static svn_error_t *py_ra_report_delete_path(void *baton, const char *path, apr_pool_t *pool)
201 PyObject *self = (PyObject *)baton, *ret;
202 PyGILState_STATE state = PyGILState_Ensure();
203 ret = PyObject_CallMethod(self, "delete_path", "s", path);
204 CB_CHECK_PYRETVAL(ret);
206 PyGILState_Release(state);
210 static svn_error_t *py_ra_report_finish(void *baton, apr_pool_t *pool)
212 PyObject *self = (PyObject *)baton, *ret;
213 PyGILState_STATE state = PyGILState_Ensure();
214 ret = PyObject_CallMethod(self, "finish", "");
215 CB_CHECK_PYRETVAL(ret);
217 PyGILState_Release(state);
221 static svn_error_t *py_ra_report_abort(void *baton, apr_pool_t *pool)
223 PyObject *self = (PyObject *)baton, *ret;
224 PyGILState_STATE state = PyGILState_Ensure();
225 ret = PyObject_CallMethod(self, "abort", "");
226 CB_CHECK_PYRETVAL(ret);
228 PyGILState_Release(state);
232 static const REPORTER_T py_ra_reporter = {
233 py_ra_report_set_path,
234 py_ra_report_delete_path,
235 py_ra_report_link_path,
243 * Get runtime libsvn_wc version information.
245 * :return: tuple with major, minor, patch version number and tag.
247 static PyObject *version(PyObject *self)
249 const svn_version_t *ver = svn_wc_version();
250 return Py_BuildValue("(iiis)", ver->major, ver->minor,
251 ver->patch, ver->tag);
254 SVN_VERSION_DEFINE(svn_api_version);
257 * Get compile-time libsvn_wc version information.
259 * :return: tuple with major, minor, patch version number and tag.
261 static PyObject *api_version(PyObject *self)
263 const svn_version_t *ver = &svn_api_version;
264 return Py_BuildValue("(iiis)", ver->major, ver->minor,
265 ver->patch, ver->tag);
268 static svn_error_t *py_wc_found_entry(const char *path, const svn_wc_entry_t *entry, void *walk_baton, apr_pool_t *pool)
271 PyObject *callbacks = (PyObject *)walk_baton;
272 PyGILState_STATE state = PyGILState_Ensure();
273 if (PyTuple_Check(callbacks)) {
274 fn = PyTuple_GET_ITEM(callbacks, 0);
276 fn = (PyObject *)walk_baton;
278 ret = PyObject_CallFunction(fn, "sO", path, py_entry(entry));
279 CB_CHECK_PYRETVAL(ret);
281 PyGILState_Release(state);
285 #if ONLY_SINCE_SVN(1, 5)
287 svn_error_t *py_wc_handle_error(const char *path, svn_error_t *err, void *walk_baton, apr_pool_t *pool)
291 PyGILState_STATE state;
292 PyObject *callbacks = (PyObject *)walk_baton;
293 if (PyTuple_Check(callbacks)) {
294 fn = PyTuple_GET_ITEM(callbacks, 1);
298 state = PyGILState_Ensure();
299 py_err = PyErr_NewSubversionException(err);
300 ret = PyObject_CallFunction(fn, "sO", path, py_err);
301 CB_CHECK_PYRETVAL(ret);
303 PyGILState_Release(state);
308 static svn_wc_entry_callbacks2_t py_wc_entry_callbacks2 = {
313 static svn_wc_entry_callbacks_t py_wc_entry_callbacks = {
320 void py_wc_notify_func(void *baton, const svn_wc_notify_t *notify, apr_pool_t *pool)
322 PyObject *func = baton, *ret;
326 if (notify->err != NULL) {
327 PyObject *excval = PyErr_NewSubversionException(notify->err);
328 ret = PyObject_CallFunction(func, "O", excval);
331 /* FIXME: Use return value */
338 svn_wc_entry_t entry;
341 static void entry_dealloc(PyObject *self)
343 apr_pool_destroy(((EntryObject *)self)->pool);
347 static PyMemberDef entry_members[] = {
348 { "name", T_STRING, offsetof(EntryObject, entry.name), READONLY,
350 { "copyfrom_url", T_STRING, offsetof(EntryObject, entry.copyfrom_url), READONLY,
351 "Copyfrom location" },
352 { "copyfrom_rev", T_LONG, offsetof(EntryObject, entry.copyfrom_rev), READONLY,
353 "Copyfrom revision" },
354 { "uuid", T_STRING, offsetof(EntryObject, entry.uuid), READONLY,
355 "UUID of repository" },
356 { "url", T_STRING, offsetof(EntryObject, entry.url), READONLY,
357 "URL in repository" },
358 { "repos", T_STRING, offsetof(EntryObject, entry.repos), READONLY,
359 "Canonical repository URL" },
360 { "schedule", T_INT, offsetof(EntryObject, entry.schedule), READONLY,
361 "Scheduling (add, replace, delete, etc)" },
362 { "kind", T_INT, offsetof(EntryObject, entry.kind), READONLY,
363 "Kind of file (file, dir, etc)" },
364 { "revision", T_LONG, offsetof(EntryObject, entry.revision), READONLY,
366 { "cmt_rev", T_LONG, offsetof(EntryObject, entry.cmt_rev), READONLY,
367 "Last revision this was changed" },
368 { "checksum", T_STRING, offsetof(EntryObject, entry.checksum), READONLY,
369 "Hex MD5 checksum for the untranslated text base file" },
370 { "cmt_date", T_LONG, offsetof(EntryObject, entry.cmt_date), READONLY,
371 "Last date this was changed" },
372 { "cmt_author", T_STRING, offsetof(EntryObject, entry.cmt_author), READONLY,
373 "Last commit author of this item" },
377 static PyTypeObject Entry_Type = {
378 PyObject_HEAD_INIT(NULL) 0,
379 "wc.Entry", /* const char *tp_name; For printing, in format "<module>.<name>" */
381 0,/* Py_ssize_t tp_basicsize, tp_itemsize; For allocation */
383 /* Methods to implement standard operations */
385 entry_dealloc, /* destructor tp_dealloc; */
386 NULL, /* printfunc tp_print; */
387 NULL, /* getattrfunc tp_getattr; */
388 NULL, /* setattrfunc tp_setattr; */
389 NULL, /* cmpfunc tp_compare; */
390 NULL, /* reprfunc tp_repr; */
392 /* Method suites for standard classes */
394 NULL, /* PyNumberMethods *tp_as_number; */
395 NULL, /* PySequenceMethods *tp_as_sequence; */
396 NULL, /* PyMappingMethods *tp_as_mapping; */
398 /* More standard operations (here for binary compatibility) */
400 NULL, /* hashfunc tp_hash; */
401 NULL, /* ternaryfunc tp_call; */
402 NULL, /* reprfunc tp_str; */
403 NULL, /* getattrofunc tp_getattro; */
404 NULL, /* setattrofunc tp_setattro; */
406 /* Functions to access object as input/output buffer */
407 NULL, /* PyBufferProcs *tp_as_buffer; */
409 /* Flags to define presence of optional/expanded features */
410 0, /* long tp_flags; */
412 NULL, /* const char *tp_doc; Documentation string */
414 /* Assigned meaning in release 2.0 */
415 /* call function for all accessible objects */
416 NULL, /* traverseproc tp_traverse; */
418 /* delete references to contained objects */
419 NULL, /* inquiry tp_clear; */
421 /* Assigned meaning in release 2.1 */
422 /* rich comparisons */
423 NULL, /* richcmpfunc tp_richcompare; */
425 /* weak reference enabler */
426 0, /* Py_ssize_t tp_weaklistoffset; */
428 /* Added in release 2.2 */
430 NULL, /* getiterfunc tp_iter; */
431 NULL, /* iternextfunc tp_iternext; */
433 /* Attribute descriptor and subclassing stuff */
434 NULL, /* struct PyMethodDef *tp_methods; */
435 entry_members, /* struct PyMemberDef *tp_members; */
439 static PyObject *py_entry(const svn_wc_entry_t *entry)
443 ret = PyObject_New(EntryObject, &Entry_Type);
447 ret->pool = Pool(NULL);
448 if (ret->pool == NULL)
450 ret->entry = *svn_wc_entry_dup(entry, ret->pool);
451 return (PyObject *)ret;
456 svn_wc_adm_access_t *adm;
460 #define ADM_CHECK_CLOSED(adm_obj) \
461 if (adm_obj->adm == NULL) { \
462 PyErr_SetString(PyExc_RuntimeError, "WorkingCopy instance already closed"); \
466 static PyObject *adm_init(PyTypeObject *self, PyObject *args, PyObject *kwargs)
468 PyObject *associated;
470 bool write_lock=false;
472 PyObject *cancel_func=Py_None;
473 svn_wc_adm_access_t *parent_wc;
476 char *kwnames[] = { "associated", "path", "write_lock", "depth", "cancel_func", NULL };
478 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|biO", kwnames, &associated, &path, &write_lock, &depth, &cancel_func))
481 ret = PyObject_New(AdmObject, &Adm_Type);
485 ret->pool = Pool(NULL);
486 if (ret->pool == NULL)
488 if (associated == Py_None) {
491 parent_wc = ((AdmObject *)associated)->adm;
493 Py_BEGIN_ALLOW_THREADS
494 err = svn_wc_adm_open3(&ret->adm, parent_wc,
495 svn_path_canonicalize(path, ret->pool),
496 write_lock, depth, py_cancel_func, cancel_func,
500 if (!check_error(err)) {
504 return (PyObject *)ret;
507 static PyObject *adm_access_path(PyObject *self)
509 AdmObject *admobj = (AdmObject *)self;
510 ADM_CHECK_CLOSED(admobj);
511 return PyString_FromString(svn_wc_adm_access_path(admobj->adm));
514 static PyObject *adm_locked(PyObject *self)
516 AdmObject *admobj = (AdmObject *)self;
517 ADM_CHECK_CLOSED(admobj);
518 return PyBool_FromLong(svn_wc_adm_locked(admobj->adm));
521 static PyObject *adm_prop_get(PyObject *self, PyObject *args)
524 AdmObject *admobj = (AdmObject *)self;
525 const svn_string_t *value;
526 apr_pool_t *temp_pool;
529 if (!PyArg_ParseTuple(args, "ss", &name, &path))
532 ADM_CHECK_CLOSED(admobj);
534 temp_pool = Pool(NULL);
535 if (temp_pool == NULL)
537 RUN_SVN_WITH_POOL(temp_pool, svn_wc_prop_get(&value, name, path, admobj->adm, temp_pool));
538 if (value == NULL || value->data == NULL) {
542 ret = PyString_FromStringAndSize(value->data, value->len);
544 apr_pool_destroy(temp_pool);
548 static PyObject *adm_prop_set(PyObject *self, PyObject *args)
550 char *name, *value, *path;
551 AdmObject *admobj = (AdmObject *)self;
552 bool skip_checks=false;
553 apr_pool_t *temp_pool;
555 svn_string_t *cvalue;
556 PyObject *notify_func = Py_None;
558 if (!PyArg_ParseTuple(args, "ss#s|bO", &name, &value, &vallen, &path, &skip_checks,
562 ADM_CHECK_CLOSED(admobj);
564 temp_pool = Pool(NULL);
565 if (temp_pool == NULL)
567 cvalue = svn_string_ncreate(value, vallen, temp_pool);
568 #if ONLY_SINCE_SVN(1, 6)
569 RUN_SVN_WITH_POOL(temp_pool, svn_wc_prop_set3(name, cvalue, path, admobj->adm,
570 skip_checks, py_wc_notify_func, (void *)notify_func,
573 RUN_SVN_WITH_POOL(temp_pool, svn_wc_prop_set2(name, cvalue, path, admobj->adm,
574 skip_checks, temp_pool));
576 apr_pool_destroy(temp_pool);
581 static PyObject *adm_entries_read(PyObject *self, PyObject *args)
584 AdmObject *admobj = (AdmObject *)self;
585 apr_pool_t *temp_pool;
586 bool show_hidden=false;
587 apr_hash_index_t *idx;
590 svn_wc_entry_t *entry;
591 PyObject *py_entries, *obj;
593 if (!PyArg_ParseTuple(args, "|b", &show_hidden))
596 ADM_CHECK_CLOSED(admobj);
598 temp_pool = Pool(NULL);
599 if (temp_pool == NULL)
601 RUN_SVN_WITH_POOL(temp_pool, svn_wc_entries_read(&entries, admobj->adm,
602 show_hidden, temp_pool));
603 py_entries = PyDict_New();
604 if (py_entries == NULL) {
605 apr_pool_destroy(temp_pool);
608 idx = apr_hash_first(temp_pool, entries);
609 while (idx != NULL) {
610 apr_hash_this(idx, (const void **)&key, &klen, (void **)&entry);
615 obj = py_entry(entry);
617 PyDict_SetItemString(py_entries, key, obj);
619 idx = apr_hash_next(idx);
621 apr_pool_destroy(temp_pool);
625 static PyObject *adm_walk_entries(PyObject *self, PyObject *args)
629 bool show_hidden=false;
630 PyObject *cancel_func=Py_None;
631 apr_pool_t *temp_pool;
632 AdmObject *admobj = (AdmObject *)self;
633 svn_depth_t depth = svn_depth_infinity;
635 if (!PyArg_ParseTuple(args, "sO|bOi", &path, &callbacks, &show_hidden, &cancel_func,
639 ADM_CHECK_CLOSED(admobj);
641 temp_pool = Pool(NULL);
642 if (temp_pool == NULL)
644 #if ONLY_SINCE_SVN(1, 5)
645 RUN_SVN_WITH_POOL(temp_pool, svn_wc_walk_entries3(path, admobj->adm,
646 &py_wc_entry_callbacks2, (void *)callbacks,
647 depth, show_hidden, py_cancel_func, (void *)cancel_func,
650 if (depth != svn_depth_infinity) {
651 PyErr_SetString(PyExc_NotImplementedError,
652 "depth != infinity not supported for svn < 1.5");
653 apr_pool_destroy(temp_pool);
656 RUN_SVN_WITH_POOL(temp_pool, svn_wc_walk_entries2(path, admobj->adm,
657 &py_wc_entry_callbacks, (void *)callbacks,
658 show_hidden, py_cancel_func, (void *)cancel_func,
661 apr_pool_destroy(temp_pool);
666 static PyObject *adm_entry(PyObject *self, PyObject *args)
669 bool show_hidden=false;
670 apr_pool_t *temp_pool;
671 AdmObject *admobj = (AdmObject *)self;
672 const svn_wc_entry_t *entry;
675 if (!PyArg_ParseTuple(args, "s|b", &path, &show_hidden))
678 ADM_CHECK_CLOSED(admobj);
680 temp_pool = Pool(NULL);
681 if (temp_pool == NULL)
683 RUN_SVN_WITH_POOL(temp_pool, svn_wc_entry(&entry, svn_path_canonicalize(path, temp_pool), admobj->adm, show_hidden, temp_pool));
686 PyErr_Format(PyExc_KeyError, "No such entry '%s'", path);
689 ret = py_entry(entry);
692 apr_pool_destroy(temp_pool);
696 static PyObject *adm_get_prop_diffs(PyObject *self, PyObject *args)
699 apr_pool_t *temp_pool;
700 apr_array_header_t *propchanges;
701 apr_hash_t *original_props;
702 AdmObject *admobj = (AdmObject *)self;
705 PyObject *py_propchanges, *py_orig_props, *pyval;
707 if (!PyArg_ParseTuple(args, "s", &path))
710 ADM_CHECK_CLOSED(admobj);
712 temp_pool = Pool(NULL);
713 if (temp_pool == NULL)
715 RUN_SVN_WITH_POOL(temp_pool, svn_wc_get_prop_diffs(&propchanges, &original_props,
716 svn_path_canonicalize(path, temp_pool), admobj->adm, temp_pool));
717 py_propchanges = PyList_New(propchanges->nelts);
718 if (py_propchanges == NULL) {
719 apr_pool_destroy(temp_pool);
722 for (i = 0; i < propchanges->nelts; i++) {
723 el = APR_ARRAY_IDX(propchanges, i, svn_prop_t);
724 if (el.value != NULL)
725 pyval = Py_BuildValue("(sz#)", el.name, el.value->data, el.value->len);
727 pyval = Py_BuildValue("(sO)", el.name, Py_None);
729 apr_pool_destroy(temp_pool);
732 PyList_SetItem(py_propchanges, i, pyval);
734 py_orig_props = prop_hash_to_dict(original_props);
735 apr_pool_destroy(temp_pool);
736 if (py_orig_props == NULL)
738 return Py_BuildValue("(NN)", py_propchanges, py_orig_props);
741 static PyObject *adm_add(PyObject *self, PyObject *args, PyObject *kwargs)
743 char *path, *copyfrom_url=NULL;
744 svn_revnum_t copyfrom_rev=-1;
745 char *kwnames[] = { "path", "copyfrom_url", "copyfrom_rev", "cancel_func",
746 "notify_func", "depth", NULL };
747 PyObject *cancel_func=Py_None, *notify_func=Py_None;
748 AdmObject *admobj = (AdmObject *)self;
749 apr_pool_t *temp_pool;
750 svn_depth_t depth = svn_depth_infinity;
752 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zlOOi", kwnames, &path, ©from_url, ©from_rev, &cancel_func, ¬ify_func, &depth))
755 ADM_CHECK_CLOSED(admobj);
757 temp_pool = Pool(NULL);
758 if (temp_pool == NULL)
761 #if ONLY_SINCE_SVN(1, 6)
762 RUN_SVN_WITH_POOL(temp_pool, svn_wc_add3(
763 svn_path_canonicalize(path, temp_pool), admobj->adm, depth, copyfrom_url,
764 copyfrom_rev, py_cancel_func,
770 if (depth != svn_depth_infinity) {
771 PyErr_SetString(PyExc_NotImplementedError, "depth != infinity not supported on svn < 1.6");
772 apr_pool_destroy(temp_pool);
775 RUN_SVN_WITH_POOL(temp_pool, svn_wc_add2(
776 svn_path_canonicalize(path, temp_pool), admobj->adm, copyfrom_url,
777 copyfrom_rev, py_cancel_func,
783 apr_pool_destroy(temp_pool);
788 static PyObject *adm_copy(PyObject *self, PyObject *args)
790 AdmObject *admobj = (AdmObject *)self;
792 PyObject *cancel_func=Py_None, *notify_func=Py_None;
793 apr_pool_t *temp_pool;
795 if (!PyArg_ParseTuple(args, "ss|OO", &src, &dst, &cancel_func, ¬ify_func))
798 ADM_CHECK_CLOSED(admobj);
800 temp_pool = Pool(NULL);
801 if (temp_pool == NULL)
803 RUN_SVN_WITH_POOL(temp_pool, svn_wc_copy2(src, admobj->adm, dst,
804 py_cancel_func, (void *)cancel_func,
805 py_wc_notify_func, (void *)notify_func,
807 apr_pool_destroy(temp_pool);
812 static PyObject *adm_delete(PyObject *self, PyObject *args, PyObject *kwargs)
814 AdmObject *admobj = (AdmObject *)self;
815 apr_pool_t *temp_pool;
816 char *kwnames[] = { "path", "cancel_func", "notify_func", "keep_local",
819 PyObject *cancel_func=Py_None, *notify_func=Py_None;
820 bool keep_local = false;
822 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOb", kwnames,
823 &path, &cancel_func, ¬ify_func,
827 ADM_CHECK_CLOSED(admobj);
829 temp_pool = Pool(NULL);
830 if (temp_pool == NULL)
833 #if ONLY_SINCE_SVN(1, 5)
834 RUN_SVN_WITH_POOL(temp_pool, svn_wc_delete3(path, admobj->adm,
835 py_cancel_func, (void *)cancel_func,
836 py_wc_notify_func, (void *)notify_func,
841 PyErr_SetString(PyExc_NotImplementedError,
842 "keep_local not supported on Subversion < 1.5");
846 RUN_SVN_WITH_POOL(temp_pool, svn_wc_delete2(path, admobj->adm,
847 py_cancel_func, (void *)cancel_func,
848 py_wc_notify_func, (void *)notify_func,
851 apr_pool_destroy(temp_pool);
856 static PyObject *adm_crawl_revisions(PyObject *self, PyObject *args, PyObject *kwargs)
860 bool restore_files=true, recurse=true, use_commit_times=true;
861 PyObject *notify_func=Py_None;
862 apr_pool_t *temp_pool;
863 AdmObject *admobj = (AdmObject *)self;
864 svn_wc_traversal_info_t *traversal_info;
865 svn_boolean_t depth_compatibility_trick = FALSE;
866 svn_boolean_t honor_depth_exclude = FALSE;
867 char *kwnames[] = { "path", "reporter", "restore_files", "recurse", "use_commit_times", "notify_func", "depth_compatibility_trick", "honor_depth_exclude,", NULL };
869 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|bbbObb", kwnames, &path, &reporter, &restore_files, &recurse, &use_commit_times,
870 ¬ify_func, &depth_compatibility_trick, &honor_depth_exclude))
873 ADM_CHECK_CLOSED(admobj);
875 temp_pool = Pool(NULL);
876 if (temp_pool == NULL)
878 traversal_info = svn_wc_init_traversal_info(temp_pool);
879 #if ONLY_SINCE_SVN(1, 6)
880 RUN_SVN_WITH_POOL(temp_pool, svn_wc_crawl_revisions4(path, admobj->adm,
881 &py_ra_reporter, (void *)reporter,
882 restore_files, recurse?svn_depth_infinity:svn_depth_files,
884 depth_compatibility_trick, use_commit_times,
885 py_wc_notify_func, (void *)notify_func,
886 traversal_info, temp_pool));
887 #elif ONLY_SINCE_SVN(1, 5)
888 RUN_SVN_WITH_POOL(temp_pool, svn_wc_crawl_revisions3(path, admobj->adm,
889 &py_ra_reporter, (void *)reporter,
890 restore_files, recurse?svn_depth_infinity:svn_depth_files,
891 depth_compatibility_trick, use_commit_times,
892 py_wc_notify_func, (void *)notify_func,
893 traversal_info, temp_pool));
895 RUN_SVN_WITH_POOL(temp_pool, svn_wc_crawl_revisions2(path, admobj->adm,
896 &py_ra_reporter, (void *)reporter,
897 restore_files, recurse, use_commit_times,
898 py_wc_notify_func, (void *)notify_func,
899 traversal_info, temp_pool));
901 apr_pool_destroy(temp_pool);
906 static PyObject *adm_get_update_editor(PyObject *self, PyObject *args)
909 bool use_commit_times=true, recurse=true;
910 PyObject * notify_func=Py_None, *cancel_func=Py_None;
911 char *diff3_cmd=NULL;
912 const svn_delta_editor_t *editor;
913 AdmObject *admobj = (AdmObject *)self;
916 svn_revnum_t *latest_revnum;
918 svn_boolean_t allow_unver_obstructions = FALSE;
919 svn_boolean_t depth_is_sticky = FALSE;
921 if (!PyArg_ParseTuple(args, "s|bbOOzbb", &target, &use_commit_times, &recurse, ¬ify_func, &cancel_func, &diff3_cmd,
922 &depth_is_sticky, &allow_unver_obstructions))
925 ADM_CHECK_CLOSED(admobj);
930 latest_revnum = (svn_revnum_t *)apr_palloc(pool, sizeof(svn_revnum_t));
931 Py_BEGIN_ALLOW_THREADS
932 #if ONLY_SINCE_SVN(1, 5)
933 /* FIXME: Support all values of depth */
934 /* FIXME: Support fetch_func */
935 /* FIXME: Support conflict func */
936 err = svn_wc_get_update_editor3(latest_revnum, admobj->adm, target,
937 use_commit_times, recurse?svn_depth_infinity:svn_depth_files, depth_is_sticky, allow_unver_obstructions,
938 py_wc_notify_func, (void *)notify_func,
939 py_cancel_func, (void *)cancel_func,
940 NULL, NULL, NULL, NULL,
941 diff3_cmd, NULL, &editor, &edit_baton,
944 if (allow_unver_obstructions) {
945 PyErr_SetString(PyExc_NotImplementedError,
946 "allow_unver_obstructions is not supported in svn < 1.5");
947 apr_pool_destroy(pool);
948 PyEval_RestoreThread(_save);
951 if (depth_is_sticky) {
952 PyErr_SetString(PyExc_NotImplementedError,
953 "depth_is_sticky is not supported in svn < 1.5");
954 apr_pool_destroy(pool);
955 PyEval_RestoreThread(_save);
958 err = svn_wc_get_update_editor2(latest_revnum, admobj->adm, target,
959 use_commit_times, recurse, py_wc_notify_func, (void *)notify_func,
960 py_cancel_func, (void *)cancel_func, diff3_cmd, &editor, &edit_baton,
963 if (!check_error(err)) {
964 apr_pool_destroy(pool);
965 PyEval_RestoreThread(_save);
969 return new_editor_object(editor, edit_baton, pool, &Editor_Type, NULL, NULL, NULL);
972 static bool py_dict_to_wcprop_changes(PyObject *dict, apr_pool_t *pool, apr_array_header_t **ret)
977 if (dict == Py_None) {
982 if (!PyDict_Check(dict)) {
983 PyErr_SetString(PyExc_TypeError, "Expected dictionary with property changes");
987 *ret = apr_array_make(pool, PyDict_Size(dict), sizeof(char *));
989 while (PyDict_Next(dict, &idx, &key, &val)) {
990 svn_prop_t *prop = apr_palloc(pool, sizeof(svn_prop_t));
991 prop->name = PyString_AsString(key);
992 if (val == Py_None) {
995 prop->value = svn_string_ncreate(PyString_AsString(val), PyString_Size(val), pool);
997 APR_ARRAY_PUSH(*ret, svn_prop_t *) = prop;
1003 static PyObject *adm_has_binary_prop(PyObject *self, PyObject *args)
1006 svn_boolean_t binary;
1007 AdmObject *admobj = (AdmObject *)self;
1008 apr_pool_t *temp_pool;
1010 if (!PyArg_ParseTuple(args, "s", &path))
1013 ADM_CHECK_CLOSED(admobj);
1015 temp_pool = Pool(NULL);
1016 if (temp_pool == NULL)
1019 RUN_SVN_WITH_POOL(temp_pool, svn_wc_has_binary_prop(&binary, path, admobj->adm, temp_pool));
1021 apr_pool_destroy(temp_pool);
1023 return PyBool_FromLong(binary);
1026 static PyObject *adm_process_committed(PyObject *self, PyObject *args, PyObject *kwargs)
1028 char *path, *rev_date = NULL, *rev_author = NULL;
1029 bool recurse, remove_lock = false;
1030 unsigned char *digest = NULL;
1031 svn_revnum_t new_revnum;
1032 PyObject *py_wcprop_changes = Py_None;
1033 apr_array_header_t *wcprop_changes = NULL;
1034 AdmObject *admobj = (AdmObject *)self;
1035 apr_pool_t *temp_pool;
1036 svn_boolean_t remove_changelist = FALSE;
1037 char *kwnames[] = { "path", "recurse", "new_revnum", "rev_date", "rev_author",
1038 "wcprop_changes", "remove_lock", "digest", "remove_changelist", NULL };
1040 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sblzz|Obzb", kwnames,
1041 &path, &recurse, &new_revnum, &rev_date,
1042 &rev_author, &py_wcprop_changes,
1043 &remove_lock, &digest, &remove_changelist))
1046 #if PY_VERSION_HEX < 0x02050000
1047 PyErr_Warn(PyExc_DeprecationWarning, "process_committed is deprecated. Use process_committed_queue instead.");
1049 PyErr_WarnEx(PyExc_DeprecationWarning, "process_committed is deprecated. Use process_committed_queue instead.", 2);
1053 ADM_CHECK_CLOSED(admobj);
1055 temp_pool = Pool(NULL);
1056 if (temp_pool == NULL)
1059 if (!py_dict_to_wcprop_changes(py_wcprop_changes, temp_pool, &wcprop_changes)) {
1060 apr_pool_destroy(temp_pool);
1064 #if ONLY_SINCE_SVN(1, 6)
1065 RUN_SVN_WITH_POOL(temp_pool, svn_wc_process_committed4(
1066 svn_path_canonicalize(path, temp_pool), admobj->adm, recurse, new_revnum,
1067 rev_date, rev_author, wcprop_changes,
1068 remove_lock, remove_changelist, digest, temp_pool));
1070 if (remove_changelist) {
1071 PyErr_SetString(PyExc_NotImplementedError, "remove_changelist only supported in svn < 1.6");
1072 apr_pool_destroy(temp_pool);
1075 RUN_SVN_WITH_POOL(temp_pool, svn_wc_process_committed3(svn_path_canonicalize(path, temp_pool), admobj->adm, recurse, new_revnum,
1076 rev_date, rev_author, wcprop_changes,
1077 remove_lock, digest, temp_pool));
1080 apr_pool_destroy(temp_pool);
1085 static PyObject *adm_close(PyObject *self)
1087 AdmObject *admobj = (AdmObject *)self;
1088 if (admobj->adm != NULL) {
1089 #if ONLY_SINCE_SVN(1, 6)
1090 apr_pool_t *temp_pool = Pool(NULL);
1091 Py_BEGIN_ALLOW_THREADS
1092 svn_wc_adm_close2(admobj->adm, temp_pool);
1093 apr_pool_destroy(temp_pool);
1095 Py_BEGIN_ALLOW_THREADS
1096 svn_wc_adm_close(admobj->adm);
1098 Py_END_ALLOW_THREADS
1105 static void adm_dealloc(PyObject *self)
1107 apr_pool_destroy(((AdmObject *)self)->pool);
1111 static PyObject *adm_repr(PyObject *self)
1113 AdmObject *admobj = (AdmObject *)self;
1115 if (admobj->adm == NULL) {
1116 return PyString_FromFormat("<wc.WorkingCopy (closed) at 0x%p>", admobj);
1118 return PyString_FromFormat("<wc.WorkingCopy at '%s'>",
1119 svn_wc_adm_access_path(admobj->adm));
1123 static PyObject *adm_remove_lock(PyObject *self, PyObject *args)
1126 AdmObject *admobj = (AdmObject *)self;
1127 apr_pool_t *temp_pool;
1129 if (!PyArg_ParseTuple(args, "s", &path))
1132 ADM_CHECK_CLOSED(admobj);
1134 temp_pool = Pool(NULL);
1135 if (temp_pool == NULL)
1138 RUN_SVN_WITH_POOL(temp_pool, svn_wc_remove_lock(path, admobj->adm, temp_pool))
1140 apr_pool_destroy(temp_pool);
1145 static PyObject *get_ancestry(PyObject *self, PyObject *args)
1150 apr_pool_t *temp_pool;
1151 AdmObject *admobj = (AdmObject *)self;
1153 if (!PyArg_ParseTuple(args, "s", &path))
1156 ADM_CHECK_CLOSED(admobj);
1158 temp_pool = Pool(NULL);
1159 if (temp_pool == NULL)
1162 RUN_SVN_WITH_POOL(temp_pool, svn_wc_get_ancestry(&url, &rev, path, admobj->adm, temp_pool));
1164 apr_pool_destroy(temp_pool);
1166 return Py_BuildValue("(si)", url, rev);
1169 static PyObject *maybe_set_repos_root(PyObject *self, PyObject *args)
1172 apr_pool_t *temp_pool;
1173 AdmObject *admobj = (AdmObject *)self;
1175 if (!PyArg_ParseTuple(args, "ss", &path, &repos))
1178 ADM_CHECK_CLOSED(admobj);
1180 temp_pool = Pool(NULL);
1181 if (temp_pool == NULL)
1184 RUN_SVN_WITH_POOL(temp_pool, svn_wc_maybe_set_repos_root(admobj->adm, path, repos, temp_pool));
1189 static PyObject *add_repos_file(PyObject *self, PyObject *args, PyObject *kwargs)
1191 char *kwnames[] = { "dst_path", "new_base_contents", "new_contents",
1192 "new_base_props", "new_props", "copyfrom_url", "copyfrom_rev",
1193 "cancel_func", "notify", NULL };
1194 AdmObject *admobj = (AdmObject *)self;
1195 apr_pool_t *temp_pool;
1196 char *dst_path, *copyfrom_url = NULL;
1197 svn_revnum_t copyfrom_rev = -1;
1198 PyObject *py_new_base_contents, *py_new_contents, *py_new_base_props,
1199 *py_new_props, *cancel_func = Py_None, *notify = Py_None;
1200 svn_stream_t *new_contents, *new_base_contents;
1201 apr_hash_t *new_props, *new_base_props;
1203 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sOOOO|ziOO", kwnames,
1204 &dst_path, &py_new_base_contents, &py_new_contents, &py_new_base_props,
1205 &py_new_props, ©from_url, ©from_rev, &cancel_func, ¬ify))
1208 ADM_CHECK_CLOSED(admobj);
1210 temp_pool = Pool(NULL);
1211 if (temp_pool == NULL)
1214 new_base_props = prop_dict_to_hash(temp_pool, py_new_base_props);
1216 new_props = prop_dict_to_hash(temp_pool, py_new_props);
1218 new_base_contents = new_py_stream(temp_pool, py_new_base_contents);
1220 new_contents = new_py_stream(temp_pool, py_new_contents);
1222 #if ONLY_BEFORE_SVN(1, 6)
1223 if (cancel_func != Py_None) {
1224 PyErr_SetString(PyExc_NotImplementedError,
1225 "cancel not support for svn < 1.6");
1230 #if ONLY_SINCE_SVN(1, 6)
1231 RUN_SVN_WITH_POOL(temp_pool, svn_wc_add_repos_file3(dst_path, admobj->adm,
1236 copyfrom_url, copyfrom_rev,
1237 py_cancel_func, cancel_func,
1238 py_wc_notify_func, notify, temp_pool));
1240 PyErr_SetString(PyExc_NotImplementedError,
1241 "add_repos_file3 not supported on svn < 1.6");
1242 apr_pool_destroy(temp_pool);
1245 apr_pool_destroy(temp_pool);
1250 static PyObject *mark_missing_deleted(PyObject *self, PyObject *args)
1253 AdmObject *admobj = (AdmObject *)self;
1254 apr_pool_t *temp_pool;
1256 if (!PyArg_ParseTuple(args, "s", &path))
1259 ADM_CHECK_CLOSED(admobj);
1261 temp_pool = Pool(NULL);
1262 if (temp_pool == NULL)
1265 RUN_SVN_WITH_POOL(temp_pool, svn_wc_mark_missing_deleted(path, admobj->adm, temp_pool));
1267 apr_pool_destroy(temp_pool);
1272 static PyObject *remove_from_revision_control(PyObject *self, PyObject *args)
1275 svn_boolean_t destroy_wf = FALSE, instant_error = FALSE;
1276 AdmObject *admobj = (AdmObject *)self;
1277 PyObject *cancel_func = Py_None;
1278 apr_pool_t *temp_pool;
1280 if (!PyArg_ParseTuple(args, "s|bbO", &name, &destroy_wf, &instant_error, &cancel_func))
1283 ADM_CHECK_CLOSED(admobj);
1285 temp_pool = Pool(NULL);
1286 if (temp_pool == NULL)
1289 RUN_SVN_WITH_POOL(temp_pool,
1290 svn_wc_remove_from_revision_control(admobj->adm, name,
1291 destroy_wf, instant_error, py_cancel_func, cancel_func, temp_pool));
1293 apr_pool_destroy(temp_pool);
1298 #if ONLY_SINCE_SVN(1, 6)
1299 static svn_error_t *wc_validator3(void *baton, const char *uuid, const char *url, const char *root_url, apr_pool_t *pool)
1301 PyObject *py_validator = baton, *ret;
1303 if (py_validator == Py_None) {
1307 ret = PyObject_CallFunction(py_validator, "sss", uuid, url, root_url);
1309 return py_svn_error();
1319 static svn_error_t *wc_validator2(void *baton, const char *uuid, const char *url, svn_boolean_t root, apr_pool_t *pool)
1321 PyObject *py_validator = baton, *ret;
1323 if (py_validator == Py_None) {
1327 ret = PyObject_CallFunction(py_validator, "ssO", uuid, url, Py_None);
1329 return py_svn_error();
1339 static PyObject *relocate(PyObject *self, PyObject *args)
1341 char *path, *from, *to;
1342 AdmObject *admobj = (AdmObject *)self;
1343 apr_pool_t *temp_pool;
1344 svn_boolean_t recurse = TRUE;
1345 PyObject *py_validator = Py_None;
1347 if (!PyArg_ParseTuple(args, "sss|bO", &path, &from, &to, &recurse, &py_validator))
1350 ADM_CHECK_CLOSED(admobj);
1352 temp_pool = Pool(NULL);
1353 if (temp_pool == NULL)
1356 #if ONLY_SINCE_SVN(1, 6)
1357 RUN_SVN_WITH_POOL(temp_pool, svn_wc_relocate3(path, admobj->adm, from, to, recurse, wc_validator3, py_validator, temp_pool));
1359 RUN_SVN_WITH_POOL(temp_pool, svn_wc_relocate2(path, admobj->adm, from, to, recurse, wc_validator2, py_validator, temp_pool));
1362 apr_pool_destroy(temp_pool);
1367 static PyObject *crop_tree(PyObject *self, PyObject *args)
1371 PyObject *notify, *cancel;
1372 apr_pool_t *temp_pool;
1373 AdmObject *admobj = (AdmObject *)self;
1375 if (!PyArg_ParseTuple(args, "si|OO", &target, &depth, ¬ify, &cancel))
1378 ADM_CHECK_CLOSED(admobj);
1380 #if ONLY_SINCE_SVN(1, 6)
1381 temp_pool = Pool(NULL);
1382 if (temp_pool == NULL)
1385 RUN_SVN_WITH_POOL(temp_pool, svn_wc_crop_tree(admobj->adm,
1386 target, depth, py_wc_notify_func, notify,
1387 py_cancel_func, cancel, temp_pool));
1389 apr_pool_destroy(temp_pool);
1393 PyErr_SetString(PyExc_NotImplementedError,
1394 "crop_tree only available on subversion < 1.6");
1399 static PyObject *translated_stream(PyObject *self, PyObject *args)
1401 char *path, *versioned_file;
1403 svn_stream_t *stream;
1404 AdmObject *admobj = (AdmObject *)self;
1405 apr_pool_t *stream_pool;
1408 if (!PyArg_ParseTuple(args, "ssi", &path, &versioned_file, &flags))
1411 ADM_CHECK_CLOSED(admobj);
1413 #if ONLY_SINCE_SVN(1, 5)
1414 stream_pool = Pool(NULL);
1415 if (stream_pool == NULL)
1418 RUN_SVN_WITH_POOL(stream_pool,
1419 svn_wc_translated_stream(&stream, path, versioned_file, admobj->adm,
1420 flags, stream_pool));
1422 ret = PyObject_New(StreamObject, &Stream_Type);
1426 ret->pool = stream_pool;
1427 ret->closed = FALSE;
1428 ret->stream = stream;
1430 return (PyObject *)ret;
1432 PyErr_SetString(PyExc_NotImplementedError,
1433 "translated_stream() is only available on Subversion >= 1.5");
1438 static PyObject *adm_text_modified(PyObject *self, PyObject *args)
1441 svn_boolean_t force_comparison = FALSE;
1442 apr_pool_t *temp_pool;
1444 AdmObject *admobj = (AdmObject *)self;
1446 if (!PyArg_ParseTuple(args, "s|b", &path, &force_comparison))
1449 ADM_CHECK_CLOSED(admobj);
1451 temp_pool = Pool(NULL);
1452 if (temp_pool == NULL)
1455 RUN_SVN_WITH_POOL(temp_pool,
1456 svn_wc_text_modified_p(&ret, path, force_comparison, admobj->adm,
1459 apr_pool_destroy(temp_pool);
1461 return PyBool_FromLong(ret);
1464 static PyObject *adm_props_modified(PyObject *self, PyObject *args)
1467 apr_pool_t *temp_pool;
1469 AdmObject *admobj = (AdmObject *)self;
1471 if (!PyArg_ParseTuple(args, "s", &path))
1474 ADM_CHECK_CLOSED(admobj);
1476 temp_pool = Pool(NULL);
1477 if (temp_pool == NULL)
1480 RUN_SVN_WITH_POOL(temp_pool,
1481 svn_wc_props_modified_p(&ret, path, admobj->adm, temp_pool));
1483 apr_pool_destroy(temp_pool);
1485 return PyBool_FromLong(ret);
1488 static PyObject *adm_process_committed_queue(PyObject *self, PyObject *args)
1490 apr_pool_t *temp_pool;
1491 AdmObject *admobj = (AdmObject *)self;
1492 svn_revnum_t revnum;
1493 char *date, *author;
1494 CommittedQueueObject *py_queue;
1496 if (!PyArg_ParseTuple(args, "O!Iss", &CommittedQueue_Type, &py_queue, &revnum, &date, &author))
1499 ADM_CHECK_CLOSED(admobj);
1501 temp_pool = Pool(NULL);
1502 if (temp_pool == NULL)
1505 #if ONLY_SINCE_SVN(1, 5)
1506 RUN_SVN_WITH_POOL(temp_pool, svn_wc_process_committed_queue(py_queue->queue, admobj->adm, revnum, date, author, temp_pool));
1510 for (i = 0; i < py_queue->queue->queue->nelts; i++) {
1511 committed_queue_item_t *cqi = APR_ARRAY_IDX(py_queue->queue->queue, i,
1512 committed_queue_item_t *);
1514 RUN_SVN_WITH_POOL(temp_pool, svn_wc_process_committed3(cqi->path, admobj->adm,
1515 cqi->recurse, revnum, date, author, cqi->wcprop_changes,
1516 cqi->remove_lock, cqi->digest, temp_pool));
1520 apr_pool_destroy(temp_pool);
1525 static PyObject *get_actual_target(PyObject *self, PyObject *args)
1528 const char *anchor = NULL, *target = NULL;
1529 apr_pool_t *temp_pool;
1532 if (!PyArg_ParseTuple(args, "s", &path))
1535 temp_pool = Pool(NULL);
1536 if (temp_pool == NULL)
1539 RUN_SVN_WITH_POOL(temp_pool,
1540 svn_wc_get_actual_target(svn_path_canonicalize(path, temp_pool),
1541 &anchor, &target, temp_pool));
1543 ret = Py_BuildValue("(ss)", anchor, target);
1545 apr_pool_destroy(temp_pool);
1550 static PyObject *is_wc_root(PyObject *self, PyObject *args)
1553 svn_boolean_t wc_root;
1554 apr_pool_t *temp_pool;
1555 AdmObject *admobj = (AdmObject *)self;
1557 if (!PyArg_ParseTuple(args, "s", &path))
1560 ADM_CHECK_CLOSED(admobj);
1562 temp_pool = Pool(NULL);
1563 if (temp_pool == NULL)
1566 RUN_SVN_WITH_POOL(temp_pool,
1567 svn_wc_is_wc_root(&wc_root, path, admobj->adm, temp_pool));
1569 apr_pool_destroy(temp_pool);
1571 return PyBool_FromLong(wc_root);
1574 static PyObject *transmit_text_deltas(PyObject *self, PyObject *args)
1577 const char *tempfile;
1578 svn_boolean_t fulltext;
1579 PyObject *editor_obj, *py_digest;
1580 unsigned char digest[APR_MD5_DIGESTSIZE];
1581 apr_pool_t *temp_pool;
1582 AdmObject *admobj = (AdmObject *)self;
1585 if (!PyArg_ParseTuple(args, "sbO", &path, &fulltext, &editor_obj))
1588 ADM_CHECK_CLOSED(admobj);
1590 temp_pool = Pool(NULL);
1591 if (temp_pool == NULL)
1594 Py_INCREF(editor_obj);
1596 RUN_SVN_WITH_POOL(temp_pool,
1597 svn_wc_transmit_text_deltas2(&tempfile, digest,
1598 svn_path_canonicalize(path, temp_pool), admobj->adm, fulltext,
1599 &py_editor, editor_obj, temp_pool));
1601 py_digest = PyString_FromStringAndSize((char *)digest, APR_MD5_DIGESTSIZE);
1602 if (py_digest == NULL) {
1603 apr_pool_destroy(temp_pool);
1607 ret = Py_BuildValue("sN", tempfile, py_digest);
1609 apr_pool_destroy(temp_pool);
1613 apr_pool_destroy(temp_pool);
1618 static PyObject *transmit_prop_deltas(PyObject *self, PyObject *args)
1621 PyObject *editor_obj;
1622 apr_pool_t *temp_pool;
1623 AdmObject *admobj = (AdmObject *)self;
1624 EntryObject *py_entry;
1626 if (!PyArg_ParseTuple(args, "sO!O", &path, &Entry_Type, &py_entry, &editor_obj))
1629 ADM_CHECK_CLOSED(admobj);
1631 temp_pool = Pool(NULL);
1632 if (temp_pool == NULL)
1635 Py_INCREF(editor_obj);
1637 RUN_SVN_WITH_POOL(temp_pool,
1638 svn_wc_transmit_prop_deltas(svn_path_canonicalize(path, temp_pool),
1639 admobj->adm, &(py_entry->entry), &py_editor, editor_obj, NULL, temp_pool));
1641 apr_pool_destroy(temp_pool);
1646 static PyObject *retrieve(PyObject *self, PyObject *args)
1649 svn_wc_adm_access_t *result;
1650 AdmObject *admobj = (AdmObject *)self, *ret;
1653 if (!PyArg_ParseTuple(args, "s", &path))
1656 ADM_CHECK_CLOSED(admobj);
1662 RUN_SVN_WITH_POOL(pool, svn_wc_adm_retrieve(&result, admobj->adm,
1663 svn_path_canonicalize(path, pool), pool));
1665 ret = PyObject_New(AdmObject, &Adm_Type);
1672 return (PyObject *)ret;
1675 static PyObject *probe_retrieve(PyObject *self, PyObject *args)
1678 svn_wc_adm_access_t *result;
1679 AdmObject *admobj = (AdmObject *)self, *ret;
1682 if (!PyArg_ParseTuple(args, "s", &path))
1685 ADM_CHECK_CLOSED(admobj);
1691 RUN_SVN_WITH_POOL(pool, svn_wc_adm_probe_retrieve(&result, admobj->adm,
1692 svn_path_canonicalize(path, pool), pool));
1694 ret = PyObject_New(AdmObject, &Adm_Type);
1701 return (PyObject *)ret;
1704 static PyObject *probe_try(PyObject *self, PyObject *args)
1707 svn_wc_adm_access_t *result = NULL;
1708 AdmObject *admobj = (AdmObject *)self, *ret;
1710 PyObject *cancelfunc = Py_None;
1711 int levels_to_lock = -1;
1712 svn_boolean_t writelock = FALSE;
1714 if (!PyArg_ParseTuple(args, "s|biO", &path, &writelock, &levels_to_lock, &cancelfunc))
1717 ADM_CHECK_CLOSED(admobj);
1723 RUN_SVN_WITH_POOL(pool, svn_wc_adm_probe_try3(&result, admobj->adm,
1724 svn_path_canonicalize(path, pool), writelock, levels_to_lock,
1725 py_cancel_func, cancelfunc, pool));
1727 if (result == NULL) {
1728 apr_pool_destroy(pool);
1732 ret = PyObject_New(AdmObject, &Adm_Type);
1739 return (PyObject *)ret;
1742 static PyObject *resolved_conflict(PyObject *self, PyObject *args)
1744 AdmObject *admobj = (AdmObject *)self;
1745 apr_pool_t *temp_pool;
1746 svn_boolean_t resolve_props, resolve_tree, resolve_text;
1748 svn_wc_conflict_choice_t conflict_choice;
1749 PyObject *notify_func = Py_None, *cancel_func = Py_None;
1752 if (!PyArg_ParseTuple(args, "sbbbii|OO", &path, &resolve_text,
1753 &resolve_props, &resolve_tree, &depth,
1754 &conflict_choice, ¬ify_func, &cancel_func))
1757 ADM_CHECK_CLOSED(admobj);
1759 temp_pool = Pool(NULL);
1760 if (temp_pool == NULL)
1763 #if ONLY_SINCE_SVN(1, 6)
1764 RUN_SVN_WITH_POOL(temp_pool,
1765 svn_wc_resolved_conflict4(path, admobj->adm, resolve_text,
1766 resolve_props, resolve_tree, depth,
1767 conflict_choice, py_wc_notify_func,
1768 (void *)notify_func, py_cancel_func,
1769 cancel_func, temp_pool));
1770 #elif ONLY_SINCE_SVN(1, 5)
1772 PyErr_SetString(PyExc_NotImplementedError,
1773 "resolve_tree not supported with svn < 1.6");
1775 RUN_SVN_WITH_POOL(temp_pool,
1776 svn_wc_resolved_conflict3(path, admobj->adm, resolve_text,
1777 resolve_props, depth,
1778 conflict_choice, py_wc_notify_func,
1779 (void *)notify_func, py_cancel_func,
1780 cancel_func, temp_pool));
1784 PyErr_SetString(PyExc_NotImplementedError,
1785 "resolve_tree not supported with svn < 1.6");
1786 } else if (depth != svn_depth_infinity && depth != svn_depth_empty) {
1787 PyErr_SetString(PyExc_NotImplementedError,
1788 "only infinity and empty values for depth are supported");
1790 RUN_SVN_WITH_POOL(temp_pool,
1791 svn_wc_resolved_conflict3(path, admobj->adm, resolve_text,
1793 (depth == svn_depth_infinity),
1794 conflict_choice, py_wc_notify_func,
1795 (void *)notify_func, py_cancel_func,
1796 cancel_func, temp_pool));
1800 apr_pool_destroy(temp_pool);
1805 static PyObject *conflicted(PyObject *self, PyObject *args)
1808 apr_pool_t *temp_pool;
1810 AdmObject *admobj = (AdmObject *)self;
1811 svn_boolean_t text_conflicted, prop_conflicted, tree_conflicted;
1813 if (!PyArg_ParseTuple(args, "s", &path))
1816 ADM_CHECK_CLOSED(admobj);
1818 temp_pool = Pool(NULL);
1819 if (temp_pool == NULL)
1822 #if ONLY_SINCE_SVN(1, 6)
1823 RUN_SVN_WITH_POOL(temp_pool, svn_wc_conflicted_p2(&text_conflicted,
1824 &prop_conflicted, &tree_conflicted, path, admobj->adm, temp_pool));
1826 ret = Py_BuildValue("(bbb)", text_conflicted, prop_conflicted, tree_conflicted);
1828 RUN_SVN_WITH_POOL(temp_pool, svn_wc_conflicted_p(&text_conflicted,
1829 &prop_conflicted, path, admobj->adm, temp_pool));
1831 ret = Py_BuildValue("(bbO)", text_conflicted, prop_conflicted, Py_None);
1834 apr_pool_destroy(temp_pool);
1839 static PyMethodDef adm_methods[] = {
1840 { "prop_set", adm_prop_set, METH_VARARGS, "S.prop_set(name, value, path, skip_checks=False)" },
1841 { "access_path", (PyCFunction)adm_access_path, METH_NOARGS,
1842 "S.access_path() -> path\n"
1843 "Returns the base path for this working copy handle." },
1844 { "prop_get", adm_prop_get, METH_VARARGS, "S.prop_get(name, path) -> value" },
1845 { "entries_read", adm_entries_read, METH_VARARGS, "S.entries_read(include_hidden=False) -> dict" },
1846 { "walk_entries", adm_walk_entries, METH_VARARGS,
1847 "S.walk_entries(path, callback, show_hidden=False, cancel_func=None)\n"
1848 "callback should be a function that takes a path and a wc entry" },
1849 { "locked", (PyCFunction)adm_locked, METH_NOARGS,
1850 "S.locked() -> bool" },
1851 { "get_prop_diffs", adm_get_prop_diffs, METH_VARARGS,
1852 "S.get_prop_diffs(path) -> (propchanges, originalprops)" },
1853 { "add", (PyCFunction)adm_add, METH_VARARGS|METH_KEYWORDS, "S.add(path, copyfrom_url=None, copyfrom_rev=-1, cancel_func=None, notify_func=None)" },
1854 { "copy", adm_copy, METH_VARARGS, "S.copy(src_path, dest_path, cancel_func=None, notify_func=None)" },
1855 { "delete", (PyCFunction)adm_delete, METH_VARARGS|METH_KEYWORDS, "S.delete(path, cancel_func=None, notify_func=None, keep_local=False)" },
1856 { "crawl_revisions", (PyCFunction)adm_crawl_revisions, METH_VARARGS|METH_KEYWORDS,
1857 "S.crawl_revisions(path, reporter, restore_files=True, recurse=True, use_commit_times=True, notify_func=None) -> None" },
1858 { "get_update_editor", adm_get_update_editor, METH_VARARGS, NULL },
1859 { "close", (PyCFunction)adm_close, METH_NOARGS,
1861 { "entry", (PyCFunction)adm_entry, METH_VARARGS,
1862 "s.entry(path, show_hidden=False) -> entry" },
1863 { "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)" },
1864 { "process_committed_queue", (PyCFunction)adm_process_committed_queue, METH_VARARGS, "S.process_committed_queue(queue, new_revnum, rev_date, rev_author)" },
1865 { "remove_lock", (PyCFunction)adm_remove_lock, METH_VARARGS, "S.remove_lock(path)" },
1866 { "has_binary_prop", (PyCFunction)adm_has_binary_prop, METH_VARARGS, "S.has_binary_prop(path) -> bool" },
1867 { "text_modified", (PyCFunction)adm_text_modified, METH_VARARGS, "S.text_modified(filename, force_comparison=False) -> bool" },
1868 { "props_modified", (PyCFunction)adm_props_modified, METH_VARARGS, "S.props_modified(filename) -> bool" },
1869 { "get_ancestry", (PyCFunction)get_ancestry, METH_VARARGS,
1870 "S.get_ancestry(path) -> (url, rev)" },
1871 { "maybe_set_repos_root", (PyCFunction)maybe_set_repos_root, METH_VARARGS, "S.maybe_set_repos_root(path, repos)" },
1872 { "add_repos_file", (PyCFunction)add_repos_file, METH_KEYWORDS,
1873 "S.add_repos_file(dst_path, new_base_contents, new_contents, new_base_props, new_props, copyfrom_url=None, copyfrom_rev=-1, cancel_func=None, notify_func=None)" },
1874 { "mark_missing_deleted", (PyCFunction)mark_missing_deleted, METH_VARARGS,
1875 "S.mark_missing_deleted(path)" },
1876 { "remove_from_revision_control", (PyCFunction)remove_from_revision_control, METH_VARARGS,
1877 "S.remove_from_revision_control(name, destroy_wf=False, instant_error=False, cancel_func=None)" },
1878 { "relocate", (PyCFunction)relocate, METH_VARARGS,
1879 "S.relocate(path, from, to, recurse=TRUE, validator=None)" },
1880 { "crop_tree", (PyCFunction)crop_tree, METH_VARARGS,
1881 "S.crop_tree(target, depth, notify_func=None, cancel=None)" },
1882 { "translated_stream", (PyCFunction)translated_stream, METH_VARARGS,
1883 "S.translated_stream(path, versioned_file, flags) -> stream" },
1884 { "is_wc_root", (PyCFunction)is_wc_root, METH_VARARGS,
1885 "S.is_wc_root(path) -> wc_root" },
1886 { "transmit_text_deltas", (PyCFunction)transmit_text_deltas, METH_VARARGS,
1887 "S.transmit_text_deltas(fulltext, editor) -> (tempfile, digest)" },
1888 { "transmit_prop_deltas", (PyCFunction)transmit_prop_deltas, METH_VARARGS,
1889 "S.transmit_prop_deltas(path, entry, editor)" },
1890 { "probe_retrieve", (PyCFunction)probe_retrieve, METH_VARARGS,
1891 "S.probe_retrieve(path) -> WorkingCopy" },
1892 { "retrieve", (PyCFunction)retrieve, METH_VARARGS,
1893 "S.retrieve(path) -> WorkingCopy" },
1894 { "probe_try", (PyCFunction)probe_try, METH_VARARGS,
1895 "S.probe_try(path, write_lock=False, levels_to_lock=-1)" },
1896 { "conflicted", (PyCFunction)conflicted, METH_VARARGS,
1897 "S.conflicted(path) -> (text_conflicted, prop_conflicted, tree_conflicted)" },
1898 { "resolved_conflict", (PyCFunction)resolved_conflict, METH_VARARGS,
1899 "S.resolved_conflict(path, resolve_text, resolve_props, resolve_tree, depth, conflict_choice, notify_func=None, cancel=None)" },
1903 static PyTypeObject Adm_Type = {
1904 PyObject_HEAD_INIT(NULL) 0,
1905 "wc.WorkingCopy", /* const char *tp_name; For printing, in format "<module>.<name>" */
1907 0,/* Py_ssize_t tp_basicsize, tp_itemsize; For allocation */
1909 /* Methods to implement standard operations */
1911 adm_dealloc, /* destructor tp_dealloc; */
1912 NULL, /* printfunc tp_print; */
1913 NULL, /* getattrfunc tp_getattr; */
1914 NULL, /* setattrfunc tp_setattr; */
1915 NULL, /* cmpfunc tp_compare; */
1916 adm_repr, /* reprfunc tp_repr; */
1918 /* Method suites for standard classes */
1920 NULL, /* PyNumberMethods *tp_as_number; */
1921 NULL, /* PySequenceMethods *tp_as_sequence; */
1922 NULL, /* PyMappingMethods *tp_as_mapping; */
1924 /* More standard operations (here for binary compatibility) */
1926 NULL, /* hashfunc tp_hash; */
1927 NULL, /* ternaryfunc tp_call; */
1928 adm_repr, /* reprfunc tp_repr; */
1929 NULL, /* getattrofunc tp_getattro; */
1930 NULL, /* setattrofunc tp_setattro; */
1932 /* Functions to access object as input/output buffer */
1933 NULL, /* PyBufferProcs *tp_as_buffer; */
1935 /* Flags to define presence of optional/expanded features */
1936 0, /* long tp_flags; */
1938 "Local working copy", /* const char *tp_doc; Documentation string */
1940 /* Assigned meaning in release 2.0 */
1941 /* call function for all accessible objects */
1942 NULL, /* traverseproc tp_traverse; */
1944 /* delete references to contained objects */
1945 NULL, /* inquiry tp_clear; */
1947 /* Assigned meaning in release 2.1 */
1948 /* rich comparisons */
1949 NULL, /* richcmpfunc tp_richcompare; */
1951 /* weak reference enabler */
1952 0, /* Py_ssize_t tp_weaklistoffset; */
1954 /* Added in release 2.2 */
1956 NULL, /* getiterfunc tp_iter; */
1957 NULL, /* iternextfunc tp_iternext; */
1959 /* Attribute descriptor and subclassing stuff */
1960 adm_methods, /* struct PyMethodDef *tp_methods; */
1961 NULL, /* struct PyMemberDef *tp_members; */
1962 NULL, /* struct PyGetSetDef *tp_getset; */
1963 NULL, /* struct _typeobject *tp_base; */
1964 NULL, /* PyObject *tp_dict; */
1965 NULL, /* descrgetfunc tp_descr_get; */
1966 NULL, /* descrsetfunc tp_descr_set; */
1967 0, /* Py_ssize_t tp_dictoffset; */
1968 NULL, /* initproc tp_init; */
1969 NULL, /* allocfunc tp_alloc; */
1970 adm_init, /* newfunc tp_new; */
1973 static void committed_queue_dealloc(PyObject *self)
1975 apr_pool_destroy(((CommittedQueueObject *)self)->pool);
1979 static PyObject *committed_queue_repr(PyObject *self)
1981 CommittedQueueObject *cqobj = (CommittedQueueObject *)self;
1983 return PyString_FromFormat("<wc.CommittedQueue at 0x%p>", cqobj->queue);
1986 static PyObject *committed_queue_init(PyTypeObject *self, PyObject *args, PyObject *kwargs)
1988 CommittedQueueObject *ret;
1989 char *kwnames[] = { NULL };
1991 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "", kwnames))
1994 ret = PyObject_New(CommittedQueueObject, &CommittedQueue_Type);
1998 ret->pool = Pool(NULL);
1999 if (ret->pool == NULL)
2001 ret->queue = svn_wc_committed_queue_create(ret->pool);
2002 if (ret->queue == NULL) {
2008 return (PyObject *)ret;
2011 static PyObject *committed_queue_queue(CommittedQueueObject *self, PyObject *args)
2015 PyObject *py_wcprop_changes = Py_None;
2016 svn_boolean_t remove_lock = FALSE, remove_changelist = FALSE;
2017 char *digest = NULL;
2018 svn_boolean_t recurse = FALSE;
2019 apr_pool_t *temp_pool;
2020 apr_array_header_t *wcprop_changes;
2022 if (!PyArg_ParseTuple(args, "sO!|bObbz", &path, &Adm_Type, &admobj, &recurse, &py_wcprop_changes, &remove_lock, &remove_changelist, &digest))
2025 temp_pool = Pool(NULL);
2026 if (temp_pool == NULL)
2029 if (!py_dict_to_wcprop_changes(py_wcprop_changes, self->pool, &wcprop_changes)) {
2030 apr_pool_destroy(temp_pool);
2034 path = apr_pstrdup(self->pool, path);
2040 if (digest != NULL) {
2041 digest = apr_pstrdup(self->pool, digest);
2042 if (digest == NULL) {
2048 RUN_SVN_WITH_POOL(temp_pool,
2049 svn_wc_queue_committed(&self->queue, path, admobj->adm, recurse,
2050 wcprop_changes, remove_lock, remove_changelist,
2051 (unsigned char *)digest, temp_pool));
2053 apr_pool_destroy(temp_pool);
2058 static PyMethodDef committed_queue_methods[] = {
2059 { "queue", (PyCFunction)committed_queue_queue, METH_VARARGS,
2060 "S.queue(path, adm, recurse, wcprop_changes, remove_lock, remove_changelist, digest)" },
2064 static PyTypeObject CommittedQueue_Type = {
2065 PyObject_HEAD_INIT(NULL) 0,
2066 "wc.CommittedQueue", /* const char *tp_name; For printing, in format "<module>.<name>" */
2067 sizeof(CommittedQueueObject),
2068 0,/* Py_ssize_t tp_basicsize, tp_itemsize; For allocation */
2070 /* Methods to implement standard operations */
2072 committed_queue_dealloc, /* destructor tp_dealloc; */
2073 NULL, /* printfunc tp_print; */
2074 NULL, /* getattrfunc tp_getattr; */
2075 NULL, /* setattrfunc tp_setattr; */
2076 NULL, /* cmpfunc tp_compare; */
2077 committed_queue_repr, /* reprfunc tp_repr; */
2079 /* Method suites for standard classes */
2081 NULL, /* PyNumberMethods *tp_as_number; */
2082 NULL, /* PySequenceMethods *tp_as_sequence; */
2083 NULL, /* PyMappingMethods *tp_as_mapping; */
2085 /* More standard operations (here for binary compatibility) */
2087 NULL, /* hashfunc tp_hash; */
2088 NULL, /* ternaryfunc tp_call; */
2089 NULL, /* reprfunc tp_str; */
2090 NULL, /* getattrofunc tp_getattro; */
2091 NULL, /* setattrofunc tp_setattro; */
2093 /* Functions to access object as input/output buffer */
2094 NULL, /* PyBufferProcs *tp_as_buffer; */
2096 /* Flags to define presence of optional/expanded features */
2097 0, /* long tp_flags; */
2099 "Committed queue", /* const char *tp_doc; Documentation string */
2101 /* Assigned meaning in release 2.0 */
2102 /* call function for all accessible objects */
2103 NULL, /* traverseproc tp_traverse; */
2105 /* delete references to contained objects */
2106 NULL, /* inquiry tp_clear; */
2108 /* Assigned meaning in release 2.1 */
2109 /* rich comparisons */
2110 NULL, /* richcmpfunc tp_richcompare; */
2112 /* weak reference enabler */
2113 0, /* Py_ssize_t tp_weaklistoffset; */
2115 /* Added in release 2.2 */
2117 NULL, /* getiterfunc tp_iter; */
2118 NULL, /* iternextfunc tp_iternext; */
2120 /* Attribute descriptor and subclassing stuff */
2121 committed_queue_methods, /* struct PyMethodDef *tp_methods; */
2122 NULL, /* struct PyMemberDef *tp_members; */
2123 NULL, /* struct PyGetSetDef *tp_getset; */
2124 NULL, /* struct _typeobject *tp_base; */
2125 NULL, /* PyObject *tp_dict; */
2126 NULL, /* descrgetfunc tp_descr_get; */
2127 NULL, /* descrsetfunc tp_descr_set; */
2128 0, /* Py_ssize_t tp_dictoffset; */
2129 NULL, /* initproc tp_init; */
2130 NULL, /* allocfunc tp_alloc; */
2131 committed_queue_init, /* newfunc tp_new; */
2135 * Determine the revision status of a specified working copy.
2137 * :return: Tuple with minimum and maximum revnums found, whether the
2138 * working copy was switched and whether it was modified.
2140 static PyObject *revision_status(PyObject *self, PyObject *args, PyObject *kwargs)
2142 char *kwnames[] = { "wc_path", "trail_url", "committed", "cancel_func", NULL };
2143 char *wc_path, *trail_url=NULL;
2144 bool committed=false;
2145 PyObject *cancel_func=Py_None, *ret;
2146 svn_wc_revision_status_t *revstatus;
2147 apr_pool_t *temp_pool;
2149 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zbO", kwnames, &wc_path,
2150 &trail_url, &committed, &cancel_func))
2153 temp_pool = Pool(NULL);
2154 if (temp_pool == NULL)
2156 RUN_SVN_WITH_POOL(temp_pool,
2157 svn_wc_revision_status(
2159 svn_path_canonicalize(wc_path, temp_pool),
2161 committed, py_cancel_func, cancel_func, temp_pool));
2162 ret = Py_BuildValue("(llbb)", revstatus->min_rev, revstatus->max_rev,
2163 revstatus->switched, revstatus->modified);
2164 apr_pool_destroy(temp_pool);
2168 static PyObject *is_normal_prop(PyObject *self, PyObject *args)
2172 if (!PyArg_ParseTuple(args, "s", &name))
2175 return PyBool_FromLong(svn_wc_is_normal_prop(name));
2178 static PyObject *is_adm_dir(PyObject *self, PyObject *args)
2184 if (!PyArg_ParseTuple(args, "s", &name))
2191 ret = svn_wc_is_adm_dir(name, pool);
2193 apr_pool_destroy(pool);
2195 return PyBool_FromLong(ret);
2198 static PyObject *is_wc_prop(PyObject *self, PyObject *args)
2202 if (!PyArg_ParseTuple(args, "s", &name))
2205 return PyBool_FromLong(svn_wc_is_wc_prop(name));
2208 static PyObject *is_entry_prop(PyObject *self, PyObject *args)
2212 if (!PyArg_ParseTuple(args, "s", &name))
2215 return PyBool_FromLong(svn_wc_is_entry_prop(name));
2218 static PyObject *get_adm_dir(PyObject *self)
2226 dir = svn_wc_get_adm_dir(pool);
2227 ret = PyString_FromString(dir);
2228 apr_pool_destroy(pool);
2232 static PyObject *set_adm_dir(PyObject *self, PyObject *args)
2234 apr_pool_t *temp_pool;
2237 if (!PyArg_ParseTuple(args, "s", &name))
2240 temp_pool = Pool(NULL);
2241 if (temp_pool == NULL)
2243 RUN_SVN_WITH_POOL(temp_pool, svn_wc_set_adm_dir(name, temp_pool));
2244 apr_pool_destroy(temp_pool);
2248 static PyObject *get_pristine_copy_path(PyObject *self, PyObject *args)
2251 const char *pristine_path;
2255 if (!PyArg_ParseTuple(args, "s", &path))
2261 #if PY_VERSION_HEX < 0x02050000
2262 PyErr_Warn(PyExc_DeprecationWarning, "get_pristine_copy_path is deprecated. Use get_pristine_contents instead.");
2264 PyErr_WarnEx(PyExc_DeprecationWarning, "get_pristine_copy_path is deprecated. Use get_pristine_contents instead.", 2);
2266 RUN_SVN_WITH_POOL(pool,
2267 svn_wc_get_pristine_copy_path(svn_path_canonicalize(path, pool),
2268 &pristine_path, pool));
2269 ret = PyString_FromString(pristine_path);
2270 apr_pool_destroy(pool);
2274 static PyObject *get_pristine_contents(PyObject *self, PyObject *args)
2277 apr_pool_t *temp_pool;
2278 #if ONLY_SINCE_SVN(1, 6)
2279 apr_pool_t *stream_pool;
2281 svn_stream_t *stream;
2284 const char *pristine_path;
2287 if (!PyArg_ParseTuple(args, "s", &path))
2290 #if ONLY_SINCE_SVN(1, 6)
2291 stream_pool = Pool(NULL);
2292 if (stream_pool == NULL)
2295 temp_pool = Pool(stream_pool);
2296 if (temp_pool == NULL) {
2297 apr_pool_destroy(stream_pool);
2301 RUN_SVN_WITH_POOL(stream_pool, svn_wc_get_pristine_contents(&stream, svn_path_canonicalize(path, temp_pool), stream_pool, temp_pool));
2302 apr_pool_destroy(temp_pool);
2304 if (stream == NULL) {
2305 apr_pool_destroy(stream_pool);
2309 ret = PyObject_New(StreamObject, &Stream_Type);
2313 ret->pool = stream_pool;
2314 ret->closed = FALSE;
2315 ret->stream = stream;
2317 return (PyObject *)ret;
2319 temp_pool = Pool(NULL);
2320 if (temp_pool == NULL)
2322 RUN_SVN_WITH_POOL(temp_pool, svn_wc_get_pristine_copy_path(svn_path_canonicalize(path, temp_pool), &pristine_path, temp_pool));
2323 ret = PyFile_FromString((char *)pristine_path, "rb");
2324 apr_pool_destroy(temp_pool);
2329 static PyObject *ensure_adm(PyObject *self, PyObject *args, PyObject *kwargs)
2331 char *path, *uuid, *url;
2333 svn_revnum_t rev=-1;
2335 char *kwnames[] = { "path", "uuid", "url", "repos", "rev", "depth", NULL };
2336 svn_depth_t depth = svn_depth_infinity;
2338 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss|sli", kwnames,
2339 &path, &uuid, &url, &repos, &rev, &depth))
2345 #if ONLY_SINCE_SVN(1, 5)
2346 RUN_SVN_WITH_POOL(pool,
2347 svn_wc_ensure_adm3(svn_path_canonicalize(path, pool),
2348 uuid, url, repos, rev, depth, pool));
2350 if (depth != svn_depth_infinity) {
2351 PyErr_SetString(PyExc_NotImplementedError,
2352 "depth != infinity not supported with svn < 1.5");
2353 apr_pool_destroy(pool);
2356 RUN_SVN_WITH_POOL(pool,
2357 svn_wc_ensure_adm2(svn_path_canonicalize(path, pool),
2358 uuid, url, repos, rev, pool));
2360 apr_pool_destroy(pool);
2364 static PyObject *check_wc(PyObject *self, PyObject *args)
2370 if (!PyArg_ParseTuple(args, "s", &path))
2376 RUN_SVN_WITH_POOL(pool, svn_wc_check_wc(svn_path_canonicalize(path, pool), &wc_format, pool));
2377 apr_pool_destroy(pool);
2378 return PyLong_FromLong(wc_format);
2381 static PyObject *cleanup_wc(PyObject *self, PyObject *args, PyObject *kwargs)
2383 PyObject *cancel_func = Py_None;
2385 char *diff3_cmd = NULL;
2386 char *kwnames[] = { "path", "diff3_cmd", "cancel_func", NULL };
2387 apr_pool_t *temp_pool;
2389 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zO", kwnames,
2390 &path, &diff3_cmd, &cancel_func))
2393 temp_pool = Pool(NULL);
2394 if (temp_pool == NULL)
2396 RUN_SVN_WITH_POOL(temp_pool,
2397 svn_wc_cleanup2(path, diff3_cmd, py_cancel_func, cancel_func,
2399 apr_pool_destroy(temp_pool);
2404 static PyObject *match_ignore_list(PyObject *self, PyObject *args)
2406 #if ONLY_SINCE_SVN(1, 5)
2409 apr_array_header_t *list;
2410 apr_pool_t *temp_pool;
2413 if (!PyArg_ParseTuple(args, "sO", &str, &py_list))
2416 temp_pool = Pool(NULL);
2418 if (!string_list_to_apr_array(temp_pool, py_list, &list)) {
2419 apr_pool_destroy(temp_pool);
2423 ret = svn_wc_match_ignore_list(str, list, temp_pool);
2425 apr_pool_destroy(temp_pool);
2427 return PyBool_FromLong(ret);
2429 PyErr_SetNone(PyExc_NotImplementedError);
2434 static PyMethodDef wc_methods[] = {
2435 { "check_wc", check_wc, METH_VARARGS, "check_wc(path) -> version\n"
2436 "Check whether path contains a Subversion working copy\n"
2437 "return the workdir version"},
2438 { "cleanup", (PyCFunction)cleanup_wc, METH_VARARGS|METH_KEYWORDS, "cleanup(path, diff3_cmd=None, cancel_func=None)\n" },
2439 { "ensure_adm", (PyCFunction)ensure_adm, METH_KEYWORDS|METH_VARARGS,
2440 "ensure_adm(path, uuid, url, repos=None, rev=None)" },
2441 { "get_adm_dir", (PyCFunction)get_adm_dir, METH_NOARGS,
2442 "get_adm_dir() -> name" },
2443 { "set_adm_dir", (PyCFunction)set_adm_dir, METH_VARARGS,
2444 "set_adm_dir(name)" },
2445 { "get_pristine_copy_path", get_pristine_copy_path, METH_VARARGS,
2446 "get_pristine_copy_path(path) -> path" },
2447 { "get_pristine_contents", get_pristine_contents, METH_VARARGS,
2448 "get_pristine_contents(path) -> stream" },
2449 { "is_adm_dir", is_adm_dir, METH_VARARGS,
2450 "is_adm_dir(name) -> bool" },
2451 { "is_normal_prop", is_normal_prop, METH_VARARGS,
2452 "is_normal_prop(name) -> bool" },
2453 { "is_entry_prop", is_entry_prop, METH_VARARGS,
2454 "is_entry_prop(name) -> bool" },
2455 { "is_wc_prop", is_wc_prop, METH_VARARGS,
2456 "is_wc_prop(name) -> bool" },
2457 { "revision_status", (PyCFunction)revision_status, METH_KEYWORDS|METH_VARARGS, "revision_status(wc_path, trail_url=None, committed=False, cancel_func=None) -> (min_rev, max_rev, switched, modified)" },
2458 { "version", (PyCFunction)version, METH_NOARGS,
2459 "version() -> (major, minor, patch, tag)\n\n"
2460 "Version of libsvn_wc currently used."
2462 { "api_version", (PyCFunction)api_version, METH_NOARGS,
2463 "api_version() -> (major, minor, patch, tag)\n\n"
2464 "Version of libsvn_wc Subvertpy was compiled against."
2466 { "match_ignore_list", (PyCFunction)match_ignore_list, METH_VARARGS,
2467 "match_ignore_list(str, patterns) -> bool" },
2468 { "get_actual_target", (PyCFunction)get_actual_target, METH_VARARGS,
2469 "get_actual_target(path) -> (anchor, target)" },
2477 if (PyType_Ready(&Entry_Type) < 0)
2480 if (PyType_Ready(&Adm_Type) < 0)
2483 if (PyType_Ready(&Editor_Type) < 0)
2486 if (PyType_Ready(&FileEditor_Type) < 0)
2489 if (PyType_Ready(&DirectoryEditor_Type) < 0)
2492 if (PyType_Ready(&TxDeltaWindowHandler_Type) < 0)
2495 if (PyType_Ready(&Stream_Type) < 0)
2498 if (PyType_Ready(&CommittedQueue_Type) < 0)
2505 mod = Py_InitModule3("wc", wc_methods, "Working Copies");
2509 PyModule_AddIntConstant(mod, "SCHEDULE_NORMAL", 0);
2510 PyModule_AddIntConstant(mod, "SCHEDULE_ADD", 1);
2511 PyModule_AddIntConstant(mod, "SCHEDULE_DELETE", 2);
2512 PyModule_AddIntConstant(mod, "SCHEDULE_REPLACE", 3);
2514 #if ONLY_SINCE_SVN(1, 5)
2515 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_POSTPONE",
2516 svn_wc_conflict_choose_postpone);
2517 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_BASE",
2518 svn_wc_conflict_choose_base);
2519 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_THEIRS_FULL",
2520 svn_wc_conflict_choose_theirs_full);
2521 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MINE_FULL",
2522 svn_wc_conflict_choose_mine_full);
2523 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_THEIRS_CONFLICT",
2524 svn_wc_conflict_choose_theirs_conflict);
2525 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MINE_CONFLICT",
2526 svn_wc_conflict_choose_mine_conflict);
2527 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MERGED",
2528 svn_wc_conflict_choose_merged);
2531 PyModule_AddIntConstant(mod, "STATUS_NONE", svn_wc_status_none);
2532 PyModule_AddIntConstant(mod, "STATUS_UNVERSIONED", svn_wc_status_unversioned);
2533 PyModule_AddIntConstant(mod, "STATUS_NORMAL", svn_wc_status_normal);
2534 PyModule_AddIntConstant(mod, "STATUS_ADDED", svn_wc_status_added);
2535 PyModule_AddIntConstant(mod, "STATUS_MISSING", svn_wc_status_missing);
2536 PyModule_AddIntConstant(mod, "STATUS_DELETED", svn_wc_status_deleted);
2537 PyModule_AddIntConstant(mod, "STATUS_REPLACED", svn_wc_status_replaced);
2538 PyModule_AddIntConstant(mod, "STATUS_MODIFIED", svn_wc_status_modified);
2539 PyModule_AddIntConstant(mod, "STATUS_MERGED", svn_wc_status_merged);
2540 PyModule_AddIntConstant(mod, "STATUS_CONFLICTED", svn_wc_status_conflicted);
2541 PyModule_AddIntConstant(mod, "STATUS_IGNORED", svn_wc_status_ignored);
2542 PyModule_AddIntConstant(mod, "STATUS_OBSTRUCTED", svn_wc_status_obstructed);
2543 PyModule_AddIntConstant(mod, "STATUS_EXTERNAL", svn_wc_status_external);
2544 PyModule_AddIntConstant(mod, "STATUS_INCOMPLETE", svn_wc_status_incomplete);
2546 PyModule_AddIntConstant(mod, "TRANSLATE_FROM_NF", SVN_WC_TRANSLATE_FROM_NF);
2547 PyModule_AddIntConstant(mod, "TRANSLATE_TO_NF", SVN_WC_TRANSLATE_TO_NF);
2548 PyModule_AddIntConstant(mod, "TRANSLATE_FORCE_EOL_REPAIR", SVN_WC_TRANSLATE_FORCE_EOL_REPAIR);
2549 PyModule_AddIntConstant(mod, "TRANSLATE_NO_OUTPUT_CLEANUP", SVN_WC_TRANSLATE_NO_OUTPUT_CLEANUP);
2550 PyModule_AddIntConstant(mod, "TRANSLATE_FORCE_COPY", SVN_WC_TRANSLATE_FORCE_COPY);
2551 PyModule_AddIntConstant(mod, "TRANSLATE_USE_GLOBAL_TMP", SVN_WC_TRANSLATE_USE_GLOBAL_TMP);
2553 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_POSTPONE", svn_wc_conflict_choose_postpone);
2554 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_BASE", svn_wc_conflict_choose_base);
2555 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_THEIRS_FULL", svn_wc_conflict_choose_theirs_full);
2556 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MINE_FULL", svn_wc_conflict_choose_mine_full);
2557 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_THEIRS_CONFLICT", svn_wc_conflict_choose_theirs_conflict);
2558 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MINE_CONFLICT", svn_wc_conflict_choose_mine_conflict);
2559 PyModule_AddIntConstant(mod, "CONFLICT_CHOOSE_MERGED", svn_wc_conflict_choose_merged);
2561 PyModule_AddObject(mod, "WorkingCopy", (PyObject *)&Adm_Type);
2562 Py_INCREF(&Adm_Type);
2564 PyModule_AddObject(mod, "CommittedQueue", (PyObject *)&CommittedQueue_Type);
2565 Py_INCREF(&CommittedQueue_Type);