Show More
@@ -1,134 +1,125 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2007 Daniel Holth <dholth@fastmail.fm> |
|
3 | # Copyright (C) 2007 Daniel Holth <dholth@fastmail.fm> | |
4 | # This is a stripped-down version of the original bzr-svn transport.py, |
|
4 | # This is a stripped-down version of the original bzr-svn transport.py, | |
5 | # Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org> |
|
5 | # Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org> | |
6 |
|
6 | |||
7 | # This program is free software; you can redistribute it and/or modify |
|
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by |
|
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or |
|
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. |
|
10 | # (at your option) any later version. | |
11 |
|
11 | |||
12 | # This program is distributed in the hope that it will be useful, |
|
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. |
|
15 | # GNU General Public License for more details. | |
16 |
|
16 | |||
17 | # You should have received a copy of the GNU General Public License |
|
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program; if not, write to the Free Software |
|
18 | # along with this program; if not, write to the Free Software | |
19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 |
|
20 | |||
21 | from cStringIO import StringIO |
|
21 | from cStringIO import StringIO | |
22 | import os |
|
22 | import os | |
23 | from tempfile import mktemp |
|
23 | from tempfile import mktemp | |
24 |
|
24 | |||
25 | from svn.core import SubversionException, Pool |
|
25 | from svn.core import SubversionException, Pool | |
26 | import svn.ra |
|
26 | import svn.ra | |
|
27 | import svn.client | |||
27 | import svn.core |
|
28 | import svn.core | |
28 |
|
29 | |||
29 | # Some older versions of the Python bindings need to be |
|
30 | # Some older versions of the Python bindings need to be | |
30 | # explicitly initialized. But what we want to do probably |
|
31 | # explicitly initialized. But what we want to do probably | |
31 | # won't work worth a darn against those libraries anyway! |
|
32 | # won't work worth a darn against those libraries anyway! | |
32 | svn.ra.initialize() |
|
33 | svn.ra.initialize() | |
33 |
|
34 | |||
34 | svn_config = svn.core.svn_config_get_config(None) |
|
35 | svn_config = svn.core.svn_config_get_config(None) | |
35 |
|
36 | |||
36 |
|
37 | |||
37 | def _create_auth_baton(pool): |
|
38 | def _create_auth_baton(pool): | |
38 | """Create a Subversion authentication baton. """ |
|
39 | """Create a Subversion authentication baton. """ | |
39 | import svn.client |
|
40 | import svn.client | |
40 | # Give the client context baton a suite of authentication |
|
41 | # Give the client context baton a suite of authentication | |
41 | # providers.h |
|
42 | # providers.h | |
42 | providers = [ |
|
43 | providers = [ | |
43 | svn.client.get_simple_provider(pool), |
|
44 | svn.client.get_simple_provider(pool), | |
44 | svn.client.get_username_provider(pool), |
|
45 | svn.client.get_username_provider(pool), | |
45 | svn.client.get_ssl_client_cert_file_provider(pool), |
|
46 | svn.client.get_ssl_client_cert_file_provider(pool), | |
46 | svn.client.get_ssl_client_cert_pw_file_provider(pool), |
|
47 | svn.client.get_ssl_client_cert_pw_file_provider(pool), | |
47 | svn.client.get_ssl_server_trust_file_provider(pool), |
|
48 | svn.client.get_ssl_server_trust_file_provider(pool), | |
48 | ] |
|
49 | ] | |
49 | return svn.core.svn_auth_open(providers, pool) |
|
50 | return svn.core.svn_auth_open(providers, pool) | |
50 |
|
51 | |||
51 |
|
||||
52 | # # The SVN libraries don't like trailing slashes... |
|
|||
53 | # return url.rstrip('/') |
|
|||
54 |
|
||||
55 |
|
||||
56 | class SvnRaCallbacks(svn.ra.callbacks2_t): |
|
|||
57 | """Remote access callbacks implementation for bzr-svn.""" |
|
|||
58 | def __init__(self, pool): |
|
|||
59 | svn.ra.callbacks2_t.__init__(self) |
|
|||
60 | self.auth_baton = _create_auth_baton(pool) |
|
|||
61 | self.pool = pool |
|
|||
62 |
|
||||
63 | def open_tmp_file(self, pool): |
|
|||
64 | return mktemp(prefix='tailor-svn') |
|
|||
65 |
|
||||
66 | class NotBranchError(SubversionException): |
|
52 | class NotBranchError(SubversionException): | |
67 | pass |
|
53 | pass | |
68 |
|
54 | |||
69 | class SvnRaTransport(object): |
|
55 | class SvnRaTransport(object): | |
70 | """ |
|
56 | """ | |
71 | Open an ra connection to a Subversion repository. |
|
57 | Open an ra connection to a Subversion repository. | |
72 | """ |
|
58 | """ | |
73 | def __init__(self, url="", ra=None): |
|
59 | def __init__(self, url="", ra=None): | |
74 | self.pool = Pool() |
|
60 | self.pool = Pool() | |
75 | self.svn_url = url |
|
61 | self.svn_url = url | |
|
62 | self.username = '' | |||
|
63 | self.password = '' | |||
76 |
|
64 | |||
77 | # Only Subversion 1.4 has reparent() |
|
65 | # Only Subversion 1.4 has reparent() | |
78 | if ra is None or not hasattr(svn.ra, 'reparent'): |
|
66 | if ra is None or not hasattr(svn.ra, 'reparent'): | |
79 |
self.c |
|
67 | self.client = svn.client.create_context(self.pool) | |
|
68 | ab = _create_auth_baton(self.pool) | |||
|
69 | if False: | |||
|
70 | svn.core.svn_auth_set_parameter( | |||
|
71 | ab, svn.core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username) | |||
|
72 | svn.core.svn_auth_set_parameter( | |||
|
73 | ab, svn.core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, self.password) | |||
|
74 | self.client.auth_baton = ab | |||
|
75 | self.client.config = svn_config | |||
80 | try: |
|
76 | try: | |
81 |
|
|
77 | self.ra = svn.client.open_ra_session( | |
82 | try: # Older SVN bindings |
|
78 | self.svn_url.encode('utf8'), | |
83 | self.ra = svn.ra.open2(self.svn_url.encode('utf8'), self.callbacks, None, svn_config, None) |
|
79 | self.client, self.pool) | |
84 | except TypeError, e: |
|
|||
85 | self.ra = svn.ra.open2(self.svn_url.encode('utf8'), self.callbacks, svn_config, None) |
|
|||
86 | except SubversionException, (_, num): |
|
80 | except SubversionException, (_, num): | |
87 |
if num |
|
81 | if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL, | |
88 | raise NotBranchError(url) |
|
82 | svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, | |
89 |
|
|
83 | svn.core.SVN_ERR_BAD_URL): | |
90 | raise NotBranchError(url) |
|
|||
91 | if num == svn.core.SVN_ERR_BAD_URL: |
|
|||
92 | raise NotBranchError(url) |
|
84 | raise NotBranchError(url) | |
93 | raise |
|
85 | raise | |
94 |
|
||||
95 | else: |
|
86 | else: | |
96 | self.ra = ra |
|
87 | self.ra = ra | |
97 | svn.ra.reparent(self.ra, self.svn_url.encode('utf8')) |
|
88 | svn.ra.reparent(self.ra, self.svn_url.encode('utf8')) | |
98 |
|
89 | |||
99 | class Reporter: |
|
90 | class Reporter: | |
100 | def __init__(self, (reporter, report_baton)): |
|
91 | def __init__(self, (reporter, report_baton)): | |
101 | self._reporter = reporter |
|
92 | self._reporter = reporter | |
102 | self._baton = report_baton |
|
93 | self._baton = report_baton | |
103 |
|
94 | |||
104 | def set_path(self, path, revnum, start_empty, lock_token, pool=None): |
|
95 | def set_path(self, path, revnum, start_empty, lock_token, pool=None): | |
105 | svn.ra.reporter2_invoke_set_path(self._reporter, self._baton, |
|
96 | svn.ra.reporter2_invoke_set_path(self._reporter, self._baton, | |
106 | path, revnum, start_empty, lock_token, pool) |
|
97 | path, revnum, start_empty, lock_token, pool) | |
107 |
|
98 | |||
108 | def delete_path(self, path, pool=None): |
|
99 | def delete_path(self, path, pool=None): | |
109 | svn.ra.reporter2_invoke_delete_path(self._reporter, self._baton, |
|
100 | svn.ra.reporter2_invoke_delete_path(self._reporter, self._baton, | |
110 | path, pool) |
|
101 | path, pool) | |
111 |
|
102 | |||
112 | def link_path(self, path, url, revision, start_empty, lock_token, |
|
103 | def link_path(self, path, url, revision, start_empty, lock_token, | |
113 | pool=None): |
|
104 | pool=None): | |
114 | svn.ra.reporter2_invoke_link_path(self._reporter, self._baton, |
|
105 | svn.ra.reporter2_invoke_link_path(self._reporter, self._baton, | |
115 | path, url, revision, start_empty, lock_token, |
|
106 | path, url, revision, start_empty, lock_token, | |
116 | pool) |
|
107 | pool) | |
117 |
|
108 | |||
118 | def finish_report(self, pool=None): |
|
109 | def finish_report(self, pool=None): | |
119 | svn.ra.reporter2_invoke_finish_report(self._reporter, |
|
110 | svn.ra.reporter2_invoke_finish_report(self._reporter, | |
120 | self._baton, pool) |
|
111 | self._baton, pool) | |
121 |
|
112 | |||
122 | def abort_report(self, pool=None): |
|
113 | def abort_report(self, pool=None): | |
123 | svn.ra.reporter2_invoke_abort_report(self._reporter, |
|
114 | svn.ra.reporter2_invoke_abort_report(self._reporter, | |
124 | self._baton, pool) |
|
115 | self._baton, pool) | |
125 |
|
116 | |||
126 | def do_update(self, revnum, path, *args, **kwargs): |
|
117 | def do_update(self, revnum, path, *args, **kwargs): | |
127 | return self.Reporter(svn.ra.do_update(self.ra, revnum, path, *args, **kwargs)) |
|
118 | return self.Reporter(svn.ra.do_update(self.ra, revnum, path, *args, **kwargs)) | |
128 |
|
119 | |||
129 | def clone(self, offset=None): |
|
120 | def clone(self, offset=None): | |
130 | """See Transport.clone().""" |
|
121 | """See Transport.clone().""" | |
131 | if offset is None: |
|
122 | if offset is None: | |
132 | return self.__class__(self.base) |
|
123 | return self.__class__(self.base) | |
133 |
|
124 | |||
134 | return SvnRaTransport(urlutils.join(self.base, offset), ra=self.ra) |
|
125 | return SvnRaTransport(urlutils.join(self.base, offset), ra=self.ra) |
General Comments 0
You need to be logged in to leave comments.
Login now