Mercurial > public > mercurial-scm > hg-stable
diff mercurial/scmutil.py @ 24635:21e1ece30f8c
util: move dirs() and finddirs() from scmutil to util
An upcoming commit requires that match.py be able to call scmutil.dirs(), but
when match.py imports scmutil, a dependency cycle is created. This commit
avoids the cycle by moving dirs() and its related finddirs() function from
scmutil to util, which match.py already depends on.
author | Drew Gottlieb <drgott@google.com> |
---|---|
date | Mon, 06 Apr 2015 14:36:08 -0700 |
parents | a0b47885a1c5 |
children | ca3a90096c95 |
line wrap: on
line diff
--- a/mercurial/scmutil.py Mon Apr 06 13:59:36 2015 -0700 +++ b/mercurial/scmutil.py Mon Apr 06 14:36:08 2015 -0700 @@ -7,7 +7,7 @@ from i18n import _ from mercurial.node import nullrev -import util, error, osutil, revset, similar, encoding, phases, parsers +import util, error, osutil, revset, similar, encoding, phases import pathutil import match as matchmod import os, errno, re, glob, tempfile @@ -1083,48 +1083,3 @@ del obj.__dict__[self.name] except KeyError: raise AttributeError(self.name) - -class dirs(object): - '''a multiset of directory names from a dirstate or manifest''' - - def __init__(self, map, skip=None): - self._dirs = {} - addpath = self.addpath - if util.safehasattr(map, 'iteritems') and skip is not None: - for f, s in map.iteritems(): - if s[0] != skip: - addpath(f) - else: - for f in map: - addpath(f) - - def addpath(self, path): - dirs = self._dirs - for base in finddirs(path): - if base in dirs: - dirs[base] += 1 - return - dirs[base] = 1 - - def delpath(self, path): - dirs = self._dirs - for base in finddirs(path): - if dirs[base] > 1: - dirs[base] -= 1 - return - del dirs[base] - - def __iter__(self): - return self._dirs.iterkeys() - - def __contains__(self, d): - return d in self._dirs - -if util.safehasattr(parsers, 'dirs'): - dirs = parsers.dirs - -def finddirs(path): - pos = path.rfind('/') - while pos != -1: - yield path[:pos] - pos = path.rfind('/', 0, pos)