Rev 4521: Implement RevisionTree.annotate_iter and WT.annotate_iter in http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate
John Arbash Meinel
john at arbash-meinel.com
Mon Jul 6 21:48:31 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate
------------------------------------------------------------
revno: 4521
revision-id: john at arbash-meinel.com-20090706204800-twnc8rfatyaroi1s
parent: john at arbash-meinel.com-20090706202529-maqhhfzsweu9tx9k
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.17-rework-annotate
timestamp: Mon 2009-07-06 15:48:00 -0500
message:
Implement RevisionTree.annotate_iter and WT.annotate_iter
in terms of the new VF.get_annotator().
Only PreviewTree is left, though the logic there is yet-again different.
Also, feels like there are some missing tests, but I'll check on that.
-------------- next part --------------
=== modified file 'bzrlib/revisiontree.py'
--- a/bzrlib/revisiontree.py 2009-06-17 03:41:33 +0000
+++ b/bzrlib/revisiontree.py 2009-07-06 20:48:00 +0000
@@ -87,7 +87,8 @@
default_revision=revision.CURRENT_REVISION):
"""See Tree.annotate_iter"""
text_key = (file_id, self.inventory[file_id].revision)
- annotations = self._repository.texts.annotate(text_key)
+ annotator = self._repository.texts.get_annotator()
+ annotations = annotator.annotate_flat(text_key)
return [(key[-1], line) for key, line in annotations]
def get_file_size(self, file_id):
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2009-07-06 18:57:02 +0000
+++ b/bzrlib/workingtree.py 2009-07-06 20:48:00 +0000
@@ -58,6 +58,7 @@
errors,
generate_ids,
globbing,
+ graph as _mod_graph,
hashcache,
ignores,
inventory,
@@ -477,31 +478,37 @@
incorrectly attributed to CURRENT_REVISION (but after committing, the
attribution will be correct).
"""
- basis = self.basis_tree()
- basis.lock_read()
- try:
- changes = self.iter_changes(basis, True, [self.id2path(file_id)],
- require_versioned=True).next()
- changed_content, kind = changes[2], changes[6]
- if not changed_content:
- return basis.annotate_iter(file_id)
- if kind[1] is None:
- return None
- from bzrlib import annotate
- if kind[0] != 'file':
- old_lines = []
- else:
- old_lines = list(basis.annotate_iter(file_id))
- old = [old_lines]
- for tree in self.branch.repository.revision_trees(
- self.get_parent_ids()[1:]):
- if file_id not in tree:
+ maybe_file_parent_keys = []
+ for parent_id in self.get_parent_ids():
+ try:
+ parent_tree = self.revision_tree(parent_id)
+ except errors.NoSuchRevisionInTree:
+ parent_tree = self.branch.repository.revision_tree(parent_id)
+ parent_tree.lock_read()
+ try:
+ if file_id not in parent_tree:
continue
- old.append(list(tree.annotate_iter(file_id)))
- return annotate.reannotate(old, self.get_file(file_id).readlines(),
- default_revision)
- finally:
- basis.unlock()
+ ie = parent_tree.inventory[file_id]
+ parent_text_key = (file_id, ie.revision)
+ if parent_text_key not in maybe_file_parent_keys:
+ maybe_file_parent_keys.append(parent_text_key)
+ finally:
+ parent_tree.unlock()
+ graph = _mod_graph.Graph(self.branch.repository.texts)
+ heads = graph.heads(maybe_file_parent_keys)
+ file_parent_keys = []
+ for key in maybe_file_parent_keys:
+ if key in heads:
+ file_parent_keys.append(key)
+
+ # Now we have the parents of this content
+ annotator = self.branch.repository.texts.get_annotator()
+ text = self.get_file(file_id).read()
+ this_key =(file_id, default_revision)
+ annotator.add_special_text(this_key, file_parent_keys, text)
+ annotations = [(key[-1], line)
+ for key, line in annotator.annotate_flat(this_key)]
+ return annotations
def _get_ancestors(self, default_revision):
ancestors = set([default_revision])
More information about the bazaar-commits
mailing list