D493: dirstate: perform transactions with _copymap using single call, where possible

mbolin (Michael Bolin) phabricator at mercurial-scm.org
Wed Aug 23 18:23:55 UTC 2017


mbolin created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This replaces patterns such as this:
  
    if f in self._copymap:
        del self._copymap[f]
  
  with this:
  
    self._copymap.pop(f, None)
  
  Although eliminating the extra lookup/call may be a negligible performance win
  in the standard dirstate, alternative implementations, such as
  sqldirstate <https://bitbucket.org/facebook/hg-experimental/src/default/sqldirstate/>
  may see a bigger win where each of these calls results in an RPC,
  so the savings is greater.

TEST PLAN
  `make tests`

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -406,13 +406,15 @@
 
                 # Discard 'm' markers when moving away from a merge state
                 if s[0] == 'm':
-                    if f in self._copymap:
-                        copies[f] = self._copymap[f]
+                    source = self._copymap.get(f)
+                    if source:
+                        copies[f] = source
                     self.normallookup(f)
                 # Also fix up otherparent markers
                 elif s[0] == 'n' and s[2] == -2:
+                    source = self._copymap.get(f)
                     if f in self._copymap:
-                        copies[f] = self._copymap[f]
+                        copies[f] = source
                     self.add(f)
         return copies
 
@@ -518,8 +520,7 @@
             self._copymap[dest] = source
             self._updatedfiles.add(source)
             self._updatedfiles.add(dest)
-        elif dest in self._copymap:
-            del self._copymap[dest]
+        elif self._copymap.pop(dest, None):
             self._updatedfiles.add(dest)
 
     def copied(self, file):
@@ -568,8 +569,7 @@
         mtime = s.st_mtime
         self._addpath(f, 'n', s.st_mode,
                       s.st_size & _rangemask, mtime & _rangemask)
-        if f in self._copymap:
-            del self._copymap[f]
+        self._copymap.pop(f, None)
         if f in self._nonnormalset:
             self._nonnormalset.remove(f)
         if mtime > self._lastnormaltime:
@@ -597,8 +597,7 @@
             if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2:
                 return
         self._addpath(f, 'n', 0, -1, -1)
-        if f in self._copymap:
-            del self._copymap[f]
+        self._copymap.pop(f, None)
         if f in self._nonnormalset:
             self._nonnormalset.remove(f)
 
@@ -613,15 +612,12 @@
         else:
             # add-like
             self._addpath(f, 'n', 0, -2, -1)
-
-        if f in self._copymap:
-            del self._copymap[f]
+        self._copymap.pop(f, None)
 
     def add(self, f):
         '''Mark a file added.'''
         self._addpath(f, 'a', 0, -1, -1)
-        if f in self._copymap:
-            del self._copymap[f]
+        self._copymap.pop(f, None)
 
     def remove(self, f):
         '''Mark a file removed.'''
@@ -638,8 +634,8 @@
                 self._otherparentset.add(f)
         self._map[f] = dirstatetuple('r', 0, size, 0)
         self._nonnormalset.add(f)
-        if size == 0 and f in self._copymap:
-            del self._copymap[f]
+        if size == 0:
+            self._copymap.pop(f, None)
 
     def merge(self, f):
         '''Mark a file merged.'''
@@ -655,8 +651,7 @@
             del self._map[f]
             if f in self._nonnormalset:
                 self._nonnormalset.remove(f)
-            if f in self._copymap:
-                del self._copymap[f]
+            self._copymap.pop(f, None)
 
     def _discoverpath(self, path, normed, ignoremissing, exists, storemap):
         if exists is None:



To: mbolin, rdamazio, durin42, quark, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list