Rev 5795: (jelmer) Split InventoryRevisionTree out of RevisionTree. (Jelmer Vernooij) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Apr 18 01:45:51 UTC 2011


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

------------------------------------------------------------
revno: 5795 [merge]
revision-id: pqm at pqm.ubuntu.com-20110418014548-4mge2g9h5b04vpcr
parent: pqm at pqm.ubuntu.com-20110418005805-o8aidovucdgbaxwy
parent: jelmer at samba.org-20110417182456-9o23uca8swe75ip7
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-04-18 01:45:48 +0000
message:
  (jelmer) Split InventoryRevisionTree out of RevisionTree. (Jelmer Vernooij)
modified:
  bzrlib/mutabletree.py          mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/revisiontree.py         revisiontree.py-20060724012533-bg8xyryhxd0o0i0h-1
  bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
  doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py	2011-04-09 21:00:33 +0000
+++ b/bzrlib/mutabletree.py	2011-04-17 18:24:56 +0000
@@ -696,7 +696,7 @@
         inventory = basis.inventory._get_mutable_inventory()
         basis.unlock()
         inventory.apply_delta(delta)
-        rev_tree = revisiontree.RevisionTree(self.branch.repository,
+        rev_tree = revisiontree.InventoryRevisionTree(self.branch.repository,
                                              inventory, new_revid)
         self.set_parent_trees([(new_revid, rev_tree)])
 

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2011-04-16 14:16:50 +0000
+++ b/bzrlib/repository.py	2011-04-17 18:24:56 +0000
@@ -41,7 +41,7 @@
     )
 from bzrlib.bundle import serializer
 from bzrlib.recordcounter import RecordCounter
-from bzrlib.revisiontree import RevisionTree
+from bzrlib.revisiontree import InventoryRevisionTree
 from bzrlib.store.versioned import VersionedFileStore
 from bzrlib.testament import Testament
 """)
@@ -236,16 +236,16 @@
     def revision_tree(self):
         """Return the tree that was just committed.
 
-        After calling commit() this can be called to get a RevisionTree
-        representing the newly committed tree. This is preferred to
-        calling Repository.revision_tree() because that may require
-        deserializing the inventory, while we already have a copy in
+        After calling commit() this can be called to get a
+        InventoryRevisionTree representing the newly committed tree. This is
+        preferred to calling Repository.revision_tree() because that may
+        require deserializing the inventory, while we already have a copy in
         memory.
         """
         if self.new_inventory is None:
             self.new_inventory = self.repository.get_inventory(
                 self._new_revision_id)
-        return RevisionTree(self.repository, self.new_inventory,
+        return InventoryRevisionTree(self.repository, self.new_inventory,
             self._new_revision_id)
 
     def finish_inventory(self):
@@ -2513,11 +2513,11 @@
         # TODO: refactor this to use an existing revision object
         # so we don't need to read it in twice.
         if revision_id == _mod_revision.NULL_REVISION:
-            return RevisionTree(self, Inventory(root_id=None),
-                                _mod_revision.NULL_REVISION)
+            return InventoryRevisionTree(self,
+                Inventory(root_id=None), _mod_revision.NULL_REVISION)
         else:
             inv = self.get_inventory(revision_id)
-            return RevisionTree(self, inv, revision_id)
+            return InventoryRevisionTree(self, inv, revision_id)
 
     def revision_trees(self, revision_ids):
         """Return Trees for revisions in this repository.
@@ -2527,7 +2527,7 @@
         """
         inventories = self.iter_inventories(revision_ids)
         for inv in inventories:
-            yield RevisionTree(self, inv, inv.revision_id)
+            yield InventoryRevisionTree(self, inv, inv.revision_id)
 
     def _filtered_revision_trees(self, revision_ids, file_ids):
         """Return Tree for a revision on this branch with only some files.
@@ -2543,7 +2543,7 @@
             # Should we introduce a FilteredRevisionTree class rather
             # than pre-filter the inventory here?
             filtered_inv = inv.filter(file_ids)
-            yield RevisionTree(self, filtered_inv, filtered_inv.revision_id)
+            yield InventoryRevisionTree(self, filtered_inv, filtered_inv.revision_id)
 
     @needs_read_lock
     def get_ancestry(self, revision_id, topo_sorted=True):

=== modified file 'bzrlib/revisiontree.py'
--- a/bzrlib/revisiontree.py	2011-04-09 19:25:42 +0000
+++ b/bzrlib/revisiontree.py	2011-04-17 18:24:56 +0000
@@ -25,20 +25,14 @@
     )
 
 
-class RevisionTree(tree.InventoryTree):
+class RevisionTree(tree.Tree):
     """Tree viewing a previous revision.
 
     File text can be retrieved from the text store.
     """
 
-    def __init__(self, branch, inv, revision_id):
-        # for compatability the 'branch' parameter has not been renamed to
-        # repository at this point. However, we should change RevisionTree's
-        # construction to always be via Repository and not via direct
-        # construction - this will mean that we can change the constructor
-        # with much less chance of breaking client code.
-        self._repository = branch
-        self._inventory = inv
+    def __init__(self, repository, revision_id):
+        self._repository = repository
         self._revision_id = revision_id
         self._rules_searcher = None
 
@@ -69,28 +63,43 @@
     def get_file(self, file_id, path=None):
         return StringIO(self.get_file_text(file_id))
 
-    def iter_files_bytes(self, desired_files):
-        """See Tree.iter_files_bytes.
-
-        This version is implemented on top of Repository.extract_files_bytes"""
-        repo_desired_files = [(f, self.inventory[f].revision, i)
-                              for f, i in desired_files]
+    def is_locked(self):
+        return self._repository.is_locked()
+
+    def lock_read(self):
+        self._repository.lock_read()
+        return self
+
+    def __repr__(self):
+        return '<%s instance at %x, rev_id=%r>' % (
+            self.__class__.__name__, id(self), self._revision_id)
+
+    def unlock(self):
+        self._repository.unlock()
+
+    def _get_rules_searcher(self, default_searcher):
+        """See Tree._get_rules_searcher."""
+        if self._rules_searcher is None:
+            self._rules_searcher = super(RevisionTree,
+                self)._get_rules_searcher(default_searcher)
+        return self._rules_searcher
+
+
+class InventoryRevisionTree(RevisionTree,tree.InventoryTree):
+
+    def __init__(self, repository, inv, revision_id):
+        RevisionTree.__init__(self, repository, revision_id)
+        self._inventory = inv
+
+    def get_file_mtime(self, file_id, path=None):
+        ie = self._inventory[file_id]
         try:
-            for result in self._repository.iter_files_bytes(repo_desired_files):
-                yield result
-        except errors.RevisionNotPresent, e:
-            raise errors.NoSuchFile(e.revision_id)
-
-    def annotate_iter(self, file_id,
-                      default_revision=revision.CURRENT_REVISION):
-        """See Tree.annotate_iter"""
-        text_key = (file_id, self.inventory[file_id].revision)
-        annotator = self._repository.texts.get_annotator()
-        annotations = annotator.annotate_flat(text_key)
-        return [(key[-1], line) for key, line in annotations]
+            revision = self._repository.get_revision(ie.revision)
+        except errors.NoSuchRevision:
+            raise errors.FileTimestampUnavailable(self.id2path(file_id))
+        return revision.timestamp
 
     def get_file_size(self, file_id):
-        """See Tree.get_file_size"""
         return self._inventory[file_id].text_size
 
     def get_file_sha1(self, file_id, path=None, stat_value=None):
@@ -99,14 +108,6 @@
             return ie.text_sha1
         return None
 
-    def get_file_mtime(self, file_id, path=None):
-        ie = self._inventory[file_id]
-        try:
-            revision = self._repository.get_revision(ie.revision)
-        except errors.NoSuchRevision:
-            raise errors.FileTimestampUnavailable(self.id2path(file_id))
-        return revision.timestamp
-
     def is_executable(self, file_id, path=None):
         ie = self._inventory[file_id]
         if ie.kind != "file":
@@ -174,20 +175,6 @@
         return set(self._repository.get_ancestry(self._revision_id,
                                                  topo_sorted=False))
 
-    def is_locked(self):
-        return self._repository.is_locked()
-
-    def lock_read(self):
-        self._repository.lock_read()
-        return self
-
-    def __repr__(self):
-        return '<%s instance at %x, rev_id=%r>' % (
-            self.__class__.__name__, id(self), self._revision_id)
-
-    def unlock(self):
-        self._repository.unlock()
-
     def walkdirs(self, prefix=""):
         _directory = 'directory'
         inv = self.inventory
@@ -217,12 +204,25 @@
                 if dir[2] == _directory:
                     pending.append(dir)
 
-    def _get_rules_searcher(self, default_searcher):
-        """See Tree._get_rules_searcher."""
-        if self._rules_searcher is None:
-            self._rules_searcher = super(RevisionTree,
-                self)._get_rules_searcher(default_searcher)
-        return self._rules_searcher
+    def iter_files_bytes(self, desired_files):
+        """See Tree.iter_files_bytes.
+
+        This version is implemented on top of Repository.extract_files_bytes"""
+        repo_desired_files = [(f, self.inventory[f].revision, i)
+                              for f, i in desired_files]
+        try:
+            for result in self._repository.iter_files_bytes(repo_desired_files):
+                yield result
+        except errors.RevisionNotPresent, e:
+            raise errors.NoSuchFile(e.revision_id)
+
+    def annotate_iter(self, file_id,
+                      default_revision=revision.CURRENT_REVISION):
+        """See Tree.annotate_iter"""
+        text_key = (file_id, self.inventory[file_id].revision)
+        annotator = self._repository.texts.get_annotator()
+        annotations = annotator.annotate_flat(text_key)
+        return [(key[-1], line) for key, line in annotations]
 
 
 class InterCHKRevisionTree(tree.InterTree):

=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py	2011-04-11 18:31:46 +0000
+++ b/bzrlib/tree.py	2011-04-17 17:49:43 +0000
@@ -182,6 +182,17 @@
         """
         raise NotImplementedError(self.iter_entries_by_dir)
 
+    def list_files(self, include_root=False, from_dir=None, recursive=True):
+        """List all files in this tree.
+
+        :param include_root: Whether to include the entry for the tree root
+        :param from_dir: Directory under which to list files
+        :param recursive: Whether to list files recursively
+        :return: iterator over tuples of (path, versioned, kind, file_id,
+            inventory entry)
+        """
+        raise NotImplementedError(self.list_files)
+
     def iter_references(self):
         if self.supports_tree_reference():
             for path, entry in self.iter_entries_by_dir():

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2011-04-15 10:31:18 +0000
+++ b/bzrlib/workingtree.py	2011-04-17 18:24:56 +0000
@@ -2183,8 +2183,8 @@
                     # dont use the repository revision_tree api because we want
                     # to supply the inventory.
                     if inv.revision_id == revision_id:
-                        return revisiontree.RevisionTree(self.branch.repository,
-                            inv, revision_id)
+                        return revisiontree.InventoryRevisionTree(
+                            self.branch.repository, inv, revision_id)
                 except errors.BadInventoryFormat:
                     pass
         # raise if there was no inventory, or if we read the wrong inventory.

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-04-16 14:16:50 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-04-17 18:24:56 +0000
@@ -117,6 +117,10 @@
   a new ``InventoryTree`` class. Tree instances no longer
   necessarily provide an ``inventory`` attribute. (Jelmer Vernooij)
 
+* Inventory-specific functionality has been split out of ``RevisionTree``
+  into a new ``InventoryRevisionTree`` class. RevisionTree instances no
+  longer necessarily provide an ``inventory`` attribute. (Jelmer Vernooij)
+
 * New method ``Hooks.uninstall_named_hook``. (Jelmer Vernooij, #301472)
 
 * ``revision_graph_can_have_wrong_parents`` is now an attribute




More information about the bazaar-commits mailing list