dirstate: introduce a symbolic constant for the NONNORMAL marker
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 01 Jul 2021 19:15:22 +0200
changeset 47483 4ac418b4a6af
parent 47482 cb29484eaade
child 47484 3f13dfa1fa78
dirstate: introduce a symbolic constant for the NONNORMAL marker This is going to be clearer and easier to track than -1. Ultimately I would like to get ride of this special value everywhere but in the lower level, however we need to clarify the API first. This changeset is part of such clarification. Differential Revision: https://phab.mercurial-scm.org/D10927
mercurial/dirstate.py
--- a/mercurial/dirstate.py	Thu Jul 01 19:04:11 2021 +0200
+++ b/mercurial/dirstate.py	Thu Jul 01 19:15:22 2021 +0200
@@ -51,6 +51,9 @@
 # a special value used internally for `size` if the file come from the other parent
 FROM_P2 = -2
 
+# a special value used internally for `size` if the file is modified/merged/added
+NONNORMAL = -1
+
 
 class repocache(filecache):
     """filecache for files in .hg/"""
@@ -488,9 +491,9 @@
             # being removed, restore that state.
             entry = self._map.get(f)
             if entry is not None:
-                if entry[0] == b'r' and entry[2] in (-1, FROM_P2):
+                if entry[0] == b'r' and entry[2] in (NONNORMAL, FROM_P2):
                     source = self._map.copymap.get(f)
-                    if entry[2] == -1:
+                    if entry[2] == NONNORMAL:
                         self.merge(f)
                     elif entry[2] == FROM_P2:
                         self.otherparent(f)
@@ -499,7 +502,7 @@
                     return
                 if entry[0] == b'm' or entry[0] == b'n' and entry[2] == FROM_P2:
                     return
-        self._addpath(f, b'n', 0, -1, -1)
+        self._addpath(f, b'n', 0, NONNORMAL, -1)
         self._map.copymap.pop(f, None)
 
     def otherparent(self, f):
@@ -517,7 +520,7 @@
 
     def add(self, f):
         '''Mark a file added.'''
-        self._addpath(f, b'a', 0, -1, -1)
+        self._addpath(f, b'a', 0, NONNORMAL, -1)
         self._map.copymap.pop(f, None)
 
     def remove(self, f):
@@ -530,7 +533,7 @@
             if entry is not None:
                 # backup the previous state
                 if entry[0] == b'm':  # merge
-                    size = -1
+                    size = NONNORMAL
                 elif entry[0] == b'n' and entry[2] == FROM_P2:  # other parent
                     size = FROM_P2
                     self._map.otherparentset.add(f)