/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-08-23 01:15:41 UTC
  • mfrom: (7520.1.4 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200823011541-nv0oh7nzaganx2qy
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/389690

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 .lazy_import import lazy_import
20
20
lazy_import(globals(), """
21
 
from bzrlib import annotate # Must be lazy to avoid circular importing
 
21
 
 
22
import patiencediff
 
23
 
 
24
from breezy import (
 
25
    annotate, # Must be lazy to avoid circular importing
 
26
    graph as _mod_graph,
 
27
    )
22
28
""")
23
 
from bzrlib import (
 
29
from . import (
24
30
    errors,
25
 
    graph as _mod_graph,
26
31
    osutils,
27
 
    patiencediff,
28
32
    ui,
29
33
    )
30
34
 
66
70
        self._num_needed_children[key] = 1
67
71
        vf_keys_needed = set()
68
72
        ann_keys_needed = set()
69
 
        needed_keys = set([key])
 
73
        needed_keys = {key}
70
74
        while needed_keys:
71
75
            parent_lookup = []
72
76
            next_parent_map = {}
85
89
                    vf_keys_needed.add(key)
86
90
            needed_keys = set()
87
91
            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
 
92
            for key, parent_keys in next_parent_map.items():
 
93
                if parent_keys is None:  # No graph versionedfile
90
94
                    parent_keys = ()
91
95
                    next_parent_map[key] = ()
92
96
                self._update_needed_children(key, parent_keys)
93
97
                needed_keys.update([key for key in parent_keys
94
 
                                         if key not in parent_map])
 
98
                                    if key not in parent_map])
95
99
            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
 
100
            # _heads_provider does some graph caching, so it is only valid
 
101
            # while self._parent_map hasn't changed
98
102
            self._heads_provider = None
99
103
        return vf_keys_needed, ann_keys_needed
100
104
 
110
114
        keys, ann_keys = self._get_needed_keys(key)
111
115
        if pb is not None:
112
116
            pb.update('getting stream', 0, len(keys))
113
 
        stream  = self._vf.get_record_stream(keys, 'topological', True)
 
117
        stream = self._vf.get_record_stream(keys, 'topological', True)
114
118
        for idx, record in enumerate(stream):
115
119
            if pb is not None:
116
120
                pb.update('extracting', 0, len(keys))
117
121
            if record.storage_kind == 'absent':
118
122
                raise errors.RevisionNotPresent(record.key, self._vf)
119
123
            this_key = record.key
120
 
            lines = osutils.chunks_to_lines(record.get_bytes_as('chunked'))
 
124
            lines = record.get_bytes_as('lines')
121
125
            num_lines = len(lines)
122
126
            self._text_cache[this_key] = lines
123
127
            yield this_key, lines, num_lines
140
144
        parent_lines = self._text_cache[parent_key]
141
145
        parent_annotations = self._annotations_cache[parent_key]
142
146
        # PatienceSequenceMatcher should probably be part of Policy
143
 
        matcher = patiencediff.PatienceSequenceMatcher(None,
144
 
            parent_lines, text)
 
147
        matcher = patiencediff.PatienceSequenceMatcher(
 
148
            None, parent_lines, text)
145
149
        matching_blocks = matcher.get_matching_blocks()
146
150
        return parent_annotations, matching_blocks
147
151
 
149
153
        """Reannotate this text relative to its first parent."""
150
154
        (parent_annotations,
151
155
         matching_blocks) = self._get_parent_annotations_and_matches(
152
 
                                key, lines, parent_key)
 
156
             key, lines, parent_key)
153
157
 
154
158
        for parent_idx, lines_idx, match_len in matching_blocks:
155
159
            # For all matching regions we copy across the parent annotations
161
165
        """Reannotate this text relative to a second (or more) parent."""
162
166
        (parent_annotations,
163
167
         matching_blocks) = self._get_parent_annotations_and_matches(
164
 
                                key, lines, parent_key)
 
168
             key, lines, parent_key)
165
169
 
166
170
        last_ann = None
167
171
        last_parent = None
179
183
            par_sub = parent_annotations[parent_idx:parent_idx + match_len]
180
184
            if ann_sub == par_sub:
181
185
                continue
182
 
            for idx in xrange(match_len):
 
186
            for idx in range(match_len):
183
187
                ann = ann_sub[idx]
184
188
                par_ann = par_sub[idx]
185
189
                ann_idx = lines_idx + idx
253
257
                        each key is a possible source for the given line.
254
258
            lines the text of "key" as a list of lines
255
259
        """
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):
 
260
        with ui.ui_factory.nested_progress_bar() as pb:
 
261
            for text_key, text, num_lines in self._get_needed_texts(
 
262
                    key, pb=pb):
259
263
                self._annotate_one(text_key, text, num_lines)
260
 
        finally:
261
 
            pb.finished()
262
264
        try:
263
265
            annotations = self._annotations_cache[key]
264
266
        except KeyError:
277
279
            # Backwards compatibility, break up the heads into pairs and
278
280
            # resolve the result
279
281
            next_head = iter(the_heads)
280
 
            head = next_head.next()
 
282
            head = next(next_head)
281
283
            for possible_head in next_head:
282
284
                annotated_lines = ((head, line), (possible_head, line))
283
285
                head = tiebreaker(annotated_lines)[0]
301
303
            else:
302
304
                the_heads = heads(annotation)
303
305
                if len(the_heads) == 1:
304
 
                    for head in the_heads: break # get the item out of the set
 
306
                    for head in the_heads:
 
307
                        break  # get the item out of the set
305
308
                else:
306
309
                    head = self._resolve_annotation_tie(the_heads, line,
307
310
                                                        custom_tiebreaker)