changeset 3080:461c9d940519

evolve: registed configitems if available The config are registered as 'dynamicdefault' because we still need to explicitly pass the config option for older version of Mercurial. (4.2 and before).
author Boris Feld <boris.feld@octobus.net>
date Thu, 19 Oct 2017 14:46:06 +0200
parents 039313d772d2
children 25a6a2520255
files hgext3rd/evolve/__init__.py hgext3rd/evolve/exthelper.py hgext3rd/evolve/obsdiscovery.py hgext3rd/evolve/obsexchange.py hgext3rd/evolve/obshistory.py hgext3rd/evolve/safeguard.py hgext3rd/evolve/serveronly.py
diffstat 7 files changed, 63 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py	Thu Oct 19 21:23:21 2017 +0200
+++ b/hgext3rd/evolve/__init__.py	Thu Oct 19 14:46:06 2017 +0200
@@ -374,6 +374,15 @@
 extsetup = eh.final_extsetup
 reposetup = eh.final_reposetup
 cmdtable = eh.cmdtable
+configtable = eh.configtable
+
+# Configuration
+eh.configitem('experimental', 'evolutioncommands')
+eh.configitem('experimental', 'evolution.allnewcommands')
+eh.configitem('experimental', 'prunestrip')
+
+# hack around because we need an actual default there
+configtable['experimental']['evolution.allnewcommands'].default = None
 
 # pre hg 4.0 compat
 
@@ -418,7 +427,7 @@
     # This must be in the same function as the option configuration above to
     # guarantee it happens after the above configuration, but before the
     # extsetup functions.
-    evolvecommands = ui.configlist('experimental', 'evolutioncommands')
+    evolvecommands = ui.configlist('experimental', 'evolutioncommands', [])
     evolveopts = ui.configlist('experimental', 'evolution')
     if evolveopts and (commandopt not in evolveopts and
                        'all' not in evolveopts):
@@ -2247,7 +2256,7 @@
                            "backup bundle")),
     ])
 def stripwrapper(orig, ui, repo, *revs, **kwargs):
-    if (not ui.configbool('experimental', 'prunestrip') or
+    if (not ui.configbool('experimental', 'prunestrip', False) or
         kwargs.get('bundle', False)):
         return orig(ui, repo, *revs, **kwargs)
 
--- a/hgext3rd/evolve/exthelper.py	Thu Oct 19 21:23:21 2017 +0200
+++ b/hgext3rd/evolve/exthelper.py	Thu Oct 19 14:46:06 2017 +0200
@@ -17,6 +17,13 @@
     from mercurial import cmdutil
     command = cmdutil.command
 
+configitem = None
+dynamicdefault = None
+if util.safehasattr(registrar, 'configitem'):
+    configitem = registrar.configitem
+    from mercurial import configitems
+    dynamicdefault = configitems.dynamicdefault
+
 class exthelper(object):
     """Helper for modular extension setup
 
@@ -39,6 +46,22 @@
         self.cmdtable = {}
         self.command = command(self.cmdtable)
 
+        self.configtable = {}
+        self._configitem = None
+        if configitem is not None:
+            self._configitem = configitem(self.configtable)
+
+    def configitem(self, section, config):
+        """For Mercurial 4.4 and above, register a config item
+
+        For now constraint to 'dynamicdefault' until we only support version with the feature.
+        Older version would otherwise not use the declare default.
+
+        For older version no-op fallback for old Mercurial versions
+        """
+        if self._configitem is not None:
+            self._configitem(section, config, default=dynamicdefault)
+
     def merge(self, other):
         self._uicallables.extend(other._uicallables)
         self._extcallables.extend(other._extcallables)
@@ -50,6 +73,11 @@
         self._functionwrappers.extend(other._functionwrappers)
         self._duckpunchers.extend(other._duckpunchers)
         self.cmdtable.update(other.cmdtable)
+        for section, items in other.configtable.iteritems():
+            if section in self.configtable:
+                self.configtable[section].update(items)
+            else:
+                self.configtable[section] = items
 
     def final_uisetup(self, ui):
         """Method to be used as the extension uisetup
--- a/hgext3rd/evolve/obsdiscovery.py	Thu Oct 19 21:23:21 2017 +0200
+++ b/hgext3rd/evolve/obsdiscovery.py	Thu Oct 19 14:46:06 2017 +0200
@@ -72,6 +72,13 @@
 eh.merge(stablerange.eh)
 obsexcmsg = utility.obsexcmsg
 
+# Config
+eh.configitem('experimental', 'evolution.obsdiscovery')
+eh.configitem('experimental', 'obshashrange')
+eh.configitem('experimental', 'obshashrange.warm-cache')
+eh.configitem('experimental', 'obshashrange.max-revs')
+eh.configitem('experimental', 'obshashrange.lru-size')
+
 ##################################
 ###  Code performing discovery ###
 ##################################
--- a/hgext3rd/evolve/obsexchange.py	Thu Oct 19 21:23:21 2017 +0200
+++ b/hgext3rd/evolve/obsexchange.py	Thu Oct 19 14:46:06 2017 +0200
@@ -44,6 +44,7 @@
 obsexcmsg = utility.obsexcmsg
 obsexcprg = utility.obsexcprg
 
+eh.configitem('experimental', 'verbose-obsolescence-exchange')
 
 _bestformat = max(obsolete.formats.keys())
 
--- a/hgext3rd/evolve/obshistory.py	Thu Oct 19 21:23:21 2017 +0200
+++ b/hgext3rd/evolve/obshistory.py	Thu Oct 19 14:46:06 2017 +0200
@@ -30,6 +30,18 @@
 
 eh = exthelper.exthelper()
 
+# Config
+efd = {'default': True} # pass a default value unless the config is registered
+
+@eh.extsetup
+def enableeffectflags(ui):
+    item = (getattr(ui, '_knownconfig', {})
+            .get('experimental', {})
+            .get('evolution.effect-flags'))
+    if item is not None:
+        item.default = True
+        efd.clear()
+
 @eh.command(
     'obslog|olog',
     [('G', 'graph', True, _("show the revision DAG")),
@@ -634,7 +646,7 @@
     meaningful data. In the future, we can introduce way for commands to
     provide precomputed effect to avoid the overhead.
     """
-    if not repo.ui.configbool('experimental', 'evolution.effect-flags', True):
+    if not repo.ui.configbool('experimental', 'evolution.effect-flags', **efd):
         return orig(repo, relations, flag, date, metadata, **kwargs)
     if metadata is None:
         metadata = {}
--- a/hgext3rd/evolve/safeguard.py	Thu Oct 19 21:23:21 2017 +0200
+++ b/hgext3rd/evolve/safeguard.py	Thu Oct 19 14:46:06 2017 +0200
@@ -16,6 +16,8 @@
 
 eh = exthelper.exthelper()
 
+eh.configitem('experimental', 'auto-publish')
+
 @eh.reposetup
 def setuppublishprevention(ui, repo):
 
--- a/hgext3rd/evolve/serveronly.py	Thu Oct 19 21:23:21 2017 +0200
+++ b/hgext3rd/evolve/serveronly.py	Thu Oct 19 14:46:06 2017 +0200
@@ -47,6 +47,7 @@
 extsetup = eh.final_extsetup
 reposetup = eh.final_reposetup
 cmdtable = eh.cmdtable
+configtable = eh.configtable
 
 @eh.reposetup
 def default2evolution(ui, repo):