Rev 3505: Shortcut iter_references when we know references aren't supported. in http://bzr.arbash-meinel.com/branches/bzr/jam-integration

John Arbash Meinel john at arbash-meinel.com
Fri Jun 20 20:07:17 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/jam-integration

------------------------------------------------------------
revno: 3505
revision-id: john at arbash-meinel.com-20080620190638-0vayap44pyg1kfrq
parent: pqm at pqm.ubuntu.com-20080619070027-3xv1vy81m3ix2oup
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: jam-integration
timestamp: Fri 2008-06-20 14:06:38 -0500
message:
  Shortcut iter_references when we know references aren't supported.
  
  Also, improve the test coverage for RevisionTree and DirStateRevisionTree.
-------------- next part --------------
=== modified file 'bzrlib/tests/tree_implementations/__init__.py'
--- a/bzrlib/tests/tree_implementations/__init__.py	2008-04-30 20:09:39 +0000
+++ b/bzrlib/tests/tree_implementations/__init__.py	2008-06-20 19:06:38 +0000
@@ -67,7 +67,7 @@
 
 
 def _dirstate_tree_from_workingtree(testcase, tree):
-    revid = tree.commit('save tree', allow_pointless=True)
+    revid = tree.commit('save tree', allow_pointless=True, recursive=None)
     return tree.basis_tree()
 
 
@@ -334,7 +334,7 @@
             to be used as members of the TestCase.
         """
         if workingtree_format is None:
-            workingtree_format = WorkingTreeFormat3()
+            workingtree_format = WorkingTreeFormat._default_format
         scenario_options = WorkingTreeTestProviderAdapter.create_scenario(self,
             workingtree_format, workingtree_format._matchingbzrdir)[1]
         scenario_options["_workingtree_to_test_tree"] = converter

=== modified file 'bzrlib/tests/tree_implementations/test_tree.py'
--- a/bzrlib/tests/tree_implementations/test_tree.py	2008-01-03 22:14:40 +0000
+++ b/bzrlib/tests/tree_implementations/test_tree.py	2008-06-20 19:06:38 +0000
@@ -69,7 +69,7 @@
 
     def skip_if_no_reference(self, tree):
         if not getattr(tree, 'supports_tree_reference', lambda: False)():
-            raise tests.TestSkipped('Tree references not supported')
+            raise tests.TestNotApplicable('Tree references not supported')
 
     def create_nested(self):
         work_tree = self.make_branch_and_tree('wt')
@@ -88,6 +88,8 @@
 
     def test_get_reference_revision(self):
         tree = self.create_nested()
+        tree.lock_read()
+        self.addCleanup(tree.unlock)
         path = tree.id2path('sub-root')
         self.assertEqual('sub-1', tree.get_reference_revision('sub-root', path))
 
@@ -96,7 +98,7 @@
         tree.lock_read()
         self.addCleanup(tree.unlock)
         entry = tree.inventory['sub-root']
-        self.assertEqual([(tree.abspath('subtree'), 'sub-root')],
+        self.assertEqual([(u'subtree', 'sub-root')],
             list(tree.iter_references()))
 
     def test_get_root_id(self):

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2008-06-06 16:40:46 +0000
+++ b/bzrlib/workingtree_4.py	2008-06-20 19:06:38 +0000
@@ -528,6 +528,10 @@
         return iter(result)
 
     def iter_references(self):
+        if not self._repo_supports_tree_reference:
+            # When the repo doesn't support references, we will have nothing to
+            # return
+            return
         for key, tree_details in self.current_dirstate()._iter_entries():
             if tree_details[0][0] in ('a', 'r'): # absent, relocated
                 # not relevant to the working tree
@@ -535,10 +539,10 @@
             if not key[1]:
                 # the root is not a reference.
                 continue
-            path = pathjoin(self.basedir, key[0].decode('utf8'), key[1].decode('utf8'))
+            relpath = pathjoin(key[0].decode('utf8'), key[1].decode('utf8'))
             try:
-                if self._kind(path) == 'tree-reference':
-                    yield path, key[2]
+                if self._kind(relpath) == 'tree-reference':
+                    yield relpath, key[2]
             except errors.NoSuchFile:
                 # path is missing on disk.
                 continue
@@ -1415,6 +1419,9 @@
         self._inventory = None
         self._locked = 0
         self._dirstate_locked = False
+        self._repo_supports_tree_reference = getattr(
+            repository._format, "supports_tree_reference",
+            False)
 
     def __repr__(self):
         return "<%s of %s in %s>" % \
@@ -1459,6 +1466,14 @@
         path_utf8 = osutils.pathjoin(entry[0][0], entry[0][1])
         return path_utf8.decode('utf8')
 
+    def iter_references(self):
+        if not self._repo_supports_tree_reference:
+            # When the repo doesn't support references, we will have nothing to
+            # return
+            return iter([])
+        # Otherwise, fall back to the default implementation
+        return super(DirStateRevisionTree, self).iter_references()
+
     def _get_parent_index(self):
         """Return the index in the dirstate referenced by this tree."""
         return self._dirstate.get_parent_ids().index(self._revision_id) + 1
@@ -1725,6 +1740,10 @@
                 self._dirstate_locked = False
             self._repository.unlock()
 
+    @needs_read_lock
+    def supports_tree_reference(self):
+        return self._repo_supports_tree_reference
+
     def walkdirs(self, prefix=""):
         # TODO: jam 20070215 This is the lazy way by using the RevisionTree
         # implementation based on an inventory.  



More information about the bazaar-commits mailing list