Rev 2487: Make WorkingTree4 report support for references based on the repositories capabilities. in http://bazaar.launchpad.net/~bzr/bzr/dirstate

Robert Collins robertc at robertcollins.net
Tue Mar 6 22:56:20 GMT 2007


At http://bazaar.launchpad.net/~bzr/bzr/dirstate

------------------------------------------------------------
revno: 2487
revision-id: robertc at robertcollins.net-20070306225507-natrr5l50ppfndpz
parent: robertc at robertcollins.net-20070306214551-ayvx2ziz2hgbkqm0
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate.dogfood
timestamp: Wed 2007-03-07 09:55:07 +1100
message:
  Make WorkingTree4 report support for references based on the repositories capabilities.
modified:
  bzrlib/tests/test_delta.py     test_delta.py-20070110134455-sqpd1y7mbjndelxf-1
  bzrlib/tests/test_workingtree_4.py test_workingtree_4.p-20070223025758-531n3tznl3zacv2o-1
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/tests/test_delta.py'
--- a/bzrlib/tests/test_delta.py	2007-03-05 03:10:21 +0000
+++ b/bzrlib/tests/test_delta.py	2007-03-06 22:55:07 +0000
@@ -83,8 +83,10 @@
         self.assertReport(' D  path/', modified='deleted',
                           kind=('directory', None), old_path='old')
         self.assertReport('-   path/', versioned_change='removed',
+                          old_path='path',
                           kind=(None, 'directory'))
         self.assertReport('-D  path', versioned_change='removed',
+                          old_path='path',
                           modified='deleted', kind=('file', 'directory'))
 
     def test_modification(self):

=== modified file 'bzrlib/tests/test_workingtree_4.py'
--- a/bzrlib/tests/test_workingtree_4.py	2007-03-06 13:47:33 +0000
+++ b/bzrlib/tests/test_workingtree_4.py	2007-03-06 22:55:07 +0000
@@ -17,6 +17,8 @@
 
 """Tests for WorkingTreeFormat4"""
 
+import os
+
 from bzrlib import (
     bzrdir,
     dirstate,
@@ -467,3 +469,55 @@
         validate()
         wt.commit('again')
         validate()
+
+    def test_non_subtree_with_nested_trees(self):
+        # prior to dirstate, st/diff/commit ignored nested trees.
+        # dirstate, as opposed to dirstate-with-subtree, should
+        # behave the same way.
+        tree = self.make_branch_and_tree('.', format='dirstate')
+        self.assertFalse(tree.supports_tree_reference())
+        self.build_tree(['dir/'])
+        # for testing easily.
+        tree.set_root_id('root')
+        tree.add(['dir'], ['dir-id'])
+        subtree = self.make_branch_and_tree('dir')
+        # the most primitive operation: kind
+        self.assertEqual('directory', tree.kind('dir-id'))
+        # a diff against the basis should give us a directory
+        tree.lock_read()
+        expected = [('dir-id',
+            (None, u'dir'),
+            True,
+            (False, True),
+            (None, 'root'),
+            (None, u'dir'),
+            (None, 'directory'),
+            (None, False))]
+        self.assertEqual(expected, list(tree._iter_changes(tree.basis_tree(),
+            specific_files=['dir'])))
+        tree.unlock()
+        # do a commit, we want to trigger the dirstate fast-path too
+        tree.commit('first post')
+        # change the path for the subdir, which will trigger getting all
+        # its data:
+        os.rename('dir', 'also-dir')
+        # now the diff will use the fast path
+        tree.lock_read()
+        expected = [('dir-id',
+            (u'dir', u'dir'),
+            True,
+            (True, True),
+            ('root', 'root'),
+            ('dir', 'dir'),
+            ('directory', None),
+            (False, False))]
+        self.assertEqual(expected, list(tree._iter_changes(tree.basis_tree())))
+        tree.unlock()
+
+    def test_with_subtree_supports_tree_references(self):
+        # dirstate-with-subtree should support tree-references.
+        tree = self.make_branch_and_tree('.', format='dirstate-with-subtree')
+        self.assertTrue(tree.supports_tree_reference())
+        # having checked this is on, the tree interface, and intertree
+        # interface tests, will proceed to test the subtree support of
+        # workingtree_4.

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2007-03-06 08:41:40 +0000
+++ b/bzrlib/workingtree.py	2007-03-06 22:55:07 +0000
@@ -308,7 +308,7 @@
         return self._format.requires_rich_root
 
     def supports_tree_reference(self):
-        return getattr(self._format, 'supports_tree_reference', False)
+        return False
 
     def _set_inventory(self, inv, dirty):
         """Set the internal cached inventory.

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2007-03-06 13:47:33 +0000
+++ b/bzrlib/workingtree_4.py	2007-03-06 22:55:07 +0000
@@ -225,7 +225,9 @@
             WorkingTree3._comparison_data(self, entry, path)
         # it looks like a plain directory, but it's really a reference -- see
         # also kind()
-        if kind == 'directory' and self._directory_is_tree_reference(path):
+        if (self._repo_supports_tree_reference and
+            kind == 'directory' and
+            self._directory_is_tree_reference(path)):
             kind = 'tree-reference'
         return kind, executable, stat_value
 
@@ -353,6 +355,7 @@
                     # add this entry to the parent map.
                     parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
                 elif kind == 'tree-reference':
+                    assert self._repo_supports_tree_reference
                     inv_entry.reference_revision = link_or_sha1 or None
                 else:
                     assert 'unknown kind'
@@ -500,7 +503,9 @@
     def _kind(self, relpath):
         abspath = self.abspath(relpath)
         kind = file_kind(abspath)
-        if kind == 'directory' and self._directory_is_tree_reference(relpath):
+        if (self._repo_supports_tree_reference and
+            kind == 'directory' and
+            self._directory_is_tree_reference(relpath)):
             kind = 'tree-reference'
         return kind
 
@@ -522,6 +527,11 @@
                 state = self.current_dirstate()
                 if not state._lock_token:
                     state.lock_read()
+                # set our support for tree references from the repository in
+                # use.
+                self._repo_supports_tree_reference = getattr(
+                    self.branch.repository._format, "support_tree_reference",
+                    False)
             except:
                 self._control_files.unlock()
                 raise
@@ -537,6 +547,11 @@
                 state = self.current_dirstate()
                 if not state._lock_token:
                     state.lock_write()
+                # set our support for tree references from the repository in
+                # use.
+                self._repo_supports_tree_reference = getattr(
+                    self.branch.repository._format, "support_tree_reference",
+                    False)
             except:
                 self._control_files.unlock()
                 raise
@@ -1039,6 +1054,10 @@
         if state._dirblock_state == dirstate.DirState.IN_MEMORY_MODIFIED:
             self._make_dirty(reset_inventory=True)
 
+    @needs_read_lock
+    def supports_tree_reference(self):
+        return self._repo_supports_tree_reference
+
     def unlock(self):
         """Unlock in format 4 trees needs to write the entire dirstate."""
         if self._control_files._lock_count == 1:
@@ -1167,8 +1186,6 @@
         - uses a LockDir to guard access to it.
     """
 
-    supports_tree_reference = True
-
     def get_format_string(self):
         """See WorkingTreeFormat.get_format_string()."""
         return "Bazaar Working Tree Format 4 (bzr 0.15)\n"



More information about the bazaar-commits mailing list