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