comparison hgext/lfs/wrapper.py @ 35506:fa865878a849

lfs: show a friendly message when pushing lfs to a server without lfs enabled Upfront disclaimer: I don't know anything about the wire protocol, and this was pretty much cargo-culted from largefiles, and then clonebundles, since it seems more modern. I was surprised that exchange.push() will ensure all of the proper requirements when exchanging between two local repos, but doesn't care when one is remote. All this new capability marker does is inform the client that the extension is enabled remotely. It may or may not contain commits with external blobs. Open issues: - largefiles uses 'largefiles=serve' for its capability. Someday I hope to be able to push lfs blobs to an `hg serve` instance. That will probably require a distinct capability. Should it change to '=serve' then? Or just add an 'lfs-serve' capability then? - The flip side of this is more complicated. It looks like largefiles adds an 'lheads' command for the client to signal to the server that the extension is loaded. That is then converted to 'heads' and sent through the normal wire protocol plumbing. A client using the 'heads' command directly is kicked out with a message indicating that the largefiles extension must be loaded. We could do similar with 'lfsheads', but then a repo with both largefiles and lfs blobs can't be pushed over the wire. Hopefully somebody with more wire protocol experience can think of something else. I see 'x-hgarg-1' on some commands in the tests, but not on heads, and didn't dig any further.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 23 Dec 2017 17:49:12 -0500
parents 2526579a30e0
children a77418095530
comparison
equal deleted inserted replaced
35505:2526579a30e0 35506:fa865878a849
36 36
37 def allsupportedversions(orig, ui): 37 def allsupportedversions(orig, ui):
38 versions = orig(ui) 38 versions = orig(ui)
39 versions.add('03') 39 versions.add('03')
40 return versions 40 return versions
41
42 def _capabilities(orig, repo, proto):
43 '''Wrap server command to announce lfs server capability'''
44 caps = orig(repo, proto)
45 # XXX: change to 'lfs=serve' when separate git server isn't required?
46 caps.append('lfs')
47 return caps
41 48
42 def bypasscheckhash(self, text): 49 def bypasscheckhash(self, text):
43 return False 50 return False
44 51
45 def readfromstore(self, text): 52 def readfromstore(self, text):
262 Read through the revisions to push, looking for filelog entries that can be 269 Read through the revisions to push, looking for filelog entries that can be
263 deserialized into metadata so that we can block the push on their upload to 270 deserialized into metadata so that we can block the push on their upload to
264 the remote blobstore. 271 the remote blobstore.
265 """ 272 """
266 return uploadblobsfromrevs(pushop.repo, pushop.outgoing.missing) 273 return uploadblobsfromrevs(pushop.repo, pushop.outgoing.missing)
274
275 def push(orig, repo, remote, *args, **kwargs):
276 """bail on push if the extension isn't enabled on remote when needed"""
277 if 'lfs' in repo.requirements:
278 # If the remote peer is for a local repo, the requirement tests in the
279 # base class method enforce lfs support. Otherwise, some revisions in
280 # this repo use lfs, and the remote repo needs the extension loaded.
281 if not remote.local() and not remote.capable('lfs'):
282 # This is a copy of the message in exchange.push() when requirements
283 # are missing between local repos.
284 m = _("required features are not supported in the destination: %s")
285 raise error.Abort(m % 'lfs',
286 hint=_('enable the lfs extension on the server'))
287 return orig(repo, remote, *args, **kwargs)
267 288
268 def writenewbundle(orig, ui, repo, source, filename, bundletype, outgoing, 289 def writenewbundle(orig, ui, repo, source, filename, bundletype, outgoing,
269 *args, **kwargs): 290 *args, **kwargs):
270 """upload LFS blobs added by outgoing revisions on 'hg bundle'""" 291 """upload LFS blobs added by outgoing revisions on 'hg bundle'"""
271 uploadblobsfromrevs(repo, outgoing.missing) 292 uploadblobsfromrevs(repo, outgoing.missing)