# HG changeset patch # User Drew Gottlieb # Date 1428356168 25200 # Node ID 21e1ece30f8c35991d37113ec7c1b72001210ee8 # Parent 4ece2847cf4c762ae26f22ad90844ae8efb1df2a 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. diff -r 4ece2847cf4c -r 21e1ece30f8c mercurial/cmdutil.py --- a/mercurial/cmdutil.py Mon Apr 06 13:59:36 2015 -0700 +++ b/mercurial/cmdutil.py Mon Apr 06 14:36:08 2015 -0700 @@ -2328,7 +2328,7 @@ % join(subpath)) # warn about failure to delete explicit files/dirs - deleteddirs = scmutil.dirs(deleted) + deleteddirs = util.dirs(deleted) for f in m.files(): def insubrepo(): for subpath in wctx.substate: diff -r 4ece2847cf4c -r 21e1ece30f8c mercurial/dirstate.py --- a/mercurial/dirstate.py Mon Apr 06 13:59:36 2015 -0700 +++ b/mercurial/dirstate.py Mon Apr 06 14:36:08 2015 -0700 @@ -139,7 +139,7 @@ @propertycache def _dirs(self): - return scmutil.dirs(self._map, 'r') + return util.dirs(self._map, 'r') def dirs(self): return self._dirs @@ -381,7 +381,7 @@ if f in self._dirs: raise util.Abort(_('directory %r already in dirstate') % f) # shadows - for d in scmutil.finddirs(f): + for d in util.finddirs(f): if d in self._dirs: break if d in self._map and self[d] != 'r': @@ -601,7 +601,7 @@ return False if self._ignore(f): return True - for p in scmutil.finddirs(f): + for p in util.finddirs(f): if self._ignore(p): return True return False @@ -698,7 +698,7 @@ results[nf] = None else: # does it match a missing directory? if alldirs is None: - alldirs = scmutil.dirs(dmap) + alldirs = util.dirs(dmap) if nf in alldirs: if matchedir: matchedir(nf) diff -r 4ece2847cf4c -r 21e1ece30f8c mercurial/manifest.py --- a/mercurial/manifest.py Mon Apr 06 13:59:36 2015 -0700 +++ b/mercurial/manifest.py Mon Apr 06 14:36:08 2015 -0700 @@ -6,7 +6,7 @@ # GNU General Public License version 2 or any later version. from i18n import _ -import mdiff, parsers, error, revlog, util, scmutil +import mdiff, parsers, error, revlog, util import array, struct import os @@ -217,7 +217,7 @@ @propertycache def _dirs(self): - return scmutil.dirs(self) + return util.dirs(self) def dirs(self): return self._dirs @@ -561,7 +561,7 @@ @propertycache def _alldirs(self): - return scmutil.dirs(self) + return util.dirs(self) def dirs(self): return self._alldirs diff -r 4ece2847cf4c -r 21e1ece30f8c mercurial/scmutil.py --- 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) diff -r 4ece2847cf4c -r 21e1ece30f8c mercurial/util.py --- a/mercurial/util.py Mon Apr 06 13:59:36 2015 -0700 +++ b/mercurial/util.py Mon Apr 06 14:36:08 2015 -0700 @@ -15,7 +15,7 @@ import i18n _ = i18n._ -import error, osutil, encoding +import error, osutil, encoding, parsers import errno, shutil, sys, tempfile, traceback import re as remod import os, time, datetime, calendar, textwrap, signal, collections @@ -2240,5 +2240,50 @@ f.write(' %-*s in %s\n' % (fnmax, fnln, func)) f.flush() +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 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 safehasattr(parsers, 'dirs'): + dirs = parsers.dirs + +def finddirs(path): + pos = path.rfind('/') + while pos != -1: + yield path[:pos] + pos = path.rfind('/', 0, pos) + # convenient shortcut dst = debugstacktrace