Patchwork D6878: hg: have `updatetotally` more thoroughly check updatecheck argument (API)

login
register
mail settings
Submitter phabricator
Date Sept. 25, 2019, 3:10 p.m.
Message ID <differential-rev-PHID-DREV-yswrbcvjlnmtpjzq222d-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41755/
State Superseded
Headers show

Comments

phabricator - Sept. 25, 2019, 3:10 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

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

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/hg.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -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