22
22
cdef extern from "python-compat.h":
25
cdef extern from "Python.h":
26
ctypedef int Py_ssize_t
27
ctypedef struct PyObject:
30
int PyString_CheckExact(object)
32
int PyObject_RichCompareBool(object, object, int)
35
int PyTuple_CheckExact(object)
36
object PyTuple_New(Py_ssize_t n)
37
Py_ssize_t PyTuple_GET_SIZE(object t)
38
PyObject * PyTuple_GET_ITEM(object t, Py_ssize_t o)
39
void PyTuple_SET_ITEM(object t, Py_ssize_t o, object v)
41
int PyList_CheckExact(object)
42
Py_ssize_t PyList_GET_SIZE(object l)
43
PyObject * PyList_GET_ITEM(object l, Py_ssize_t o)
44
int PyList_SetItem(object l, Py_ssize_t o, object l) except -1
45
int PyList_Append(object l, object v) except -1
47
int PyDict_CheckExact(object d)
48
Py_ssize_t PyDict_Size(object d) except -1
49
PyObject * PyDict_GetItem(object d, object k)
50
int PyDict_SetItem(object d, object k, object v) except -1
51
int PyDict_DelItem(object d, object k) except -1
52
int PyDict_Next(object d, Py_ssize_t *pos, PyObject **k, PyObject **v)
54
void Py_INCREF(object)
25
from cpython.bytes cimport (
28
from cpython.dict cimport (
36
from cpython.list cimport (
43
from cpython.object cimport (
46
PyObject_RichCompareBool,
48
from cpython.ref cimport (
51
from cpython.tuple cimport (
96
99
if self.parents is None:
99
102
cdef _KnownGraphNode parent
102
105
for parent in self.parents:
103
106
PyList_Append(keys, parent.key)
106
109
cdef clear_references(self):
107
110
self.parents = None
108
111
self.children = None
266
269
- all nodes found will also have child_keys populated with all known
269
cdef PyObject *temp_key, *temp_parent_keys, *temp_node
272
cdef PyObject *temp_key
273
cdef PyObject *temp_parent_keys
274
cdef PyObject *temp_node
270
275
cdef Py_ssize_t pos
271
276
cdef _KnownGraphNode node
272
277
cdef _KnownGraphNode parent_node
580
585
for pos from 0 <= pos < PyList_GET_SIZE(tips):
581
586
node = _get_list_node(tips, pos)
582
if PyString_CheckExact(node.key) or len(node.key) == 1:
587
if PyBytes_CheckExact(node.key) or len(node.key) == 1:
585
590
prefix = node.key[0]
640
645
# shown a specific impact, yet.
641
646
sorter = _MergeSorter(self, tip_key)
642
647
return sorter.topo_order()
644
649
def get_parent_keys(self, key):
645
650
"""Get the parents for a key
647
652
Returns a list containg the parents keys. If the key is a ghost,
648
653
None is returned. A KeyError will be raised if the key is not in
651
656
:param keys: Key to check (eg revision_id)
652
657
:return: A list of parents
654
return self._nodes[key].parent_keys
659
return self._nodes[key].parent_keys
656
661
def get_child_keys(self, key):
657
662
"""Get the children for a key
659
664
Returns a list containg the children keys. A KeyError will be raised
660
665
if the key is not in the graph.
662
667
:param keys: Key to check (eg revision_id)
663
668
:return: A list of children
665
return self._nodes[key].child_keys
670
return self._nodes[key].child_keys
668
673
cdef class _MergeSortNode:
929
934
cdef _MergeSortNode ms_node
930
935
cdef _KnownGraphNode node
931
936
cdef Py_ssize_t pos
932
cdef PyObject *temp_key, *temp_node
937
cdef PyObject *temp_key
938
cdef PyObject *temp_node
934
940
# Note: allocating a _MergeSortNode and deallocating it for all nodes
935
941
# costs approx 8.52ms (21%) of the total runtime