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