Mercurial > hg
comparison mercurial/manifest.py @ 23305:0cc283f44655
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()).
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 22 Oct 2014 21:38:30 -0700 |
parents | ff93aa006e6a |
children | a4679a74df14 |
comparison
equal
deleted
inserted
replaced
23304:dd3f857598a0 | 23305:0cc283f44655 |
---|---|
36 ret[fn] = self[fn] | 36 ret[fn] = self[fn] |
37 flags = self._flags.get(fn, None) | 37 flags = self._flags.get(fn, None) |
38 if flags: | 38 if flags: |
39 ret._flags[fn] = flags | 39 ret._flags[fn] = flags |
40 return ret | 40 return ret |
41 | |
42 def matches(self, match): | |
43 '''generate a new manifest filtered by the match argument''' | |
44 if match.always(): | |
45 return self.copy() | |
46 | |
47 files = match.files() | |
48 if (match.matchfn == match.exact or | |
49 (not match.anypats() and util.all(fn in self for fn in files))): | |
50 return self.intersectfiles(files) | |
51 | |
52 mf = self.copy() | |
53 for fn in mf.keys(): | |
54 if not match(fn): | |
55 del mf[fn] | |
56 return mf | |
41 | 57 |
42 def diff(self, m2): | 58 def diff(self, m2): |
43 '''Finds changes between the current manifest and m2. The result is | 59 '''Finds changes between the current manifest and m2. The result is |
44 returned as a dict with filename as key and values of the form | 60 returned as a dict with filename as key and values of the form |
45 ((n1,fl1),(n2,fl2)), where n1/n2 is the nodeid in the current/other | 61 ((n1,fl1),(n2,fl2)), where n1/n2 is the nodeid in the current/other |