|
1 # This software may be used and distributed according to the terms of the |
|
2 # GNU General Public License version 2 or any later version. |
|
3 |
|
4 from __future__ import absolute_import |
|
5 |
|
6 import re |
|
7 |
|
8 from mercurial.i18n import _ |
|
9 |
|
10 from mercurial import ( |
|
11 error, |
|
12 hg, |
|
13 util, |
|
14 ) |
|
15 |
|
16 from . import ( |
|
17 lfutil, |
|
18 localstore, |
|
19 wirestore, |
|
20 ) |
|
21 |
|
22 # During clone this function is passed the src's ui object |
|
23 # but it needs the dest's ui object so it can read out of |
|
24 # the config file. Use repo.ui instead. |
|
25 def _openstore(repo, remote=None, put=False): |
|
26 ui = repo.ui |
|
27 |
|
28 if not remote: |
|
29 lfpullsource = getattr(repo, 'lfpullsource', None) |
|
30 if lfpullsource: |
|
31 path = ui.expandpath(lfpullsource) |
|
32 elif put: |
|
33 path = ui.expandpath('default-push', 'default') |
|
34 else: |
|
35 path = ui.expandpath('default') |
|
36 |
|
37 # ui.expandpath() leaves 'default-push' and 'default' alone if |
|
38 # they cannot be expanded: fallback to the empty string, |
|
39 # meaning the current directory. |
|
40 if path == 'default-push' or path == 'default': |
|
41 path = '' |
|
42 remote = repo |
|
43 else: |
|
44 path, _branches = hg.parseurl(path) |
|
45 remote = hg.peer(repo, {}, path) |
|
46 |
|
47 # The path could be a scheme so use Mercurial's normal functionality |
|
48 # to resolve the scheme to a repository and use its path |
|
49 path = util.safehasattr(remote, 'url') and remote.url() or remote.path |
|
50 |
|
51 match = _scheme_re.match(path) |
|
52 if not match: # regular filesystem path |
|
53 scheme = 'file' |
|
54 else: |
|
55 scheme = match.group(1) |
|
56 |
|
57 try: |
|
58 storeproviders = _storeprovider[scheme] |
|
59 except KeyError: |
|
60 raise error.Abort(_('unsupported URL scheme %r') % scheme) |
|
61 |
|
62 for classobj in storeproviders: |
|
63 try: |
|
64 return classobj(ui, repo, remote) |
|
65 except lfutil.storeprotonotcapable: |
|
66 pass |
|
67 |
|
68 raise error.Abort(_('%s does not appear to be a largefile store') % |
|
69 util.hidepassword(path)) |
|
70 |
|
71 _storeprovider = { |
|
72 'file': [localstore.localstore], |
|
73 'http': [wirestore.wirestore], |
|
74 'https': [wirestore.wirestore], |
|
75 'ssh': [wirestore.wirestore], |
|
76 } |
|
77 |
|
78 _scheme_re = re.compile(r'^([a-zA-Z0-9+-.]+)://') |