Rev 4456: Start moving bits into helper functions. Add tests for multiple revs. in http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate
John Arbash Meinel
john at arbash-meinel.com
Wed Jun 17 20:46:34 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate
------------------------------------------------------------
revno: 4456
revision-id: john at arbash-meinel.com-20090617194624-m9hn15i7ps2yd253
parent: john at arbash-meinel.com-20090617193858-y7qy0zhsxeoewoyd
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.17-rework-annotate
timestamp: Wed 2009-06-17 14:46:24 -0500
message:
Start moving bits into helper functions. Add tests for multiple revs.
-------------- next part --------------
=== modified file 'bzrlib/_annotator_py.py'
--- a/bzrlib/_annotator_py.py 2009-06-17 19:38:58 +0000
+++ b/bzrlib/_annotator_py.py 2009-06-17 19:46:24 +0000
@@ -34,30 +34,42 @@
def __init__(self, vf):
"""Create a new Annotator from a VersionedFile."""
self._vf = vf
+ self._parent_map = {}
+ self._parent_lines_cache = {}
+ self._parent_annotations_cache = {}
+ self._heads_provider = None
- def annotate(self, key):
- """Return annotated fulltext for the given key."""
+ def _get_needed_texts(self, key):
graph = _mod_graph.Graph(self._vf)
parent_map = dict((k, v) for k, v in graph.iter_ancestry([key])
if v is not None)
- if not parent_map:
- raise errors.RevisionNotPresent(key, self)
+ self._parent_map.update(parent_map)
keys = parent_map.keys()
- heads_provider = _mod_graph.KnownGraph(parent_map)
- parent_cache = {}
+ return keys
+
+ def _get_heads_provider(self):
+ if self._heads_provider is None:
+ self._heads_provider = _mod_graph.KnownGraph(self._parent_map)
+ return self._heads_provider
+
+ 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
- fulltext = osutils.chunks_to_lines(record.get_bytes_as('chunked'))
- parents = parent_map[key]
+ lines = osutils.chunks_to_lines(record.get_bytes_as('chunked'))
+ parents = self._parent_map[key]
if parents is not None:
- parent_lines = [parent_cache[parent] for parent in parent_map[key]]
+ parent_lines = [self._parent_lines_cache[parent]
+ for parent in parents]
else:
parent_lines = []
- parent_cache[key] = list(
- reannotate(parent_lines, fulltext, key, None, heads_provider))
+ self._parent_lines_cache[key] = list(reannotate(
+ parent_lines, lines, key, None, heads_provider))
try:
- annotated = parent_cache[key]
+ annotated = self._parent_lines_cache[key]
except KeyError, e:
raise errors.RevisionNotPresent(key, self._vf)
annotations = [(a,) for a,l in annotated]
=== modified file 'bzrlib/tests/test__annotator.py'
--- a/bzrlib/tests/test__annotator.py 2009-06-17 19:38:58 +0000
+++ b/bzrlib/tests/test__annotator.py 2009-06-17 19:46:24 +0000
@@ -61,25 +61,36 @@
module = None # Set by load_tests
- def make_single_text(self):
+ def make_simple_text(self):
repo = self.make_repository('repo')
repo.lock_write()
self.addCleanup(repo.unlock)
vf = repo.texts
repo.start_write_group()
- vf.add_lines(('f-id', 'a-id'), (), ['simple\n', 'content\n'])
- repo.commit_write_group()
+ try:
+ fa_key = ('f-id', 'a-id')
+ fb_key = ('f-id', 'b-id')
+ vf.add_lines(fa_key, (), ['simple\n', 'content\n'])
+ vf.add_lines(fb_key, (fa_key,), ['simple\n', 'new content\n'])
+ except:
+ repo.abort_write_group()
+ raise
+ else:
+ repo.commit_write_group()
return vf
def test_annotate_missing(self):
- vf = self.make_single_text()
+ vf = self.make_simple_text()
ann = self.module.Annotator(vf)
self.assertRaises(errors.RevisionNotPresent,
ann.annotate, ('not', 'present'))
def test_annotate_simple(self):
- vf = self.make_single_text()
+ vf = self.make_simple_text()
ann = self.module.Annotator(vf)
f_key = ('f-id', 'a-id')
self.assertEqual(([(f_key,)]*2, ['simple\n', 'content\n']),
ann.annotate(f_key))
+ fb_key = ('f-id', 'b-id')
+ self.assertEqual(([(f_key,), (fb_key,)], ['simple\n', 'new content\n']),
+ ann.annotate(fb_key))
More information about the bazaar-commits
mailing list