mercurial/manifest.c
changeset 24295 2b7ab29627fd
parent 24294 3d485727e45e
child 24298 49cd847fd69a
equal deleted inserted replaced
24294:3d485727e45e 24295:2b7ab29627fd
   292 	0,                               /* tp_weaklistoffset */
   292 	0,                               /* tp_weaklistoffset */
   293 	PyObject_SelfIter,               /* tp_iter: __iter__() method */
   293 	PyObject_SelfIter,               /* tp_iter: __iter__() method */
   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)
   300 {
   344 {
   301 	lmIter *i = NULL;
   345 	lmIter *i = NULL;
   303 	if (!t) {
   347 	if (!t) {
   304 		PyErr_NoMemory();
   348 		PyErr_NoMemory();
   305 		return NULL;
   349 		return NULL;
   306 	}
   350 	}
   307 	i = PyObject_New(lmIter, &lazymanifestIterator);
   351 	i = PyObject_New(lmIter, &lazymanifestIterator);
       
   352 	if (i) {
       
   353 		i->m = t;
       
   354 		i->pos = -1;
       
   355 	} else {
       
   356 		Py_DECREF(t);
       
   357 		PyErr_NoMemory();
       
   358 	}
       
   359 	return (PyObject *)i;
       
   360 }
       
   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);
   308 	if (i) {
   371 	if (i) {
   309 		i->m = t;
   372 		i->m = t;
   310 		i->pos = -1;
   373 		i->pos = -1;
   311 	} else {
   374 	} else {
   312 		Py_DECREF(t);
   375 		Py_DECREF(t);
   793 	Py_XDECREF(emptyTup);
   856 	Py_XDECREF(emptyTup);
   794 	return NULL;
   857 	return NULL;
   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,
   801 	 "Make a copy of this manifest filtered by matchfn."},
   866 	 "Make a copy of this manifest filtered by matchfn."},
   802 	{"diff", (PyCFunction)lazymanifest_diff, METH_VARARGS,
   867 	{"diff", (PyCFunction)lazymanifest_diff, METH_VARARGS,