mercurial/cext/revlog.c
changeset 40862 54a60968f0aa
parent 40861 b12700dd261f
child 40960 43974cd44967
equal deleted inserted replaced
40861:b12700dd261f 40862:54a60968f0aa
  2708 	    indexObject *index; /* Ref kept to avoid GC'ing the index */
  2708 	    indexObject *index; /* Ref kept to avoid GC'ing the index */
  2709 	void *iter;             /* Rust iterator */
  2709 	void *iter;             /* Rust iterator */
  2710 };
  2710 };
  2711 
  2711 
  2712 /* FFI exposed from Rust code */
  2712 /* FFI exposed from Rust code */
  2713 rustlazyancestorsObject *
  2713 rustlazyancestorsObject *rustlazyancestors_init(indexObject *index,
  2714 rustlazyancestors_init(indexObject *index,
  2714                                                 /* intrevs vector */
  2715                        /* to pass index_get_parents() */
  2715                                                 Py_ssize_t initrevslen,
  2716                        int (*)(indexObject *, Py_ssize_t, int *, int),
  2716                                                 long *initrevs, long stoprev,
  2717                        /* intrevs vector */
  2717                                                 int inclusive);
  2718                        Py_ssize_t initrevslen, long *initrevs, long stoprev,
       
  2719                        int inclusive);
       
  2720 void rustlazyancestors_drop(rustlazyancestorsObject *self);
  2718 void rustlazyancestors_drop(rustlazyancestorsObject *self);
  2721 int rustlazyancestors_next(rustlazyancestorsObject *self);
  2719 int rustlazyancestors_next(rustlazyancestorsObject *self);
  2722 int rustlazyancestors_contains(rustlazyancestorsObject *self, long rev);
  2720 int rustlazyancestors_contains(rustlazyancestorsObject *self, long rev);
  2723 
       
  2724 static int index_get_parents_checked(indexObject *self, Py_ssize_t rev, int *ps,
       
  2725                                      int maxrev)
       
  2726 {
       
  2727 	if (rev < 0 || rev >= index_length(self)) {
       
  2728 		PyErr_SetString(PyExc_ValueError, "rev out of range");
       
  2729 		return -1;
       
  2730 	}
       
  2731 	return index_get_parents(self, rev, ps, maxrev);
       
  2732 }
       
  2733 
  2721 
  2734 /* CPython instance methods */
  2722 /* CPython instance methods */
  2735 static int rustla_init(rustlazyancestorsObject *self, PyObject *args)
  2723 static int rustla_init(rustlazyancestorsObject *self, PyObject *args)
  2736 {
  2724 {
  2737 	PyObject *initrevsarg = NULL;
  2725 	PyObject *initrevsarg = NULL;
  2766 		initrevs[i] = PyInt_AsLong(PyList_GET_ITEM(initrevsarg, i));
  2754 		initrevs[i] = PyInt_AsLong(PyList_GET_ITEM(initrevsarg, i));
  2767 	}
  2755 	}
  2768 	if (PyErr_Occurred())
  2756 	if (PyErr_Occurred())
  2769 		goto bail;
  2757 		goto bail;
  2770 
  2758 
  2771 	self->iter = rustlazyancestors_init(index, index_get_parents, linit,
  2759 	self->iter =
  2772 	                                    initrevs, stoprev, inclusive);
  2760 	    rustlazyancestors_init(index, linit, initrevs, stoprev, inclusive);
  2773 	if (self->iter == NULL) {
  2761 	if (self->iter == NULL) {
  2774 		/* if this is because of GraphError::ParentOutOfRange
  2762 		/* if this is because of GraphError::ParentOutOfRange
  2775 		 * index_get_parents_checked() has already set the proper
  2763 		 * HgRevlogIndex_GetParents() has already set the proper
  2776 		 * ValueError */
  2764 		 * exception */
  2777 		goto bail;
  2765 		goto bail;
  2778 	}
  2766 	}
  2779 
  2767 
  2780 	free(initrevs);
  2768 	free(initrevs);
  2781 	return 0;
  2769 	return 0;