Skip to content
Snippets Groups Projects
Commit 84d61fdc authored by Matt Harbison's avatar Matt Harbison
Browse files

lfs: convert to using exthelper to wrap functions

I'm not 100% sure that upgraderequirements() can be double annotated safely, but
it seems OK based on printing the address of the function being wrapped.

One thing I've noticed is that @eh.reposetup doesn't do the usual check to
ensure that it's a local repo.  Should that be baked into @eh.reposetup()
somehow, possibly with a non-default option to skip the check?  It seems like a
gaping hole if every function that gets registered needs to add this check.
parent 555215e2
No related branches found
No related tags found
No related merge requests found
......@@ -129,7 +129,4 @@
from mercurial.i18n import _
from mercurial import (
bundle2,
changegroup,
cmdutil,
config,
......@@ -135,5 +132,4 @@
config,
context,
error,
exchange,
extensions,
......@@ -137,6 +133,7 @@
error,
exchange,
extensions,
exthelper,
filelog,
filesetlang,
localrepo,
......@@ -148,5 +145,4 @@
revlog,
scmutil,
templateutil,
upgrade,
util,
......@@ -152,7 +148,4 @@
util,
vfs as vfsmod,
wireprotoserver,
wireprotov1server,
)
from . import (
......@@ -167,6 +160,7 @@
# leave the attribute unspecified.
testedwith = 'ships-with-hg-core'
configtable = {}
configitem = registrar.configitem(configtable)
eh = exthelper.exthelper()
eh.merge(wrapper.eh)
eh.merge(wireprotolfsserver.eh)
......@@ -172,4 +166,10 @@
configitem('experimental', 'lfs.serve',
cmdtable = eh.cmdtable
configtable = eh.configtable
extsetup = eh.finalextsetup
uisetup = eh.finaluisetup
reposetup = eh.finalreposetup
eh.configitem('experimental', 'lfs.serve',
default=True,
)
......@@ -174,5 +174,5 @@
default=True,
)
configitem('experimental', 'lfs.user-agent',
eh.configitem('experimental', 'lfs.user-agent',
default=None,
)
......@@ -177,5 +177,5 @@
default=None,
)
configitem('experimental', 'lfs.disableusercache',
eh.configitem('experimental', 'lfs.disableusercache',
default=False,
)
......@@ -180,6 +180,6 @@
default=False,
)
configitem('experimental', 'lfs.worker-enable',
eh.configitem('experimental', 'lfs.worker-enable',
default=False,
)
......@@ -183,6 +183,6 @@
default=False,
)
configitem('lfs', 'url',
eh.configitem('lfs', 'url',
default=None,
)
......@@ -187,6 +187,6 @@
default=None,
)
configitem('lfs', 'usercache',
eh.configitem('lfs', 'usercache',
default=None,
)
# Deprecated
......@@ -190,6 +190,6 @@
default=None,
)
# Deprecated
configitem('lfs', 'threshold',
eh.configitem('lfs', 'threshold',
default=None,
)
......@@ -194,5 +194,5 @@
default=None,
)
configitem('lfs', 'track',
eh.configitem('lfs', 'track',
default='none()',
)
......@@ -197,5 +197,5 @@
default='none()',
)
configitem('lfs', 'retry',
eh.configitem('lfs', 'retry',
default=5,
)
......@@ -200,9 +200,5 @@
default=5,
)
cmdtable = {}
command = registrar.command(cmdtable)
templatekeyword = registrar.templatekeyword()
filesetpredicate = registrar.filesetpredicate()
......@@ -216,6 +212,7 @@
# don't die on seeing a repo with the lfs requirement
supported |= {'lfs'}
def uisetup(ui):
@eh.uisetup
def _uisetup(ui):
localrepo.featuresetupfuncs.add(featuresetup)
......@@ -220,6 +217,7 @@
localrepo.featuresetupfuncs.add(featuresetup)
def reposetup(ui, repo):
@eh.reposetup
def _reposetup(ui, repo):
# Nothing to do with a remote repo
if not repo.local():
return
......@@ -305,6 +303,7 @@
return _match
# Called by remotefilelog
def wrapfilelog(filelog):
wrapfunction = extensions.wrapfunction
......@@ -312,6 +311,7 @@
wrapfunction(filelog, 'renamed', wrapper.filelogrenamed)
wrapfunction(filelog, 'size', wrapper.filelogsize)
@eh.wrapfunction(localrepo, 'resolverevlogstorevfsoptions')
def _resolverevlogstorevfsoptions(orig, ui, requirements, features):
opts = orig(ui, requirements, features)
for name, module in extensions.extensions(ui):
......@@ -326,6 +326,7 @@
return opts
def extsetup(ui):
@eh.extsetup
def _extsetup(ui):
wrapfilelog(filelog.filelog)
......@@ -330,36 +331,5 @@
wrapfilelog(filelog.filelog)
wrapfunction = extensions.wrapfunction
wrapfunction(localrepo, 'makefilestorage', wrapper.localrepomakefilestorage)
wrapfunction(localrepo, 'resolverevlogstorevfsoptions',
_resolverevlogstorevfsoptions)
wrapfunction(cmdutil, '_updatecatformatter', wrapper._updatecatformatter)
wrapfunction(scmutil, 'wrapconvertsink', wrapper.convertsink)
wrapfunction(upgrade, '_finishdatamigration',
wrapper.upgradefinishdatamigration)
wrapfunction(upgrade, 'preservedrequirements',
wrapper.upgraderequirements)
wrapfunction(upgrade, 'supporteddestrequirements',
wrapper.upgraderequirements)
wrapfunction(changegroup,
'allsupportedversions',
wrapper.allsupportedversions)
wrapfunction(exchange, 'push', wrapper.push)
wrapfunction(wireprotov1server, '_capabilities', wrapper._capabilities)
wrapfunction(wireprotoserver, 'handlewsgirequest',
wireprotolfsserver.handlewsgirequest)
wrapfunction(context.basefilectx, 'cmp', wrapper.filectxcmp)
wrapfunction(context.basefilectx, 'isbinary', wrapper.filectxisbinary)
context.basefilectx.islfs = wrapper.filectxislfs
scmutil.fileprefetchhooks.add('lfs', wrapper._prefetchfiles)
# Make bundle choose changegroup3 instead of changegroup2. This affects
......@@ -367,13 +337,6 @@
# "packed1". Using "packed1" with lfs will likely cause trouble.
exchange._bundlespeccontentopts["v2"]["cg.version"] = "03"
# bundlerepo uses "vfsmod.readonlyvfs(othervfs)", we need to make sure lfs
# options and blob stores are passed from othervfs to the new readonlyvfs.
wrapfunction(vfsmod.readonlyvfs, '__init__', wrapper.vfsinit)
# when writing a bundle via "hg bundle" command, upload related LFS blobs
wrapfunction(bundle2, 'writenewbundle', wrapper.writenewbundle)
@filesetpredicate('lfs()')
def lfsfileset(mctx, x):
"""File that uses LFS storage."""
......@@ -409,8 +372,8 @@
f = templateutil._showcompatlist(context, mapping, 'lfs_file', files)
return templateutil.hybrid(f, files, makemap, pycompat.identity)
@command('debuglfsupload',
[('r', 'rev', [], _('upload large files introduced by REV'))])
@eh.command('debuglfsupload',
[('r', 'rev', [], _('upload large files introduced by REV'))])
def debuglfsupload(ui, repo, **opts):
"""upload lfs blobs added by the working copy parent or given revisions"""
revs = opts.get(r'rev', [])
......
......@@ -17,5 +17,6 @@
)
from mercurial import (
exthelper,
pycompat,
util,
......@@ -20,5 +21,6 @@
pycompat,
util,
wireprotoserver,
)
from . import blobstore
......@@ -31,6 +33,9 @@
HTTP_NOT_ACCEPTABLE = hgwebcommon.HTTP_NOT_ACCEPTABLE
HTTP_UNSUPPORTED_MEDIA_TYPE = hgwebcommon.HTTP_UNSUPPORTED_MEDIA_TYPE
eh = exthelper.exthelper()
@eh.wrapfunction(wireprotoserver, 'handlewsgirequest')
def handlewsgirequest(orig, rctx, req, res, checkperm):
"""Wrap wireprotoserver.handlewsgirequest() to possibly process an LFS
request if it is left unprocessed by the wrapped method.
......
......@@ -13,4 +13,8 @@
from mercurial.node import bin, hex, nullid, short
from mercurial import (
bundle2,
changegroup,
cmdutil,
context,
error,
......@@ -16,3 +20,6 @@
error,
exchange,
exthelper,
localrepo,
repository,
revlog,
......@@ -17,3 +24,5 @@
repository,
revlog,
scmutil,
upgrade,
util,
......@@ -19,4 +28,6 @@
util,
vfs as vfsmod,
wireprotov1server,
)
from mercurial.utils import (
......@@ -31,9 +42,12 @@
pointer,
)
eh = exthelper.exthelper()
@eh.wrapfunction(localrepo, 'makefilestorage')
def localrepomakefilestorage(orig, requirements, features, **kwargs):
if b'lfs' in requirements:
features.add(repository.REPO_FEATURE_LFS)
return orig(requirements=requirements, features=features, **kwargs)
......@@ -34,11 +48,12 @@
def localrepomakefilestorage(orig, requirements, features, **kwargs):
if b'lfs' in requirements:
features.add(repository.REPO_FEATURE_LFS)
return orig(requirements=requirements, features=features, **kwargs)
@eh.wrapfunction(changegroup, 'allsupportedversions')
def allsupportedversions(orig, ui):
versions = orig(ui)
versions.add('03')
return versions
......@@ -40,8 +55,9 @@
def allsupportedversions(orig, ui):
versions = orig(ui)
versions.add('03')
return versions
@eh.wrapfunction(wireprotov1server, '_capabilities')
def _capabilities(orig, repo, proto):
'''Wrap server command to announce lfs server capability'''
caps = orig(repo, proto)
......@@ -130,6 +146,7 @@
flags = rlog._revlog.flags(rev)
return bool(flags & revlog.REVIDX_EXTSTORED)
# Wrapping may also be applied by remotefilelog
def filelogaddrevision(orig, self, text, transaction, link, p1, p2,
cachedelta=None, node=None,
flags=revlog.REVIDX_DEFAULT_FLAGS, **kwds):
......@@ -149,6 +166,7 @@
return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta,
node=node, flags=flags, **kwds)
# Wrapping may also be applied by remotefilelog
def filelogrenamed(orig, self, node):
if _islfs(self, node):
rawtext = self._revlog.revision(node, raw=True)
......@@ -161,6 +179,7 @@
return False
return orig(self, node)
# Wrapping may also be applied by remotefilelog
def filelogsize(orig, self, rev):
if _islfs(self, rev=rev):
# fast path: use lfs metadata to answer size
......@@ -169,6 +188,7 @@
return int(metadata['size'])
return orig(self, rev)
@eh.wrapfunction(context.basefilectx, 'cmp')
def filectxcmp(orig, self, fctx):
"""returns True if text is different than fctx"""
# some fctx (ex. hg-git) is not based on basefilectx and do not have islfs
......@@ -179,6 +199,7 @@
return p1.oid() != p2.oid()
return orig(self, fctx)
@eh.wrapfunction(context.basefilectx, 'isbinary')
def filectxisbinary(orig, self):
if self.islfs():
# fast path: use lfs metadata to answer isbinary
......@@ -187,6 +208,7 @@
return bool(int(metadata.get('x-is-binary', 1)))
return orig(self)
@eh.addattr(context.basefilectx, 'islfs')
def filectxislfs(self):
return _islfs(self.filelog(), self.filenode())
......@@ -190,7 +212,8 @@
def filectxislfs(self):
return _islfs(self.filelog(), self.filenode())
@eh.wrapfunction(cmdutil, '_updatecatformatter')
def _updatecatformatter(orig, fm, ctx, matcher, path, decode):
orig(fm, ctx, matcher, path, decode)
fm.data(rawdata=ctx[path].rawdata())
......@@ -193,7 +216,8 @@
def _updatecatformatter(orig, fm, ctx, matcher, path, decode):
orig(fm, ctx, matcher, path, decode)
fm.data(rawdata=ctx[path].rawdata())
@eh.wrapfunction(scmutil, 'wrapconvertsink')
def convertsink(orig, sink):
sink = orig(sink)
if sink.repotype == 'hg':
......@@ -219,6 +243,9 @@
return sink
# bundlerepo uses "vfsmod.readonlyvfs(othervfs)", we need to make sure lfs
# options and blob stores are passed from othervfs to the new readonlyvfs.
@eh.wrapfunction(vfsmod.readonlyvfs, '__init__')
def vfsinit(orig, self, othervfs):
orig(self, othervfs)
# copy lfs related options
......@@ -290,6 +317,7 @@
"""
return uploadblobsfromrevs(pushop.repo, pushop.outgoing.missing)
@eh.wrapfunction(exchange, 'push')
def push(orig, repo, remote, *args, **kwargs):
"""bail on push if the extension isn't enabled on remote when needed, and
update the remote store based on the destination path."""
......@@ -316,6 +344,8 @@
else:
return orig(repo, remote, *args, **kwargs)
# when writing a bundle via "hg bundle" command, upload related LFS blobs
@eh.wrapfunction(bundle2, 'writenewbundle')
def writenewbundle(orig, ui, repo, source, filename, bundletype, outgoing,
*args, **kwargs):
"""upload LFS blobs added by outgoing revisions on 'hg bundle'"""
......@@ -393,6 +423,7 @@
remoteblob = repo.svfs.lfsremoteblobstore
remoteblob.writebatch(pointers, repo.svfs.lfslocalblobstore)
@eh.wrapfunction(upgrade, '_finishdatamigration')
def upgradefinishdatamigration(orig, ui, srcrepo, dstrepo, requirements):
orig(ui, srcrepo, dstrepo, requirements)
......@@ -407,6 +438,8 @@
ui.write(_('copying lfs blob %s\n') % oid)
lfutil.link(srclfsvfs.join(oid), dstlfsvfs.join(oid))
@eh.wrapfunction(upgrade, 'preservedrequirements')
@eh.wrapfunction(upgrade, 'supporteddestrequirements')
def upgraderequirements(orig, repo):
reqs = orig(repo)
if 'lfs' in repo.requirements:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment