Rev 3494: hack together a way to expose the --policy to the command line. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation_policy_cmd
John Arbash Meinel
john at arbash-meinel.com
Thu Jun 12 17:34:32 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation_policy_cmd
------------------------------------------------------------
revno: 3494
revision-id: john at arbash-meinel.com-20080612163426-vnox9ay0bbnz30px
parent: john at arbash-meinel.com-20080612163311-977q08c89jqwjcul
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: annotation_policy_cmd
timestamp: Thu 2008-06-12 11:34:26 -0500
message:
hack together a way to expose the --policy to the command line.
-------------- next part --------------
=== modified file 'bzrlib/annotate.py'
--- a/bzrlib/annotate.py 2008-06-11 18:11:44 +0000
+++ b/bzrlib/annotate.py 2008-06-12 16:34:26 +0000
@@ -37,7 +37,8 @@
def annotate_file(branch, rev_id, file_id, verbose=False, full=False,
- to_file=None, show_ids=False):
+ to_file=None, show_ids=False,
+ policy=None):
"""Annotate file_id at revision rev_id in branch.
The branch should already be read_locked() when annotate_file is called.
@@ -58,7 +59,8 @@
# Handle the show_ids case
last_rev_id = None
if show_ids:
- annotations = _annotations(branch.repository, file_id, rev_id)
+ annotations = _annotations(branch.repository, file_id, rev_id,
+ policy=policy)
max_origin_len = max(len(origin) for origin, text in annotations)
for origin, text in annotations:
if full or last_rev_id != origin:
@@ -109,20 +111,21 @@
prevanno = anno
-def _annotations(repo, file_id, rev_id):
+def _annotations(repo, file_id, rev_id, policy=None):
"""Return the list of (origin,text) for a revision of a file in a repository."""
w = repo.weave_store.get_weave(file_id, repo.get_transaction())
- return w.annotate(rev_id)
-
-
-def _annotate_file(branch, rev_id, file_id):
+ return w.annotate(rev_id, policy=policy)
+
+
+def _annotate_file(branch, rev_id, file_id, policy=None):
"""Yield the origins for each line of a file.
This includes detailed information, such as the author name, and
date string for the commit, rather than just the revision id.
"""
revision_id_to_revno = branch.get_revision_id_to_revno_map()
- annotations = _annotations(branch.repository, file_id, rev_id)
+ annotations = _annotations(branch.repository, file_id, rev_id,
+ policy=policy)
last_origin = None
revision_ids = set(o for o, t in annotations)
revision_ids = [o for o in revision_ids if
@@ -156,7 +159,7 @@
def reannotate(parents_lines, new_lines, new_revision_id,
_left_matching_blocks=None,
- heads_provider=None):
+ heads_provider=None, policy=None):
"""Create a new annotated version from new lines and parent annotations.
:param parents_lines: List of annotated lines for all parents
@@ -171,8 +174,9 @@
if any revision ids are children of others.
If None, then any ancestry disputes will be resolved with
new_revision_id
+ :param policy: The name of a policy to use, None uses the default
"""
from bzrlib import annotation_policy
- policy = annotation_policy.registry.get()(heads_provider)
- return policy.reannotate(parents_lines, new_lines, new_revision_id,
- left_matching_blocks=_left_matching_blocks)
+ policy_obj = annotation_policy.registry.get(policy)(heads_provider)
+ return policy_obj.reannotate(parents_lines, new_lines, new_revision_id,
+ left_matching_blocks=_left_matching_blocks)
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2008-05-28 23:20:33 +0000
+++ b/bzrlib/builtins.py 2008-06-12 16:34:26 +0000
@@ -3517,12 +3517,13 @@
Option('long', help='Show commit date in annotations.'),
'revision',
'show-ids',
+ Option('policy', type=str),
]
encoding_type = 'exact'
@display_command
def run(self, filename, all=False, long=False, revision=None,
- show_ids=False):
+ show_ids=False, policy=None):
from bzrlib.annotate import annotate_file
wt, branch, relpath = \
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
@@ -3546,7 +3547,7 @@
raise errors.NotVersionedError(filename)
file_version = tree.inventory[file_id].revision
annotate_file(branch, file_version, file_id, long, all, self.outf,
- show_ids=show_ids)
+ show_ids=show_ids, policy=policy)
finally:
if wt is not None:
wt.unlock()
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py 2008-05-12 02:40:40 +0000
+++ b/bzrlib/knit.py 2008-06-12 16:34:26 +0000
@@ -624,9 +624,9 @@
out.extend(lines)
return out
- def annotate(self, knit, version_id):
+ def annotate(self, knit, version_id, policy=None):
annotator = _KnitAnnotator(knit)
- return annotator.annotate(version_id)
+ return annotator.annotate(version_id, policy=policy)
def make_empty_knit(transport, relpath):
@@ -1536,9 +1536,9 @@
__len__ = num_versions
- def annotate(self, version_id):
+ def annotate(self, version_id, policy=None):
"""See VersionedFile.annotate."""
- return self.factory.annotate(self, version_id)
+ return self.factory.annotate(self, version_id, policy=policy)
def get_parent_map(self, version_ids):
"""See VersionedFile.get_parent_map."""
@@ -3154,7 +3154,7 @@
annotated_parent_lines = [a[p] for p in parent_ids]
annotated_lines = list(annotate.reannotate(annotated_parent_lines,
fulltext, revision_id, left_matching_blocks,
- heads_provider=self._get_heads_provider()))
+ heads_provider=self._get_heads_provider(), policy=self.policy))
self._annotated_lines[revision_id] = annotated_lines
for p in parent_ids:
ann_children = self._annotate_children[p]
@@ -3328,11 +3328,12 @@
self._heads_provider = head_cache
return head_cache
- def annotate(self, revision_id):
+ def annotate(self, revision_id, policy=None):
"""Return the annotated fulltext at the given revision.
:param revision_id: The revision id for this file
"""
+ self.policy = policy
records = self._get_build_graph(revision_id)
if revision_id in self._ghosts:
raise errors.RevisionNotPresent(revision_id, self._knit)
=== modified file 'bzrlib/revisiontree.py'
--- a/bzrlib/revisiontree.py 2008-05-08 04:33:38 +0000
+++ b/bzrlib/revisiontree.py 2008-06-12 16:34:26 +0000
@@ -86,10 +86,11 @@
return self._repository.iter_files_bytes(repo_desired_files)
def annotate_iter(self, file_id,
- default_revision=revision.CURRENT_REVISION):
+ default_revision=revision.CURRENT_REVISION,
+ policy=None):
"""See Tree.annotate_iter"""
w = self._get_weave(file_id)
- return w.annotate(self.inventory[file_id].revision)
+ return w.annotate(self.inventory[file_id].revision, policy=policy)
def get_file_size(self, file_id):
"""See Tree.get_file_size"""
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2008-05-22 05:48:22 +0000
+++ b/bzrlib/workingtree.py 2008-06-12 16:34:26 +0000
@@ -431,7 +431,8 @@
return file(self.abspath(filename), 'rb')
@needs_read_lock
- def annotate_iter(self, file_id, default_revision=CURRENT_REVISION):
+ def annotate_iter(self, file_id, default_revision=CURRENT_REVISION,
+ policy=None):
"""See Tree.annotate_iter
This implementation will use the basis tree implementation if possible.
@@ -448,7 +449,7 @@
require_versioned=True).next()
changed_content, kind = changes[2], changes[6]
if not changed_content:
- return basis.annotate_iter(file_id)
+ return basis.annotate_iter(file_id, policy=policy)
if kind[1] is None:
return None
import annotate
More information about the bazaar-commits
mailing list