Re: [PATCH remotenames] configs: update configs to use registrar
I didn't fill in the commit message on this one. V2 incoming On 10/24/17 2:15 PM, Durham Goode wrote: # HG changeset patch # User Durham Goode # Date 1508879615 25200 # Tue Oct 24 14:13:35 2017 -0700 # Node ID 9ead5c33dd22a9a66cea009bcf76ffd801d5677e # Parent 5fb97b6b3d46fcd4dc1b3cb6be137762eb9e60e7 configs: update configs to use registrar diff --git a/remotenames.py b/remotenames.py --- a/remotenames.py +++ b/remotenames.py @@ -32,12 +32,14 @@ from mercurial import localrepo from mercurial import lock as lockmod from mercurial import namespaces from mercurial import obsutil +from mercurial import registrar from mercurial import repair from mercurial import repoview from mercurial import revset from mercurial import scmutil from mercurial import setdiscovery from mercurial import templatekw +from mercurial import ui as uimod from mercurial import url from mercurial import util from mercurial import vfs as vfsmod @@ -51,12 +53,64 @@ try: except ImportError: smartset = revset +configtable = {} +try: +from mercurial import registrar +if not util.safehasattr(registrar, 'configitem'): +raise ImportError() +# Supported in 4.3+ +configitem = registrar.configitem(configtable) +except ImportError: +# Support older releases that didn't register config defaults +registrar = None +def configitem(section, name, default=None): +configtable[(section, name)] = default + +def configdefault(orig, self, section, name, default=None, + untrusted=False): +if default is None: +default = configtable.get((section, name)) +return orig(self, section, name, default=default, untrusted=untrusted) + +configitem('remotenames', 'alias.default', default=False) +configitem('remotenames', 'allownonfastforward', default=False) +configitem('remotenames', 'bookmarks', default=True) +configitem('remotenames', 'branches', default=True) +configitem('remotenames', 'calculatedistance', default=True) +configitem('remotenames', 'disallowedbookmarks', default=[]) +configitem('remotenames', 'disallowedhint', default=None) +configitem('remotenames', 'disallowedto', default=None) +configitem('remotenames', 'fastheaddiscovery', default=True) +configitem('remotenames', 'forcecompat', default=False) +configitem('remotenames', 'forceto', default=False) +configitem('remotenames', 'hoist', default='default') +configitem('remotenames', 'precachecurrent', default=True) +configitem('remotenames', 'precachedistance', default=True) +configitem('remotenames', 'pushanonheads', default=False) +configitem('remotenames', 'pushrev', default=None) +configitem('remotenames', 'resolvenodes', default=True) +configitem('remotenames', 'selectivepull', default=False) +configitem('remotenames', 'selectivepulldefault', default=[]) +configitem('remotenames', 'suppressbranches', default=False) +configitem('remotenames', 'syncbookmarks', default=False) +configitem('remotenames', 'tracking', default=True) +configitem('remotenames', 'transitionbookmarks', default=[]) +configitem('remotenames', 'transitionmessage', default=None) +configitem('remotenames', 'upstream', default=[]) + # namespace to use when recording an hg journal entry journalremotebookmarktype = 'remotebookmark' # name of the file that is used to mark that transition to selectivepull has # happened _selectivepullenabledfile = 'selectivepullenabled' +def uisetup(ui): +if registrar is None: +if util.safehasattr(uimod.ui, '_config'): +extensions.wrapfunction(uimod.ui, '_config', configdefault) +else: +extensions.wrapfunction(uimod.ui, 'config', configdefault) + def exbookcalcupdate(orig, ui, repo, checkout): '''Return a tuple (targetrev, movemarkfrom) indicating the rev to check out and where to move the active bookmark from, if needed.''' @@ -85,7 +139,7 @@ def expushop(orig, pushop, repo, remote, setattr(pushop, flag, kwargs.pop(flag, None)) def _isselectivepull(ui): -return ui.configbool('remotenames', 'selectivepull', False) +return ui.configbool('remotenames', 'selectivepull') def _getselectivepulldefaultbookmarks(ui): default_books = ui.configlist('remotenames', 'selectivepulldefault') @@ -186,7 +240,7 @@ def exfindcommonheads(orig, ui, local, r # the current remotenames are representative of what's on the server. In the # worst case the data might be slightly out of sync and the server sends us # more data than necessary, but this should be rare. -if not ui.configbool('remotenames', 'fastheaddiscovery', True): +if not ui.configbool('remotenames', 'fastheaddiscovery'): return orig(ui, local, remote, **kwargs) cl = local.changelog @@ -280,7 +334,7 @@ def blockerhook(orig, repo, *args, **kwa return blockers def exupdatefromremote(orig, ui, repo, remotemarks, path, trfunc, explicit=()): -if ui.configbool('remotenames', 'syncbookmarks', False): +if ui.configb
[PATCH remotenames] configs: update configs to use registrar
# HG changeset patch # User Durham Goode # Date 1508879615 25200 # Tue Oct 24 14:13:35 2017 -0700 # Node ID 9ead5c33dd22a9a66cea009bcf76ffd801d5677e # Parent 5fb97b6b3d46fcd4dc1b3cb6be137762eb9e60e7 configs: update configs to use registrar diff --git a/remotenames.py b/remotenames.py --- a/remotenames.py +++ b/remotenames.py @@ -32,12 +32,14 @@ from mercurial import localrepo from mercurial import lock as lockmod from mercurial import namespaces from mercurial import obsutil +from mercurial import registrar from mercurial import repair from mercurial import repoview from mercurial import revset from mercurial import scmutil from mercurial import setdiscovery from mercurial import templatekw +from mercurial import ui as uimod from mercurial import url from mercurial import util from mercurial import vfs as vfsmod @@ -51,12 +53,64 @@ try: except ImportError: smartset = revset +configtable = {} +try: +from mercurial import registrar +if not util.safehasattr(registrar, 'configitem'): +raise ImportError() +# Supported in 4.3+ +configitem = registrar.configitem(configtable) +except ImportError: +# Support older releases that didn't register config defaults +registrar = None +def configitem(section, name, default=None): +configtable[(section, name)] = default + +def configdefault(orig, self, section, name, default=None, + untrusted=False): +if default is None: +default = configtable.get((section, name)) +return orig(self, section, name, default=default, untrusted=untrusted) + +configitem('remotenames', 'alias.default', default=False) +configitem('remotenames', 'allownonfastforward', default=False) +configitem('remotenames', 'bookmarks', default=True) +configitem('remotenames', 'branches', default=True) +configitem('remotenames', 'calculatedistance', default=True) +configitem('remotenames', 'disallowedbookmarks', default=[]) +configitem('remotenames', 'disallowedhint', default=None) +configitem('remotenames', 'disallowedto', default=None) +configitem('remotenames', 'fastheaddiscovery', default=True) +configitem('remotenames', 'forcecompat', default=False) +configitem('remotenames', 'forceto', default=False) +configitem('remotenames', 'hoist', default='default') +configitem('remotenames', 'precachecurrent', default=True) +configitem('remotenames', 'precachedistance', default=True) +configitem('remotenames', 'pushanonheads', default=False) +configitem('remotenames', 'pushrev', default=None) +configitem('remotenames', 'resolvenodes', default=True) +configitem('remotenames', 'selectivepull', default=False) +configitem('remotenames', 'selectivepulldefault', default=[]) +configitem('remotenames', 'suppressbranches', default=False) +configitem('remotenames', 'syncbookmarks', default=False) +configitem('remotenames', 'tracking', default=True) +configitem('remotenames', 'transitionbookmarks', default=[]) +configitem('remotenames', 'transitionmessage', default=None) +configitem('remotenames', 'upstream', default=[]) + # namespace to use when recording an hg journal entry journalremotebookmarktype = 'remotebookmark' # name of the file that is used to mark that transition to selectivepull has # happened _selectivepullenabledfile = 'selectivepullenabled' +def uisetup(ui): +if registrar is None: +if util.safehasattr(uimod.ui, '_config'): +extensions.wrapfunction(uimod.ui, '_config', configdefault) +else: +extensions.wrapfunction(uimod.ui, 'config', configdefault) + def exbookcalcupdate(orig, ui, repo, checkout): '''Return a tuple (targetrev, movemarkfrom) indicating the rev to check out and where to move the active bookmark from, if needed.''' @@ -85,7 +139,7 @@ def expushop(orig, pushop, repo, remote, setattr(pushop, flag, kwargs.pop(flag, None)) def _isselectivepull(ui): -return ui.configbool('remotenames', 'selectivepull', False) +return ui.configbool('remotenames', 'selectivepull') def _getselectivepulldefaultbookmarks(ui): default_books = ui.configlist('remotenames', 'selectivepulldefault') @@ -186,7 +240,7 @@ def exfindcommonheads(orig, ui, local, r # the current remotenames are representative of what's on the server. In the # worst case the data might be slightly out of sync and the server sends us # more data than necessary, but this should be rare. -if not ui.configbool('remotenames', 'fastheaddiscovery', True): +if not ui.configbool('remotenames', 'fastheaddiscovery'): return orig(ui, local, remote, **kwargs) cl = local.changelog @@ -280,7 +334,7 @@ def blockerhook(orig, repo, *args, **kwa return blockers def exupdatefromremote(orig, ui, repo, remotemarks, path, trfunc, explicit=()): -if ui.configbool('remotenames', 'syncbookmarks', False): +if ui.configbool('remotenames', 'syncbookmarks'): return orig(ui, repo, remotemarks, path, trfunc, expl