[PATCH 1 of 4] dirstate: factor common update code into _addpath

Joshua Redstone joshua.redstone at fb.com
Fri Jun 22 15:49:46 CDT 2012


# HG changeset patch
# User Joshua Redstone <joshua.redstone at fb.com>
# Date 1340032002 25200
# Node ID 2f02917a5f6ea7e6a8fbd55e4c90c3cf1d61fe94
# Parent  efd2e14f72353626355dc82465bdf23bf6416aa2
dirstate: factor common update code into _addpath

Factor update code common to all callers of _addpath into _addpath.
By centralizing the update code here, it provides one place to put
updates to new data structures - in a future patch.  It also removes
a few lines of duplicate code.

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -312,7 +312,8 @@
         if self[f] not in "?r" and "_dirs" in self.__dict__:
             _decdirs(self._dirs, f)
 
-    def _addpath(self, f, check=False):
+    def _addpath(self, f, state, mode, size, mtime, check=False):
+        assert state not in "?r"
         oldstate = self[f]
         if check or oldstate == "r":
             scmutil.checkfilename(f)
@@ -327,14 +328,14 @@
                         _('file %r in dirstate clashes with %r') % (d, f))
         if oldstate in "?r" and "_dirs" in self.__dict__:
             _incdirs(self._dirs, f)
+        self._dirty = True
+        self._map[f] = (state, mode, size, mtime)
 
     def normal(self, f):
         '''Mark a file normal and clean.'''
-        self._dirty = True
-        self._addpath(f)
         s = os.lstat(self._join(f))
         mtime = int(s.st_mtime)
-        self._map[f] = ('n', s.st_mode, s.st_size, mtime)
+        self._addpath(f, 'n', s.st_mode, s.st_size, mtime)
         if f in self._copymap:
             del self._copymap[f]
         if mtime > self._lastnormaltime:
@@ -361,9 +362,7 @@
                 return
             if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2:
                 return
-        self._dirty = True
-        self._addpath(f)
-        self._map[f] = ('n', 0, -1, -1)
+        self._addpath(f, 'n', 0, -1, -1)
         if f in self._copymap:
             del self._copymap[f]
 
@@ -372,17 +371,13 @@
         if self._pl[1] == nullid:
             raise util.Abort(_("setting %r to other parent "
                                "only allowed in merges") % f)
-        self._dirty = True
-        self._addpath(f)
-        self._map[f] = ('n', 0, -2, -1)
+        self._addpath(f, 'n', 0, -2, -1)
         if f in self._copymap:
             del self._copymap[f]
 
     def add(self, f):
         '''Mark a file added.'''
-        self._dirty = True
-        self._addpath(f, True)
-        self._map[f] = ('a', 0, -1, -1)
+        self._addpath(f, 'a', 0, -1, -1, True)
         if f in self._copymap:
             del self._copymap[f]
 
@@ -406,10 +401,8 @@
         '''Mark a file merged.'''
         if self._pl[1] == nullid:
             return self.normallookup(f)
-        self._dirty = True
         s = os.lstat(self._join(f))
-        self._addpath(f)
-        self._map[f] = ('m', s.st_mode, s.st_size, int(s.st_mtime))
+        self._addpath(f, 'm', s.st_mode, s.st_size, int(s.st_mtime))
         if f in self._copymap:
             del self._copymap[f]
 


More information about the Mercurial-devel mailing list