# HG changeset patch # User Pierre-Yves David # Date 2021-07-01 17:15:22 # Node ID 4ac418b4a6af0ae72264b563260e16eb4f1f94b6 # Parent cb29484eaade8876a5255c04dd4f5cf3b566dc2c 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 diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -51,6 +51,9 @@ dirstatetuple = parsers.dirstatetuple # 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 @@ class dirstate(object): # 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 @@ class dirstate(object): 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 @@ class dirstate(object): 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 @@ class dirstate(object): 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)