Rev 5826: (jelmer) Avoid directly accessing VersionedFiles.annotate(); in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed May 4 22:17:25 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5826 [merge]
revision-id: pqm at pqm.ubuntu.com-20110504221722-fz5hr1xagchptyje
parent: pqm at pqm.ubuntu.com-20110504204414-j893hspmx3k1rki4
parent: jelmer at samba.org-20110503150400-9of47sxsmv38vap5
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-05-04 22:17:22 +0000
message:
(jelmer) Avoid directly accessing VersionedFiles.annotate();
rather, access it through RevisionTree.annotate_iter(). (Jelmer Vernooij)
modified:
bzrlib/annotate.py annotate.py-20050922133147-7c60541d2614f022
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/test_annotate.py test_annotate.py-20061213215015-sttc9agsxomls7q0-1
doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/annotate.py'
--- a/bzrlib/annotate.py 2010-06-17 09:23:19 +0000
+++ b/bzrlib/annotate.py 2011-05-03 15:04:00 +0000
@@ -41,9 +41,17 @@
)
from bzrlib.config import extract_email_address
from bzrlib.repository import _strip_NULL_ghosts
-from bzrlib.revision import CURRENT_REVISION, Revision
-
-
+from bzrlib.revision import (
+ CURRENT_REVISION,
+ Revision,
+ )
+from bzrlib.symbol_versioning import (
+ deprecated_function,
+ deprecated_in,
+ )
+
+
+ at deprecated_function(deprecated_in((2, 4, 0)))
def annotate_file(branch, rev_id, file_id, verbose=False, full=False,
to_file=None, show_ids=False):
"""Annotate file_id at revision rev_id in branch.
@@ -60,21 +68,13 @@
used.
:param show_ids: Show revision ids in the annotation output.
"""
- if to_file is None:
- to_file = sys.stdout
-
- # Handle the show_ids case
- annotations = _annotations(branch.repository, file_id, rev_id)
- if show_ids:
- return _show_id_annotations(annotations, to_file, full)
-
- # Calculate the lengths of the various columns
- annotation = list(_expand_annotations(annotations, branch))
- _print_annotations(annotation, verbose, to_file, full)
+ tree = branch.repository.revision_tree(rev_id)
+ annotate_file_tree(tree, file_id, to_file, verbose=verbose,
+ full=full, show_ids=show_ids, branch=branch)
def annotate_file_tree(tree, file_id, to_file, verbose=False, full=False,
- show_ids=False):
+ show_ids=False, branch=None):
"""Annotate file_id in a tree.
The tree should already be read_locked() when annotate_file_tree is called.
@@ -86,25 +86,31 @@
reasonable text width.
:param full: XXXX Not sure what this does.
:param show_ids: Show revision ids in the annotation output.
+ :param branch: Branch to use for revision revno lookups
"""
- rev_id = tree.last_revision()
- branch = tree.branch
+ if branch is None:
+ branch = tree.branch
+ if to_file is None:
+ to_file = sys.stdout
# Handle the show_ids case
annotations = list(tree.annotate_iter(file_id))
if show_ids:
return _show_id_annotations(annotations, to_file, full)
- # Create a virtual revision to represent the current tree state.
- # Should get some more pending commit attributes, like pending tags,
- # bugfixes etc.
- current_rev = Revision(CURRENT_REVISION)
- current_rev.parent_ids = tree.get_parent_ids()
- current_rev.committer = tree.branch.get_config().username()
- current_rev.message = "?"
- current_rev.timestamp = round(time.time(), 3)
- current_rev.timezone = osutils.local_time_offset()
- annotation = list(_expand_annotations(annotations, tree.branch,
+ if not getattr(tree, "get_revision_id", False):
+ # Create a virtual revision to represent the current tree state.
+ # Should get some more pending commit attributes, like pending tags,
+ # bugfixes etc.
+ current_rev = Revision(CURRENT_REVISION)
+ current_rev.parent_ids = tree.get_parent_ids()
+ current_rev.committer = branch.get_config().username()
+ current_rev.message = "?"
+ current_rev.timestamp = round(time.time(), 3)
+ current_rev.timezone = osutils.local_time_offset()
+ else:
+ current_rev = None
+ annotation = list(_expand_annotations(annotations, branch,
current_rev))
_print_annotations(annotation, verbose, to_file, full)
@@ -170,13 +176,6 @@
return
-def _annotations(repo, file_id, rev_id):
- """Return the list of (origin_revision_id, line_text) for a revision of a file in a repository."""
- annotations = repo.texts.annotate((file_id, rev_id))
- #
- return [(key[-1], line) for (key, line) in annotations]
-
-
def _expand_annotations(annotations, branch, current_rev=None):
"""Expand a file's annotations into command line UI ready tuples.
@@ -189,8 +188,8 @@
"""
repository = branch.repository
if current_rev is not None:
- # This can probably become a function on MutableTree, get_revno_map there,
- # or something.
+ # This can probably become a function on MutableTree, get_revno_map
+ # there, or something.
last_revision = current_rev.revision_id
# XXX: Partially Cloned from branch, uses the old_get_graph, eep.
# XXX: The main difficulty is that we need to inject a single new node
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2011-04-28 12:26:34 +0000
+++ b/bzrlib/builtins.py 2011-05-03 13:53:46 +0000
@@ -4693,7 +4693,9 @@
@display_command
def run(self, filename, all=False, long=False, revision=None,
show_ids=False, directory=None):
- from bzrlib.annotate import annotate_file, annotate_file_tree
+ from bzrlib.annotate import (
+ annotate_file_tree,
+ )
wt, branch, relpath = \
_open_directory_or_containing_tree_or_branch(filename, directory)
if wt is not None:
@@ -4714,9 +4716,8 @@
annotate_file_tree(wt, file_id, self.outf, long, all,
show_ids=show_ids)
else:
- file_version = tree.get_file_revision(file_id)
- annotate_file(branch, file_version, file_id, long, all, self.outf,
- show_ids=show_ids)
+ annotate_file_tree(tree, file_id, self.outf, long, all,
+ show_ids=show_ids, branch=branch)
class cmd_re_sign(Command):
=== modified file 'bzrlib/tests/test_annotate.py'
--- a/bzrlib/tests/test_annotate.py 2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_annotate.py 2011-05-03 13:53:46 +0000
@@ -21,6 +21,7 @@
from bzrlib import (
annotate,
+ symbol_versioning,
tests,
)
@@ -260,15 +261,26 @@
('modify', ('file-id', e_text))])
return builder
- def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
- """Assert that the revision is properly annotated."""
- actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
+ def assertAnnotateEqualDiff(self, actual, expected):
if actual != expected:
# Create an easier to understand diff when the lines don't actually
# match
self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
''.join('\t'.join(l) for l in actual))
+ def assertBranchAnnotate(self, expected, branch, file_id, revision_id,
+ verbose=False, full=False, show_ids=False):
+ tree = branch.repository.revision_tree(revision_id)
+ to_file = StringIO()
+ annotate.annotate_file_tree(tree, file_id, to_file,
+ verbose=verbose, full=full, show_ids=show_ids, branch=branch)
+ self.assertAnnotateEqualDiff(to_file.getvalue(), expected)
+
+ def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
+ """Assert that the revision is properly annotated."""
+ actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
+ self.assertAnnotateEqualDiff(actual, expected)
+
def test_annotate_duplicate_lines(self):
# XXX: Should this be a per_repository test?
builder = self.create_duplicate_lines_tree()
@@ -285,62 +297,64 @@
def test_annotate_shows_dotted_revnos(self):
builder = self.create_merged_trees()
- sio = StringIO()
- annotate.annotate_file(builder.get_branch(), 'rev-3', 'a-id',
- to_file=sio)
- self.assertEqualDiff('1 joe at foo | first\n'
- '2 joe at foo | second\n'
- '1.1.1 barry at f | third\n',
- sio.getvalue())
+ self.assertBranchAnnotate('1 joe at foo | first\n'
+ '2 joe at foo | second\n'
+ '1.1.1 barry at f | third\n',
+ builder.get_branch(), 'a-id', 'rev-3')
+
+ def test_annotate_file(self):
+ builder = self.create_merged_trees()
+
+ to_file = StringIO()
+ self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
+ annotate.annotate_file, builder.get_branch(),
+ 'rev-3', 'a-id', to_file=to_file)
+
+ self.assertAnnotateEqualDiff('1 joe at foo | first\n'
+ '2 joe at foo | second\n'
+ '1.1.1 barry at f | third\n',
+ to_file.getvalue())
def test_annotate_limits_dotted_revnos(self):
"""Annotate should limit dotted revnos to a depth of 12"""
builder = self.create_deeply_merged_trees()
- sio = StringIO()
- annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
- to_file=sio, verbose=False, full=False)
- self.assertEqualDiff('1 joe at foo | first\n'
- '2 joe at foo | second\n'
- '1.1.1 barry at f | third\n'
- '1.2.1 jerry at f | fourth\n'
- '1.3.1 george@ | fifth\n'
- ' | sixth\n',
- sio.getvalue())
+ self.assertBranchAnnotate('1 joe at foo | first\n'
+ '2 joe at foo | second\n'
+ '1.1.1 barry at f | third\n'
+ '1.2.1 jerry at f | fourth\n'
+ '1.3.1 george@ | fifth\n'
+ ' | sixth\n',
+ builder.get_branch(), 'a-id', 'rev-6',
+ verbose=False, full=False)
- sio = StringIO()
- annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
- to_file=sio, verbose=False, full=True)
- self.assertEqualDiff('1 joe at foo | first\n'
- '2 joe at foo | second\n'
- '1.1.1 barry at f | third\n'
- '1.2.1 jerry at f | fourth\n'
- '1.3.1 george@ | fifth\n'
- '1.3.1 george@ | sixth\n',
- sio.getvalue())
+ self.assertBranchAnnotate('1 joe at foo | first\n'
+ '2 joe at foo | second\n'
+ '1.1.1 barry at f | third\n'
+ '1.2.1 jerry at f | fourth\n'
+ '1.3.1 george@ | fifth\n'
+ '1.3.1 george@ | sixth\n',
+ builder.get_branch(), 'a-id', 'rev-6',
+ verbose=False, full=True)
# verbose=True shows everything, the full revno, user id, and date
- sio = StringIO()
- annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
- to_file=sio, verbose=True, full=False)
- self.assertEqualDiff('1 joe at foo.com 20061213 | first\n'
- '2 joe at foo.com 20061213 | second\n'
- '1.1.1 barry at foo.com 20061213 | third\n'
- '1.2.1 jerry at foo.com 20061213 | fourth\n'
- '1.3.1 george at foo.com 20061213 | fifth\n'
- ' | sixth\n',
- sio.getvalue())
+ self.assertBranchAnnotate('1 joe at foo.com 20061213 | first\n'
+ '2 joe at foo.com 20061213 | second\n'
+ '1.1.1 barry at foo.com 20061213 | third\n'
+ '1.2.1 jerry at foo.com 20061213 | fourth\n'
+ '1.3.1 george at foo.com 20061213 | fifth\n'
+ ' | sixth\n',
+ builder.get_branch(), 'a-id', 'rev-6',
+ verbose=True, full=False)
- sio = StringIO()
- annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
- to_file=sio, verbose=True, full=True)
- self.assertEqualDiff('1 joe at foo.com 20061213 | first\n'
- '2 joe at foo.com 20061213 | second\n'
- '1.1.1 barry at foo.com 20061213 | third\n'
- '1.2.1 jerry at foo.com 20061213 | fourth\n'
- '1.3.1 george at foo.com 20061213 | fifth\n'
- '1.3.1 george at foo.com 20061213 | sixth\n',
- sio.getvalue())
+ self.assertBranchAnnotate('1 joe at foo.com 20061213 | first\n'
+ '2 joe at foo.com 20061213 | second\n'
+ '1.1.1 barry at foo.com 20061213 | third\n'
+ '1.2.1 jerry at foo.com 20061213 | fourth\n'
+ '1.3.1 george at foo.com 20061213 | fifth\n'
+ '1.3.1 george at foo.com 20061213 | sixth\n',
+ builder.get_branch(), 'a-id', 'rev-6',
+ verbose=True, full=True)
def test_annotate_uses_branch_context(self):
"""Dotted revnos should use the Branch context.
@@ -350,43 +364,35 @@
"""
builder = self.create_deeply_merged_trees()
- sio = StringIO()
- annotate.annotate_file(builder.get_branch(), 'rev-1_3_1', 'a-id',
- to_file=sio, verbose=False, full=False)
- self.assertEqualDiff('1 joe at foo | first\n'
- '1.1.1 barry at f | third\n'
- '1.2.1 jerry at f | fourth\n'
- '1.3.1 george@ | fifth\n'
- ' | sixth\n',
- sio.getvalue())
+ self.assertBranchAnnotate('1 joe at foo | first\n'
+ '1.1.1 barry at f | third\n'
+ '1.2.1 jerry at f | fourth\n'
+ '1.3.1 george@ | fifth\n'
+ ' | sixth\n',
+ builder.get_branch(), 'a-id', 'rev-1_3_1',
+ verbose=False, full=False)
def test_annotate_show_ids(self):
builder = self.create_deeply_merged_trees()
- sio = StringIO()
- annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
- to_file=sio, show_ids=True, full=False)
-
# It looks better with real revision ids :)
- self.assertEqualDiff(' rev-1 | first\n'
- ' rev-2 | second\n'
- 'rev-1_1_1 | third\n'
- 'rev-1_2_1 | fourth\n'
- 'rev-1_3_1 | fifth\n'
- ' | sixth\n',
- sio.getvalue())
-
- sio = StringIO()
- annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
- to_file=sio, show_ids=True, full=True)
-
- self.assertEqualDiff(' rev-1 | first\n'
- ' rev-2 | second\n'
- 'rev-1_1_1 | third\n'
- 'rev-1_2_1 | fourth\n'
- 'rev-1_3_1 | fifth\n'
- 'rev-1_3_1 | sixth\n',
- sio.getvalue())
+ self.assertBranchAnnotate(' rev-1 | first\n'
+ ' rev-2 | second\n'
+ 'rev-1_1_1 | third\n'
+ 'rev-1_2_1 | fourth\n'
+ 'rev-1_3_1 | fifth\n'
+ ' | sixth\n',
+ builder.get_branch(), 'a-id', 'rev-6',
+ show_ids=True, full=False)
+
+ self.assertBranchAnnotate(' rev-1 | first\n'
+ ' rev-2 | second\n'
+ 'rev-1_1_1 | third\n'
+ 'rev-1_2_1 | fourth\n'
+ 'rev-1_3_1 | fifth\n'
+ 'rev-1_3_1 | sixth\n',
+ builder.get_branch(), 'a-id', 'rev-6',
+ show_ids=True, full=True)
def test_annotate_unicode_author(self):
tree1 = self.make_branch_and_tree('tree1')
@@ -405,25 +411,33 @@
tree1.lock_read()
self.addCleanup(tree1.unlock)
+
+ revtree_1 = tree1.branch.repository.revision_tree('rev-1')
+ revtree_2 = tree1.branch.repository.revision_tree('rev-2')
+
# this passes if no exception is raised
to_file = StringIO()
- annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
+ annotate.annotate_file_tree(revtree_1, 'a-id',
+ to_file=to_file, branch=tree1.branch)
sio = StringIO()
to_file = codecs.getwriter('ascii')(sio)
to_file.encoding = 'ascii' # codecs does not set it
- annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
+ annotate.annotate_file_tree(revtree_2, 'b-id',
+ to_file=to_file, branch=tree1.branch)
self.assertEqualDiff('2 p?rez | bye\n', sio.getvalue())
# test now with to_file.encoding = None
to_file = tests.StringIOWrapper()
to_file.encoding = None
- annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
+ annotate.annotate_file_tree(revtree_2, 'b-id',
+ to_file=to_file, branch=tree1.branch)
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
# and when it does not exist
to_file = StringIO()
- annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
+ annotate.annotate_file_tree(revtree_2, 'b-id',
+ to_file=to_file, branch=tree1.branch)
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
def test_annotate_author_or_committer(self):
@@ -444,13 +458,13 @@
tree1.lock_read()
self.addCleanup(tree1.unlock)
- to_file = StringIO()
- annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
- self.assertEqual('1 committ | hello\n', to_file.getvalue())
-
- to_file = StringIO()
- annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
- self.assertEqual('2 author@ | bye\n', to_file.getvalue())
+
+ self.assertBranchAnnotate('1 committ | hello\n', tree1.branch,
+ 'a-id', 'rev-1')
+
+ to_file = StringIO()
+ self.assertBranchAnnotate('2 author@ | bye\n', tree1.branch,
+ 'b-id', 'rev-2')
class TestReannotate(tests.TestCase):
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt 2011-04-28 14:12:08 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt 2011-05-02 14:03:38 +0000
@@ -43,6 +43,9 @@
.. Changes that may require updates in plugins or other code that uses
bzrlib.
+* ``annotate_file`` has been deprecated in favor of
+ ``annotate_file_revision_tree``. (Jelmer Vernooij, #775598)
+
Internals
*********
More information about the bazaar-commits
mailing list