Mercurial > public > mercurial-scm > hg
diff mercurial/manifest.py @ 24298:49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
The _lazymanifest type(s) behave very much like a sorted dict with
filenames as keys and (nodeid, flags) as values. It therefore seems
surprising that its __iter__ generates 3-tuples of (path, nodeid,
flags). Let's make it match dict's behavior of generating the keys
instead, and add a new iterentries method for the 3-tuples. With this
change, the "x" in "if x in lm" and "for x in lm" now have the same
type (a filename string).
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 12 Mar 2015 18:18:29 -0700 |
parents | 0178f500d61e |
children | f263814c72ac |
line wrap: on
line diff
--- a/mercurial/manifest.py Thu Mar 12 18:53:44 2015 -0700 +++ b/mercurial/manifest.py Thu Mar 12 18:18:29 2015 -0700 @@ -44,11 +44,14 @@ dict.__setitem__(self, k, (node, flag)) def __iter__(self): - return ((f, e[0], e[1]) for f, e in sorted(self.iteritems())) + return iter(sorted(dict.keys(self))) def iterkeys(self): return iter(sorted(dict.keys(self))) + def iterentries(self): + return ((f, e[0], e[1]) for f, e in sorted(self.iteritems())) + def copy(self): c = _lazymanifest('') c.update(self) @@ -76,14 +79,14 @@ def filtercopy(self, filterfn): c = _lazymanifest('') - for f, n, fl in self: + for f, n, fl in self.iterentries(): if filterfn(f): c[f] = n, fl return c def text(self): """Get the full data of this manifest as a bytestring.""" - fl = sorted(self) + fl = sorted(self.iterentries()) _hex = revlog.hex # if this is changed to support newlines in filenames, @@ -119,7 +122,7 @@ del self._lm[key] def __iter__(self): - return self._lm.iterkeys() + return self._lm.__iter__() def iterkeys(self): return self._lm.iterkeys() @@ -140,8 +143,8 @@ def filesnotin(self, m2): '''Set of files in this manifest that are not in the other''' - files = set(self.iterkeys()) - files.difference_update(m2.iterkeys()) + files = set(self) + files.difference_update(m2) return files def matches(self, match): @@ -196,7 +199,7 @@ return c def iteritems(self): - return (x[:2] for x in self._lm) + return (x[:2] for x in self._lm.iterentries()) def text(self): return self._lm.text()