mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 23:07:18 +03:00
manifest: add matches() method
Move the code in context._manifestmatches() into a new manifest.matches(). It's a natural place for the code to live and it allows other callers to easily use it. It should also make it easier to optimize the new method in alternative implementations of the manifest (same reasoning as with manifest.diff()).
This commit is contained in:
parent
cfd2a961bd
commit
455810026c
@ -71,19 +71,7 @@ class basectx(object):
|
||||
object oriented way for other contexts to customize the manifest
|
||||
generation.
|
||||
"""
|
||||
if match.always():
|
||||
return self.manifest().copy()
|
||||
|
||||
files = match.files()
|
||||
if (match.matchfn == match.exact or
|
||||
(not match.anypats() and util.all(fn in self for fn in files))):
|
||||
return self.manifest().intersectfiles(files)
|
||||
|
||||
mf = self.manifest().copy()
|
||||
for fn in mf.keys():
|
||||
if not match(fn):
|
||||
del mf[fn]
|
||||
return mf
|
||||
return self.manifest().matches(match)
|
||||
|
||||
def _matchstatus(self, other, match):
|
||||
"""return match.always if match is none
|
||||
|
@ -39,6 +39,22 @@ class manifestdict(dict):
|
||||
ret._flags[fn] = flags
|
||||
return ret
|
||||
|
||||
def matches(self, match):
|
||||
'''generate a new manifest filtered by the match argument'''
|
||||
if match.always():
|
||||
return self.copy()
|
||||
|
||||
files = match.files()
|
||||
if (match.matchfn == match.exact or
|
||||
(not match.anypats() and util.all(fn in self for fn in files))):
|
||||
return self.intersectfiles(files)
|
||||
|
||||
mf = self.copy()
|
||||
for fn in mf.keys():
|
||||
if not match(fn):
|
||||
del mf[fn]
|
||||
return mf
|
||||
|
||||
def diff(self, m2):
|
||||
'''Finds changes between the current manifest and m2. The result is
|
||||
returned as a dict with filename as key and values of the form
|
||||
|
Loading…
Reference in New Issue
Block a user