changeset 5988:ef73f0d2232d

evolve: use obsolete.isenabled() instead of ui.configbool() directly
author Anton Shestakov <av6@dwimlabs.net>
date Wed, 28 Jul 2021 02:44:12 +0300
parents e97fbded40a5
children d28c9f359464
files hgext3rd/evolve/compat.py hgext3rd/evolve/rewriteutil.py
diffstat 2 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/compat.py	Fri Aug 06 00:04:46 2021 +0200
+++ b/hgext3rd/evolve/compat.py	Wed Jul 28 02:44:12 2021 +0300
@@ -471,6 +471,20 @@
         for other in others:
             check_at_most_one_arg(opts, first, other)
 
+# allowdivergenceopt is a much newer addition to obsolete.py
+# hg <= 5.8 (ba6881c6a178)
+allowdivergenceopt = b'allowdivergence'
+def isenabled(repo, option):
+    if option == allowdivergenceopt:
+        if obsolete._getoptionvalue(repo, obsolete.createmarkersopt):
+            return obsolete._getoptionvalue(repo, allowdivergenceopt)
+        else:
+            # note that we're not raising error.Abort when divergence is
+            # allowed, but creating markers is not, even on older hg versions
+            return False
+    else:
+        return obsolete.isenabled(repo, option)
+
 if util.safehasattr(dirstate.dirstate, 'set_clean'):
     movedirstate = scmutil.movedirstate
 else:  # hg <= 5.8 (8a50fb0784a9)
--- a/hgext3rd/evolve/rewriteutil.py	Fri Aug 06 00:04:46 2021 +0200
+++ b/hgext3rd/evolve/rewriteutil.py	Wed Jul 28 02:44:12 2021 +0300
@@ -85,8 +85,7 @@
         hint = _(b"see 'hg help evolution.instability'")
         raise error.Abort(msg, hint=hint)
     divrisk = revs_hascontentdivrisk(repo, revs)
-    allowdivergence = repo.ui.configbool(b'experimental',
-                                         b'evolution.allowdivergence')
+    allowdivergence = compat.isenabled(repo, compat.allowdivergenceopt)
     if divrisk and not allowdivergence:
         localdiv = repo[divrisk[0]]
         otherdiv, base = repo[divrisk[1][0]], repo[divrisk[1][1]]
@@ -155,9 +154,9 @@
     if len(baseparents) > 2:
         raise error.Abort(_(b"cannot fold revisions that merge with more than "
                             b"one external changeset (not in revisions)"))
-    if not repo.ui.configbool(b'experimental', b'evolution.allowdivergence'):
-        obsolete = repo.revs(b'%ld and obsolete()', revs)
-        if obsolete:
+    if not compat.isenabled(repo, compat.allowdivergenceopt):
+        obsoleterevs = repo.revs(b'%ld and obsolete()', revs)
+        if obsoleterevs:
             msg = _(b'folding obsolete revisions may cause divergence')
             hint = _(b'set experimental.evolution.allowdivergence=yes'
                      b' to allow folding them')