Patchwork [1,of,5] obsolete: add isenabled function for option checking

login
register
mail settings
Submitter Durham Goode
Date Oct. 14, 2014, 9:51 p.m.
Message ID <a22ff14b5ff64123d37e.1413323508@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/6256/
State Superseded
Headers show

Comments

Durham Goode - Oct. 14, 2014, 9:51 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1413317855 25200
#      Tue Oct 14 13:17:35 2014 -0700
# Node ID a22ff14b5ff64123d37e1fc42cad86cf76a4c3b1
# Parent  75d0edb68b417964110e3fcd69187c867f31a119
obsolete: add isenabled function for option checking

Previously, obsolete used the module level _enabled flag to determine whether it
was on or off. We need a bit more granular control, so we'll be introducing
toggle options. The isenabled() function is how you check if a particular option
is enabled for the given repository.

Future patches will add options such as 'createmarkers', 'allowunstable', and
'exchange' to enable various features of obsolete markers.
Durham Goode - Oct. 14, 2014, 9:53 p.m.
On 10/14/14 2:51 PM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1413317855 25200
> #      Tue Oct 14 13:17:35 2014 -0700
> # Node ID a22ff14b5ff64123d37e1fc42cad86cf76a4c3b1
> # Parent  75d0edb68b417964110e3fcd69187c867f31a119
> obsolete: add isenabled function for option checking
This series just introduces the options.  A future series will update 
the tests and remove the old obsolete._enabled flag.

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -1144,3 +1144,18 @@  def createmarkers(repo, relations, flag=
         tr.close()
     finally:
         tr.release()
+
+def isenabled(repo, option):
+    """Returns True if the given repository has the given obsolete option
+    enabled.
+    """
+    result = set(repo.ui.configlist('experimental', 'obsoleteoptions'))
+    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
+
+    return option in result