##// END OF EJS Templates
largefile: use sysstr to check for attribute presence in `openstore`...
marmoute -
r51784:1b265336 default
parent child Browse files
Show More
@@ -1,96 +1,96 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
4
5 import re
5 import re
6
6
7 from mercurial.i18n import _
7 from mercurial.i18n import _
8 from mercurial.pycompat import getattr
8 from mercurial.pycompat import getattr
9 from mercurial import (
9 from mercurial import (
10 error,
10 error,
11 hg,
11 hg,
12 util,
12 util,
13 )
13 )
14 from mercurial.utils import (
14 from mercurial.utils import (
15 urlutil,
15 urlutil,
16 )
16 )
17
17
18 from . import (
18 from . import (
19 lfutil,
19 lfutil,
20 localstore,
20 localstore,
21 wirestore,
21 wirestore,
22 )
22 )
23
23
24
24
25 # During clone this function is passed the src's ui object
25 # During clone this function is passed the src's ui object
26 # but it needs the dest's ui object so it can read out of
26 # but it needs the dest's ui object so it can read out of
27 # the config file. Use repo.ui instead.
27 # the config file. Use repo.ui instead.
28 def openstore(repo=None, remote=None, put=False, ui=None):
28 def openstore(repo=None, remote=None, put=False, ui=None):
29 if ui is None:
29 if ui is None:
30 ui = repo.ui
30 ui = repo.ui
31
31
32 if not remote:
32 if not remote:
33 lfpullsource = getattr(repo, 'lfpullsource', None)
33 lfpullsource = getattr(repo, 'lfpullsource', None)
34 if put:
34 if put:
35 path = urlutil.get_unique_push_path(
35 path = urlutil.get_unique_push_path(
36 b'lfpullsource', repo, ui, lfpullsource
36 b'lfpullsource', repo, ui, lfpullsource
37 )
37 )
38 else:
38 else:
39 path = urlutil.get_unique_pull_path_obj(
39 path = urlutil.get_unique_pull_path_obj(
40 b'lfpullsource', ui, lfpullsource
40 b'lfpullsource', ui, lfpullsource
41 )
41 )
42
42
43 # XXX we should not explicitly pass b'default', as this will result in
43 # XXX we should not explicitly pass b'default', as this will result in
44 # b'default' being returned if no `paths.default` was defined. We
44 # b'default' being returned if no `paths.default` was defined. We
45 # should explicitely handle the lack of value instead.
45 # should explicitely handle the lack of value instead.
46 if repo is None:
46 if repo is None:
47 path = urlutil.get_unique_pull_path_obj(
47 path = urlutil.get_unique_pull_path_obj(
48 b'lfs',
48 b'lfs',
49 ui,
49 ui,
50 b'default',
50 b'default',
51 )
51 )
52 remote = hg.peer(repo or ui, {}, path)
52 remote = hg.peer(repo or ui, {}, path)
53 elif path.loc == b'default-push' or path.loc == b'default':
53 elif path.loc == b'default-push' or path.loc == b'default':
54 remote = repo
54 remote = repo
55 else:
55 else:
56 remote = hg.peer(repo or ui, {}, path)
56 remote = hg.peer(repo or ui, {}, path)
57
57
58 # The path could be a scheme so use Mercurial's normal functionality
58 # The path could be a scheme so use Mercurial's normal functionality
59 # to resolve the scheme to a repository and use its path
59 # to resolve the scheme to a repository and use its path
60 path = util.safehasattr(remote, b'url') and remote.url() or remote.path
60 path = util.safehasattr(remote, 'url') and remote.url() or remote.path
61
61
62 match = _scheme_re.match(path)
62 match = _scheme_re.match(path)
63 if not match: # regular filesystem path
63 if not match: # regular filesystem path
64 scheme = b'file'
64 scheme = b'file'
65 else:
65 else:
66 scheme = match.group(1)
66 scheme = match.group(1)
67
67
68 try:
68 try:
69 storeproviders = _storeprovider[scheme]
69 storeproviders = _storeprovider[scheme]
70 except KeyError:
70 except KeyError:
71 raise error.Abort(_(b'unsupported URL scheme %r') % scheme)
71 raise error.Abort(_(b'unsupported URL scheme %r') % scheme)
72
72
73 for classobj in storeproviders:
73 for classobj in storeproviders:
74 try:
74 try:
75 return classobj(ui, repo, remote)
75 return classobj(ui, repo, remote)
76 except lfutil.storeprotonotcapable:
76 except lfutil.storeprotonotcapable:
77 pass
77 pass
78
78
79 raise error.Abort(
79 raise error.Abort(
80 _(b'%s does not appear to be a largefile store')
80 _(b'%s does not appear to be a largefile store')
81 % urlutil.hidepassword(path)
81 % urlutil.hidepassword(path)
82 )
82 )
83
83
84
84
85 _storeprovider = {
85 _storeprovider = {
86 b'file': [localstore.localstore],
86 b'file': [localstore.localstore],
87 b'http': [wirestore.wirestore],
87 b'http': [wirestore.wirestore],
88 b'https': [wirestore.wirestore],
88 b'https': [wirestore.wirestore],
89 b'ssh': [wirestore.wirestore],
89 b'ssh': [wirestore.wirestore],
90 }
90 }
91
91
92 _scheme_re = re.compile(br'^([a-zA-Z0-9+-.]+)://')
92 _scheme_re = re.compile(br'^([a-zA-Z0-9+-.]+)://')
93
93
94
94
95 def getlfile(ui, hash):
95 def getlfile(ui, hash):
96 return util.chunkbuffer(openstore(ui=ui)._get(hash))
96 return util.chunkbuffer(openstore(ui=ui)._get(hash))
General Comments 0
You need to be logged in to leave comments. Login now