Show More
@@ -1,137 +1,132 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, see <http://www.gnu.org/licenses/>. |
|
18 | # along with this program; if not, see <http://www.gnu.org/licenses/>. | |
19 | from __future__ import absolute_import |
|
19 | from __future__ import absolute_import | |
20 |
|
20 | |||
21 | import svn.client |
|
21 | import svn.client | |
22 | import svn.core |
|
22 | import svn.core | |
23 | import svn.ra |
|
23 | import svn.ra | |
24 |
|
24 | |||
25 | Pool = svn.core.Pool |
|
25 | Pool = svn.core.Pool | |
26 | SubversionException = svn.core.SubversionException |
|
26 | SubversionException = svn.core.SubversionException | |
27 |
|
27 | |||
28 | from mercurial import ( |
|
28 | from mercurial import ( | |
29 | util, |
|
29 | util, | |
30 | ) |
|
30 | ) | |
31 |
|
31 | |||
32 | # Some older versions of the Python bindings need to be |
|
32 | # Some older versions of the Python bindings need to be | |
33 | # explicitly initialized. But what we want to do probably |
|
33 | # explicitly initialized. But what we want to do probably | |
34 | # won't work worth a darn against those libraries anyway! |
|
34 | # won't work worth a darn against those libraries anyway! | |
35 | svn.ra.initialize() |
|
35 | svn.ra.initialize() | |
36 |
|
36 | |||
37 | svn_config = None |
|
37 | svn_config = None | |
38 |
|
38 | |||
39 | def _create_auth_baton(pool): |
|
39 | def _create_auth_baton(pool): | |
40 | """Create a Subversion authentication baton. """ |
|
40 | """Create a Subversion authentication baton. """ | |
41 | import svn.client |
|
41 | import svn.client | |
42 | # Give the client context baton a suite of authentication |
|
42 | # Give the client context baton a suite of authentication | |
43 | # providers.h |
|
43 | # providers.h | |
44 | providers = [ |
|
44 | providers = [ | |
45 | svn.client.get_simple_provider(pool), |
|
45 | svn.client.get_simple_provider(pool), | |
46 | svn.client.get_username_provider(pool), |
|
46 | svn.client.get_username_provider(pool), | |
47 | svn.client.get_ssl_client_cert_file_provider(pool), |
|
47 | svn.client.get_ssl_client_cert_file_provider(pool), | |
48 | svn.client.get_ssl_client_cert_pw_file_provider(pool), |
|
48 | svn.client.get_ssl_client_cert_pw_file_provider(pool), | |
49 | svn.client.get_ssl_server_trust_file_provider(pool), |
|
49 | svn.client.get_ssl_server_trust_file_provider(pool), | |
50 | ] |
|
50 | ] | |
51 | # Platform-dependent authentication methods |
|
51 | # Platform-dependent authentication methods | |
52 | getprovider = getattr(svn.core, 'svn_auth_get_platform_specific_provider', |
|
52 | getprovider = getattr(svn.core, 'svn_auth_get_platform_specific_provider', | |
53 | None) |
|
53 | None) | |
54 | if getprovider: |
|
54 | if getprovider: | |
55 | # Available in svn >= 1.6 |
|
55 | # Available in svn >= 1.6 | |
56 | for name in ('gnome_keyring', 'keychain', 'kwallet', 'windows'): |
|
56 | for name in ('gnome_keyring', 'keychain', 'kwallet', 'windows'): | |
57 | for type in ('simple', 'ssl_client_cert_pw', 'ssl_server_trust'): |
|
57 | for type in ('simple', 'ssl_client_cert_pw', 'ssl_server_trust'): | |
58 | p = getprovider(name, type, pool) |
|
58 | p = getprovider(name, type, pool) | |
59 | if p: |
|
59 | if p: | |
60 | providers.append(p) |
|
60 | providers.append(p) | |
61 | else: |
|
61 | else: | |
62 | if util.safehasattr(svn.client, 'get_windows_simple_provider'): |
|
62 | if util.safehasattr(svn.client, 'get_windows_simple_provider'): | |
63 | providers.append(svn.client.get_windows_simple_provider(pool)) |
|
63 | providers.append(svn.client.get_windows_simple_provider(pool)) | |
64 |
|
64 | |||
65 | return svn.core.svn_auth_open(providers, pool) |
|
65 | return svn.core.svn_auth_open(providers, pool) | |
66 |
|
66 | |||
67 | class NotBranchError(SubversionException): |
|
67 | class NotBranchError(SubversionException): | |
68 | pass |
|
68 | pass | |
69 |
|
69 | |||
70 | class SvnRaTransport(object): |
|
70 | class SvnRaTransport(object): | |
71 | """ |
|
71 | """ | |
72 | Open an ra connection to a Subversion repository. |
|
72 | Open an ra connection to a Subversion repository. | |
73 | """ |
|
73 | """ | |
74 | def __init__(self, url="", ra=None): |
|
74 | def __init__(self, url="", ra=None): | |
75 | self.pool = Pool() |
|
75 | self.pool = Pool() | |
76 | self.svn_url = url |
|
76 | self.svn_url = url | |
77 | self.username = '' |
|
77 | self.username = '' | |
78 | self.password = '' |
|
78 | self.password = '' | |
79 |
|
79 | |||
80 | # Only Subversion 1.4 has reparent() |
|
80 | # Only Subversion 1.4 has reparent() | |
81 | if ra is None or not util.safehasattr(svn.ra, 'reparent'): |
|
81 | if ra is None or not util.safehasattr(svn.ra, 'reparent'): | |
82 | self.client = svn.client.create_context(self.pool) |
|
82 | self.client = svn.client.create_context(self.pool) | |
83 | ab = _create_auth_baton(self.pool) |
|
83 | ab = _create_auth_baton(self.pool) | |
84 | if False: |
|
|||
85 | svn.core.svn_auth_set_parameter( |
|
|||
86 | ab, svn.core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username) |
|
|||
87 | svn.core.svn_auth_set_parameter( |
|
|||
88 | ab, svn.core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, self.password) |
|
|||
89 | self.client.auth_baton = ab |
|
84 | self.client.auth_baton = ab | |
90 | global svn_config |
|
85 | global svn_config | |
91 | if svn_config is None: |
|
86 | if svn_config is None: | |
92 | svn_config = svn.core.svn_config_get_config(None) |
|
87 | svn_config = svn.core.svn_config_get_config(None) | |
93 | self.client.config = svn_config |
|
88 | self.client.config = svn_config | |
94 | try: |
|
89 | try: | |
95 | self.ra = svn.client.open_ra_session( |
|
90 | self.ra = svn.client.open_ra_session( | |
96 | self.svn_url, |
|
91 | self.svn_url, | |
97 | self.client, self.pool) |
|
92 | self.client, self.pool) | |
98 | except SubversionException as xxx_todo_changeme: |
|
93 | except SubversionException as xxx_todo_changeme: | |
99 | (inst, num) = xxx_todo_changeme.args |
|
94 | (inst, num) = xxx_todo_changeme.args | |
100 | if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL, |
|
95 | if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL, | |
101 | svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, |
|
96 | svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, | |
102 | svn.core.SVN_ERR_BAD_URL): |
|
97 | svn.core.SVN_ERR_BAD_URL): | |
103 | raise NotBranchError(url) |
|
98 | raise NotBranchError(url) | |
104 | raise |
|
99 | raise | |
105 | else: |
|
100 | else: | |
106 | self.ra = ra |
|
101 | self.ra = ra | |
107 | svn.ra.reparent(self.ra, self.svn_url.encode('utf8')) |
|
102 | svn.ra.reparent(self.ra, self.svn_url.encode('utf8')) | |
108 |
|
103 | |||
109 | class Reporter(object): |
|
104 | class Reporter(object): | |
110 | def __init__(self, reporter_data): |
|
105 | def __init__(self, reporter_data): | |
111 | self._reporter, self._baton = reporter_data |
|
106 | self._reporter, self._baton = reporter_data | |
112 |
|
107 | |||
113 | def set_path(self, path, revnum, start_empty, lock_token, pool=None): |
|
108 | def set_path(self, path, revnum, start_empty, lock_token, pool=None): | |
114 | svn.ra.reporter2_invoke_set_path(self._reporter, self._baton, |
|
109 | svn.ra.reporter2_invoke_set_path(self._reporter, self._baton, | |
115 | path, revnum, start_empty, lock_token, pool) |
|
110 | path, revnum, start_empty, lock_token, pool) | |
116 |
|
111 | |||
117 | def delete_path(self, path, pool=None): |
|
112 | def delete_path(self, path, pool=None): | |
118 | svn.ra.reporter2_invoke_delete_path(self._reporter, self._baton, |
|
113 | svn.ra.reporter2_invoke_delete_path(self._reporter, self._baton, | |
119 | path, pool) |
|
114 | path, pool) | |
120 |
|
115 | |||
121 | def link_path(self, path, url, revision, start_empty, lock_token, |
|
116 | def link_path(self, path, url, revision, start_empty, lock_token, | |
122 | pool=None): |
|
117 | pool=None): | |
123 | svn.ra.reporter2_invoke_link_path(self._reporter, self._baton, |
|
118 | svn.ra.reporter2_invoke_link_path(self._reporter, self._baton, | |
124 | path, url, revision, start_empty, lock_token, |
|
119 | path, url, revision, start_empty, lock_token, | |
125 | pool) |
|
120 | pool) | |
126 |
|
121 | |||
127 | def finish_report(self, pool=None): |
|
122 | def finish_report(self, pool=None): | |
128 | svn.ra.reporter2_invoke_finish_report(self._reporter, |
|
123 | svn.ra.reporter2_invoke_finish_report(self._reporter, | |
129 | self._baton, pool) |
|
124 | self._baton, pool) | |
130 |
|
125 | |||
131 | def abort_report(self, pool=None): |
|
126 | def abort_report(self, pool=None): | |
132 | svn.ra.reporter2_invoke_abort_report(self._reporter, |
|
127 | svn.ra.reporter2_invoke_abort_report(self._reporter, | |
133 | self._baton, pool) |
|
128 | self._baton, pool) | |
134 |
|
129 | |||
135 | def do_update(self, revnum, path, *args, **kwargs): |
|
130 | def do_update(self, revnum, path, *args, **kwargs): | |
136 | return self.Reporter(svn.ra.do_update(self.ra, revnum, path, |
|
131 | return self.Reporter(svn.ra.do_update(self.ra, revnum, path, | |
137 | *args, **kwargs)) |
|
132 | *args, **kwargs)) |
General Comments 0
You need to be logged in to leave comments.
Login now