Rev 2656: Make GraphKnitIndex get_ancestry the same as regular knits. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Sun Jul 15 09:30:08 BST 2007


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

------------------------------------------------------------
revno: 2656
revision-id: robertc at robertcollins.net-20070715083005-naa3a3i0am1xtj1e
parent: robertc at robertcollins.net-20070715073554-ge1dpaaa12s4ex7p
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Sun 2007-07-15 18:30:05 +1000
message:
  Make GraphKnitIndex get_ancestry the same as regular knits.
modified:
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2007-07-14 07:02:10 +0000
+++ b/bzrlib/knit.py	2007-07-15 08:30:05 +0000
@@ -1347,6 +1347,8 @@
         # it should be altered to be a index core feature?
         # get a graph of all the mentioned versions:
         graph = {}
+        ghosts = set()
+        versions = set(versions)
         pending = set(versions)
         while pending:
             # get all pending nodes
@@ -1354,14 +1356,18 @@
             new_nodes = self._get_entries(this_iteration)
             pending = set()
             for (key, node_refs, value) in new_nodes:
-                graph[key] = node_refs[0]
+                # dont ask for ghosties - otherwise
+                # we we can end up looping with pending
+                # being entirely ghosted.
+                graph[key] = [parent for parent in node_refs[0]
+                    if parent not in ghosts]
                 # queue parents 
                 pending.update(graph[key])
-            missing_versions = this_iteration.difference(graph)
-            if missing_versions:
-                raise RevisionNotPresent(missing_versions.pop(), self)
+            ghosts.difference_update(graph)
             # dont examine known nodes
             pending.difference_update(graph)
+        if versions.difference(graph):
+            raise RevisionNotPresent(versions.difference(graph).pop(), self)
         if not topo_sorted:
             return graph.keys()
         return topo_sort(graph.items())

=== modified file 'bzrlib/repofmt/knitrepo.py'
--- a/bzrlib/repofmt/knitrepo.py	2007-07-15 04:10:46 +0000
+++ b/bzrlib/repofmt/knitrepo.py	2007-07-15 08:30:05 +0000
@@ -347,8 +347,9 @@
             add_callback = self.repo._revision_write_index.add_nodes
         else:
             add_callback = None # no data-adding permitted.
-        all_indices = CombinedGraphIndex(indices)
-        knit_index = KnitGraphIndex(all_indices, add_callback=add_callback)
+        self.repo._revision_all_indices = CombinedGraphIndex(indices)
+        knit_index = KnitGraphIndex(self.repo._revision_all_indices,
+            add_callback=add_callback)
         self.repo._revision_knit = knit.KnitVersionedFile(
             'revisions', index_transport.clone('..'),
             self.repo.control_files._file_mode,
@@ -361,15 +362,23 @@
         # have we done anything?
         if getattr(self.repo, '_revision_knit', None):
             index_transport = self.get_indices_transport()
-            index_transport.put_file(self.repo._revision_indices.allocate(),
+            new_index_name = self.repo._revision_indices.allocate()
+            index_transport.put_file(new_index_name,
                 self.repo._revision_write_index.finish())
             self.repo._revision_indices.save()
+            self.repo._revision_write_index = None
+            self.repo._revision_all_indices.insert_index(0,
+                GraphIndex(index_transport, new_index_name))
+            # remove the write buffering index. XXX: API break
+            # - clearly we need a remove_index call too.
+            del self.repo._revision_all_indices._indices[-1]
 
     def reset(self):
         """Clear all cached data."""
         self.repo._revision_knit = None
         self.repo._revision_indices = None
         self.repo._revision_write_index = None
+        self.repo._revision_all_indices = None
 
 
 class GraphKnitRepository1(KnitRepository):

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2007-07-14 07:49:13 +0000
+++ b/bzrlib/tests/test_knit.py	2007-07-15 08:30:05 +0000
@@ -1589,7 +1589,8 @@
             ]), set(index.get_graph()))
 
     def test_get_ancestry(self):
-        index = self.two_graph_index_no_ghosts()
+        # get_ancestry is defined as eliding ghosts, not erroring.
+        index = self.two_graph_index()
         self.assertEqual([], index.get_ancestry([]))
         self.assertEqual(['separate'], index.get_ancestry(['separate']))
         self.assertEqual(['tail'], index.get_ancestry(['tail']))
@@ -1610,12 +1611,8 @@
             set(index.get_ancestry(['tip'], topo_sorted=False)))
         self.assertEqual(set(['separate', 'tail', 'parent', 'tip']),
             set(index.get_ancestry(['tip', 'separate'])))
-        # with ghosts it blows up early
-        index = self.two_graph_index()
-        self.assertEqual([], index.get_ancestry([]))
-        self.assertEqual(['separate'], index.get_ancestry(['separate']))
-        self.assertEqual(['tail'], index.get_ancestry(['tail']))
-        self.assertRaises(errors.RevisionNotPresent, index.get_ancestry, ['parent'])
+        # asking for a ghost makes it go boom.
+        self.assertRaises(errors.RevisionNotPresent, index.get_ancestry, ['ghost'])
 
     def test_get_ancestry_with_ghosts(self):
         index = self.two_graph_index()
@@ -1636,6 +1633,8 @@
              ['separate', 'tail', 'ghost', 'parent', 'tip'],
              ['separate', 'ghost', 'tail', 'parent', 'tip'],
             ))
+        # asking for a ghost makes it go boom.
+        self.assertRaises(errors.RevisionNotPresent, index.get_ancestry, ['ghost'])
 
     def test_num_versions(self):
         index = self.two_graph_index()



More information about the bazaar-commits mailing list