Rev 3187: Automatically exclude ghosts. in http://people.ubuntu.com/~robertc/baz2.0/search-results

Robert Collins robertc at robertcollins.net
Wed Jan 16 00:10:55 GMT 2008


At http://people.ubuntu.com/~robertc/baz2.0/search-results

------------------------------------------------------------
revno: 3187
revision-id:robertc at robertcollins.net-20080116001050-za7seokm1owjr7ee
parent: robertc at robertcollins.net-20080115232617-8ybv6rq1yqmesqzd
committer: Robert Collins <robertc at robertcollins.net>
branch nick: search-results
timestamp: Wed 2008-01-16 11:10:50 +1100
message:
  Automatically exclude ghosts.
modified:
  bzrlib/graph.py                graph_walker.py-20070525030359-y852guab65d4wtn0-1
  bzrlib/tests/test_graph.py     test_graph_walker.py-20070525030405-enq4r60hhi9xrujc-1
=== modified file 'bzrlib/graph.py'
--- a/bzrlib/graph.py	2008-01-15 23:26:17 +0000
+++ b/bzrlib/graph.py	2008-01-16 00:10:50 +0000
@@ -529,6 +529,13 @@
     def get_recipe(self):
         """Return a recipe that can be used to replay this search.
         
+        The recipe allows reconstruction of the same results at a later date
+        without knowing all the found keys. The essential elements are a list
+        of keys to start and and to stop at. In order to give reproducible
+        results when ghosts are encountered by a search they are automatically
+        added to the exclude list (or else ghost filling may alter the
+        results).
+
         :return: A tuple (start_keys_set, exclude_keys_set). To recreate the
             results of this search, create a breadth first searcher on the same
             graph starting at start_keys. Then call next() (or
@@ -545,7 +552,7 @@
             # pretend we didn't query: perhaps we should tweak _do_query to be
             # entirely stateless?
             self.seen.difference_update(next)
-            next_query = next
+            next_query = next.union(ghosts)
         else:
             next_query = self._next_query
         return self._started_keys, self._stopped_keys.union(next_query)
@@ -607,6 +614,9 @@
         self._current_ghosts = ghosts
         self._next_query = next
         self._current_parents = parents
+        # ghosts are implicit stop points, otherwise the search cannot be
+        # repeated when ghosts are filled.
+        self._stopped_keys.update(ghosts)
 
     def _do_query(self, revisions):
         """Query for revisions.

=== modified file 'bzrlib/tests/test_graph.py'
--- a/bzrlib/tests/test_graph.py	2008-01-15 23:26:17 +0000
+++ b/bzrlib/tests/test_graph.py	2008-01-16 00:10:50 +0000
@@ -751,6 +751,7 @@
         graph = self.make_graph({
             'head':['child'],
             'child':[NULL_REVISION],
+            NULL_REVISION:[],
             })
         search = graph._make_breadth_first_searcher(['head'])
         # At the start, nothing has been seen, to its all excluded:
@@ -776,6 +777,7 @@
             'otherhead':['otherchild'],
             'otherchild':['excluded'],
             'excluded':[NULL_REVISION],
+            NULL_REVISION:[]
             })
         search = graph._make_breadth_first_searcher([])
         # Starting with nothing and adding a search works:
@@ -805,6 +807,27 @@
         search.start_searching(['head'])
         self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
 
+    def test_breadth_first_get_recipe_ghosts_are_excluded(self):
+        graph = self.make_graph({
+            'head':['child', 'ghost'],
+            'child':[NULL_REVISION],
+            NULL_REVISION:[],
+            })
+        search = graph._make_breadth_first_searcher(['head'])
+        # using next:
+        expected = [
+            (set(['head']),
+             (set(['head']), set(['ghost', 'child'])),
+             None, None),
+            (set(['head', 'child', 'ghost']),
+             (set(['head']), set([NULL_REVISION, 'ghost'])),
+             None, None),
+            ]
+        self.assertSeenAndRecipes(expected, search, search.next)
+        # using next_with_ghosts:
+        search = graph._make_breadth_first_searcher(['head'])
+        self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
+
 
 class TestCachingParentsProvider(tests.TestCase):
 



More information about the bazaar-commits mailing list