comparison hgext/largefiles/basestore.py @ 29305:814076f4ace3

largefiles: move basestore._openstore into new module to remove cycle
author liscju <piotr.listkiewicz@gmail.com>
date Sat, 04 Jun 2016 16:53:44 +0200
parents 207c0db08953
children 67999697221a
comparison
equal deleted inserted replaced
29304:5e32852fa4bd 29305:814076f4ace3
6 # This software may be used and distributed according to the terms of the 6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 8
9 '''base class for store implementations and store-related utility code''' 9 '''base class for store implementations and store-related utility code'''
10 10
11 import re 11 from mercurial import util, node
12
13 from mercurial import util, node, hg, error
14 from mercurial.i18n import _ 12 from mercurial.i18n import _
15 13
16 import lfutil 14 import lfutil
17 15
18 class StoreError(Exception): 16 class StoreError(Exception):
162 'contents' controls verification of content hash. 160 'contents' controls verification of content hash.
163 'filestocheck' is list of files to check. 161 'filestocheck' is list of files to check.
164 Returns _true_ if any problems are found! 162 Returns _true_ if any problems are found!
165 ''' 163 '''
166 raise NotImplementedError('abstract method') 164 raise NotImplementedError('abstract method')
167
168 import localstore, wirestore
169
170 _storeprovider = {
171 'file': [localstore.localstore],
172 'http': [wirestore.wirestore],
173 'https': [wirestore.wirestore],
174 'ssh': [wirestore.wirestore],
175 }
176
177 _scheme_re = re.compile(r'^([a-zA-Z0-9+-.]+)://')
178
179 # During clone this function is passed the src's ui object
180 # but it needs the dest's ui object so it can read out of
181 # the config file. Use repo.ui instead.
182 def _openstore(repo, remote=None, put=False):
183 ui = repo.ui
184
185 if not remote:
186 lfpullsource = getattr(repo, 'lfpullsource', None)
187 if lfpullsource:
188 path = ui.expandpath(lfpullsource)
189 elif put:
190 path = ui.expandpath('default-push', 'default')
191 else:
192 path = ui.expandpath('default')
193
194 # ui.expandpath() leaves 'default-push' and 'default' alone if
195 # they cannot be expanded: fallback to the empty string,
196 # meaning the current directory.
197 if path == 'default-push' or path == 'default':
198 path = ''
199 remote = repo
200 else:
201 path, _branches = hg.parseurl(path)
202 remote = hg.peer(repo, {}, path)
203
204 # The path could be a scheme so use Mercurial's normal functionality
205 # to resolve the scheme to a repository and use its path
206 path = util.safehasattr(remote, 'url') and remote.url() or remote.path
207
208 match = _scheme_re.match(path)
209 if not match: # regular filesystem path
210 scheme = 'file'
211 else:
212 scheme = match.group(1)
213
214 try:
215 storeproviders = _storeprovider[scheme]
216 except KeyError:
217 raise error.Abort(_('unsupported URL scheme %r') % scheme)
218
219 for classobj in storeproviders:
220 try:
221 return classobj(ui, repo, remote)
222 except lfutil.storeprotonotcapable:
223 pass
224
225 raise error.Abort(_('%s does not appear to be a largefile store') %
226 util.hidepassword(path))