changeset 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 856960173630
children 02ee846b246a
files mercurial/context.py mercurial/copies.py mercurial/dirstate.py
diffstat 3 files changed, 7 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Wed Apr 10 15:08:26 2013 -0700
+++ b/mercurial/context.py	Wed Apr 10 15:08:26 2013 -0700
@@ -374,16 +374,7 @@
 
     @propertycache
     def _dirs(self):
-        dirs = set()
-        for f in self._manifest:
-            pos = f.rfind('/')
-            while pos != -1:
-                f = f[:pos]
-                if f in dirs:
-                    break # dirs already contains this and above
-                dirs.add(f)
-                pos = f.rfind('/')
-        return dirs
+        return scmutil.dirs(self._manifest)
 
     def dirs(self):
         return self._dirs
@@ -1155,7 +1146,7 @@
         self._repo.dirstate.setparents(node)
 
     def dirs(self):
-        return set(self._repo.dirstate.dirs())
+        return self._repo.dirstate.dirs()
 
 class workingfilectx(filectx):
     """A workingfilectx object makes access to data related to a particular
--- a/mercurial/copies.py	Wed Apr 10 15:08:26 2013 -0700
+++ b/mercurial/copies.py	Wed Apr 10 15:08:26 2013 -0700
@@ -335,8 +335,8 @@
 
     # generate a directory move map
     d1, d2 = c1.dirs(), c2.dirs()
-    d1.add('')
-    d2.add('')
+    d1.addpath('/')
+    d2.addpath('/')
     invalid = set()
     dirmove = {}
 
--- 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)