Rev 3905: Merge Ian fix for Inventory.filter in file:///home/vila/src/bzr/experimental/brisbane-core/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Mar 25 13:33:22 GMT 2009


At file:///home/vila/src/bzr/experimental/brisbane-core/

------------------------------------------------------------
revno: 3905
revision-id: v.ladeuil+lp at free.fr-20090325133320-ure31c8txrg1ihgn
parent: v.ladeuil+lp at free.fr-20090325075411-ae1ivprnz6htlgd1
parent: ian.clatworthy at canonical.com-20090325121809-el4l5ie9ifqt5ur9
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: brisbane-core
timestamp: Wed 2009-03-25 14:33:20 +0100
message:
  Merge Ian fix for Inventory.filter
modified:
  bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
    ------------------------------------------------------------
    revno: 3901.1.6
    revision-id: ian.clatworthy at canonical.com-20090325121809-el4l5ie9ifqt5ur9
    parent: john at arbash-meinel.com-20090324210500-cxe6eialv4lzed3e
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: brisbane-core
    timestamp: Wed 2009-03-25 22:18:09 +1000
    message:
      get inventory filtering working for CHKInventory
    modified:
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
-------------- next part --------------
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2009-03-25 07:54:11 +0000
+++ b/bzrlib/inventory.py	2009-03-25 13:33:20 +0000
@@ -964,6 +964,52 @@
 
         return parent.file_id
 
+    def filter(self, specific_fileids):
+        """Get an inventory view filtered against a set of file-ids.
+
+        Children of directories and parents are included.
+
+        The result may or may not reference the underlying inventory
+        so it should be treated as immutable.
+        """
+        interesting_parents = set()
+        for fileid in specific_fileids:
+            try:
+                interesting_parents.update(self.get_idpath(fileid))
+            except errors.NoSuchId:
+                # This fileid is not in the inventory - that's ok
+                pass
+        entries = self.iter_entries()
+        if self.root is None:
+            return Inventory(root_id=None)
+        other = Inventory(entries.next()[1].file_id)
+        other.root.revision = self.root.revision
+        other.revision_id = self.revision_id
+        directories_to_expand = set()
+        for path, entry in entries:
+            file_id = entry.file_id
+            if (file_id in specific_fileids
+                or entry.parent_id in directories_to_expand):
+                if entry.kind == 'directory':
+                    directories_to_expand.add(file_id)
+            elif file_id not in interesting_parents:
+                continue
+            other.add(entry.copy())
+        return other
+
+    def get_idpath(self, file_id):
+        """Return a list of file_ids for the path to an entry.
+
+        The list contains one element for each directory followed by
+        the id of the file itself.  So the length of the returned list
+        is equal to the depth of the file in the tree, counting the
+        root directory as depth 1.
+        """
+        p = []
+        for parent in self._iter_file_id_parents(file_id):
+            p.insert(0, parent.file_id)
+        return p
+
 
 class Inventory(CommonInventory):
     """Inventory of versioned files in a tree.
@@ -1296,19 +1342,6 @@
             yield ie
             file_id = ie.parent_id
 
-    def get_idpath(self, file_id):
-        """Return a list of file_ids for the path to an entry.
-
-        The list contains one element for each directory followed by
-        the id of the file itself.  So the length of the returned list
-        is equal to the depth of the file in the tree, counting the
-        root directory as depth 1.
-        """
-        p = []
-        for parent in self._iter_file_id_parents(file_id):
-            p.insert(0, parent.file_id)
-        return p
-
     def has_filename(self, names):
         return bool(self.path2id(names))
 
@@ -1400,39 +1433,6 @@
     def is_root(self, file_id):
         return self.root is not None and file_id == self.root.file_id
 
-    def filter(self, specific_fileids):
-        """Get an inventory view filtered against a set of file-ids.
-
-        Children of directories and parents are included.
-
-        The result may or may not reference the underlying inventory
-        so it should be treated as immutable.
-        """
-        interesting_parents = set()
-        for fileid in specific_fileids:
-            try:
-                interesting_parents.update(self.get_idpath(fileid))
-            except errors.NoSuchId:
-                # This fileid is not in the inventory - that's ok
-                pass
-        entries = self.iter_entries()
-        if self.root is None:
-            return Inventory(root_id=None)
-        other = Inventory(entries.next()[1].file_id)
-        other.root.revision = self.root.revision
-        other.revision_id = self.revision_id
-        directories_to_expand = set()
-        for path, entry in entries:
-            file_id = entry.file_id
-            if (file_id in specific_fileids
-                or entry.parent_id in directories_to_expand):
-                if entry.kind == 'directory':
-                    directories_to_expand.add(file_id)
-            elif file_id not in interesting_parents:
-                continue
-            other.add(entry.copy())
-        return other
-
 
 class CHKInventory(CommonInventory):
     """An inventory persisted in a CHK store.



More information about the bazaar-commits mailing list