changeset 37110:1b158ca37ea4

merge: use constants for merge driver state Named constants are superior to magic values. Differential Revision: https://phab.mercurial-scm.org/D2699
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 05 Mar 2018 14:15:31 -0500
parents a532b2f54f95
children aa5199c7aa42
files mercurial/merge.py
diffstat 1 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/merge.py	Mon Mar 05 14:09:23 2018 -0500
+++ b/mercurial/merge.py	Mon Mar 05 14:15:31 2018 -0500
@@ -61,6 +61,10 @@
 RECORD_UNSUPPORTED_MANDATORY = b'X'
 RECORD_UNSUPPORTED_ADVISORY = b'x'
 
+MERGE_DRIVER_STATE_UNMARKED = b'u'
+MERGE_DRIVER_STATE_MARKED = b'm'
+MERGE_DRIVER_STATE_SUCCESS = b's'
+
 class mergestate(object):
     '''track 3-way merge state of individual files
 
@@ -147,9 +151,9 @@
             self._other = other
         self._readmergedriver = None
         if self.mergedriver:
-            self._mdstate = 's'
+            self._mdstate = MERGE_DRIVER_STATE_SUCCESS
         else:
-            self._mdstate = 'u'
+            self._mdstate = MERGE_DRIVER_STATE_UNMARKED
         shutil.rmtree(self._repo.vfs.join('merge'), True)
         self._results = {}
         self._dirty = False
@@ -168,7 +172,7 @@
             if var in vars(self):
                 delattr(self, var)
         self._readmergedriver = None
-        self._mdstate = 's'
+        self._mdstate = MERGE_DRIVER_STATE_SUCCESS
         unsupported = set()
         records = self._readrecords()
         for rtype, record in records:
@@ -179,9 +183,11 @@
             elif rtype == RECORD_MERGE_DRIVER_STATE:
                 bits = record.split('\0', 1)
                 mdstate = bits[1]
-                if len(mdstate) != 1 or mdstate not in 'ums':
+                if len(mdstate) != 1 or mdstate not in (
+                    MERGE_DRIVER_STATE_UNMARKED, MERGE_DRIVER_STATE_MARKED,
+                    MERGE_DRIVER_STATE_SUCCESS):
                     # the merge driver should be idempotent, so just rerun it
-                    mdstate = 'u'
+                    mdstate = MERGE_DRIVER_STATE_UNMARKED
 
                 self._readmergedriver = bits[0]
                 self._mdstate = mdstate
@@ -1665,7 +1671,8 @@
 
     unresolved = ms.unresolvedcount()
 
-    if usemergedriver and not unresolved and ms.mdstate() != 's':
+    if (usemergedriver and not unresolved
+        and ms.mdstate() != MERGE_DRIVER_STATE_SUCCESS):
         if not driverconclude(repo, ms, wctx, labels=labels):
             # XXX setting unresolved to at least 1 is a hack to make sure we
             # error out