# HG changeset patch # User Bryan O'Sullivan # Date 2013-04-10 22:08:26 # Node ID d8ff607ef72135f2c1ede7b718cf57d304c041dc # Parent 856960173630ed4ba73fae6173ce63bd2107832a 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. diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -374,16 +374,7 @@ class changectx(object): @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 @@ class workingctx(changectx): 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 diff --git a/mercurial/copies.py b/mercurial/copies.py --- a/mercurial/copies.py +++ b/mercurial/copies.py @@ -335,8 +335,8 @@ def mergecopies(repo, c1, c2, ca): # generate a directory move map d1, d2 = c1.dirs(), c2.dirs() - d1.add('') - d2.add('') + d1.addpath('/') + d2.addpath('/') invalid = set() dirmove = {} diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -25,20 +25,6 @@ class rootcache(filecache): 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 @@ class dirstate(object): @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 @@ class dirstate(object): 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 @@ class dirstate(object): 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)