Patchwork D10931: dirstate: add an explicit `from_p2` parameter to `_addpath`

login
register
mail settings
Submitter phabricator
Date July 2, 2021, 3:18 p.m.
Message ID <differential-rev-PHID-DREV-3co7bvaksw2454atsteh-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49245/
State Superseded
Headers show

Comments

phabricator - July 2, 2021, 3:18 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This lets says what we mean instead of using magic value. The lower level can
  then decide how to express that.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -438,7 +438,15 @@ 
     def copies(self):
         return self._map.copymap
 
-    def _addpath(self, f, state, mode, size=NONNORMAL, mtime=AMBIGUOUS_TIME):
+    def _addpath(
+        self,
+        f,
+        state,
+        mode,
+        size=NONNORMAL,
+        mtime=AMBIGUOUS_TIME,
+        from_p2=False,
+    ):
         oldstate = self[f]
         if state == b'a' or oldstate == b'r':
             scmutil.checkfilename(f)
@@ -455,10 +463,15 @@ 
                     msg = _(b'file %r in dirstate clashes with %r')
                     msg %= (pycompat.bytestr(d), pycompat.bytestr(f))
                     raise error.Abort(msg)
-        if size != NONNORMAL and size != FROM_P2:
-            size = size & _rangemask
-        if mtime != AMBIGUOUS_TIME:
-            mtime = mtime & _rangemask
+        if from_p2:
+            size = FROM_P2
+            mtime = AMBIGUOUS_TIME
+        else:
+            assert size != FROM_P2
+            if size != NONNORMAL:
+                size = size & _rangemask
+            if mtime != AMBIGUOUS_TIME:
+                mtime = mtime & _rangemask
         self._dirty = True
         self._updatedfiles.add(f)
         self._map.addfile(f, oldstate, state, mode, size, mtime)
@@ -519,10 +532,10 @@ 
             raise error.Abort(msg)
         if f in self and self[f] == b'n':
             # merge-like
-            self._addpath(f, b'm', 0, FROM_P2)
+            self._addpath(f, b'm', 0, from_p2=True)
         else:
             # add-like
-            self._addpath(f, b'n', 0, FROM_P2)
+            self._addpath(f, b'n', 0, from_p2=True)
         self._map.copymap.pop(f, None)
 
     def add(self, f):