Rev 3507: (jam) Updates to Tree.iter_references, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Jun 23 21:38:17 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3507
revision-id:pqm at pqm.ubuntu.com-20080623203807-3uudpo6dw8nxhxzz
parent: pqm at pqm.ubuntu.com-20080620010918-64z4xylh1ap5hgyf
parent: john at arbash-meinel.com-20080623201216-0hm9dxvq6murh8jl
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2008-06-23 21:38:07 +0100
message:
  (jam) Updates to Tree.iter_references,
  	mostly to shortcut when there can be no references.
modified:
  bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
  bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
  bzrlib/tests/tree_implementations/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
    ------------------------------------------------------------
    revno: 3504.2.2
    revision-id:john at arbash-meinel.com-20080623201216-0hm9dxvq6murh8jl
    parent: john at arbash-meinel.com-20080620190638-0vayap44pyg1kfrq
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: jam-integration
    timestamp: Mon 2008-06-23 15:12:16 -0500
    message:
      Find some code that thought we were dealing in absolute paths
    modified:
      bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
    ------------------------------------------------------------
    revno: 3504.2.1
    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.
    modified:
      bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
      bzrlib/tests/tree_implementations/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py	2008-05-29 19:46:01 +0000
+++ b/bzrlib/merge.py	2008-06-23 20:12:16 +0000
@@ -419,15 +419,14 @@
             merge = self.make_merger()
             merge.do_merge()
             if self.recurse == 'down':
-                for path, file_id in self.this_tree.iter_references():
-                    sub_tree = self.this_tree.get_nested_tree(file_id, path)
+                for relpath, file_id in self.this_tree.iter_references():
+                    sub_tree = self.this_tree.get_nested_tree(file_id, relpath)
                     other_revision = self.other_tree.get_reference_revision(
-                        file_id, path)
+                        file_id, relpath)
                     if  other_revision == sub_tree.last_revision():
                         continue
                     sub_merge = Merger(sub_tree.branch, this_tree=sub_tree)
                     sub_merge.merge_type = self.merge_type
-                    relpath = self.this_tree.relpath(path)
                     other_branch = self.other_branch.reference_parent(file_id, relpath)
                     sub_merge.set_other_revision(other_revision, other_branch)
                     base_revision = self.base_tree.get_reference_revision(file_id)

=== 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