##// END OF EJS Templates
lazymanifest: make __iter__ generate filenames, not 3-tuples...
Martin von Zweigbergk -
r24298:49cd847f default
parent child Browse files
Show More
@@ -234,7 +234,7 b' static line *lmiter_nextline(lmIter *sel'
234 234 return self->m->lines + self->pos;
235 235 }
236 236
237 static PyObject *lmiter_iternext(PyObject *o)
237 static PyObject *lmiter_iterentriesnext(PyObject *o)
238 238 {
239 239 size_t pl;
240 240 line *l;
@@ -261,10 +261,10 b' static PyObject *lmiter_iternext(PyObjec'
261 261 return NULL;
262 262 }
263 263
264 static PyTypeObject lazymanifestIterator = {
264 static PyTypeObject lazymanifestEntriesIterator = {
265 265 PyObject_HEAD_INIT(NULL)
266 266 0, /*ob_size */
267 "parsers.lazymanifest.iterator", /*tp_name */
267 "parsers.lazymanifest.entriesiterator", /*tp_name */
268 268 sizeof(lmIter), /*tp_basicsize */
269 269 0, /*tp_itemsize */
270 270 lmiter_dealloc, /*tp_dealloc */
@@ -285,13 +285,13 b' static PyTypeObject lazymanifestIterator'
285 285 /* tp_flags: Py_TPFLAGS_HAVE_ITER tells python to
286 286 use tp_iter and tp_iternext fields. */
287 287 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
288 "Iterator for a lazymanifest.", /* tp_doc */
288 "Iterator for 3-tuples in a lazymanifest.", /* tp_doc */
289 289 0, /* tp_traverse */
290 290 0, /* tp_clear */
291 291 0, /* tp_richcompare */
292 292 0, /* tp_weaklistoffset */
293 293 PyObject_SelfIter, /* tp_iter: __iter__() method */
294 lmiter_iternext, /* tp_iternext: next() method */
294 lmiter_iterentriesnext, /* tp_iternext: next() method */
295 295 };
296 296
297 297 static PyObject *lmiter_iterkeysnext(PyObject *o)
@@ -340,7 +340,7 b' static PyTypeObject lazymanifestKeysIter'
340 340
341 341 static lazymanifest *lazymanifest_copy(lazymanifest *self);
342 342
343 static PyObject *lazymanifest_getiter(lazymanifest *self)
343 static PyObject *lazymanifest_getentriesiter(lazymanifest *self)
344 344 {
345 345 lmIter *i = NULL;
346 346 lazymanifest *t = lazymanifest_copy(self);
@@ -348,7 +348,7 b' static PyObject *lazymanifest_getiter(la'
348 348 PyErr_NoMemory();
349 349 return NULL;
350 350 }
351 i = PyObject_New(lmIter, &lazymanifestIterator);
351 i = PyObject_New(lmIter, &lazymanifestEntriesIterator);
352 352 if (i) {
353 353 i->m = t;
354 354 i->pos = -1;
@@ -860,6 +860,8 b' static PyObject *lazymanifest_diff(lazym'
860 860 static PyMethodDef lazymanifest_methods[] = {
861 861 {"iterkeys", (PyCFunction)lazymanifest_getkeysiter, METH_NOARGS,
862 862 "Iterate over file names in this lazymanifest."},
863 {"iterentries", (PyCFunction)lazymanifest_getentriesiter, METH_NOARGS,
864 "Iterate over (path, nodeid, flags) typles in this lazymanifest."},
863 865 {"copy", (PyCFunction)lazymanifest_copy, METH_NOARGS,
864 866 "Make a copy of this lazymanifest."},
865 867 {"filtercopy", (PyCFunction)lazymanifest_filtercopy, METH_O,
@@ -898,7 +900,7 b' static PyTypeObject lazymanifestType = {'
898 900 0, /* tp_clear */
899 901 0, /* tp_richcompare */
900 902 0, /* tp_weaklistoffset */
901 (getiterfunc)lazymanifest_getiter, /* tp_iter */
903 (getiterfunc)lazymanifest_getkeysiter, /* tp_iter */
902 904 0, /* tp_iternext */
903 905 lazymanifest_methods, /* tp_methods */
904 906 0, /* tp_members */
@@ -44,11 +44,14 b' class _lazymanifest(dict):'
44 44 dict.__setitem__(self, k, (node, flag))
45 45
46 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 49 def iterkeys(self):
50 50 return iter(sorted(dict.keys(self)))
51 51
52 def iterentries(self):
53 return ((f, e[0], e[1]) for f, e in sorted(self.iteritems()))
54
52 55 def copy(self):
53 56 c = _lazymanifest('')
54 57 c.update(self)
@@ -76,14 +79,14 b' class _lazymanifest(dict):'
76 79
77 80 def filtercopy(self, filterfn):
78 81 c = _lazymanifest('')
79 for f, n, fl in self:
82 for f, n, fl in self.iterentries():
80 83 if filterfn(f):
81 84 c[f] = n, fl
82 85 return c
83 86
84 87 def text(self):
85 88 """Get the full data of this manifest as a bytestring."""
86 fl = sorted(self)
89 fl = sorted(self.iterentries())
87 90
88 91 _hex = revlog.hex
89 92 # if this is changed to support newlines in filenames,
@@ -119,7 +122,7 b' class manifestdict(object):'
119 122 del self._lm[key]
120 123
121 124 def __iter__(self):
122 return self._lm.iterkeys()
125 return self._lm.__iter__()
123 126
124 127 def iterkeys(self):
125 128 return self._lm.iterkeys()
@@ -140,8 +143,8 b' class manifestdict(object):'
140 143
141 144 def filesnotin(self, m2):
142 145 '''Set of files in this manifest that are not in the other'''
143 files = set(self.iterkeys())
144 files.difference_update(m2.iterkeys())
146 files = set(self)
147 files.difference_update(m2)
145 148 return files
146 149
147 150 def matches(self, match):
@@ -196,7 +199,7 b' class manifestdict(object):'
196 199 return c
197 200
198 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 204 def text(self):
202 205 return self._lm.text()
@@ -40,7 +40,7 b' class testmanifest(unittest.TestCase):'
40 40 def testEmptyManifest(self):
41 41 m = manifestmod._lazymanifest('')
42 42 self.assertEqual(0, len(m))
43 self.assertEqual([], list(m))
43 self.assertEqual([], list(m.iterentries()))
44 44
45 45 def testManifest(self):
46 46 m = manifestmod._lazymanifest(A_SHORT_MANIFEST)
@@ -49,7 +49,7 b' class testmanifest(unittest.TestCase):'
49 49 ('foo', binascii.unhexlify(HASH_1), ''),
50 50 ]
51 51 self.assertEqual(len(want), len(m))
52 self.assertEqual(want, list(m))
52 self.assertEqual(want, list(m.iterentries()))
53 53 self.assertEqual((binascii.unhexlify(HASH_1), ''), m['foo'])
54 54 self.assertRaises(KeyError, lambda : m['wat'])
55 55 self.assertEqual((binascii.unhexlify(HASH_2), 'l'),
@@ -88,7 +88,7 b' class testmanifest(unittest.TestCase):'
88 88 self.assertEqual((h2, ''), m['beta'])
89 89 self.assertRaises(KeyError, lambda : m['foo'])
90 90 w = [('alpha', h1, ''), ('bar/baz/qux.py', h2, 'l'), ('beta', h2, '')]
91 self.assertEqual(w, list(m))
91 self.assertEqual(w, list(m.iterentries()))
92 92
93 93 def testSetGetNodeSuffix(self):
94 94 clean = manifestmod._lazymanifest(A_SHORT_MANIFEST)
@@ -100,7 +100,7 b' class testmanifest(unittest.TestCase):'
100 100 self.assertEqual(want, m['foo'])
101 101 self.assertEqual([('bar/baz/qux.py', binascii.unhexlify(HASH_2), 'l'),
102 102 ('foo', binascii.unhexlify(HASH_1) + 'a', '')],
103 list(m))
103 list(m.iterentries()))
104 104 # Sometimes it even tries a 22-byte fake hash, but we can
105 105 # return 21 and it'll work out
106 106 m['foo'] = want[0] + '+', f
@@ -114,7 +114,7 b' class testmanifest(unittest.TestCase):'
114 114 self.assertEqual(want, m2['foo'])
115 115 # suffix with iteration
116 116 self.assertEqual([('bar/baz/qux.py', binascii.unhexlify(HASH_2), 'l'),
117 ('foo', want[0], '')], list(m))
117 ('foo', want[0], '')], list(m.iterentries()))
118 118 # shows up in diff
119 119 self.assertEqual({'foo': (want, (h, ''))}, m.diff(clean))
120 120 self.assertEqual({'foo': ((h, ''), want)}, clean.diff(m))
General Comments 0
You need to be logged in to leave comments. Login now