Rev 4457: Start implementing the reannotation functionality directly. in http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate
John Arbash Meinel
john at arbash-meinel.com
Wed Jun 17 20:57:55 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate
------------------------------------------------------------
revno: 4457
revision-id: john at arbash-meinel.com-20090617195744-vugtpm7w05sfdmxm
parent: john at arbash-meinel.com-20090617194624-m9hn15i7ps2yd253
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.17-rework-annotate
timestamp: Wed 2009-06-17 14:57:44 -0500
message:
Start implementing the reannotation functionality directly.
-------------- next part --------------
=== modified file 'bzrlib/_annotator_py.py'
--- a/bzrlib/_annotator_py.py 2009-06-17 19:46:24 +0000
+++ b/bzrlib/_annotator_py.py 2009-06-17 19:57:44 +0000
@@ -21,6 +21,7 @@
errors,
graph as _mod_graph,
osutils,
+ patiencediff,
)
@@ -35,8 +36,8 @@
"""Create a new Annotator from a VersionedFile."""
self._vf = vf
self._parent_map = {}
- self._parent_lines_cache = {}
- self._parent_annotations_cache = {}
+ self._lines_cache = {}
+ self._annotations_cache = {}
self._heads_provider = None
def _get_needed_texts(self, key):
@@ -52,26 +53,37 @@
self._heads_provider = _mod_graph.KnownGraph(self._parent_map)
return self._heads_provider
+ def _reannotate_one_parent(self, annotations, lines, key, parent_key):
+ """Reannotate this text relative to its first parent."""
+ parent_lines = self._lines_cache[parent_key]
+ parent_annotations = self._annotations_cache[parent_key]
+ # PatienceSequenceMatcher should probably be part of Policy
+ matcher = patiencediff.PatienceSequenceMatcher(None,
+ parent_lines, lines)
+ matching_blocks = matcher.get_matching_blocks()
+
+ for parent_idx, lines_idx, match_len in matching_blocks:
+ # For all matching regions we copy across the parent annotations
+ annotations[lines_idx:lines_idx + match_len] = \
+ parent_annotations[parent_idx:parent_idx + match_len]
+
def annotate(self, key):
"""Return annotated fulltext for the given key."""
keys = self._get_needed_texts(key)
- reannotate = annotate.reannotate
heads_provider = self._get_heads_provider
for record in self._vf.get_record_stream(keys, 'topological', True):
- key = record.key
+ this_key = record.key
lines = osutils.chunks_to_lines(record.get_bytes_as('chunked'))
- parents = self._parent_map[key]
- if parents is not None:
- parent_lines = [self._parent_lines_cache[parent]
- for parent in parents]
- else:
- parent_lines = []
- self._parent_lines_cache[key] = list(reannotate(
- parent_lines, lines, key, None, heads_provider))
+ annotations = [(this_key,)]*len(lines)
+ self._lines_cache[this_key] = lines
+ self._annotations_cache[this_key] = annotations
+
+ parents = self._parent_map[this_key]
+ if not parents:
+ continue
+ self._reannotate_one_parent(annotations, lines, key, parents[0])
try:
- annotated = self._parent_lines_cache[key]
- except KeyError, e:
+ annotations = self._annotations_cache[key]
+ except KeyError:
raise errors.RevisionNotPresent(key, self._vf)
- annotations = [(a,) for a,l in annotated]
- lines = [l for a,l in annotated]
- return annotations, lines
+ return annotations, self._lines_cache[key]
More information about the bazaar-commits
mailing list