hg: have `updatetotally` more thoroughly check updatecheck argument (API)
authorAugie Fackler <augie@google.com>
Wed, 25 Sep 2019 11:02:32 -0400
changeset 42971 ee1ef76d7339
parent 42970 1ad3ebb39c61
child 42972 71bb9363818c
hg: have `updatetotally` more thoroughly check updatecheck argument (API) .. api:: `mercurial.hg.updatetotally` is now more thorough about checking its `updatecheck` keyword argument. Previously invalid values would have used the configured default updatecheck method, but now will raise ValueError. Differential Revision: https://phab.mercurial-scm.org/D6878
mercurial/hg.py
--- a/mercurial/hg.py	Wed Sep 25 10:53:10 2019 -0400
+++ b/mercurial/hg.py	Wed Sep 25 11:02:32 2019 -0400
@@ -883,6 +883,12 @@
 # naming conflict in updatetotally()
 _clean = clean
 
+_VALID_UPDATECHECKS = {mergemod.UPDATECHECK_ABORT,
+                       mergemod.UPDATECHECK_NONE,
+                       mergemod.UPDATECHECK_LINEAR,
+                       mergemod.UPDATECHECK_NO_CONFLICT,
+}
+
 def updatetotally(ui, repo, checkout, brev, clean=False, updatecheck=None):
     """Update the working directory with extra care for non-file components
 
@@ -911,12 +917,12 @@
     """
     if updatecheck is None:
         updatecheck = ui.config('commands', 'update.check')
-        if updatecheck not in (mergemod.UPDATECHECK_ABORT,
-                               mergemod.UPDATECHECK_NONE,
-                               mergemod.UPDATECHECK_LINEAR,
-                               mergemod.UPDATECHECK_NO_CONFLICT):
+        if updatecheck not in _VALID_UPDATECHECKS:
             # If not configured, or invalid value configured
             updatecheck = mergemod.UPDATECHECK_LINEAR
+    if updatecheck not in _VALID_UPDATECHECKS:
+        raise ValueError(r'Invalid updatecheck value %r (can accept %r)' % (
+            updatecheck, _VALID_UPDATECHECKS))
     with repo.wlock():
         movemarkfrom = None
         warndest = False