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