mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 08:18:15 +03:00
match: make _fileroots a @propertycache and rename it to _fileset
The files in the set are not necesserily roots of anything. Making it a @propertycache will help towards extracting a base class for matchers.
This commit is contained in:
parent
430b02b3ab
commit
767cd2bb63
@ -41,7 +41,7 @@ def composelargefilematcher(match, manifest):
|
||||
m = copy.copy(match)
|
||||
lfile = lambda f: lfutil.standin(f) in manifest
|
||||
m._files = filter(lfile, m._files)
|
||||
m._fileroots = set(m._files)
|
||||
m._fileset = set(m._files)
|
||||
m._always = False
|
||||
origmatchfn = m.matchfn
|
||||
m.matchfn = lambda f: lfile(f) and origmatchfn(f)
|
||||
@ -56,7 +56,7 @@ def composenormalfilematcher(match, manifest, exclude=None):
|
||||
notlfile = lambda f: not (lfutil.isstandin(f) or lfutil.standin(f) in
|
||||
manifest or f in excluded)
|
||||
m._files = filter(notlfile, m._files)
|
||||
m._fileroots = set(m._files)
|
||||
m._fileset = set(m._files)
|
||||
m._always = False
|
||||
origmatchfn = m.matchfn
|
||||
m.matchfn = lambda f: notlfile(f) and origmatchfn(f)
|
||||
@ -368,7 +368,7 @@ def overridelog(orig, ui, repo, *pats, **opts):
|
||||
elif m._files[i] not in ctx and repo.wvfs.isdir(standin):
|
||||
m._files.append(standin)
|
||||
|
||||
m._fileroots = set(m._files)
|
||||
m._fileset = set(m._files)
|
||||
m._always = False
|
||||
origmatchfn = m.matchfn
|
||||
def lfmatchfn(f):
|
||||
@ -644,7 +644,7 @@ def overridecopy(orig, ui, repo, pats, opts, rename=False):
|
||||
m = copy.copy(match)
|
||||
lfile = lambda f: lfutil.standin(f) in manifest
|
||||
m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
|
||||
m._fileroots = set(m._files)
|
||||
m._fileset = set(m._files)
|
||||
origmatchfn = m.matchfn
|
||||
def matchfn(f):
|
||||
lfile = lfutil.splitstandin(f)
|
||||
@ -767,7 +767,7 @@ def overriderevert(orig, ui, repo, ctx, parents, *pats, **opts):
|
||||
else:
|
||||
matchfiles.append(f)
|
||||
m._files = matchfiles
|
||||
m._fileroots = set(m._files)
|
||||
m._fileset = set(m._files)
|
||||
origmatchfn = m.matchfn
|
||||
def matchfn(f):
|
||||
lfile = lfutil.splitstandin(f)
|
||||
|
@ -188,7 +188,6 @@ class match(object):
|
||||
return True
|
||||
|
||||
self.matchfn = m
|
||||
self._fileroots = set(self._files)
|
||||
|
||||
def __call__(self, fn):
|
||||
return self.matchfn(fn)
|
||||
@ -234,9 +233,13 @@ class match(object):
|
||||
else: optimal roots'''
|
||||
return self._files
|
||||
|
||||
@propertycache
|
||||
def _fileset(self):
|
||||
return set(self._files)
|
||||
|
||||
@propertycache
|
||||
def _dirs(self):
|
||||
return set(util.dirs(self._fileroots)) | {'.'}
|
||||
return set(util.dirs(self._fileset)) | {'.'}
|
||||
|
||||
def visitdir(self, dir):
|
||||
'''Decides whether a directory should be visited based on whether it
|
||||
@ -250,7 +253,7 @@ class match(object):
|
||||
This function's behavior is undefined if it has returned False for
|
||||
one of the dir's parent directories.
|
||||
'''
|
||||
if self.prefix() and dir in self._fileroots:
|
||||
if self.prefix() and dir in self._fileset:
|
||||
return 'all'
|
||||
if dir in self._excluderoots:
|
||||
return False
|
||||
@ -261,16 +264,16 @@ class match(object):
|
||||
not any(parent in self._includeroots
|
||||
for parent in util.finddirs(dir))):
|
||||
return False
|
||||
return (not self._fileroots or
|
||||
'.' in self._fileroots or
|
||||
dir in self._fileroots or
|
||||
return (not self._fileset or
|
||||
'.' in self._fileset or
|
||||
dir in self._fileset or
|
||||
dir in self._dirs or
|
||||
any(parentdir in self._fileroots
|
||||
any(parentdir in self._fileset
|
||||
for parentdir in util.finddirs(dir)))
|
||||
|
||||
def exact(self, f):
|
||||
'''Returns True if f is in .files().'''
|
||||
return f in self._fileroots
|
||||
return f in self._fileset
|
||||
|
||||
def anypats(self):
|
||||
'''Matcher uses patterns or include/exclude.'''
|
||||
@ -399,7 +402,6 @@ class subdirmatcher(match):
|
||||
return matcher.visitdir(self._path)
|
||||
return matcher.visitdir(self._path + "/" + dir)
|
||||
self.visitdir = visitdir
|
||||
self._fileroots = set(self._files)
|
||||
|
||||
def abs(self, f):
|
||||
return self._matcher.abs(self._path + "/" + f)
|
||||
@ -428,8 +430,8 @@ class icasefsmatcher(match):
|
||||
# inexact case matches are treated as exact, and not noted without -v.
|
||||
if self._files:
|
||||
roots, dirs = _rootsanddirs(self._kp)
|
||||
self._fileroots = set(roots)
|
||||
self._fileroots.update(dirs)
|
||||
self._fileset = set(roots)
|
||||
self._fileset.update(dirs)
|
||||
|
||||
def _normalize(self, patterns, default, root, cwd, auditor):
|
||||
self._kp = super(icasefsmatcher, self)._normalize(patterns, default,
|
||||
|
Loading…
Reference in New Issue
Block a user