Show More
@@ -294,6 +294,50 b' static PyTypeObject lazymanifestIterator' | |||||
294 | lmiter_iternext, /* tp_iternext: next() method */ |
|
294 | lmiter_iternext, /* tp_iternext: next() method */ | |
295 | }; |
|
295 | }; | |
296 |
|
296 | |||
|
297 | static PyObject *lmiter_iterkeysnext(PyObject *o) | |||
|
298 | { | |||
|
299 | size_t pl; | |||
|
300 | line *l = lmiter_nextline((lmIter *)o); | |||
|
301 | if (!l) { | |||
|
302 | return NULL; | |||
|
303 | } | |||
|
304 | pl = pathlen(l); | |||
|
305 | return PyString_FromStringAndSize(l->start, pl); | |||
|
306 | } | |||
|
307 | ||||
|
308 | static PyTypeObject lazymanifestKeysIterator = { | |||
|
309 | PyObject_HEAD_INIT(NULL) | |||
|
310 | 0, /*ob_size */ | |||
|
311 | "parsers.lazymanifest.keysiterator", /*tp_name */ | |||
|
312 | sizeof(lmIter), /*tp_basicsize */ | |||
|
313 | 0, /*tp_itemsize */ | |||
|
314 | lmiter_dealloc, /*tp_dealloc */ | |||
|
315 | 0, /*tp_print */ | |||
|
316 | 0, /*tp_getattr */ | |||
|
317 | 0, /*tp_setattr */ | |||
|
318 | 0, /*tp_compare */ | |||
|
319 | 0, /*tp_repr */ | |||
|
320 | 0, /*tp_as_number */ | |||
|
321 | 0, /*tp_as_sequence */ | |||
|
322 | 0, /*tp_as_mapping */ | |||
|
323 | 0, /*tp_hash */ | |||
|
324 | 0, /*tp_call */ | |||
|
325 | 0, /*tp_str */ | |||
|
326 | 0, /*tp_getattro */ | |||
|
327 | 0, /*tp_setattro */ | |||
|
328 | 0, /*tp_as_buffer */ | |||
|
329 | /* tp_flags: Py_TPFLAGS_HAVE_ITER tells python to | |||
|
330 | use tp_iter and tp_iternext fields. */ | |||
|
331 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, | |||
|
332 | "Keys iterator for a lazymanifest.", /* tp_doc */ | |||
|
333 | 0, /* tp_traverse */ | |||
|
334 | 0, /* tp_clear */ | |||
|
335 | 0, /* tp_richcompare */ | |||
|
336 | 0, /* tp_weaklistoffset */ | |||
|
337 | PyObject_SelfIter, /* tp_iter: __iter__() method */ | |||
|
338 | lmiter_iterkeysnext, /* tp_iternext: next() method */ | |||
|
339 | }; | |||
|
340 | ||||
297 | static lazymanifest *lazymanifest_copy(lazymanifest *self); |
|
341 | static lazymanifest *lazymanifest_copy(lazymanifest *self); | |
298 |
|
342 | |||
299 | static PyObject *lazymanifest_getiter(lazymanifest *self) |
|
343 | static PyObject *lazymanifest_getiter(lazymanifest *self) | |
@@ -315,6 +359,25 b' static PyObject *lazymanifest_getiter(la' | |||||
315 | return (PyObject *)i; |
|
359 | return (PyObject *)i; | |
316 | } |
|
360 | } | |
317 |
|
361 | |||
|
362 | static PyObject *lazymanifest_getkeysiter(lazymanifest *self) | |||
|
363 | { | |||
|
364 | lmIter *i = NULL; | |||
|
365 | lazymanifest *t = lazymanifest_copy(self); | |||
|
366 | if (!t) { | |||
|
367 | PyErr_NoMemory(); | |||
|
368 | return NULL; | |||
|
369 | } | |||
|
370 | i = PyObject_New(lmIter, &lazymanifestKeysIterator); | |||
|
371 | if (i) { | |||
|
372 | i->m = t; | |||
|
373 | i->pos = -1; | |||
|
374 | } else { | |||
|
375 | Py_DECREF(t); | |||
|
376 | PyErr_NoMemory(); | |||
|
377 | } | |||
|
378 | return (PyObject *)i; | |||
|
379 | } | |||
|
380 | ||||
318 | /* __getitem__ and __setitem__ support */ |
|
381 | /* __getitem__ and __setitem__ support */ | |
319 |
|
382 | |||
320 | static Py_ssize_t lazymanifest_size(lazymanifest *self) |
|
383 | static Py_ssize_t lazymanifest_size(lazymanifest *self) | |
@@ -795,6 +858,8 b' static PyObject *lazymanifest_diff(lazym' | |||||
795 | } |
|
858 | } | |
796 |
|
859 | |||
797 | static PyMethodDef lazymanifest_methods[] = { |
|
860 | static PyMethodDef lazymanifest_methods[] = { | |
|
861 | {"iterkeys", (PyCFunction)lazymanifest_getkeysiter, METH_NOARGS, | |||
|
862 | "Iterate over file names in this lazymanifest."}, | |||
798 | {"copy", (PyCFunction)lazymanifest_copy, METH_NOARGS, |
|
863 | {"copy", (PyCFunction)lazymanifest_copy, METH_NOARGS, | |
799 | "Make a copy of this lazymanifest."}, |
|
864 | "Make a copy of this lazymanifest."}, | |
800 | {"filtercopy", (PyCFunction)lazymanifest_filtercopy, METH_O, |
|
865 | {"filtercopy", (PyCFunction)lazymanifest_filtercopy, METH_O, |
@@ -115,11 +115,14 b' class manifestdict(object):' | |||||
115 | def __delitem__(self, key): |
|
115 | def __delitem__(self, key): | |
116 | del self._lm[key] |
|
116 | del self._lm[key] | |
117 |
|
117 | |||
118 |
def |
|
118 | def __iter__(self): | |
119 |
return |
|
119 | return self._lm.iterkeys() | |
120 |
|
120 | |||
121 | def iterkeys(self): |
|
121 | def iterkeys(self): | |
122 |
return |
|
122 | return self._lm.iterkeys() | |
|
123 | ||||
|
124 | def keys(self): | |||
|
125 | return list(self.iterkeys()) | |||
123 |
|
126 | |||
124 | def intersectfiles(self, files): |
|
127 | def intersectfiles(self, files): | |
125 | '''make a new lazymanifest with the intersection of self with files |
|
128 | '''make a new lazymanifest with the intersection of self with files | |
@@ -184,9 +187,6 b' class manifestdict(object):' | |||||
184 | except KeyError: |
|
187 | except KeyError: | |
185 | return default |
|
188 | return default | |
186 |
|
189 | |||
187 | def __iter__(self): |
|
|||
188 | return (x[0] for x in self._lm) |
|
|||
189 |
|
||||
190 | def copy(self): |
|
190 | def copy(self): | |
191 | c = manifestdict('') |
|
191 | c = manifestdict('') | |
192 | c._lm = self._lm.copy() |
|
192 | c._lm = self._lm.copy() |
General Comments 0
You need to be logged in to leave comments.
Login now