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