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 util |
29 util, |
|
30 ) |
|
31 |
29 |
32 # Some older versions of the Python bindings need to be |
30 # Some older versions of the Python bindings need to be |
33 # explicitly initialized. But what we want to do probably |
31 # explicitly initialized. But what we want to do probably |
34 # won't work worth a darn against those libraries anyway! |
32 # won't work worth a darn against those libraries anyway! |
35 svn.ra.initialize() |
33 svn.ra.initialize() |
36 |
34 |
37 svn_config = None |
35 svn_config = None |
38 |
36 |
|
37 |
39 def _create_auth_baton(pool): |
38 def _create_auth_baton(pool): |
40 """Create a Subversion authentication baton. """ |
39 """Create a Subversion authentication baton. """ |
41 import svn.client |
40 import svn.client |
|
41 |
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( |
53 None) |
53 svn.core, 'svn_auth_get_platform_specific_provider', None |
|
54 ) |
54 if getprovider: |
55 if getprovider: |
55 # Available in svn >= 1.6 |
56 # Available in svn >= 1.6 |
56 for name in ('gnome_keyring', 'keychain', 'kwallet', 'windows'): |
57 for name in ('gnome_keyring', 'keychain', 'kwallet', 'windows'): |
57 for type in ('simple', 'ssl_client_cert_pw', 'ssl_server_trust'): |
58 for type in ('simple', 'ssl_client_cert_pw', 'ssl_server_trust'): |
58 p = getprovider(name, type, pool) |
59 p = getprovider(name, type, pool) |
62 if util.safehasattr(svn.client, 'get_windows_simple_provider'): |
63 if util.safehasattr(svn.client, 'get_windows_simple_provider'): |
63 providers.append(svn.client.get_windows_simple_provider(pool)) |
64 providers.append(svn.client.get_windows_simple_provider(pool)) |
64 |
65 |
65 return svn.core.svn_auth_open(providers, pool) |
66 return svn.core.svn_auth_open(providers, pool) |
66 |
67 |
|
68 |
67 class NotBranchError(SubversionException): |
69 class NotBranchError(SubversionException): |
68 pass |
70 pass |
|
71 |
69 |
72 |
70 class SvnRaTransport(object): |
73 class SvnRaTransport(object): |
71 """ |
74 """ |
72 Open an ra connection to a Subversion repository. |
75 Open an ra connection to a Subversion repository. |
73 """ |
76 """ |
|
77 |
74 def __init__(self, url="", ra=None): |
78 def __init__(self, url="", ra=None): |
75 self.pool = Pool() |
79 self.pool = Pool() |
76 self.svn_url = url |
80 self.svn_url = url |
77 self.username = '' |
81 self.username = '' |
78 self.password = '' |
82 self.password = '' |
86 if svn_config is None: |
90 if svn_config is None: |
87 svn_config = svn.core.svn_config_get_config(None) |
91 svn_config = svn.core.svn_config_get_config(None) |
88 self.client.config = svn_config |
92 self.client.config = svn_config |
89 try: |
93 try: |
90 self.ra = svn.client.open_ra_session( |
94 self.ra = svn.client.open_ra_session( |
91 self.svn_url, |
95 self.svn_url, self.client, self.pool |
92 self.client, self.pool) |
96 ) |
93 except SubversionException as xxx_todo_changeme: |
97 except SubversionException as xxx_todo_changeme: |
94 (inst, num) = xxx_todo_changeme.args |
98 (inst, num) = xxx_todo_changeme.args |
95 if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL, |
99 if num in ( |
96 svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, |
100 svn.core.SVN_ERR_RA_ILLEGAL_URL, |
97 svn.core.SVN_ERR_BAD_URL): |
101 svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, |
|
102 svn.core.SVN_ERR_BAD_URL, |
|
103 ): |
98 raise NotBranchError(url) |
104 raise NotBranchError(url) |
99 raise |
105 raise |
100 else: |
106 else: |
101 self.ra = ra |
107 self.ra = ra |
102 svn.ra.reparent(self.ra, self.svn_url.encode('utf8')) |
108 svn.ra.reparent(self.ra, self.svn_url.encode('utf8')) |
104 class Reporter(object): |
110 class Reporter(object): |
105 def __init__(self, reporter_data): |
111 def __init__(self, reporter_data): |
106 self._reporter, self._baton = reporter_data |
112 self._reporter, self._baton = reporter_data |
107 |
113 |
108 def set_path(self, path, revnum, start_empty, lock_token, pool=None): |
114 def set_path(self, path, revnum, start_empty, lock_token, pool=None): |
109 svn.ra.reporter2_invoke_set_path(self._reporter, self._baton, |
115 svn.ra.reporter2_invoke_set_path( |
110 path, revnum, start_empty, lock_token, pool) |
116 self._reporter, |
|
117 self._baton, |
|
118 path, |
|
119 revnum, |
|
120 start_empty, |
|
121 lock_token, |
|
122 pool, |
|
123 ) |
111 |
124 |
112 def delete_path(self, path, pool=None): |
125 def delete_path(self, path, pool=None): |
113 svn.ra.reporter2_invoke_delete_path(self._reporter, self._baton, |
126 svn.ra.reporter2_invoke_delete_path( |
114 path, pool) |
127 self._reporter, self._baton, path, pool |
|
128 ) |
115 |
129 |
116 def link_path(self, path, url, revision, start_empty, lock_token, |
130 def link_path( |
117 pool=None): |
131 self, path, url, revision, start_empty, lock_token, pool=None |
118 svn.ra.reporter2_invoke_link_path(self._reporter, self._baton, |
132 ): |
119 path, url, revision, start_empty, lock_token, |
133 svn.ra.reporter2_invoke_link_path( |
120 pool) |
134 self._reporter, |
|
135 self._baton, |
|
136 path, |
|
137 url, |
|
138 revision, |
|
139 start_empty, |
|
140 lock_token, |
|
141 pool, |
|
142 ) |
121 |
143 |
122 def finish_report(self, pool=None): |
144 def finish_report(self, pool=None): |
123 svn.ra.reporter2_invoke_finish_report(self._reporter, |
145 svn.ra.reporter2_invoke_finish_report( |
124 self._baton, pool) |
146 self._reporter, self._baton, pool |
|
147 ) |
125 |
148 |
126 def abort_report(self, pool=None): |
149 def abort_report(self, pool=None): |
127 svn.ra.reporter2_invoke_abort_report(self._reporter, |
150 svn.ra.reporter2_invoke_abort_report( |
128 self._baton, pool) |
151 self._reporter, self._baton, pool |
|
152 ) |
129 |
153 |
130 def do_update(self, revnum, path, *args, **kwargs): |
154 def do_update(self, revnum, path, *args, **kwargs): |
131 return self.Reporter(svn.ra.do_update(self.ra, revnum, path, |
155 return self.Reporter( |
132 *args, **kwargs)) |
156 svn.ra.do_update(self.ra, revnum, path, *args, **kwargs) |
|
157 ) |