##// 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 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2007 Daniel Holth <dholth@fastmail.fm>
4 4 # This is a stripped-down version of the original bzr-svn transport.py,
5 5 # Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org>
6 6
7 7 # This program is free software; you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
9 9 # the Free Software Foundation; either version 2 of the License, or
10 10 # (at your option) any later version.
11 11
12 12 # This program is distributed in the hope that it will be useful,
13 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 15 # GNU General Public License for more details.
16 16
17 17 # You should have received a copy of the GNU General Public License
18 18 # along with this program; if not, see <http://www.gnu.org/licenses/>.
19 19 from __future__ import absolute_import
20 20
21 21 import svn.client
22 22 import svn.core
23 23 import svn.ra
24 24
25 25 Pool = svn.core.Pool
26 26 SubversionException = svn.core.SubversionException
27 27
28 28 from mercurial import (
29 29 util,
30 30 )
31 31
32 32 # Some older versions of the Python bindings need to be
33 33 # explicitly initialized. But what we want to do probably
34 34 # won't work worth a darn against those libraries anyway!
35 35 svn.ra.initialize()
36 36
37 svn_config = svn.core.svn_config_get_config(None)
38
37 svn_config = None
39 38
40 39 def _create_auth_baton(pool):
41 40 """Create a Subversion authentication baton. """
42 41 import svn.client
43 42 # Give the client context baton a suite of authentication
44 43 # providers.h
45 44 providers = [
46 45 svn.client.get_simple_provider(pool),
47 46 svn.client.get_username_provider(pool),
48 47 svn.client.get_ssl_client_cert_file_provider(pool),
49 48 svn.client.get_ssl_client_cert_pw_file_provider(pool),
50 49 svn.client.get_ssl_server_trust_file_provider(pool),
51 50 ]
52 51 # Platform-dependent authentication methods
53 52 getprovider = getattr(svn.core, 'svn_auth_get_platform_specific_provider',
54 53 None)
55 54 if getprovider:
56 55 # Available in svn >= 1.6
57 56 for name in ('gnome_keyring', 'keychain', 'kwallet', 'windows'):
58 57 for type in ('simple', 'ssl_client_cert_pw', 'ssl_server_trust'):
59 58 p = getprovider(name, type, pool)
60 59 if p:
61 60 providers.append(p)
62 61 else:
63 62 if util.safehasattr(svn.client, 'get_windows_simple_provider'):
64 63 providers.append(svn.client.get_windows_simple_provider(pool))
65 64
66 65 return svn.core.svn_auth_open(providers, pool)
67 66
68 67 class NotBranchError(SubversionException):
69 68 pass
70 69
71 70 class SvnRaTransport(object):
72 71 """
73 72 Open an ra connection to a Subversion repository.
74 73 """
75 74 def __init__(self, url="", ra=None):
76 75 self.pool = Pool()
77 76 self.svn_url = url
78 77 self.username = ''
79 78 self.password = ''
80 79
81 80 # Only Subversion 1.4 has reparent()
82 81 if ra is None or not util.safehasattr(svn.ra, 'reparent'):
83 82 self.client = svn.client.create_context(self.pool)
84 83 ab = _create_auth_baton(self.pool)
85 84 if False:
86 85 svn.core.svn_auth_set_parameter(
87 86 ab, svn.core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username)
88 87 svn.core.svn_auth_set_parameter(
89 88 ab, svn.core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, self.password)
90 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 93 self.client.config = svn_config
92 94 try:
93 95 self.ra = svn.client.open_ra_session(
94 96 self.svn_url,
95 97 self.client, self.pool)
96 98 except SubversionException as xxx_todo_changeme:
97 99 (inst, num) = xxx_todo_changeme.args
98 100 if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL,
99 101 svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED,
100 102 svn.core.SVN_ERR_BAD_URL):
101 103 raise NotBranchError(url)
102 104 raise
103 105 else:
104 106 self.ra = ra
105 107 svn.ra.reparent(self.ra, self.svn_url.encode('utf8'))
106 108
107 109 class Reporter(object):
108 110 def __init__(self, reporter_data):
109 111 self._reporter, self._baton = reporter_data
110 112
111 113 def set_path(self, path, revnum, start_empty, lock_token, pool=None):
112 114 svn.ra.reporter2_invoke_set_path(self._reporter, self._baton,
113 115 path, revnum, start_empty, lock_token, pool)
114 116
115 117 def delete_path(self, path, pool=None):
116 118 svn.ra.reporter2_invoke_delete_path(self._reporter, self._baton,
117 119 path, pool)
118 120
119 121 def link_path(self, path, url, revision, start_empty, lock_token,
120 122 pool=None):
121 123 svn.ra.reporter2_invoke_link_path(self._reporter, self._baton,
122 124 path, url, revision, start_empty, lock_token,
123 125 pool)
124 126
125 127 def finish_report(self, pool=None):
126 128 svn.ra.reporter2_invoke_finish_report(self._reporter,
127 129 self._baton, pool)
128 130
129 131 def abort_report(self, pool=None):
130 132 svn.ra.reporter2_invoke_abort_report(self._reporter,
131 133 self._baton, pool)
132 134
133 135 def do_update(self, revnum, path, *args, **kwargs):
134 136 return self.Reporter(svn.ra.do_update(self.ra, revnum, path,
135 137 *args, **kwargs))
General Comments 0
You need to be logged in to leave comments. Login now