Rev 2641: Implement KnitGraphIndex.get_parents/get_parents_with_ghosts. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Fri Jul 13 21:30:36 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/repository

------------------------------------------------------------
revno: 2641
revision-id: robertc at robertcollins.net-20070713203033-mcdbqbg809n5mqzm
parent: robertc at robertcollins.net-20070713201927-5809g0zvjv17s5qf
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Sat 2007-07-14 06:30:33 +1000
message:
  Implement KnitGraphIndex.get_parents/get_parents_with_ghosts.
modified:
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2007-07-13 20:19:27 +0000
+++ b/bzrlib/knit.py	2007-07-13 20:30:33 +0000
@@ -1431,6 +1431,17 @@
             options.append('no-eol')
         return ','.join(options)
 
+    def get_parents(self, version_id):
+        """Return parents of specified version ignoring ghosts."""
+        parents = self.get_parents_with_ghosts(version_id)
+        present_parents = set([
+            parent[0] for parent in self._graph_index.iter_entries(parents)])
+        return [key for key in parents if key in present_parents]
+
+    def get_parents_with_ghosts(self, version_id):
+        """Return parents of specified version with ghosts."""
+        return self._get_node(version_id)[1][0]
+
 
 class _KnitData(_KnitComponentFile):
     """Contents of the knit data file"""

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2007-07-13 20:19:27 +0000
+++ b/bzrlib/tests/test_knit.py	2007-07-13 20:30:33 +0000
@@ -1653,6 +1653,15 @@
         self.assertEqual('fulltext,no-eol', index.get_options('tip'))
         self.assertEqual('fulltext', index.get_options('parent'))
 
+    def test_get_parents(self):
+        # get_parents ignores ghosts
+        index = self.two_graph_index()
+        self.assertEqual(['tail'], index.get_parents('parent'))
+
+    def test_get_parents_with_ghosts(self):
+        index = self.two_graph_index()
+        self.assertEqual(('tail', 'ghost'), index.get_parents_with_ghosts('parent'))
+
 
 ## --- mutating tests for later ---
 #




More information about the bazaar-commits mailing list