/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/_known_graph_pyx.pyx

  • Committer: Jelmer Vernooij
  • Date: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Implementation of Graph algorithms when we have already loaded everything.
18
18
"""
19
19
 
20
 
from __future__ import absolute_import
21
 
 
22
20
cdef extern from "python-compat.h":
23
21
    pass
24
22
 
25
 
cdef extern from "Python.h":
26
 
    ctypedef int Py_ssize_t
27
 
    ctypedef struct PyObject:
28
 
        pass
29
 
 
30
 
    int PyString_CheckExact(object)
31
 
 
32
 
    int PyObject_RichCompareBool(object, object, int)
33
 
    int Py_LT
34
 
 
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)
40
 
 
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
46
 
 
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)
53
 
 
54
 
    void Py_INCREF(object)
 
23
from cpython.bytes cimport (
 
24
    PyBytes_CheckExact,
 
25
    )
 
26
from cpython.dict cimport (
 
27
    PyDict_CheckExact,
 
28
    PyDict_DelItem,
 
29
    PyDict_GetItem,
 
30
    PyDict_Next,
 
31
    PyDict_SetItem,
 
32
    PyDict_Size,
 
33
    )
 
34
from cpython.list cimport (
 
35
    PyList_Append,
 
36
    PyList_CheckExact,
 
37
    PyList_GET_SIZE,
 
38
    PyList_GET_ITEM,
 
39
    PyList_SetItem,
 
40
    )
 
41
from cpython.object cimport (
 
42
    Py_LT,
 
43
    PyObject,
 
44
    PyObject_RichCompareBool,
 
45
    )
 
46
from cpython.ref cimport (
 
47
    Py_INCREF,
 
48
    )
 
49
from cpython.tuple cimport (
 
50
    PyTuple_CheckExact,
 
51
    PyTuple_GET_SIZE,
 
52
    PyTuple_GET_ITEM,
 
53
    PyTuple_New,
 
54
    PyTuple_SET_ITEM,
 
55
    )
55
56
 
56
57
import collections
57
58
import gc
95
96
        def __get__(self):
96
97
            if self.parents is None:
97
98
                return None
98
 
            
 
99
 
99
100
            cdef _KnownGraphNode parent
100
101
 
101
102
            keys = []
102
103
            for parent in self.parents:
103
104
                PyList_Append(keys, parent.key)
104
105
            return keys
105
 
    
 
106
 
106
107
    cdef clear_references(self):
107
108
        self.parents = None
108
109
        self.children = None
266
267
        - all nodes found will also have child_keys populated with all known
267
268
          child keys,
268
269
        """
269
 
        cdef PyObject *temp_key, *temp_parent_keys, *temp_node
 
270
        cdef PyObject *temp_key
 
271
        cdef PyObject *temp_parent_keys
 
272
        cdef PyObject *temp_node
270
273
        cdef Py_ssize_t pos
271
274
        cdef _KnownGraphNode node
272
275
        cdef _KnownGraphNode parent_node
348
351
 
349
352
        If this fills in a ghost, then the gdfos of all children will be
350
353
        updated accordingly.
351
 
        
 
354
 
352
355
        :param key: The node being added. If this is a duplicate, this is a
353
356
            no-op.
354
357
        :param parent_keys: The parents of the given node.
579
582
        prefix_tips = {}
580
583
        for pos from 0 <= pos < PyList_GET_SIZE(tips):
581
584
            node = _get_list_node(tips, pos)
582
 
            if PyString_CheckExact(node.key) or len(node.key) == 1:
 
585
            if PyBytes_CheckExact(node.key) or len(node.key) == 1:
583
586
                prefix = ''
584
587
            else:
585
588
                prefix = node.key[0]
640
643
        #       shown a specific impact, yet.
641
644
        sorter = _MergeSorter(self, tip_key)
642
645
        return sorter.topo_order()
643
 
    
 
646
 
644
647
    def get_parent_keys(self, key):
645
648
        """Get the parents for a key
646
 
        
647
 
        Returns a list containg the parents keys. If the key is a ghost,
 
649
 
 
650
        Returns a list containing the parents keys. If the key is a ghost,
648
651
        None is returned. A KeyError will be raised if the key is not in
649
652
        the graph.
650
 
        
 
653
 
651
654
        :param keys: Key to check (eg revision_id)
652
655
        :return: A list of parents
653
656
        """
654
 
        return self._nodes[key].parent_keys 
 
657
        return self._nodes[key].parent_keys
655
658
 
656
659
    def get_child_keys(self, key):
657
660
        """Get the children for a key
658
 
        
659
 
        Returns a list containg the children keys. A KeyError will be raised
 
661
 
 
662
        Returns a list containing the children keys. A KeyError will be raised
660
663
        if the key is not in the graph.
661
 
        
 
664
 
662
665
        :param keys: Key to check (eg revision_id)
663
666
        :return: A list of children
664
667
        """
665
 
        return self._nodes[key].child_keys    
 
668
        return self._nodes[key].child_keys
666
669
 
667
670
 
668
671
cdef class _MergeSortNode:
929
932
        cdef _MergeSortNode ms_node
930
933
        cdef _KnownGraphNode node
931
934
        cdef Py_ssize_t pos
932
 
        cdef PyObject *temp_key, *temp_node
 
935
        cdef PyObject *temp_key
 
936
        cdef PyObject *temp_node
933
937
 
934
938
        # Note: allocating a _MergeSortNode and deallocating it for all nodes
935
939
        #       costs approx 8.52ms (21%) of the total runtime