Mercurial > hg
diff hgext/lfs/__init__.py @ 40268:9c4cbbb0fc51
lfs: register the flag processors per repository
Previously, enabling the extension for any repo in commandserver or hgweb would
enable the flags on all repos. Since localrepo.resolverevlogstorevfsoptions()
is called so early, the check to see if the extension is enabled on the repo
(which hasn't been instantiated yet) is a bit awkward. But I don't see a better
way.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 04 Oct 2018 00:17:26 -0400 |
parents | b06303a208be |
children | ef0baff11aea |
line wrap: on
line diff
--- a/hgext/lfs/__init__.py Tue Oct 09 21:53:21 2018 -0400 +++ b/hgext/lfs/__init__.py Thu Oct 04 00:17:26 2018 -0400 @@ -124,6 +124,8 @@ from __future__ import absolute_import +import sys + from mercurial.i18n import _ from mercurial import ( @@ -204,6 +206,12 @@ templatekeyword = registrar.templatekeyword() filesetpredicate = registrar.filesetpredicate() +lfsprocessor = ( + wrapper.readfromstore, + wrapper.writetostore, + wrapper.bypasscheckhash, +) + def featuresetup(ui, supported): # don't die on seeing a repo with the lfs requirement supported |= {'lfs'} @@ -302,12 +310,28 @@ wrapfunction(filelog, 'renamed', wrapper.filelogrenamed) wrapfunction(filelog, 'size', wrapper.filelogsize) +def _resolverevlogstorevfsoptions(orig, ui, requirements, features): + opts = orig(ui, requirements, features) + for name, module in extensions.extensions(ui): + if module is sys.modules[__name__]: + if revlog.REVIDX_EXTSTORED in opts[b'flagprocessors']: + msg = (_(b"cannot register multiple processors on flag '%#x'.") + % revlog.REVIDX_EXTSTORED) + raise error.Abort(msg) + + opts[b'flagprocessors'][revlog.REVIDX_EXTSTORED] = lfsprocessor + break + + return opts + def extsetup(ui): 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) @@ -334,15 +358,6 @@ wrapfunction(context.basefilectx, 'isbinary', wrapper.filectxisbinary) context.basefilectx.islfs = wrapper.filectxislfs - revlog.addflagprocessor( - revlog.REVIDX_EXTSTORED, - ( - wrapper.readfromstore, - wrapper.writetostore, - wrapper.bypasscheckhash, - ), - ) - scmutil.fileprefetchhooks.add('lfs', wrapper._prefetchfiles) # Make bundle choose changegroup3 instead of changegroup2. This affects