comparison 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
comparison
equal deleted inserted replaced
24297:0178f500d61e 24298:49cd847fd69a
42 if len(node) > 21: 42 if len(node) > 21:
43 node = node[:21] # match c implementation behavior 43 node = node[:21] # match c implementation behavior
44 dict.__setitem__(self, k, (node, flag)) 44 dict.__setitem__(self, k, (node, flag))
45 45
46 def __iter__(self): 46 def __iter__(self):
47 return ((f, e[0], e[1]) for f, e in sorted(self.iteritems())) 47 return iter(sorted(dict.keys(self)))
48 48
49 def iterkeys(self): 49 def iterkeys(self):
50 return iter(sorted(dict.keys(self))) 50 return iter(sorted(dict.keys(self)))
51
52 def iterentries(self):
53 return ((f, e[0], e[1]) for f, e in sorted(self.iteritems()))
51 54
52 def copy(self): 55 def copy(self):
53 c = _lazymanifest('') 56 c = _lazymanifest('')
54 c.update(self) 57 c.update(self)
55 return c 58 return c
74 77
75 return diff 78 return diff
76 79
77 def filtercopy(self, filterfn): 80 def filtercopy(self, filterfn):
78 c = _lazymanifest('') 81 c = _lazymanifest('')
79 for f, n, fl in self: 82 for f, n, fl in self.iterentries():
80 if filterfn(f): 83 if filterfn(f):
81 c[f] = n, fl 84 c[f] = n, fl
82 return c 85 return c
83 86
84 def text(self): 87 def text(self):
85 """Get the full data of this manifest as a bytestring.""" 88 """Get the full data of this manifest as a bytestring."""
86 fl = sorted(self) 89 fl = sorted(self.iterentries())
87 90
88 _hex = revlog.hex 91 _hex = revlog.hex
89 # if this is changed to support newlines in filenames, 92 # if this is changed to support newlines in filenames,
90 # be sure to check the templates/ dir again (especially *-raw.tmpl) 93 # be sure to check the templates/ dir again (especially *-raw.tmpl)
91 return ''.join("%s\0%s%s\n" % ( 94 return ''.join("%s\0%s%s\n" % (
117 120
118 def __delitem__(self, key): 121 def __delitem__(self, key):
119 del self._lm[key] 122 del self._lm[key]
120 123
121 def __iter__(self): 124 def __iter__(self):
122 return self._lm.iterkeys() 125 return self._lm.__iter__()
123 126
124 def iterkeys(self): 127 def iterkeys(self):
125 return self._lm.iterkeys() 128 return self._lm.iterkeys()
126 129
127 def keys(self): 130 def keys(self):
138 ret._lm[fn] = self._lm[fn] 141 ret._lm[fn] = self._lm[fn]
139 return ret 142 return ret
140 143
141 def filesnotin(self, m2): 144 def filesnotin(self, m2):
142 '''Set of files in this manifest that are not in the other''' 145 '''Set of files in this manifest that are not in the other'''
143 files = set(self.iterkeys()) 146 files = set(self)
144 files.difference_update(m2.iterkeys()) 147 files.difference_update(m2)
145 return files 148 return files
146 149
147 def matches(self, match): 150 def matches(self, match):
148 '''generate a new manifest filtered by the match argument''' 151 '''generate a new manifest filtered by the match argument'''
149 if match.always(): 152 if match.always():
194 c = manifestdict('') 197 c = manifestdict('')
195 c._lm = self._lm.copy() 198 c._lm = self._lm.copy()
196 return c 199 return c
197 200
198 def iteritems(self): 201 def iteritems(self):
199 return (x[:2] for x in self._lm) 202 return (x[:2] for x in self._lm.iterentries())
200 203
201 def text(self): 204 def text(self):
202 return self._lm.text() 205 return self._lm.text()
203 206
204 def fastdelta(self, base, changes): 207 def fastdelta(self, base, changes):