author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Fri, 09 Jul 2021 16:28:45 +0200 | |
changeset 47576 | c3c38eb08465 |
parent 46947 | 3f29765e0d95 |
child 48875 | 6000f5b25c9b |
permissions | -rw-r--r-- |
15168 | 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 |
||
29305
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
4 |
from __future__ import absolute_import |
15168 | 5 |
|
6 |
import re |
|
7 |
||
8 |
from mercurial.i18n import _ |
|
43089
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
9 |
from mercurial.pycompat import getattr |
29305
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
10 |
from mercurial import ( |
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
11 |
error, |
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
12 |
hg, |
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
13 |
util, |
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
14 |
) |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43089
diff
changeset
|
15 |
from mercurial.utils import ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43089
diff
changeset
|
16 |
urlutil, |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43089
diff
changeset
|
17 |
) |
19918
ae65192fd6b4
largefiles: refactor basestore, extract _gethash method
Mads Kiilerich <madski@unity3d.com>
parents:
19008
diff
changeset
|
18 |
|
29305
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
19 |
from . import ( |
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
20 |
lfutil, |
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
21 |
localstore, |
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
22 |
wirestore, |
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
23 |
) |
15168 | 24 |
|
46947
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
25 |
|
15168 | 26 |
# During clone this function is passed the src's ui object |
27 |
# but it needs the dest's ui object so it can read out of |
|
28 |
# the config file. Use repo.ui instead. |
|
35564
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
29355
diff
changeset
|
29 |
def openstore(repo=None, remote=None, put=False, ui=None): |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
29355
diff
changeset
|
30 |
if ui is None: |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
29355
diff
changeset
|
31 |
ui = repo.ui |
15168 | 32 |
|
33 |
if not remote: |
|
15943
f9efb325ea32
largefiles: fix caching largefiles from an aliased repo (issue3212)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15319
diff
changeset
|
34 |
lfpullsource = getattr(repo, 'lfpullsource', None) |
46947
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
35 |
if put: |
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
36 |
path = urlutil.get_unique_push_path( |
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
37 |
b'lfpullsource', repo, ui, lfpullsource |
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
38 |
) |
15943
f9efb325ea32
largefiles: fix caching largefiles from an aliased repo (issue3212)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15319
diff
changeset
|
39 |
else: |
46947
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
40 |
path, _branches = urlutil.get_unique_pull_path( |
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
41 |
b'lfpullsource', repo, ui, lfpullsource |
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
42 |
) |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15169
diff
changeset
|
43 |
|
46947
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
44 |
# XXX we should not explicitly pass b'default', as this will result in |
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
45 |
# b'default' being returned if no `paths.default` was defined. We |
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
46 |
# should explicitely handle the lack of value instead. |
35564
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
29355
diff
changeset
|
47 |
if repo is None: |
46947
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
48 |
path, _branches = urlutil.get_unique_pull_path( |
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
49 |
b'lfs', repo, ui, b'default' |
3f29765e0d95
lfs: use the new APIs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
50 |
) |
35564
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
29355
diff
changeset
|
51 |
remote = hg.peer(repo or ui, {}, path) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
52 |
elif path == b'default-push' or path == b'default': |
15168 | 53 |
remote = repo |
54 |
else: |
|
46908
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
55 |
path, _branches = urlutil.parseurl(path) |
35564
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
29355
diff
changeset
|
56 |
remote = hg.peer(repo or ui, {}, path) |
15168 | 57 |
|
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 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
60 |
path = util.safehasattr(remote, b'url') and remote.url() or remote.path |
15168 | 61 |
|
62 |
match = _scheme_re.match(path) |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
63 |
if not match: # regular filesystem path |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
64 |
scheme = b'file' |
15168 | 65 |
else: |
66 |
scheme = match.group(1) |
|
67 |
||
68 |
try: |
|
69 |
storeproviders = _storeprovider[scheme] |
|
70 |
except KeyError: |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
71 |
raise error.Abort(_(b'unsupported URL scheme %r') % scheme) |
15168 | 72 |
|
16247
d87d9d8a8e03
largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents:
16154
diff
changeset
|
73 |
for classobj in storeproviders: |
15168 | 74 |
try: |
16247
d87d9d8a8e03
largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents:
16154
diff
changeset
|
75 |
return classobj(ui, repo, remote) |
15168 | 76 |
except lfutil.storeprotonotcapable: |
77 |
pass |
|
78 |
||
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
79 |
raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
80 |
_(b'%s does not appear to be a largefile store') |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43089
diff
changeset
|
81 |
% urlutil.hidepassword(path) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
82 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
83 |
|
29305
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
84 |
|
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
85 |
_storeprovider = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
86 |
b'file': [localstore.localstore], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
87 |
b'http': [wirestore.wirestore], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
88 |
b'https': [wirestore.wirestore], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
89 |
b'ssh': [wirestore.wirestore], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
90 |
} |
29305
814076f4ace3
largefiles: move basestore._openstore into new module to remove cycle
liscju <piotr.listkiewicz@gmail.com>
parents:
29067
diff
changeset
|
91 |
|
36310
ea62c2df882d
largefiles: make scheme regex a bytes regex
Augie Fackler <augie@google.com>
parents:
35564
diff
changeset
|
92 |
_scheme_re = re.compile(br'^([a-zA-Z0-9+-.]+)://') |
35564
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
29355
diff
changeset
|
93 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41365
diff
changeset
|
94 |
|
35564
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
29355
diff
changeset
|
95 |
def getlfile(ui, hash): |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
29355
diff
changeset
|
96 |
return util.chunkbuffer(openstore(ui=ui)._get(hash)) |