Rev 2324: Implement annotate_iter, get_revision_id, and walkdirs so that all tree_implementations now pass in http://bazaar.launchpad.net/%7Ebzr/bzr/dirstate
John Arbash Meinel
john at arbash-meinel.com
Thu Feb 15 22:52:47 GMT 2007
At http://bazaar.launchpad.net/%7Ebzr/bzr/dirstate
------------------------------------------------------------
revno: 2324
revision-id: john at arbash-meinel.com-20070215225145-2a7c9snlv3pf87si
parent: john at arbash-meinel.com-20070215223629-gt6hhv9b20maurze
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate
timestamp: Thu 2007-02-15 16:51:45 -0600
message:
Implement annotate_iter, get_revision_id, and walkdirs so that all tree_implementations now pass
modified:
bzrlib/tests/tree_implementations/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
-------------- next part --------------
=== modified file 'bzrlib/tests/tree_implementations/test_tree.py'
--- a/bzrlib/tests/tree_implementations/test_tree.py 2006-12-17 19:40:36 +0000
+++ b/bzrlib/tests/tree_implementations/test_tree.py 2007-02-15 22:51:45 +0000
@@ -17,11 +17,15 @@
from bzrlib.tests.tree_implementations import TestCaseWithTree
class TestAnnotate(TestCaseWithTree):
-
+
def test_annotate(self):
work_tree = self.make_branch_and_tree('wt')
tree = self.get_tree_no_parents_abc_content(work_tree)
tree_revision = getattr(tree, 'get_revision_id', lambda: 'current:')()
- for revision, line in tree.annotate_iter('a-id'):
- self.assertEqual('contents of a\n', line)
- self.assertEqual(tree_revision, revision)
+ tree.lock_read()
+ try:
+ for revision, line in tree.annotate_iter('a-id'):
+ self.assertEqual('contents of a\n', line)
+ self.assertEqual(tree_revision, revision)
+ finally:
+ tree.unlock()
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-02-15 22:36:29 +0000
+++ b/bzrlib/workingtree_4.py 2007-02-15 22:51:45 +0000
@@ -776,6 +776,12 @@
self._inventory = None
self._locked = 0
+ def annotate_iter(self, file_id):
+ """See Tree.annotate_iter"""
+ w = self._repository.weave_store.get_weave(file_id,
+ self._repository.get_transaction())
+ return w.annotate_iter(self.inventory[file_id].revision)
+
def _comparison_data(self, entry, path):
"""See Tree._comparison_data."""
if entry is None:
@@ -840,6 +846,10 @@
def get_file_text(self, file_id):
return ''.join(self.get_file_lines(file_id))
+ def get_revision_id(self):
+ """Return the revision id for this tree."""
+ return self._revision_id
+
def _get_inventory(self):
if self._inventory is not None:
return self._inventory
@@ -871,8 +881,6 @@
def path2id(self, path):
"""Return the id for path in this tree."""
- # TODO: jam 20070215 This should be heavily optimized for dirstate
- # I'm taking the *very* lazy way out
row = self._dirstate._get_row(path.encode('utf8'))
if row == (None, None):
return None
@@ -885,3 +893,35 @@
if not self._locked:
self._inventory = None
self._locked = False
+
+ def walkdirs(self, prefix=""):
+ # TODO: jam 20070215 This is the cheap way by cheating and using the
+ # RevisionTree implementation.
+ # This should be cleaned up to use the much faster Dirstate code
+ _directory = 'directory'
+ inv = self.inventory
+ top_id = inv.path2id(prefix)
+ if top_id is None:
+ pending = []
+ else:
+ pending = [(prefix, '', _directory, None, top_id, None)]
+ while pending:
+ dirblock = []
+ currentdir = pending.pop()
+ # 0 - relpath, 1- basename, 2- kind, 3- stat, id, v-kind
+ if currentdir[0]:
+ relroot = currentdir[0] + '/'
+ else:
+ relroot = ""
+ # FIXME: stash the node in pending
+ entry = inv[currentdir[4]]
+ for name, child in entry.sorted_children():
+ toppath = relroot + name
+ dirblock.append((toppath, name, child.kind, None,
+ child.file_id, child.kind
+ ))
+ yield (currentdir[0], entry.file_id), dirblock
+ # push the user specified dirs from dirblock
+ for dir in reversed(dirblock):
+ if dir[2] == _directory:
+ pending.append(dir)
More information about the bazaar-commits
mailing list