diff mercurial/dirstate.py @ 18899:d8ff607ef721

scmutil: use new dirs class in dirstate and context The multiset-of-directories code was open coded in each of these modules; this change gets rid of the duplication.
author Bryan O'Sullivan <bryano@fb.com>
date Wed, 10 Apr 2013 15:08:26 -0700
parents 38982de2b4eb
children 0176d0db4671
line wrap: on
line diff
--- a/mercurial/dirstate.py	Wed Apr 10 15:08:26 2013 -0700
+++ b/mercurial/dirstate.py	Wed Apr 10 15:08:26 2013 -0700
@@ -25,20 +25,6 @@
     def join(self, obj, fname):
         return obj._join(fname)
 
-def _incdirs(dirs, path):
-    for base in scmutil.finddirs(path):
-        if base in dirs:
-            dirs[base] += 1
-            return
-        dirs[base] = 1
-
-def _decdirs(dirs, path):
-    for base in scmutil.finddirs(path):
-        if dirs[base] > 1:
-            dirs[base] -= 1
-            return
-        del dirs[base]
-
 class dirstate(object):
 
     def __init__(self, opener, ui, root, validate):
@@ -107,11 +93,7 @@
 
     @propertycache
     def _dirs(self):
-        dirs = {}
-        for f, s in self._map.iteritems():
-            if s[0] != 'r':
-                _incdirs(dirs, f)
-        return dirs
+        return scmutil.dirs(self._map, 'r')
 
     def dirs(self):
         return self._dirs
@@ -331,7 +313,7 @@
 
     def _droppath(self, f):
         if self[f] not in "?r" and "_dirs" in self.__dict__:
-            _decdirs(self._dirs, f)
+            self._dirs.delpath(f)
 
     def _addpath(self, f, state, mode, size, mtime):
         oldstate = self[f]
@@ -347,7 +329,7 @@
                     raise util.Abort(
                         _('file %r in dirstate clashes with %r') % (d, f))
         if oldstate in "?r" and "_dirs" in self.__dict__:
-            _incdirs(self._dirs, f)
+            self._dirs.addpath(f)
         self._dirty = True
         self._map[f] = (state, mode, size, mtime)