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