Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
39851:1f7b3b980af8 | 39852:2c2fadbc9851 |
---|---|
444 # The .hg/hgrc file may load extensions or contain config options | 444 # The .hg/hgrc file may load extensions or contain config options |
445 # that influence repository construction. Attempt to load it and | 445 # that influence repository construction. Attempt to load it and |
446 # process any new extensions that it may have pulled in. | 446 # process any new extensions that it may have pulled in. |
447 try: | 447 try: |
448 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) | 448 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) |
449 # Run this before extensions.loadall() so extensions can be | |
450 # automatically enabled. | |
451 afterhgrcload(ui, wdirvfs, hgvfs, requirements) | |
449 except IOError: | 452 except IOError: |
450 pass | 453 pass |
451 else: | 454 else: |
452 extensions.loadall(ui) | 455 extensions.loadall(ui) |
453 | 456 |
569 sharedpath=storebasepath, | 572 sharedpath=storebasepath, |
570 store=store, | 573 store=store, |
571 cachevfs=cachevfs, | 574 cachevfs=cachevfs, |
572 features=features, | 575 features=features, |
573 intents=intents) | 576 intents=intents) |
577 | |
578 def afterhgrcload(ui, wdirvfs, hgvfs, requirements): | |
579 """Perform additional actions after .hg/hgrc is loaded. | |
580 | |
581 This function is called during repository loading immediately after | |
582 the .hg/hgrc file is loaded and before per-repo extensions are loaded. | |
583 | |
584 The function can be used to validate configs, automatically add | |
585 options (including extensions) based on requirements, etc. | |
586 """ | |
587 | |
588 # Map of requirements to list of extensions to load automatically when | |
589 # requirement is present. | |
590 autoextensions = { | |
591 b'lfs': [b'lfs'], | |
592 } | |
593 | |
594 for requirement, names in sorted(autoextensions.items()): | |
595 if requirement not in requirements: | |
596 continue | |
597 | |
598 for name in names: | |
599 if not ui.hasconfig(b'extensions', name): | |
600 ui.setconfig(b'extensions', name, b'', source='autoload') | |
574 | 601 |
575 def gathersupportedrequirements(ui): | 602 def gathersupportedrequirements(ui): |
576 """Determine the complete set of recognized requirements.""" | 603 """Determine the complete set of recognized requirements.""" |
577 # Start with all requirements supported by this file. | 604 # Start with all requirements supported by this file. |
578 supported = set(localrepository._basesupported) | 605 supported = set(localrepository._basesupported) |