config: update evolution-related config
authorBoris Feld <boris.feld@octobus.net>
Mon, 16 Oct 2017 17:14:47 +0200
changeset 34864 fec79a3f250f
parent 34863 b1e3f609bf45
child 34865 a0100f34e20b
config: update evolution-related config Update the evolution helpers function to support both old-style configuration and new-style configuration: experimental.evolution=all is renamed into experimental.evolution=true experimental.evolution=createmarkers is renamed into experimental.evolution.createmarkers=true experimental.evolution=allowunstable is renamed into experimental.evolution.allowunstable=true experimental.evolution=exchange is renamed into experimental.evolution.exchange=true We choose to not rename individual config options; keeping the same names would easy the transition for users but it's something that could be easily done in the future. Differential Revision: https://phab.mercurial-scm.org/D1147
mercurial/configitems.py
mercurial/obsolete.py
--- a/mercurial/configitems.py	Mon Oct 16 17:14:32 2017 +0200
+++ b/mercurial/configitems.py	Mon Oct 16 17:14:47 2017 +0200
@@ -349,6 +349,15 @@
     default=list,
     alias=[('experimental', 'stabilization')],
 )
+coreconfigitem('experimental', 'evolution.allowunstable',
+    default=None,
+)
+coreconfigitem('experimental', 'evolution.createmarkers',
+    default=None,
+)
+coreconfigitem('experimental', 'evolution.exchange',
+    default=None,
+)
 coreconfigitem('experimental', 'evolution.bundle-obsmarker',
     default=False,
     alias=[('experimental', 'stabilization.bundle-obsmarker')],
--- a/mercurial/obsolete.py	Mon Oct 16 17:14:32 2017 +0200
+++ b/mercurial/obsolete.py	Mon Oct 16 17:14:47 2017 +0200
@@ -98,26 +98,54 @@
 allowunstableopt = 'allowunstable'
 exchangeopt = 'exchange'
 
+def _getoptionvalue(repo, option):
+    """Returns True if the given repository has the given obsolete option
+    enabled.
+    """
+    configkey = 'evolution.%s' % option
+    newconfig = repo.ui.configbool('experimental', configkey)
+
+    # Return the value only if defined
+    if newconfig is not None:
+        return newconfig
+
+    # Fallback on generic option
+    try:
+        return repo.ui.configbool('experimental', 'evolution')
+    except (error.ConfigError, AttributeError):
+        # Fallback on old-fashion config
+        # inconsistent config: experimental.evolution
+        result = set(repo.ui.configlist('experimental', 'evolution'))
+
+        if 'all' in result:
+            return True
+
+        # For migration purposes, temporarily return true if the config hasn't
+        # been set but _enabled is true.
+        if len(result) == 0 and _enabled:
+            return True
+
+        # Temporary hack for next check
+        newconfig = repo.ui.config('experimental', 'evolution.createmarkers')
+        if newconfig:
+            result.add('createmarkers')
+
+        return option in result
+
 def isenabled(repo, option):
     """Returns True if the given repository has the given obsolete option
     enabled.
     """
-    result = set(repo.ui.configlist('experimental', 'evolution'))
-    if 'all' in result:
-        return True
-
-    # For migration purposes, temporarily return true if the config hasn't been
-    # set but _enabled is true.
-    if len(result) == 0 and _enabled:
-        return True
+    createmarkersvalue = _getoptionvalue(repo, createmarkersopt)
+    unstabluevalue = _getoptionvalue(repo, allowunstableopt)
+    exchangevalue = _getoptionvalue(repo, exchangeopt)
 
     # createmarkers must be enabled if other options are enabled
-    if ((allowunstableopt in result or exchangeopt in result) and
-        not createmarkersopt in result):
+    if ((unstabluevalue or exchangevalue) and not createmarkersvalue):
         raise error.Abort(_("'createmarkers' obsolete option must be enabled "
-                           "if other obsolete options are enabled"))
+                            "if other obsolete options are enabled"))
 
-    return option in result
+    return _getoptionvalue(repo, option)
 
 ### obsolescence marker flag