Patchwork D1147: config: update evolution-related config

login
register
mail settings
Submitter phabricator
Date Oct. 17, 2017, 3:04 p.m.
Message ID <differential-rev-PHID-DREV-lvu63fkjvfcrdublu3u3-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/25105/
State Superseded
Headers show

Comments

phabricator - Oct. 17, 2017, 3:04 p.m.
lothiraldan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1147

AFFECTED FILES
  mercurial/configitems.py
  mercurial/obsolete.py

CHANGE DETAILS




To: lothiraldan, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 18, 2017, 3:57 p.m.
indygreg accepted this revision.
indygreg added a comment.
This revision is now accepted and ready to land.


  This seems reasonable and is a much, much more flexible approach.

INLINE COMMENTS

> obsolete.py:145-146
> +    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"))
>  

It feels like we should automatically enable createmarkers in this scenario instead of being user hostile. But this can be done as a follow-up.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1147

To: lothiraldan, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -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
 
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -343,6 +343,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')],