marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is going to be clearer and easier to track than -2. 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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -48,6 +48,10 @@
 dirstatetuple = parsers.dirstatetuple
 
 
+# a special value used internally for `size` if the file come from the other 
parent
+FROM_P2 = -2
+
+
 class repocache(filecache):
     """filecache for files in .hg/"""
 
@@ -371,7 +375,7 @@
                         copies[f] = source
                     self.normallookup(f)
                 # Also fix up otherparent markers
-                elif s[0] == b'n' and s[2] == -2:
+                elif s[0] == b'n' and s[2] == FROM_P2:
                     source = self._map.copymap.get(f)
                     if source:
                         copies[f] = source
@@ -484,16 +488,16 @@
             # 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, -2):
+                if entry[0] == b'r' and entry[2] in (-1, FROM_P2):
                     source = self._map.copymap.get(f)
                     if entry[2] == -1:
                         self.merge(f)
-                    elif entry[2] == -2:
+                    elif entry[2] == FROM_P2:
                         self.otherparent(f)
                     if source:
                         self.copy(source, f)
                     return
-                if entry[0] == b'm' or entry[0] == b'n' and entry[2] == -2:
+                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._map.copymap.pop(f, None)
@@ -505,10 +509,10 @@
             raise error.Abort(msg)
         if f in self and self[f] == b'n':
             # merge-like
-            self._addpath(f, b'm', 0, -2, -1)
+            self._addpath(f, b'm', 0, FROM_P2, -1)
         else:
             # add-like
-            self._addpath(f, b'n', 0, -2, -1)
+            self._addpath(f, b'n', 0, FROM_P2, -1)
         self._map.copymap.pop(f, None)
 
     def add(self, f):
@@ -527,8 +531,8 @@
                 # backup the previous state
                 if entry[0] == b'm':  # merge
                     size = -1
-                elif entry[0] == b'n' and entry[2] == -2:  # other parent
-                    size = -2
+                elif entry[0] == b'n' and entry[2] == FROM_P2:  # other parent
+                    size = FROM_P2
                     self._map.otherparentset.add(f)
         self._updatedfiles.add(f)
         self._map.removefile(f, oldstate, size)
@@ -1302,7 +1306,7 @@
                         (size != st.st_size and size != st.st_size & 
_rangemask)
                         or ((mode ^ st.st_mode) & 0o100 and checkexec)
                     )
-                    or size == -2  # other parent
+                    or size == FROM_P2  # other parent
                     or fn in copymap
                 ):
                     if stat.S_ISLNK(st.st_mode) and size != st.st_size:
@@ -1532,7 +1536,7 @@
         self._map[f] = dirstatetuple(state, mode, size, mtime)
         if state != b'n' or mtime == -1:
             self.nonnormalset.add(f)
-        if size == -2:
+        if size == FROM_P2:
             self.otherparentset.add(f)
 
     def removefile(self, f, oldstate, size):
@@ -1587,7 +1591,7 @@
             for fname, e in pycompat.iteritems(self._map):
                 if e[0] != b'n' or e[3] == -1:
                     nonnorm.add(fname)
-                if e[0] == b'n' and e[2] == -2:
+                if e[0] == b'n' and e[2] == FROM_P2:
                     otherparent.add(fname)
             return nonnorm, otherparent
 



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to