Patchwork D2667: obsolete: refactor function for getting obsolete options

login
register
mail settings
Submitter phabricator
Date March 4, 2018, 8:23 p.m.
Message ID <differential-rev-PHID-DREV-752uzwwqcxnhwmuukkw6-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28987/
State Superseded
Headers show

Comments

phabricator - March 4, 2018, 8:23 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The function for returning obsolete option values obtains all
  options, validates, then returns the option that was requested.
  
  Let's create a new function to return all obsolete option values
  so callers needing multiple values can call that.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/obsolete.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -133,20 +133,29 @@ 
 
         return option in result
 
+def getoptions(repo):
+    """Returns dicts showing state of obsolescence features."""
+
+    createmarkersvalue = _getoptionvalue(repo, createmarkersopt)
+    unstablevalue = _getoptionvalue(repo, allowunstableopt)
+    exchangevalue = _getoptionvalue(repo, exchangeopt)
+
+    # createmarkers must be enabled if other options are enabled
+    if ((unstablevalue or exchangevalue) and not createmarkersvalue):
+        raise error.Abort(_("'createmarkers' obsolete option must be enabled "
+                            "if other obsolete options are enabled"))
+
+    return {
+        createmarkersopt: createmarkersvalue,
+        allowunstableopt: unstablevalue,
+        exchangeopt: exchangevalue,
+    }
+
 def isenabled(repo, option):
     """Returns True if the given repository has the given obsolete option
     enabled.
     """
-    createmarkersvalue = _getoptionvalue(repo, createmarkersopt)
-    unstabluevalue = _getoptionvalue(repo, allowunstableopt)
-    exchangevalue = _getoptionvalue(repo, exchangeopt)
-
-    # createmarkers must be enabled if other options are enabled
-    if ((unstabluevalue or exchangevalue) and not createmarkersvalue):
-        raise error.Abort(_("'createmarkers' obsolete option must be enabled "
-                            "if other obsolete options are enabled"))
-
-    return _getoptionvalue(repo, option)
+    return getoptions(repo)[option]
 
 ### obsolescence marker flag