[MERGE] deprecated EmptyTree

Robert Collins robertc at robertcollins.net
Thu Jul 20 14:58:40 BST 2006


This patch deprecated EmptyTree, replacing all uses of it with a
RevisionTree.

The first thing is that as a tree, EmptyTree is really very pathological
- all the methods are essentially special cases. So its very hard to
test, because you can only ever have the Empty case of it.

The second thing is that in terms of code maintenance, we would have one
less thing to maintain if we use RevisionTree instead - as this patch
does.

Thoughts? +1's ?

-Rob
-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- bzrlib/branch.py	2006-06-30 20:35:16 +0000
+++ bzrlib/branch.py	2006-07-20 13:10:24 +0000
@@ -363,10 +363,7 @@
         raise NotImplementedError('pull is abstract')
 
     def basis_tree(self):
-        """Return `Tree` object for last revision.
-
-        If there are no revisions yet, return an `EmptyTree`.
-        """
+        """Return `Tree` object for last revision."""
         return self.repository.revision_tree(self.last_revision())
 
     def rename_one(self, from_rel, to_rel):

=== modified file 'bzrlib/missing.py'
--- bzrlib/missing.py	2006-06-10 00:21:11 +0000
+++ bzrlib/missing.py	2006-07-20 13:10:57 +0000
@@ -5,8 +5,7 @@
 
 def iter_log_data(revisions, revision_source, verbose):
     from bzrlib.diff import compare_trees
-    from bzrlib.tree import EmptyTree
-    last_tree = EmptyTree
+    last_tree = revision_source.revision_tree(None)
     last_rev_id = None
     for revno, rev_id in revisions:
         rev = revision_source.get_revision(rev_id)

=== modified file 'bzrlib/repository.py'
--- bzrlib/repository.py	2006-07-10 19:23:53 +0000
+++ bzrlib/repository.py	2006-07-20 13:20:56 +0000
@@ -38,11 +38,10 @@
 from bzrlib.symbol_versioning import (deprecated_method,
         zero_nine, 
         )
+from bzrlib.testament import Testament
 from bzrlib.trace import mutter, note
-from bzrlib.tree import RevisionTree, EmptyTree
+from bzrlib.tree import RevisionTree
 from bzrlib.tsort import topo_sort
-from bzrlib.testament import Testament
-from bzrlib.tree import EmptyTree
 from bzrlib.weave import WeaveFile
 
 
@@ -347,7 +346,7 @@
                      t in self.revision_trees(required_trees))
         for revision in revisions:
             if not revision.parent_ids:
-                old_tree = EmptyTree()
+                old_tree = self.revision_tree(None)
             else:
                 old_tree = trees[revision.parent_ids[0]]
             yield delta.compare_trees(old_tree, trees[revision.revision_id])
@@ -565,12 +564,12 @@
     def revision_tree(self, revision_id):
         """Return Tree for a revision on this branch.
 
-        `revision_id` may be None for the null revision, in which case
-        an `EmptyTree` is returned."""
+        `revision_id` may be None for the empty tree revision.
+        """
         # TODO: refactor this to use an existing revision object
         # so we don't need to read it in twice.
         if revision_id is None or revision_id == NULL_REVISION:
-            return EmptyTree()
+            return RevisionTree(self, Inventory(), NULL_REVISION)
         else:
             inv = self.get_revision_inventory(revision_id)
             return RevisionTree(self, inv, revision_id)
@@ -746,7 +745,7 @@
             present_parents.append(p_id)
             parent_trees[p_id] = repository.revision_tree(p_id)
         else:
-            parent_trees[p_id] = EmptyTree()
+            parent_trees[p_id] = repository.revision_tree(None)
 
     inv = revision_tree.inventory
     

=== modified file 'bzrlib/tests/repository_implementations/test_repository.py'
--- bzrlib/tests/repository_implementations/test_repository.py	2006-07-04 17:23:00 +0000
+++ bzrlib/tests/repository_implementations/test_repository.py	2006-07-20 13:36:23 +0000
@@ -147,9 +147,9 @@
         tree = wt.branch.repository.revision_tree('revision-1')
         self.assertEqual(list(tree.list_files()), [])
         tree = wt.branch.repository.revision_tree(None)
-        self.assertEqual(len(tree.list_files()), 0)
+        self.assertEqual([], list(tree.list_files()))
         tree = wt.branch.repository.revision_tree(NULL_REVISION)
-        self.assertEqual(len(tree.list_files()), 0)
+        self.assertEqual([], list(tree.list_files()))
 
     def test_fetch(self):
         # smoke test fetch to ensure that the convenience function works.

=== modified file 'bzrlib/tree.py'
--- bzrlib/tree.py	2006-07-06 13:51:22 +0000
+++ bzrlib/tree.py	2006-07-20 13:51:44 +0000
@@ -19,6 +19,7 @@
 
 import os
 from cStringIO import StringIO
+from warnings import warn
 
 import bzrlib
 from bzrlib.errors import BzrError, BzrCheckError
@@ -28,6 +29,7 @@
 import bzrlib.revision
 from bzrlib.trace import mutter, note
 
+
 class Tree(object):
     """Abstract file tree.
 
@@ -37,8 +39,6 @@
 
     * `RevisionTree` is a tree as recorded at some point in the past.
 
-    * `EmptyTree`
-
     Trees contain an `Inventory` object, and also know how to retrieve
     file texts mentioned in the inventory, either from a working
     directory or from a store.
@@ -242,12 +242,11 @@
 
     def __init__(self):
         self._inventory = Inventory()
+        warn('EmptyTree is deprecated as of bzr 0.9 please use '
+            'repository.revision_tree instead.',
+            DeprecationWarning, stacklevel=2)
 
     def get_parent_ids(self):
-        """See Tree.get_parent_ids.
-
-        An EmptyTree always has NULL_REVISION as the only parent.
-        """
         return []
 
     def get_symlink_target(self, file_id):

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060720/1dca0654/attachment.pgp 


More information about the bazaar mailing list