/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_py.py

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Functionality for doing annotations in the 'optimal' way"""
18
18
 
19
 
from bzrlib.lazy_import import lazy_import
 
19
from __future__ import absolute_import
 
20
 
 
21
from .lazy_import import lazy_import
20
22
lazy_import(globals(), """
21
 
from bzrlib import annotate # Must be lazy to avoid circular importing
 
23
 
 
24
import patiencediff
 
25
 
 
26
from breezy import (
 
27
    annotate, # Must be lazy to avoid circular importing
 
28
    graph as _mod_graph,
 
29
    )
22
30
""")
23
 
from bzrlib import (
 
31
from . import (
24
32
    errors,
25
 
    graph as _mod_graph,
26
33
    osutils,
27
 
    patiencediff,
28
34
    ui,
29
35
    )
 
36
from .sixish import (
 
37
    range,
 
38
    viewitems,
 
39
    )
30
40
 
31
41
 
32
42
class Annotator(object):
66
76
        self._num_needed_children[key] = 1
67
77
        vf_keys_needed = set()
68
78
        ann_keys_needed = set()
69
 
        needed_keys = set([key])
 
79
        needed_keys = {key}
70
80
        while needed_keys:
71
81
            parent_lookup = []
72
82
            next_parent_map = {}
85
95
                    vf_keys_needed.add(key)
86
96
            needed_keys = set()
87
97
            next_parent_map.update(self._vf.get_parent_map(parent_lookup))
88
 
            for key, parent_keys in next_parent_map.iteritems():
89
 
                if parent_keys is None: # No graph versionedfile
 
98
            for key, parent_keys in viewitems(next_parent_map):
 
99
                if parent_keys is None:  # No graph versionedfile
90
100
                    parent_keys = ()
91
101
                    next_parent_map[key] = ()
92
102
                self._update_needed_children(key, parent_keys)
93
103
                needed_keys.update([key for key in parent_keys
94
 
                                         if key not in parent_map])
 
104
                                    if key not in parent_map])
95
105
            parent_map.update(next_parent_map)
96
 
            # _heads_provider does some graph caching, so it is only valid while
97
 
            # self._parent_map hasn't changed
 
106
            # _heads_provider does some graph caching, so it is only valid
 
107
            # while self._parent_map hasn't changed
98
108
            self._heads_provider = None
99
109
        return vf_keys_needed, ann_keys_needed
100
110
 
110
120
        keys, ann_keys = self._get_needed_keys(key)
111
121
        if pb is not None:
112
122
            pb.update('getting stream', 0, len(keys))
113
 
        stream  = self._vf.get_record_stream(keys, 'topological', True)
 
123
        stream = self._vf.get_record_stream(keys, 'topological', True)
114
124
        for idx, record in enumerate(stream):
115
125
            if pb is not None:
116
126
                pb.update('extracting', 0, len(keys))
117
127
            if record.storage_kind == 'absent':
118
128
                raise errors.RevisionNotPresent(record.key, self._vf)
119
129
            this_key = record.key
120
 
            lines = osutils.chunks_to_lines(record.get_bytes_as('chunked'))
 
130
            lines = record.get_bytes_as('lines')
121
131
            num_lines = len(lines)
122
132
            self._text_cache[this_key] = lines
123
133
            yield this_key, lines, num_lines
140
150
        parent_lines = self._text_cache[parent_key]
141
151
        parent_annotations = self._annotations_cache[parent_key]
142
152
        # PatienceSequenceMatcher should probably be part of Policy
143
 
        matcher = patiencediff.PatienceSequenceMatcher(None,
144
 
            parent_lines, text)
 
153
        matcher = patiencediff.PatienceSequenceMatcher(
 
154
            None, parent_lines, text)
145
155
        matching_blocks = matcher.get_matching_blocks()
146
156
        return parent_annotations, matching_blocks
147
157
 
149
159
        """Reannotate this text relative to its first parent."""
150
160
        (parent_annotations,
151
161
         matching_blocks) = self._get_parent_annotations_and_matches(
152
 
                                key, lines, parent_key)
 
162
             key, lines, parent_key)
153
163
 
154
164
        for parent_idx, lines_idx, match_len in matching_blocks:
155
165
            # For all matching regions we copy across the parent annotations
161
171
        """Reannotate this text relative to a second (or more) parent."""
162
172
        (parent_annotations,
163
173
         matching_blocks) = self._get_parent_annotations_and_matches(
164
 
                                key, lines, parent_key)
 
174
             key, lines, parent_key)
165
175
 
166
176
        last_ann = None
167
177
        last_parent = None
179
189
            par_sub = parent_annotations[parent_idx:parent_idx + match_len]
180
190
            if ann_sub == par_sub:
181
191
                continue
182
 
            for idx in xrange(match_len):
 
192
            for idx in range(match_len):
183
193
                ann = ann_sub[idx]
184
194
                par_ann = par_sub[idx]
185
195
                ann_idx = lines_idx + idx
253
263
                        each key is a possible source for the given line.
254
264
            lines the text of "key" as a list of lines
255
265
        """
256
 
        pb = ui.ui_factory.nested_progress_bar()
257
 
        try:
258
 
            for text_key, text, num_lines in self._get_needed_texts(key, pb=pb):
 
266
        with ui.ui_factory.nested_progress_bar() as pb:
 
267
            for text_key, text, num_lines in self._get_needed_texts(
 
268
                    key, pb=pb):
259
269
                self._annotate_one(text_key, text, num_lines)
260
 
        finally:
261
 
            pb.finished()
262
270
        try:
263
271
            annotations = self._annotations_cache[key]
264
272
        except KeyError:
277
285
            # Backwards compatibility, break up the heads into pairs and
278
286
            # resolve the result
279
287
            next_head = iter(the_heads)
280
 
            head = next_head.next()
 
288
            head = next(next_head)
281
289
            for possible_head in next_head:
282
290
                annotated_lines = ((head, line), (possible_head, line))
283
291
                head = tiebreaker(annotated_lines)[0]
301
309
            else:
302
310
                the_heads = heads(annotation)
303
311
                if len(the_heads) == 1:
304
 
                    for head in the_heads: break # get the item out of the set
 
312
                    for head in the_heads:
 
313
                        break  # get the item out of the set
305
314
                else:
306
315
                    head = self._resolve_annotation_tie(the_heads, line,
307
316
                                                        custom_tiebreaker)