D6879: merge: check argument value with if/raise instead of an assert

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Wed Sep 25 11:10:50 EDT 2019


durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This shouldn't make any difference for legal code, but it'll prevent
  the assertion from being optimized out if someone decides to do -O on
  our code.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1998,10 +1998,15 @@
         # updatecheck='abort' to better suppport some of these callers.
         if updatecheck is None:
             updatecheck = UPDATECHECK_LINEAR
-        assert updatecheck in (UPDATECHECK_NONE,
+        if updatecheck not in (UPDATECHECK_NONE,
                                UPDATECHECK_LINEAR,
                                UPDATECHECK_NO_CONFLICT,
-        )
+        ):
+            raise ValueError(r'Invalid updatecheck %r (can accept %r)' % (
+                updatecheck, (UPDATECHECK_NONE,
+                               UPDATECHECK_LINEAR,
+                               UPDATECHECK_NO_CONFLICT,
+                )))
     # If we're doing a partial update, we need to skip updating
     # the dirstate, so make a note of any partial-ness to the
     # update here.



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


More information about the Mercurial-devel mailing list