equal
deleted
inserted
replaced
685 |
685 |
686 static PyObject *index_insert(indexObject *self, PyObject *args) |
686 static PyObject *index_insert(indexObject *self, PyObject *args) |
687 { |
687 { |
688 PyObject *obj; |
688 PyObject *obj; |
689 char *node; |
689 char *node; |
690 Py_ssize_t offset, len, nodelen; |
690 int index; |
691 |
691 Py_ssize_t len, nodelen; |
692 if (!PyArg_ParseTuple(args, "nO", &offset, &obj)) |
692 |
|
693 if (!PyArg_ParseTuple(args, "iO", &index, &obj)) |
693 return NULL; |
694 return NULL; |
694 |
695 |
695 if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 8) { |
696 if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 8) { |
696 PyErr_SetString(PyExc_TypeError, "8-tuple required"); |
697 PyErr_SetString(PyExc_TypeError, "8-tuple required"); |
697 return NULL; |
698 return NULL; |
700 if (node_check(PyTuple_GET_ITEM(obj, 7), &node, &nodelen) == -1) |
701 if (node_check(PyTuple_GET_ITEM(obj, 7), &node, &nodelen) == -1) |
701 return NULL; |
702 return NULL; |
702 |
703 |
703 len = index_length(self); |
704 len = index_length(self); |
704 |
705 |
705 if (offset < 0) |
706 if (index < 0) |
706 offset += len; |
707 index += len; |
707 |
708 |
708 if (offset != len - 1) { |
709 if (index != len - 1) { |
709 PyErr_SetString(PyExc_IndexError, |
710 PyErr_SetString(PyExc_IndexError, |
710 "insert only supported at index -1"); |
711 "insert only supported at index -1"); |
711 return NULL; |
|
712 } |
|
713 |
|
714 if (offset > INT_MAX) { |
|
715 PyErr_SetString(PyExc_ValueError, |
|
716 "currently only 2**31 revs supported"); |
|
717 return NULL; |
712 return NULL; |
718 } |
713 } |
719 |
714 |
720 if (self->added == NULL) { |
715 if (self->added == NULL) { |
721 self->added = PyList_New(0); |
716 self->added = PyList_New(0); |
725 |
720 |
726 if (PyList_Append(self->added, obj) == -1) |
721 if (PyList_Append(self->added, obj) == -1) |
727 return NULL; |
722 return NULL; |
728 |
723 |
729 if (self->nt) |
724 if (self->nt) |
730 nt_insert(self, node, (int)offset); |
725 nt_insert(self, node, index); |
731 |
726 |
732 Py_CLEAR(self->headrevs); |
727 Py_CLEAR(self->headrevs); |
733 Py_RETURN_NONE; |
728 Py_RETURN_NONE; |
734 } |
729 } |
735 |
730 |