2 * Copyright © 2008 Jelmer Vernooij <jelmer@jelmer.uk>
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <apr_general.h>
23 #include <svn_props.h>
24 #include <structmember.h>
36 #if ONLY_SINCE_SVN(1, 5)
37 #define REPORTER_T svn_ra_reporter3_t
39 #define REPORTER_T svn_ra_reporter2_t
42 static PyTypeObject Entry_Type;
43 static PyTypeObject Status_Type;
44 static PyTypeObject Adm_Type;
46 static PyObject *py_entry(const svn_wc_entry_t *entry);
47 static PyObject *py_status(const svn_wc_status2_t *status);
49 #if ONLY_BEFORE_SVN(1, 5)
50 struct svn_wc_committed_queue_t
53 apr_array_header_t *queue;
54 svn_boolean_t have_recursive;
58 typedef struct svn_wc_committed_queue_t svn_wc_committed_queue_t;
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;
74 svn_wc_committed_queue_t *svn_wc_committed_queue_create(apr_pool_t *pool)
76 svn_wc_committed_queue_t *q;
78 q = apr_palloc(pool, sizeof(*q));
80 q->queue = apr_array_make(pool, 1, sizeof(committed_queue_item_t *));
81 q->have_recursive = FALSE;
89 svn_error_t *svn_wc_queue_committed(svn_wc_committed_queue_t **queue,
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)
99 committed_queue_item_t *cqi;
101 (*queue)->have_recursive |= recurse;
103 /* Use the same pool as the one QUEUE was allocated in,
104 to prevent lifetime issues. Intermediate operations
105 should use SCRATCH_POOL. */
107 /* Add to the array with paths and options */
108 cqi = apr_palloc((*queue)->pool, sizeof(*cqi));
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;
116 APR_ARRAY_PUSH((*queue)->queue, committed_queue_item_t *) = cqi;
126 svn_wc_committed_queue_t *queue;
127 } CommittedQueueObject;
128 static PyTypeObject CommittedQueue_Type;
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)
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);
139 py_lock_token = PyString_FromString(lock_token);
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);
145 PyGILState_Release(state);
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)
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);
157 py_lock_token = PyString_FromString(lock_token);
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);
163 PyGILState_Release(state);
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)
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);
177 py_lock_token = PyString_FromString(lock_token);
179 ret = PyObject_CallMethod(self, "set_path", "slbOi", path, revision, start_empty, py_lock_token, svn_depth_infinity);
180 CB_CHECK_PYRETVAL(ret);
182 PyGILState_Release(state);
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)
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);
194 py_lock_token = PyString_FromString(lock_token);
196 ret = PyObject_CallMethod(self, "link_path", "sslbOi", path, url, revision, start_empty, py_lock_token, svn_depth_infinity);
197 CB_CHECK_PYRETVAL(ret);
199 PyGILState_Release(state);
206 static svn_error_t *py_ra_report_delete_path(void *baton, const char *path, apr_pool_t *pool)
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);
213 PyGILState_Release(state);
217 static svn_error_t *py_ra_report_finish(void *baton, apr_pool_t *pool)
219 PyObject *self = (PyObject *)baton, *ret;
220 PyGILState_STATE state = PyGILState_Ensure();
221 ret = PyObject_CallMethod(self, "finish", "");
222 CB_CHECK_PYRETVAL(ret);
224 PyGILState_Release(state);
228 static svn_error_t *py_ra_report_abort(void *baton, apr_pool_t *pool)
230 PyObject *self = (PyObject *)baton, *ret;
231 PyGILState_STATE state = PyGILState_Ensure();
232 ret = PyObject_CallMethod(self, "abort", "");
233 CB_CHECK_PYRETVAL(ret);
235 PyGILState_Release(state);
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,
250 * Get runtime libsvn_wc version information.
252 * :return: tuple with major, minor, patch version number and tag.
254 static PyObject *version(PyObject *self)
256 const svn_version_t *ver = svn_wc_version();
257 return Py_BuildValue("(iiis)", ver->major, ver->minor,
258 ver->patch, ver->tag);
261 SVN_VERSION_DEFINE(svn_api_version);
264 * Get compile-time libsvn_wc version information.
266 * :return: tuple with major, minor, patch version number and tag.
268 static PyObject *api_version(PyObject *self)
270 const svn_version_t *ver = &svn_api_version;
271 return Py_BuildValue("(iiis)", ver->major, ver->minor,
272 ver->patch, ver->tag);
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)
278 PyObject *callbacks = (PyObject *)walk_baton;
279 PyGILState_STATE state = PyGILState_Ensure();
280 if (PyTuple_Check(callbacks)) {
281 fn = PyTuple_GET_ITEM(callbacks, 0);
283 fn = (PyObject *)walk_baton;
285 ret = PyObject_CallFunction(fn, "sO", path, py_entry(entry));
286 CB_CHECK_PYRETVAL(ret);
288 PyGILState_Release(state);
292 #if ONLY_SINCE_SVN(1, 5)
294 svn_error_t *py_wc_handle_error(const char *path, svn_error_t *err, void *walk_baton, apr_pool_t *pool)
298 PyGILState_STATE state;
299 PyObject *callbacks = (PyObject *)walk_baton;
300 if (PyTuple_Check(callbacks)) {
301 fn = PyTuple_GET_ITEM(callbacks, 1);
305 state = PyGILState_Ensure();
306 py_err = PyErr_NewSubversionException(err);
307 ret = PyObject_CallFunction(fn, "sO", path, py_err);
308 CB_CHECK_PYRETVAL(ret);
310 PyGILState_Release(state);
315 static svn_wc_entry_callbacks2_t py_wc_entry_callbacks2 = {
320 static svn_wc_entry_callbacks_t py_wc_entry_callbacks = {
327 void py_wc_notify_func(void *baton, const svn_wc_notify_t *notify, apr_pool_t *pool)
329 PyObject *func = baton, *ret;
333 if (notify->err != NULL) {
334 PyObject *excval = PyErr_NewSubversionException(notify->err);
335 ret = PyObject_CallFunction(func, "O", excval);
338 /* If ret was NULL, the cancel func should abort the operation. */
345 svn_wc_entry_t entry;
348 static void entry_dealloc(PyObject *self)
350 apr_pool_destroy(((EntryObject *)self)->pool);
354 static PyMemberDef entry_members[] = {
355 { "name", T_STRING, offsetof(EntryObject, entry.name), READONLY,
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,
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" },
384 static PyTypeObject Entry_Type = {
385 PyObject_HEAD_INIT(NULL) 0,
386 "wc.Entry", /* const char *tp_name; For printing, in format "<module>.<name>" */
388 0,/* Py_ssize_t tp_basicsize, tp_itemsize; For allocation */
390 /* Methods to implement standard operations */
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; */
399 /* Method suites for standard classes */
401 NULL, /* PyNumberMethods *tp_as_number; */
402 NULL, /* PySequenceMethods *tp_as_sequence; */
403 NULL, /* PyMappingMethods *tp_as_mapping; */
405 /* More standard operations (here for binary compatibility) */
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; */
413 /* Functions to access object as input/output buffer */
414 NULL, /* PyBufferProcs *tp_as_buffer; */
416 /* Flags to define presence of optional/expanded features */
417 0, /* long tp_flags; */
419 NULL, /* const char *tp_doc; Documentation string */
421 /* Assigned meaning in release 2.0 */
422 /* call function for all accessible objects */
423 NULL, /* traverseproc tp_traverse; */
425 /* delete references to contained objects */
426 NULL, /* inquiry tp_clear; */
428 /* Assigned meaning in release 2.1 */
429 /* rich comparisons */
430 NULL, /* richcmpfunc tp_richcompare; */
432 /* weak reference enabler */
433 0, /* Py_ssize_t tp_weaklistoffset; */
435 /* Added in release 2.2 */
437 NULL, /* getiterfunc tp_iter; */
438 NULL, /* iternextfunc tp_iternext; */
440 /* Attribute descriptor and subclassing stuff */
441 NULL, /* struct PyMethodDef *tp_methods; */
442 entry_members, /* struct PyMemberDef *tp_members; */
446 static PyObject *py_entry(const svn_wc_entry_t *entry)
450 ret = PyObject_New(EntryObject, &Entry_Type);
454 ret->pool = Pool(NULL);
455 if (ret->pool == NULL)
457 ret->entry = *svn_wc_entry_dup(entry, ret->pool);
458 return (PyObject *)ret;
464 svn_wc_status2_t status;
468 static void status_dealloc(PyObject *self)
470 apr_pool_destroy(((StatusObject *)self)->pool);
471 Py_XDECREF(((StatusObject *)self)->entry);
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.", },
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 */
501 /* Methods to implement standard operations */
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; */
510 /* Method suites for standard classes */
512 NULL, /* PyNumberMethods *tp_as_number; */
513 NULL, /* PySequenceMethods *tp_as_sequence; */
514 NULL, /* PyMappingMethods *tp_as_mapping; */
516 /* More standard operations (here for binary compatibility) */
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; */
524 /* Functions to access object as input/output buffer */
525 NULL, /* PyBufferProcs *tp_as_buffer; */
527 /* Flags to define presence of optional/expanded features */
528 0, /* long tp_flags; */
530 "Working copy status object", /* const char *tp_doc; Documentation string */
532 /* Assigned meaning in release 2.0 */
533 /* call function for all accessible objects */
534 NULL, /* traverseproc tp_traverse; */
536 /* delete references to contained objects */
537 NULL, /* inquiry tp_clear; */
539 /* Assigned meaning in release 2.1 */
540 /* rich comparisons */
541 NULL, /* richcmpfunc tp_richcompare; */
543 /* weak reference enabler */
544 0, /* Py_ssize_t tp_weaklistoffset; */
546 /* Added in release 2.2 */
548 NULL, /* getiterfunc tp_iter; */
549 NULL, /* iternextfunc tp_iternext; */
551 /* Attribute descriptor and subclassing stuff */
552 NULL, /* struct PyMethodDef *tp_methods; */
553 status_members, /* struct PyMemberDef *tp_members; */
557 static PyObject *py_status(const svn_wc_status2_t *status)
560 svn_wc_status2_t *dup_status;
562 ret = PyObject_New(StatusObject, &Status_Type);
566 ret->pool = Pool(NULL);
567 if (ret->pool == NULL) {
572 dup_status = svn_wc_dup_status2(status, ret->pool);
573 if (dup_status == NULL)
578 ret->status = *dup_status;
580 ret->entry = py_entry(ret->status.entry);
581 return (PyObject *)ret;
586 svn_wc_adm_access_t *adm;
590 #define ADM_CHECK_CLOSED(adm_obj) \
591 if (adm_obj->adm == NULL) { \
592 PyErr_SetString(PyExc_RuntimeError, "WorkingCopy instance already closed"); \
596 static PyObject *adm_init(PyTypeObject *self, PyObject *args, PyObject *kwargs)
598 PyObject *associated;
600 bool write_lock=false;
602 svn_wc_adm_access_t *parent_wc;
605 char *kwnames[] = { "associated", "path", "write_lock", "depth", NULL };
607 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|bi", kwnames,
608 &associated, &path, &write_lock, &depth))
611 ret = PyObject_New(AdmObject, &Adm_Type);
615 ret->pool = Pool(NULL);
616 if (ret->pool == NULL)
618 if (associated == Py_None) {
621 parent_wc = ((AdmObject *)associated)->adm;
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,
631 handle_svn_error(err);
632 svn_error_clear(err);
637 return (PyObject *)ret;
640 static PyObject *adm_access_path(PyObject *self)
642 AdmObject *admobj = (AdmObject *)self;
643 ADM_CHECK_CLOSED(admobj);
644 return PyString_FromString(svn_wc_adm_access_path(admobj->adm));
647 static PyObject *adm_locked(PyObject *self)
649 AdmObject *admobj = (AdmObject *)self;
650 ADM_CHECK_CLOSED(admobj);
651 return PyBool_FromLong(svn_wc_adm_locked(admobj->adm));
654 static PyObject *adm_prop_get(PyObject *self, PyObject *args)
657 AdmObject *admobj = (AdmObject *)self;
658 const svn_string_t *value;
659 apr_pool_t *temp_pool;
662 if (!PyArg_ParseTuple(args, "ss", &name, &path))
665 ADM_CHECK_CLOSED(admobj);
667 temp_pool = Pool(NULL);
668 if (temp_pool == 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) {
675 ret = PyString_FromStringAndSize(value->data, value->len);
677 apr_pool_destroy(temp_pool);
681 static PyObject *adm_prop_set(PyObject *self, PyObject *args)
683 char *name, *value, *path;
684 AdmObject *admobj = (AdmObject *)self;
685 bool skip_checks=false;
686 apr_pool_t *temp_pool;
688 svn_string_t *cvalue;
689 PyObject *notify_func = Py_None;
691 if (!PyArg_ParseTuple(args, "sz#s|bO", &name, &value, &vallen, &path, &skip_checks,
695 ADM_CHECK_CLOSED(admobj);
697 temp_pool = Pool(NULL);
698 if (temp_pool == NULL)
703 cvalue = svn_string_ncreate(value, vallen, temp_pool);
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,
710 RUN_SVN_WITH_POOL(temp_pool, svn_wc_prop_set2(name, cvalue, path, admobj->adm,
711 skip_checks, temp_pool));
713 apr_pool_destroy(temp_pool);
718 static PyObject *adm_entries_read(PyObject *self, PyObject *args)
721 AdmObject *admobj = (AdmObject *)self;
722 apr_pool_t *temp_pool;
723 bool show_hidden=false;
724 apr_hash_index_t *idx;
727 svn_wc_entry_t *entry;
728 PyObject *py_entries, *obj;
730 if (!PyArg_ParseTuple(args, "|b", &show_hidden))
733 ADM_CHECK_CLOSED(admobj);
735 temp_pool = Pool(NULL);
736 if (temp_pool == 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);
745 idx = apr_hash_first(temp_pool, entries);
746 while (idx != NULL) {
747 apr_hash_this(idx, (const void **)&key, &klen, (void **)&entry);
752 obj = py_entry(entry);
754 PyDict_SetItemString(py_entries, key, obj);
756 idx = apr_hash_next(idx);
758 apr_pool_destroy(temp_pool);
762 static PyObject *adm_walk_entries(PyObject *self, PyObject *args)
766 bool show_hidden=false;
767 apr_pool_t *temp_pool;
768 AdmObject *admobj = (AdmObject *)self;
769 svn_depth_t depth = svn_depth_infinity;
771 if (!PyArg_ParseTuple(args, "sO|bi", &path, &callbacks, &show_hidden, &depth))
774 ADM_CHECK_CLOSED(admobj);
776 temp_pool = Pool(NULL);
777 if (temp_pool == 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,
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);
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,
798 apr_pool_destroy(temp_pool);
803 static PyObject *adm_entry(PyObject *self, PyObject *args)
806 bool show_hidden=false;
807 apr_pool_t *temp_pool;
808 AdmObject *admobj = (AdmObject *)self;
809 const svn_wc_entry_t *entry;
812 if (!PyArg_ParseTuple(args, "s|b", &path, &show_hidden))
815 ADM_CHECK_CLOSED(admobj);
817 temp_pool = Pool(NULL);
818 if (temp_pool == NULL)
820 RUN_SVN_WITH_POOL(temp_pool, svn_wc_entry(&entry, svn_path_canonicalize(path, temp_pool), admobj->adm, show_hidden, temp_pool));
823 PyErr_Format(PyExc_KeyError, "No such entry '%s'", path);
826 ret = py_entry(entry);
829 apr_pool_destroy(temp_pool);
833 static PyObject *adm_get_prop_diffs(PyObject *self, PyObject *args)
836 apr_pool_t *temp_pool;
837 apr_array_header_t *propchanges;
838 apr_hash_t *original_props;
839 AdmObject *admobj = (AdmObject *)self;
842 PyObject *py_propchanges, *py_orig_props, *pyval;
844 if (!PyArg_ParseTuple(args, "s", &path))
847 ADM_CHECK_CLOSED(admobj);
849 temp_pool = Pool(NULL);
850 if (temp_pool == 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);
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);
864 pyval = Py_BuildValue("(sO)", el.name, Py_None);
866 apr_pool_destroy(temp_pool);
867 Py_DECREF(py_propchanges);
870 if (PyList_SetItem(py_propchanges, i, pyval) != 0) {
871 Py_DECREF(py_propchanges);
872 apr_pool_destroy(temp_pool);
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);
882 return Py_BuildValue("(NN)", py_propchanges, py_orig_props);
885 static PyObject *adm_add(PyObject *self, PyObject *args, PyObject *kwargs)
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;
895 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zlOi", kwnames, &path,
896 ©from_url, ©from_rev, ¬ify_func, &depth))
899 ADM_CHECK_CLOSED(admobj);
901 temp_pool = Pool(NULL);
902 if (temp_pool == NULL)
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,
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);
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,
925 apr_pool_destroy(temp_pool);
930 static PyObject *adm_copy(PyObject *self, PyObject *args)
932 AdmObject *admobj = (AdmObject *)self;
934 PyObject *notify_func=Py_None;
935 apr_pool_t *temp_pool;
937 if (!PyArg_ParseTuple(args, "ss|O", &src, &dst, ¬ify_func))
940 ADM_CHECK_CLOSED(admobj);
942 temp_pool = Pool(NULL);
943 if (temp_pool == 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,
949 apr_pool_destroy(temp_pool);
954 static PyObject *adm_delete(PyObject *self, PyObject *args, PyObject *kwargs)
956 AdmObject *admobj = (AdmObject *)self;
957 apr_pool_t *temp_pool;
958 char *kwnames[] = { "path", "notify_func", "keep_local",
961 PyObject *notify_func=Py_None;
962 bool keep_local = false;
964 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|Ob:delete", kwnames,
965 &path, ¬ify_func, &keep_local))
968 ADM_CHECK_CLOSED(admobj);
970 temp_pool = Pool(NULL);
971 if (temp_pool == NULL)
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,
982 PyErr_SetString(PyExc_NotImplementedError,
983 "keep_local not supported on Subversion < 1.5");
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,
992 apr_pool_destroy(temp_pool);
997 static PyObject *adm_crawl_revisions(PyObject *self, PyObject *args, PyObject *kwargs)
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 };
1010 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|bbbObb", kwnames, &path,
1011 &reporter, &restore_files, &recurse, &use_commit_times,
1012 ¬ify_func, &depth_compatibility_trick, &honor_depth_exclude))
1015 ADM_CHECK_CLOSED(admobj);
1017 temp_pool = Pool(NULL);
1018 if (temp_pool == 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));
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));
1043 apr_pool_destroy(temp_pool);
1048 static void wc_done_handler(void *self)
1050 AdmObject *admobj = (AdmObject *)self;
1055 static PyObject *adm_get_update_editor(PyObject *self, PyObject *args)
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;
1065 svn_revnum_t *latest_revnum;
1067 svn_boolean_t allow_unver_obstructions = FALSE;
1068 svn_boolean_t depth_is_sticky = FALSE;
1070 if (!PyArg_ParseTuple(args, "s|bbOzbb", &target, &use_commit_times,
1071 &recurse, ¬ify_func, &diff3_cmd, &depth_is_sticky,
1072 &allow_unver_obstructions))
1075 ADM_CHECK_CLOSED(admobj);
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,
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);
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);
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,
1114 Py_END_ALLOW_THREADS
1116 handle_svn_error(err);
1117 svn_error_clear(err);
1118 apr_pool_destroy(pool);
1122 return new_editor_object(NULL, editor, edit_baton, pool, &Editor_Type,
1123 wc_done_handler, admobj, NULL);
1126 static bool py_dict_to_wcprop_changes(PyObject *dict, apr_pool_t *pool, apr_array_header_t **ret)
1128 PyObject *key, *val;
1131 if (dict == Py_None) {
1136 if (!PyDict_Check(dict)) {
1137 PyErr_SetString(PyExc_TypeError, "Expected dictionary with property changes");
1141 *ret = apr_array_make(pool, PyDict_Size(dict), sizeof(char *));
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) {
1149 prop->value = svn_string_ncreate(PyString_AsString(val), PyString_Size(val), pool);
1151 APR_ARRAY_PUSH(*ret, svn_prop_t *) = prop;
1157 static PyObject *adm_has_binary_prop(PyObject *self, PyObject *args)
1160 svn_boolean_t binary;
1161 AdmObject *admobj = (AdmObject *)self;
1162 apr_pool_t *temp_pool;
1164 if (!PyArg_ParseTuple(args, "s", &path))
1167 ADM_CHECK_CLOSED(admobj);
1169 temp_pool = Pool(NULL);
1170 if (temp_pool == NULL)
1173 RUN_SVN_WITH_POOL(temp_pool, svn_wc_has_binary_prop(&binary, path, admobj->adm, temp_pool));
1175 apr_pool_destroy(temp_pool);
1177 return PyBool_FromLong(binary);
1180 static PyObject *adm_process_committed(PyObject *self, PyObject *args, PyObject *kwargs)
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;
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 };
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))
1201 PyErr_WarnEx(PyExc_DeprecationWarning, "process_committed is deprecated. Use process_committed_queue instead.", 2);
1204 ADM_CHECK_CLOSED(admobj);
1206 temp_pool = Pool(NULL);
1207 if (temp_pool == NULL)
1210 if (!py_dict_to_wcprop_changes(py_wcprop_changes, temp_pool, &wcprop_changes)) {
1211 apr_pool_destroy(temp_pool);
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));
1221 if (remove_changelist) {
1222 PyErr_SetString(PyExc_NotImplementedError, "remove_changelist only supported in svn < 1.6");
1223 apr_pool_destroy(temp_pool);
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));
1231 apr_pool_destroy(temp_pool);
1236 static PyObject *adm_close(PyObject *self)
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);
1246 Py_BEGIN_ALLOW_THREADS
1247 svn_wc_adm_close(admobj->adm);
1249 Py_END_ALLOW_THREADS
1256 static void adm_dealloc(PyObject *self)
1258 apr_pool_destroy(((AdmObject *)self)->pool);
1262 static PyObject *adm_repr(PyObject *self)
1264 AdmObject *admobj = (AdmObject *)self;
1266 if (admobj->adm == NULL) {
1267 return PyString_FromFormat("<wc.WorkingCopy (closed) at 0x%p>", admobj);
1269 return PyString_FromFormat("<wc.WorkingCopy at '%s'>",
1270 svn_wc_adm_access_path(admobj->adm));
1274 static PyObject *adm_remove_lock(PyObject *self, PyObject *args)
1277 AdmObject *admobj = (AdmObject *)self;
1278 apr_pool_t *temp_pool;
1280 if (!PyArg_ParseTuple(args, "s", &path))
1283 ADM_CHECK_CLOSED(admobj);
1285 temp_pool = Pool(NULL);
1286 if (temp_pool == NULL)
1289 RUN_SVN_WITH_POOL(temp_pool, svn_wc_remove_lock(path, admobj->adm, temp_pool))
1291 apr_pool_destroy(temp_pool);
1296 static PyObject *get_ancestry(PyObject *self, PyObject *args)
1301 apr_pool_t *temp_pool;
1302 AdmObject *admobj = (AdmObject *)self;
1304 if (!PyArg_ParseTuple(args, "s", &path))
1307 ADM_CHECK_CLOSED(admobj);
1309 temp_pool = Pool(NULL);
1310 if (temp_pool == NULL)
1313 RUN_SVN_WITH_POOL(temp_pool, svn_wc_get_ancestry(&url, &rev, path, admobj->adm, temp_pool));
1315 apr_pool_destroy(temp_pool);
1317 return Py_BuildValue("(si)", url, rev);
1320 static PyObject *maybe_set_repos_root(PyObject *self, PyObject *args)
1323 apr_pool_t *temp_pool;
1324 AdmObject *admobj = (AdmObject *)self;
1326 if (!PyArg_ParseTuple(args, "ss", &path, &repos))
1329 ADM_CHECK_CLOSED(admobj);
1331 temp_pool = Pool(NULL);
1332 if (temp_pool == NULL)
1335 RUN_SVN_WITH_POOL(temp_pool, svn_wc_maybe_set_repos_root(admobj->adm, path, repos, temp_pool));
1340 static PyObject *add_repos_file(PyObject *self, PyObject *args, PyObject *kwargs)
1342 char *kwnames[] = { "dst_path", "new_base_contents", "new_contents",
1343 "new_base_props", "new_props", "copyfrom_url", "copyfrom_rev",
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;
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, ©from_url, ©from_rev, ¬ify))
1359 ADM_CHECK_CLOSED(admobj);
1361 temp_pool = Pool(NULL);
1362 if (temp_pool == NULL)
1365 new_base_props = prop_dict_to_hash(temp_pool, py_new_base_props);
1367 new_props = prop_dict_to_hash(temp_pool, py_new_props);
1369 new_base_contents = new_py_stream(temp_pool, py_new_base_contents);
1371 new_contents = new_py_stream(temp_pool, py_new_contents);
1373 #if ONLY_SINCE_SVN(1, 6)
1374 RUN_SVN_WITH_POOL(temp_pool, svn_wc_add_repos_file3(dst_path, admobj->adm,
1379 copyfrom_url, copyfrom_rev,
1380 py_cancel_check, NULL,
1381 py_wc_notify_func, notify, temp_pool));
1383 PyErr_SetString(PyExc_NotImplementedError,
1384 "add_repos_file3 not supported on svn < 1.6");
1385 apr_pool_destroy(temp_pool);
1388 apr_pool_destroy(temp_pool);
1393 static PyObject *mark_missing_deleted(PyObject *self, PyObject *args)
1396 AdmObject *admobj = (AdmObject *)self;
1397 apr_pool_t *temp_pool;
1399 if (!PyArg_ParseTuple(args, "s", &path))
1402 ADM_CHECK_CLOSED(admobj);
1404 temp_pool = Pool(NULL);
1405 if (temp_pool == NULL)
1408 RUN_SVN_WITH_POOL(temp_pool, svn_wc_mark_missing_deleted(path, admobj->adm, temp_pool));
1410 apr_pool_destroy(temp_pool);
1415 static PyObject *remove_from_revision_control(PyObject *self, PyObject *args)
1418 svn_boolean_t destroy_wf = FALSE, instant_error = FALSE;
1419 AdmObject *admobj = (AdmObject *)self;
1420 apr_pool_t *temp_pool;
1422 if (!PyArg_ParseTuple(args, "s|bb", &name, &destroy_wf, &instant_error))
1425 ADM_CHECK_CLOSED(admobj);
1427 temp_pool = Pool(NULL);
1428 if (temp_pool == NULL)
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));
1435 apr_pool_destroy(temp_pool);
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)
1443 PyObject *py_validator = baton, *ret;
1445 if (py_validator == Py_None) {
1449 ret = PyObject_CallFunction(py_validator, "sss", uuid, url, root_url);
1451 return py_svn_error();
1461 static svn_error_t *wc_validator2(void *baton, const char *uuid, const char *url, svn_boolean_t root, apr_pool_t *pool)
1463 PyObject *py_validator = baton, *ret;
1465 if (py_validator == Py_None) {
1469 ret = PyObject_CallFunction(py_validator, "ssO", uuid, url, Py_None);
1471 return py_svn_error();
1481 static PyObject *relocate(PyObject *self, PyObject *args)
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;
1489 if (!PyArg_ParseTuple(args, "sss|bO:relocate", &path, &from, &to, &recurse,
1493 ADM_CHECK_CLOSED(admobj);
1495 temp_pool = Pool(NULL);
1496 if (temp_pool == NULL)
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));
1502 RUN_SVN_WITH_POOL(temp_pool, svn_wc_relocate2(path, admobj->adm, from, to, recurse, wc_validator2, py_validator, temp_pool));
1505 apr_pool_destroy(temp_pool);
1510 static PyObject *crop_tree(PyObject *self, PyObject *args)
1515 apr_pool_t *temp_pool;
1516 AdmObject *admobj = (AdmObject *)self;
1518 if (!PyArg_ParseTuple(args, "si|O", &target, &depth, ¬ify))
1521 ADM_CHECK_CLOSED(admobj);
1523 #if ONLY_SINCE_SVN(1, 6)
1524 temp_pool = Pool(NULL);
1525 if (temp_pool == NULL)
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));
1532 apr_pool_destroy(temp_pool);
1536 PyErr_SetString(PyExc_NotImplementedError,
1537 "crop_tree only available on subversion < 1.6");
1542 static PyObject *translated_stream(PyObject *self, PyObject *args)
1544 char *path, *versioned_file;
1546 svn_stream_t *stream;
1547 AdmObject *admobj = (AdmObject *)self;
1548 apr_pool_t *stream_pool;
1551 if (!PyArg_ParseTuple(args, "ssi", &path, &versioned_file, &flags))
1554 ADM_CHECK_CLOSED(admobj);
1556 #if ONLY_SINCE_SVN(1, 5)
1557 stream_pool = Pool(NULL);
1558 if (stream_pool == NULL)
1561 RUN_SVN_WITH_POOL(stream_pool,
1562 svn_wc_translated_stream(&stream, path, versioned_file, admobj->adm,
1563 flags, stream_pool));
1565 ret = PyObject_New(StreamObject, &Stream_Type);
1569 ret->pool = stream_pool;
1570 ret->closed = FALSE;
1571 ret->stream = stream;
1573 return (PyObject *)ret;
1575 PyErr_SetString(PyExc_NotImplementedError,
1576 "translated_stream() is only available on Subversion >= 1.5");
1581 static PyObject *adm_text_modified(PyObject *self, PyObject *args)
1584 svn_boolean_t force_comparison = FALSE;
1585 apr_pool_t *temp_pool;
1587 AdmObject *admobj = (AdmObject *)self;
1589 if (!PyArg_ParseTuple(args, "s|b", &path, &force_comparison))
1592 ADM_CHECK_CLOSED(admobj);
1594 temp_pool = Pool(NULL);
1595 if (temp_pool == NULL)
1598 RUN_SVN_WITH_POOL(temp_pool,
1599 svn_wc_text_modified_p(&ret, path, force_comparison, admobj->adm,
1602 apr_pool_destroy(temp_pool);
1604 return PyBool_FromLong(ret);
1607 static PyObject *adm_props_modified(PyObject *self, PyObject *args)
1610 apr_pool_t *temp_pool;
1612 AdmObject *admobj = (AdmObject *)self;
1614 if (!PyArg_ParseTuple(args, "s", &path))
1617 ADM_CHECK_CLOSED(admobj);
1619 temp_pool = Pool(NULL);
1620 if (temp_pool == NULL)
1623 RUN_SVN_WITH_POOL(temp_pool,
1624 svn_wc_props_modified_p(&ret, path, admobj->adm, temp_pool));
1626 apr_pool_destroy(temp_pool);
1628 return PyBool_FromLong(ret);
1631 static PyObject *adm_process_committed_queue(PyObject *self, PyObject *args)
1633 apr_pool_t *temp_pool;
1634 AdmObject *admobj = (AdmObject *)self;
1635 svn_revnum_t revnum;
1636 char *date, *author;
1637 CommittedQueueObject *py_queue;
1639 if (!PyArg_ParseTuple(args, "O!lss", &CommittedQueue_Type, &py_queue,
1640 &revnum, &date, &author))
1643 ADM_CHECK_CLOSED(admobj);
1645 temp_pool = Pool(NULL);
1646 if (temp_pool == NULL)
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));
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 *);
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));
1664 apr_pool_destroy(temp_pool);
1669 static PyObject *get_actual_target(PyObject *self, PyObject *args)
1672 const char *anchor = NULL, *target = NULL;
1673 apr_pool_t *temp_pool;
1676 if (!PyArg_ParseTuple(args, "s", &path))
1679 temp_pool = Pool(NULL);
1680 if (temp_pool == NULL)
1683 RUN_SVN_WITH_POOL(temp_pool,
1684 svn_wc_get_actual_target(svn_path_canonicalize(path, temp_pool),
1685 &anchor, &target, temp_pool));
1687 ret = Py_BuildValue("(ss)", anchor, target);
1689 apr_pool_destroy(temp_pool);
1694 static PyObject *is_wc_root(PyObject *self, PyObject *args)
1697 svn_boolean_t wc_root;
1698 apr_pool_t *temp_pool;
1699 AdmObject *admobj = (AdmObject *)self;
1701 if (!PyArg_ParseTuple(args, "s", &path))
1704 ADM_CHECK_CLOSED(admobj);
1706 temp_pool = Pool(NULL);
1707 if (temp_pool == NULL)
1710 RUN_SVN_WITH_POOL(temp_pool,
1711 svn_wc_is_wc_root(&wc_root, path, admobj->adm, temp_pool));
1713 apr_pool_destroy(temp_pool);
1715 return PyBool_FromLong(wc_root);
1718 static PyObject *transmit_text_deltas(PyObject *self, PyObject *args)
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;
1729 if (!PyArg_ParseTuple(args, "sbO", &path, &fulltext, &editor_obj))
1732 ADM_CHECK_CLOSED(admobj);
1734 temp_pool = Pool(NULL);
1735 if (temp_pool == NULL)
1738 Py_INCREF(editor_obj);
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));
1745 py_digest = PyString_FromStringAndSize((char *)digest, APR_MD5_DIGESTSIZE);
1746 if (py_digest == NULL) {
1747 apr_pool_destroy(temp_pool);
1751 ret = Py_BuildValue("sN", tempfile, py_digest);
1753 apr_pool_destroy(temp_pool);
1757 apr_pool_destroy(temp_pool);
1762 static PyObject *transmit_prop_deltas(PyObject *self, PyObject *args)
1765 PyObject *editor_obj;
1766 apr_pool_t *temp_pool;
1767 AdmObject *admobj = (AdmObject *)self;
1768 EntryObject *py_entry;
1770 if (!PyArg_ParseTuple(args, "sO!O", &path, &Entry_Type, &py_entry, &editor_obj))
1773 ADM_CHECK_CLOSED(admobj);
1775 temp_pool = Pool(NULL);
1776 if (temp_pool == NULL)
1779 Py_INCREF(editor_obj);
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));
1785 apr_pool_destroy(temp_pool);
1790 static PyObject *retrieve(PyObject *self, PyObject *args)
1793 svn_wc_adm_access_t *result;
1794 AdmObject *admobj = (AdmObject *)self, *ret;
1797 if (!PyArg_ParseTuple(args, "s", &path))
1800 ADM_CHECK_CLOSED(admobj);
1806 RUN_SVN_WITH_POOL(pool, svn_wc_adm_retrieve(&result, admobj->adm,
1807 svn_path_canonicalize(path, pool), pool));
1809 ret = PyObject_New(AdmObject, &Adm_Type);
1816 return (PyObject *)ret;
1819 static PyObject *probe_retrieve(PyObject *self, PyObject *args)
1822 svn_wc_adm_access_t *result;
1823 AdmObject *admobj = (AdmObject *)self, *ret;
1826 if (!PyArg_ParseTuple(args, "s", &path))
1829 ADM_CHECK_CLOSED(admobj);
1835 RUN_SVN_WITH_POOL(pool, svn_wc_adm_probe_retrieve(&result, admobj->adm,
1836 svn_path_canonicalize(path, pool), pool));
1838 ret = PyObject_New(AdmObject, &Adm_Type);
1845 return (PyObject *)ret;
1848 static PyObject *probe_try(PyObject *self, PyObject *args)
1851 svn_wc_adm_access_t *result = NULL;
1852 AdmObject *admobj = (AdmObject *)self, *ret;
1854 int levels_to_lock = -1;
1855 svn_boolean_t writelock = FALSE;
1857 if (!PyArg_ParseTuple(args, "s|bi", &path, &writelock, &levels_to_lock))
1860 ADM_CHECK_CLOSED(admobj);
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));
1870 if (result == NULL) {
1871 apr_pool_destroy(pool);
1875 ret = PyObject_New(AdmObject, &Adm_Type);
1882 return (PyObject *)ret;
1885 static PyObject *resolved_conflict(PyObject *self, PyObject *args)
1887 AdmObject *admobj = (AdmObject *)self;
1888 apr_pool_t *temp_pool;
1889 svn_boolean_t resolve_props, resolve_tree, resolve_text;
1891 #if ONLY_SINCE_SVN(1, 5)
1892 svn_wc_conflict_choice_t conflict_choice;
1894 int conflict_choice;
1896 PyObject *notify_func = Py_None;
1899 if (!PyArg_ParseTuple(args, "sbbbii|O", &path, &resolve_text,
1900 &resolve_props, &resolve_tree, &depth,
1901 &conflict_choice, ¬ify_func))
1904 ADM_CHECK_CLOSED(admobj);
1906 temp_pool = Pool(NULL);
1907 if (temp_pool == NULL)
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,
1917 #elif ONLY_SINCE_SVN(1, 5)
1919 PyErr_SetString(PyExc_NotImplementedError,
1920 "resolve_tree not supported with svn < 1.6");
1921 apr_pool_destroy(temp_pool);
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,
1933 PyErr_SetString(PyExc_NotImplementedError,
1934 "resolve_tree not supported with svn < 1.6");
1935 apr_pool_destroy(temp_pool);
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);
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);
1948 RUN_SVN_WITH_POOL(temp_pool,
1949 svn_wc_resolved_conflict2(path, admobj->adm, resolve_text,
1951 (depth == svn_depth_infinity),
1953 (void *)notify_func, py_cancel_check,
1959 apr_pool_destroy(temp_pool);
1964 static PyObject *conflicted(PyObject *self, PyObject *args)
1967 apr_pool_t *temp_pool;
1969 AdmObject *admobj = (AdmObject *)self;
1970 svn_boolean_t text_conflicted, prop_conflicted, tree_conflicted;
1972 if (!PyArg_ParseTuple(args, "s", &path))
1975 ADM_CHECK_CLOSED(admobj);
1977 temp_pool = Pool(NULL);
1978 if (temp_pool == NULL)
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));
1985 ret = Py_BuildValue("(bbb)", text_conflicted, prop_conflicted, tree_conflicted);
1987 RUN_SVN_WITH_POOL(temp_pool, svn_wc_conflicted_p(&text_conflicted,
1988 &prop_conflicted, path, admobj->adm, temp_pool));
1990 ret = Py_BuildValue("(bbO)", text_conflicted, prop_conflicted, Py_None);
1993 apr_pool_destroy(temp_pool);
1999 * Determine the status of a file in the specified working copy.
2001 * :return: A status object.
2003 static PyObject *ra_status(PyObject *self, PyObject *args)
2006 svn_wc_status2_t *st;
2007 apr_pool_t *temp_pool;
2009 AdmObject *admobj = (AdmObject *)self;
2011 if (!PyArg_ParseTuple(args, "s", &path))
2014 ADM_CHECK_CLOSED(admobj);
2016 temp_pool = Pool(NULL);
2017 if (temp_pool == NULL)
2020 RUN_SVN_WITH_POOL(temp_pool,
2023 svn_path_canonicalize(svn_path_join(svn_wc_adm_access_path(admobj->adm), path, temp_pool), temp_pool),
2027 ret = py_status(st);
2029 apr_pool_destroy(temp_pool);
2031 return (PyObject*)ret;
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,
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" },
2099 static PyTypeObject Adm_Type = {
2100 PyObject_HEAD_INIT(NULL) 0,
2101 "wc.WorkingCopy", /* const char *tp_name; For printing, in format "<module>.<name>" */
2103 0,/* Py_ssize_t tp_basicsize, tp_itemsize; For allocation */
2105 /* Methods to implement standard operations */
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; */
2114 /* Method suites for standard classes */
2116 NULL, /* PyNumberMethods *tp_as_number; */
2117 NULL, /* PySequenceMethods *tp_as_sequence; */
2118 NULL, /* PyMappingMethods *tp_as_mapping; */
2120 /* More standard operations (here for binary compatibility) */
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; */
2128 /* Functions to access object as input/output buffer */
2129 NULL, /* PyBufferProcs *tp_as_buffer; */
2131 /* Flags to define presence of optional/expanded features */
2132 0, /* long tp_flags; */
2134 "Local working copy", /* const char *tp_doc; Documentation string */
2136 /* Assigned meaning in release 2.0 */
2137 /* call function for all accessible objects */
2138 NULL, /* traverseproc tp_traverse; */
2140 /* delete references to contained objects */
2141 NULL, /* inquiry tp_clear; */
2143 /* Assigned meaning in release 2.1 */
2144 /* rich comparisons */
2145 NULL, /* richcmpfunc tp_richcompare; */
2147 /* weak reference enabler */
2148 0, /* Py_ssize_t tp_weaklistoffset; */
2150 /* Added in release 2.2 */
2152 NULL, /* getiterfunc tp_iter; */
2153 NULL, /* iternextfunc tp_iternext; */
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; */
2169 static void committed_queue_dealloc(PyObject *self)
2171 apr_pool_destroy(((CommittedQueueObject *)self)->pool);
2175 static PyObject *committed_queue_repr(PyObject *self)
2177 CommittedQueueObject *cqobj = (CommittedQueueObject *)self;
2179 return PyString_FromFormat("<wc.CommittedQueue at 0x%p>", cqobj->queue);
2182 static PyObject *committed_queue_init(PyTypeObject *self, PyObject *args, PyObject *kwargs)
2184 CommittedQueueObject *ret;
2185 char *kwnames[] = { NULL };
2187 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "", kwnames))
2190 ret = PyObject_New(CommittedQueueObject, &CommittedQueue_Type);
2194 ret->pool = Pool(NULL);
2195 if (ret->pool == NULL)
2197 ret->queue = svn_wc_committed_queue_create(ret->pool);
2198 if (ret->queue == NULL) {
2204 return (PyObject *)ret;
2207 static PyObject *committed_queue_queue(CommittedQueueObject *self, PyObject *args)
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;
2219 if (!PyArg_ParseTuple(args, "sO!|bObbz#", &path, &Adm_Type, &admobj,
2220 &recurse, &py_wcprop_changes, &remove_lock,
2221 &remove_changelist, &digest, &digest_len))
2224 temp_pool = Pool(NULL);
2225 if (temp_pool == NULL)
2228 if (!py_dict_to_wcprop_changes(py_wcprop_changes, self->pool, &wcprop_changes)) {
2229 apr_pool_destroy(temp_pool);
2233 path = apr_pstrdup(self->pool, path);
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);
2245 digest = apr_pstrdup(self->pool, digest);
2246 if (digest == NULL) {
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));
2257 apr_pool_destroy(temp_pool);
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)" },
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 */
2274 /* Methods to implement standard operations */
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; */
2283 /* Method suites for standard classes */
2285 NULL, /* PyNumberMethods *tp_as_number; */
2286 NULL, /* PySequenceMethods *tp_as_sequence; */
2287 NULL, /* PyMappingMethods *tp_as_mapping; */
2289 /* More standard operations (here for binary compatibility) */
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; */
2297 /* Functions to access object as input/output buffer */
2298 NULL, /* PyBufferProcs *tp_as_buffer; */
2300 /* Flags to define presence of optional/expanded features */
2301 0, /* long tp_flags; */
2303 "Committed queue", /* const char *tp_doc; Documentation string */
2305 /* Assigned meaning in release 2.0 */
2306 /* call function for all accessible objects */
2307 NULL, /* traverseproc tp_traverse; */
2309 /* delete references to contained objects */
2310 NULL, /* inquiry tp_clear; */
2312 /* Assigned meaning in release 2.1 */
2313 /* rich comparisons */
2314 NULL, /* richcmpfunc tp_richcompare; */
2316 /* weak reference enabler */
2317 0, /* Py_ssize_t tp_weaklistoffset; */
2319 /* Added in release 2.2 */
2321 NULL, /* getiterfunc tp_iter; */
2322 NULL, /* iternextfunc tp_iternext; */
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; */
2339 * Determine the revision status of a specified working copy.
2341 * :return: Tuple with minimum and maximum revnums found, whether the
2342 * working copy was switched and whether it was modified.
2344 static PyObject *revision_status(PyObject *self, PyObject *args, PyObject *kwargs)
2346 char *kwnames[] = { "wc_path", "trail_url", "committed", NULL };
2347 char *wc_path, *trail_url=NULL;
2348 bool committed=false;
2350 svn_wc_revision_status_t *revstatus;
2351 apr_pool_t *temp_pool;
2353 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zb", kwnames, &wc_path,
2354 &trail_url, &committed))
2357 temp_pool = Pool(NULL);
2358 if (temp_pool == NULL)
2360 RUN_SVN_WITH_POOL(temp_pool,
2361 svn_wc_revision_status(
2363 svn_path_canonicalize(wc_path, temp_pool),
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);
2372 static PyObject *is_normal_prop(PyObject *self, PyObject *args)
2376 if (!PyArg_ParseTuple(args, "s", &name))
2379 return PyBool_FromLong(svn_wc_is_normal_prop(name));
2382 static PyObject *is_adm_dir(PyObject *self, PyObject *args)
2388 if (!PyArg_ParseTuple(args, "s", &name))
2395 ret = svn_wc_is_adm_dir(name, pool);
2397 apr_pool_destroy(pool);
2399 return PyBool_FromLong(ret);
2402 static PyObject *is_wc_prop(PyObject *self, PyObject *args)
2406 if (!PyArg_ParseTuple(args, "s", &name))
2409 return PyBool_FromLong(svn_wc_is_wc_prop(name));
2412 static PyObject *is_entry_prop(PyObject *self, PyObject *args)
2416 if (!PyArg_ParseTuple(args, "s", &name))
2419 return PyBool_FromLong(svn_wc_is_entry_prop(name));
2422 static PyObject *get_adm_dir(PyObject *self)
2430 dir = svn_wc_get_adm_dir(pool);
2431 ret = PyString_FromString(dir);
2432 apr_pool_destroy(pool);
2436 static PyObject *set_adm_dir(PyObject *self, PyObject *args)
2438 apr_pool_t *temp_pool;
2441 if (!PyArg_ParseTuple(args, "s", &name))
2444 temp_pool = Pool(NULL);
2445 if (temp_pool == NULL)
2447 RUN_SVN_WITH_POOL(temp_pool, svn_wc_set_adm_dir(name, temp_pool));
2448 apr_pool_destroy(temp_pool);
2452 static PyObject *get_pristine_copy_path(PyObject *self, PyObject *args)
2455 const char *pristine_path;
2459 if (!PyArg_ParseTuple(args, "s", &path))
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);
2474 static PyObject *get_pristine_contents(PyObject *self, PyObject *args)
2477 apr_pool_t *temp_pool;
2478 #if ONLY_SINCE_SVN(1, 6)
2479 apr_pool_t *stream_pool;
2481 svn_stream_t *stream;
2484 const char *pristine_path;
2487 if (!PyArg_ParseTuple(args, "s", &path))
2490 #if ONLY_SINCE_SVN(1, 6)
2491 stream_pool = Pool(NULL);
2492 if (stream_pool == NULL)
2495 temp_pool = Pool(stream_pool);
2496 if (temp_pool == NULL) {
2497 apr_pool_destroy(stream_pool);
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);
2504 if (stream == NULL) {
2505 apr_pool_destroy(stream_pool);
2509 ret = PyObject_New(StreamObject, &Stream_Type);
2513 ret->pool = stream_pool;
2514 ret->closed = FALSE;
2515 ret->stream = stream;
2517 return (PyObject *)ret;
2519 temp_pool = Pool(NULL);
2520 if (temp_pool == 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);
2529 static PyObject *ensure_adm(PyObject *self, PyObject *args, PyObject *kwargs)
2531 char *path, *uuid, *url;
2533 svn_revnum_t rev=-1;
2535 char *kwnames[] = { "path", "uuid", "url", "repos", "rev", "depth", NULL };
2536 svn_depth_t depth = svn_depth_infinity;
2538 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss|sli", kwnames,
2539 &path, &uuid, &url, &repos, &rev, &depth))
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));
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);
2556 RUN_SVN_WITH_POOL(pool,
2557 svn_wc_ensure_adm2(svn_path_canonicalize(path, pool),
2558 uuid, url, repos, rev, pool));
2560 apr_pool_destroy(pool);
2564 static PyObject *check_wc(PyObject *self, PyObject *args)
2570 if (!PyArg_ParseTuple(args, "s", &path))
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);
2581 static PyObject *cleanup_wc(PyObject *self, PyObject *args, PyObject *kwargs)
2584 char *diff3_cmd = NULL;
2585 char *kwnames[] = { "path", "diff3_cmd", NULL };
2586 apr_pool_t *temp_pool;
2588 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|z", kwnames,
2592 temp_pool = Pool(NULL);
2593 if (temp_pool == NULL)
2595 RUN_SVN_WITH_POOL(temp_pool,
2596 svn_wc_cleanup2(path, diff3_cmd, py_cancel_check, NULL,
2598 apr_pool_destroy(temp_pool);
2603 static PyObject *match_ignore_list(PyObject *self, PyObject *args)
2605 #if ONLY_SINCE_SVN(1, 5)
2608 apr_array_header_t *list;
2609 apr_pool_t *temp_pool;
2612 if (!PyArg_ParseTuple(args, "sO", &str, &py_list))
2615 temp_pool = Pool(NULL);
2617 if (!string_list_to_apr_array(temp_pool, py_list, &list)) {
2618 apr_pool_destroy(temp_pool);
2622 ret = svn_wc_match_ignore_list(str, list, temp_pool);
2624 apr_pool_destroy(temp_pool);
2626 return PyBool_FromLong(ret);
2628 PyErr_SetNone(PyExc_NotImplementedError);
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."
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."
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)" },
2677 if (PyType_Ready(&Entry_Type) < 0)
2680 if (PyType_Ready(&Status_Type) < 0)
2683 if (PyType_Ready(&Adm_Type) < 0)
2686 if (PyType_Ready(&Editor_Type) < 0)
2689 if (PyType_Ready(&FileEditor_Type) < 0)
2692 if (PyType_Ready(&DirectoryEditor_Type) < 0)
2695 if (PyType_Ready(&TxDeltaWindowHandler_Type) < 0)
2698 if (PyType_Ready(&Stream_Type) < 0)
2701 if (PyType_Ready(&CommittedQueue_Type) < 0)
2706 #if PY_MAJOR_VERSION >= 3
2707 static struct PyModuleDef moduledef = {
2708 PyModuleDef_HEAD_INIT,
2710 "Working Copies", /* m_doc */
2712 wc_methods, /* m_methods */
2713 NULL, /* m_reload */
2714 NULL, /* m_traverse */
2718 mod = PyModule_Create(&moduledef);
2720 mod = Py_InitModule3("wc", wc_methods, "Working Copies");
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);
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);
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);
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);
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);
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.
2783 PyModule_AddObject(mod, "WorkingCopy", (PyObject *)&Adm_Type);
2784 Py_INCREF(&Adm_Type);
2786 PyModule_AddObject(mod, "CommittedQueue", (PyObject *)&CommittedQueue_Type);
2787 Py_INCREF(&CommittedQueue_Type);
2793 #if PY_MAJOR_VERSION >= 3
2797 return moduleinit();