/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/_annotator_pyx.pyx

  • Committer: Jelmer Vernooij
  • Date: 2020-02-18 01:57:45 UTC
  • mto: This revision was merged to the branch mainline in revision 7493.
  • Revision ID: jelmer@jelmer.uk-20200218015745-q2ss9tsk74h4nh61
drop use of future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Functionality for doing annotations in the 'optimal' way"""
18
18
 
 
19
 
19
20
cdef extern from "python-compat.h":
20
21
    pass
21
22
 
 
23
from cpython.dict cimport (
 
24
    PyDict_GetItem,
 
25
    PyDict_SetItem,
 
26
    )
 
27
from cpython.list cimport (
 
28
    PyList_Append,
 
29
    PyList_CheckExact,
 
30
    PyList_GET_ITEM,
 
31
    PyList_GET_SIZE,
 
32
    PyList_SetItem,
 
33
    PyList_Sort,
 
34
    )
 
35
from cpython.object cimport (
 
36
    Py_EQ,
 
37
    Py_LT,
 
38
    PyObject,
 
39
    PyObject_RichCompareBool,
 
40
    )
 
41
from cpython.ref cimport (
 
42
    Py_INCREF,
 
43
    )
 
44
from cpython.tuple cimport (
 
45
    PyTuple_CheckExact,
 
46
    PyTuple_GET_ITEM,
 
47
    PyTuple_GET_SIZE,
 
48
    PyTuple_New,
 
49
    PyTuple_SET_ITEM,
 
50
    )
 
51
 
22
52
cdef extern from "Python.h":
23
 
    ctypedef int Py_ssize_t
24
 
    ctypedef struct PyObject:
25
 
        pass
26
53
    ctypedef struct PyListObject:
27
54
        PyObject **ob_item
28
 
    int PyList_CheckExact(object)
29
 
    PyObject *PyList_GET_ITEM(object, Py_ssize_t o)
30
 
    Py_ssize_t PyList_GET_SIZE(object)
31
 
    int PyList_Append(object, object) except -1
32
 
    int PyList_SetItem(object, Py_ssize_t o, object) except -1
33
 
    int PyList_Sort(object) except -1
34
55
 
35
 
    int PyTuple_CheckExact(object)
36
 
    object PyTuple_New(Py_ssize_t len)
37
 
    void PyTuple_SET_ITEM(object, Py_ssize_t pos, object)
38
56
    void PyTuple_SET_ITEM_ptr "PyTuple_SET_ITEM" (object, Py_ssize_t,
39
57
                                                  PyObject *)
40
 
    int PyTuple_Resize(PyObject **, Py_ssize_t newlen)
41
 
    PyObject *PyTuple_GET_ITEM(object, Py_ssize_t o)
42
 
    Py_ssize_t PyTuple_GET_SIZE(object)
43
 
 
44
 
    PyObject *PyDict_GetItem(object d, object k)
45
 
    int PyDict_SetItem(object d, object k, object v) except -1
46
 
 
47
 
    void Py_INCREF(object)
 
58
 
48
59
    void Py_INCREF_ptr "Py_INCREF" (PyObject *)
49
60
    void Py_DECREF_ptr "Py_DECREF" (PyObject *)
50
61
 
51
 
    int Py_EQ
52
 
    int Py_LT
53
 
    int PyObject_RichCompareBool(object, object, int opid) except -1
54
62
    int PyObject_RichCompareBool_ptr "PyObject_RichCompareBool" (
55
63
        PyObject *, PyObject *, int opid)
56
64
 
57
65
 
58
 
from bzrlib import _annotator_py
 
66
from . import _annotator_py
59
67
 
60
68
 
61
69
cdef int _check_annotations_are_lists(annotations,
88
96
 
89
97
    :param tpl: The tuple we are investigating, *must* be a PyTuple
90
98
    :param pos: The last item we found. Will be updated to the new position.
91
 
    
 
99
 
92
100
    This cannot raise an exception, as it does no error checking.
93
101
    """
94
102
    pos[0] = pos[0] + 1
101
109
    """Combine the annotations from both sides."""
102
110
    cdef Py_ssize_t pos_one, pos_two, len_one, len_two
103
111
    cdef Py_ssize_t out_pos
104
 
    cdef PyObject *temp, *left, *right
 
112
    cdef PyObject *temp
 
113
    cdef PyObject *left
 
114
    cdef PyObject *right
105
115
 
106
116
    if (PyObject_RichCompareBool(ann_one, ann_two, Py_LT)):
107
117
        cache_key = (ann_one, ann_two)
168
178
    matching_blocks defines the ranges that match.
169
179
    """
170
180
    cdef Py_ssize_t parent_idx, lines_idx, match_len, idx
171
 
    cdef PyListObject *par_list, *ann_list
172
 
    cdef PyObject **par_temp, **ann_temp
 
181
    cdef PyListObject *par_list
 
182
    cdef PyListObject *ann_list
 
183
    cdef PyObject **par_temp
 
184
    cdef PyObject **ann_temp
173
185
 
174
186
    _check_annotations_are_lists(annotations, parent_annotations)
175
187
    par_list = <PyListObject *>parent_annotations
176
188
    ann_list = <PyListObject *>annotations
177
 
    # For NEWS and bzrlib/builtins.py, over 99% of the lines are simply copied
 
189
    # For NEWS and breezy/builtins.py, over 99% of the lines are simply copied
178
190
    # across from the parent entry. So this routine is heavily optimized for
179
191
    # that. Would be interesting if we could use memcpy() but we have to incref
180
192
    # and decref
194
206
                            matching_blocks, ann_cache) except -1:
195
207
    cdef Py_ssize_t parent_idx, ann_idx, lines_idx, match_len, idx
196
208
    cdef Py_ssize_t pos
197
 
    cdef PyObject *ann_temp, *par_temp
 
209
    cdef PyObject *ann_temp
 
210
    cdef PyObject *par_temp
198
211
 
199
212
    _check_annotations_are_lists(annotations, parent_annotations)
200
213
    last_ann = None
269
282
        """
270
283
        cdef Py_ssize_t pos, num_lines
271
284
 
272
 
        from bzrlib import annotate
 
285
        from . import annotate
273
286
 
274
287
        custom_tiebreaker = annotate._break_annotation_tie
275
288
        annotations, lines = self.annotate(key)