comparison mercurial/match.py @ 43523:c21aca51b392

utils: move the `dirs` definition in pathutil (API) Before this change, the `dirs` class was accessible through the `mercurial.util` module. That module is expected to stay free of scm specific content. The `pathutil` destination has been selection by Martin von Zweigbergk. This work is part of a refactoring to unify the revlog index and the nodemap. This unification prepare the use of a persistent nodemap. Differential Revision: https://phab.mercurial-scm.org/D7311
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 06 Nov 2019 14:13:19 +0100
parents 9f70512ae2cf
children ecd11c4d3834
comparison
equal deleted inserted replaced
43522:ce96be208ea4 43523:c21aca51b392
15 from .i18n import _ 15 from .i18n import _
16 from .pycompat import open 16 from .pycompat import open
17 from . import ( 17 from . import (
18 encoding, 18 encoding,
19 error, 19 error,
20 pathutil,
20 pathutil, 21 pathutil,
21 policy, 22 policy,
22 pycompat, 23 pycompat,
23 util, 24 util,
24 ) 25 )
596 self._prefix = _prefix(kindpats) 597 self._prefix = _prefix(kindpats)
597 self._pats, self.matchfn = _buildmatch(kindpats, b'$', root) 598 self._pats, self.matchfn = _buildmatch(kindpats, b'$', root)
598 599
599 @propertycache 600 @propertycache
600 def _dirs(self): 601 def _dirs(self):
601 return set(util.dirs(self._fileset)) 602 return set(pathutil.dirs(self._fileset))
602 603
603 def visitdir(self, dir): 604 def visitdir(self, dir):
604 dir = normalizerootdir(dir, b'visitdir') 605 dir = normalizerootdir(dir, b'visitdir')
605 if self._prefix and dir in self._fileset: 606 if self._prefix and dir in self._fileset:
606 return b'all' 607 return b'all'
627 @encoding.strmethod 628 @encoding.strmethod
628 def __repr__(self): 629 def __repr__(self):
629 return b'<patternmatcher patterns=%r>' % pycompat.bytestr(self._pats) 630 return b'<patternmatcher patterns=%r>' % pycompat.bytestr(self._pats)
630 631
631 632
632 # This is basically a reimplementation of util.dirs that stores the children 633 # This is basically a reimplementation of pathutil.dirs that stores the
633 # instead of just a count of them, plus a small optional optimization to avoid 634 # children instead of just a count of them, plus a small optional optimization
634 # some directories we don't need. 635 # to avoid some directories we don't need.
635 class _dirchildren(object): 636 class _dirchildren(object):
636 def __init__(self, paths, onlyinclude=None): 637 def __init__(self, paths, onlyinclude=None):
637 self._dirs = {} 638 self._dirs = {}
638 self._onlyinclude = onlyinclude or [] 639 self._onlyinclude = onlyinclude or []
639 addpath = self.addpath 640 addpath = self.addpath
761 762
762 matchfn = basematcher.exact 763 matchfn = basematcher.exact
763 764
764 @propertycache 765 @propertycache
765 def _dirs(self): 766 def _dirs(self):
766 return set(util.dirs(self._fileset)) 767 return set(pathutil.dirs(self._fileset))
767 768
768 def visitdir(self, dir): 769 def visitdir(self, dir):
769 dir = normalizerootdir(dir, b'visitdir') 770 dir = normalizerootdir(dir, b'visitdir')
770 return dir in self._dirs 771 return dir in self._dirs
771 772
1508 r, d = _patternrootsanddirs(kindpats) 1509 r, d = _patternrootsanddirs(kindpats)
1509 1510
1510 p = set() 1511 p = set()
1511 # Add the parents as non-recursive/exact directories, since they must be 1512 # Add the parents as non-recursive/exact directories, since they must be
1512 # scanned to get to either the roots or the other exact directories. 1513 # scanned to get to either the roots or the other exact directories.
1513 p.update(util.dirs(d)) 1514 p.update(pathutil.dirs(d))
1514 p.update(util.dirs(r)) 1515 p.update(pathutil.dirs(r))
1515 1516
1516 # FIXME: all uses of this function convert these to sets, do so before 1517 # FIXME: all uses of this function convert these to sets, do so before
1517 # returning. 1518 # returning.
1518 # FIXME: all uses of this function do not need anything in 'roots' and 1519 # FIXME: all uses of this function do not need anything in 'roots' and
1519 # 'dirs' to also be in 'parents', consider removing them before returning. 1520 # 'dirs' to also be in 'parents', consider removing them before returning.