Mercurial > hg
diff mercurial/localrepo.py @ 39852:2c2fadbc9851
localrepo: automatically load lfs extension when required (BC)
If an unrecognized requirement is present (possibly due to an unloaded
extension), the user will get an error message telling them to go to
https://mercurial-scm.org/wiki/MissingRequirement for more info.
And some requirements clearly map to known extensions shipped by
Mercurial.
This commit teaches repository loading to automatically map
requirements to extensions. We implement support for loading the
lfs extension when the "lfs" requirement is present.
This behavior feels more user-friendly to me and I'm having trouble
coming up with a compelling reason to not do it. The strongest
argument I have against is that - strictly speaking - requirements
are general repository features and there could be N providers of that
feature. e.g. in the case of LFS, there could be another extension
implementing LFS support. And the user would want to use this
non-official extension rather than the built-in one. The way this
patch implements things, the non-official extension could be
missing and Mercurial would load the official lfs extension, leading
to unexpected behavior. But this feels like a highly marginal use
case to me and doesn't outweigh the user benefit of "it just works."
If someone really wanted to e.g. use a custom LFS extension, they
could prevent the built-in one from being loaded by either defining
"extensions.lfs=/path/to/custom/extension" or "extensions.lfs=!",
as the automatic extension loading only occurs if there is no config
entry for that extension.
Differential Revision: https://phab.mercurial-scm.org/D4711
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 20 Sep 2018 15:06:43 -0700 |
parents | d89d5bc06eaa |
children | 823a580448d7 |
line wrap: on
line diff
--- a/mercurial/localrepo.py Wed Sep 19 13:48:59 2018 -0700 +++ b/mercurial/localrepo.py Thu Sep 20 15:06:43 2018 -0700 @@ -446,6 +446,9 @@ # process any new extensions that it may have pulled in. try: ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) + # Run this before extensions.loadall() so extensions can be + # automatically enabled. + afterhgrcload(ui, wdirvfs, hgvfs, requirements) except IOError: pass else: @@ -572,6 +575,30 @@ features=features, intents=intents) +def afterhgrcload(ui, wdirvfs, hgvfs, requirements): + """Perform additional actions after .hg/hgrc is loaded. + + This function is called during repository loading immediately after + the .hg/hgrc file is loaded and before per-repo extensions are loaded. + + The function can be used to validate configs, automatically add + options (including extensions) based on requirements, etc. + """ + + # Map of requirements to list of extensions to load automatically when + # requirement is present. + autoextensions = { + b'lfs': [b'lfs'], + } + + for requirement, names in sorted(autoextensions.items()): + if requirement not in requirements: + continue + + for name in names: + if not ui.hasconfig(b'extensions', name): + ui.setconfig(b'extensions', name, b'', source='autoload') + def gathersupportedrequirements(ui): """Determine the complete set of recognized requirements.""" # Start with all requirements supported by this file.