Rev 3189: Record the number of found revisions for cross checking. in http://people.ubuntu.com/~robertc/baz2.0/search-results

Robert Collins robertc at robertcollins.net
Wed Jan 16 00:53:13 GMT 2008


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

------------------------------------------------------------
revno: 3189
revision-id:robertc at robertcollins.net-20080116005306-4o2tny789tuo60gb
parent: robertc at robertcollins.net-20080116002205-3jwn1aqhu76o97w9
committer: Robert Collins <robertc at robertcollins.net>
branch nick: search-results
timestamp: Wed 2008-01-16 11:53:06 +1100
message:
  Record the number of found revisions for cross checking.
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-16 00:22:05 +0000
+++ b/bzrlib/graph.py	2008-01-16 00:53:06 +0000
@@ -536,11 +536,16 @@
         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
-            next_with_ghosts()) repeatedly, and on every result, call
-            stop_searching_any on any keys from the exclude_keys set.
+        :return: A tuple (start_keys_set, exclude_keys_set, revision_count). To
+            recreate the results of this search, create a breadth first
+            searcher on the same graph starting at start_keys. Then call next()
+            (or next_with_ghosts()) repeatedly, and on every result, call
+            stop_searching_any on any keys from the exclude_keys set. The
+            revision_count value acts as a trivial cross-check - the found
+            revisions of the new search should have as many elements as
+            revision_count. If it does not, then additional revisions have been
+            ghosted since the search was executed the first time and the second
+            time.
         """
         if self._returning == 'next':
             # We have to know the current nodes children to be able to list the
@@ -555,7 +560,9 @@
             next_query = next.union(ghosts)
         else:
             next_query = self._next_query
-        return self._started_keys, self._stopped_keys.union(next_query)
+        excludes = self._stopped_keys.union(next_query)
+        return (self._started_keys, excludes,
+            len(self.seen.difference(excludes)))
 
     def next(self):
         """Return the next ancestors of this revision.

=== modified file 'bzrlib/tests/test_graph.py'
--- a/bzrlib/tests/test_graph.py	2008-01-16 00:22:05 +0000
+++ b/bzrlib/tests/test_graph.py	2008-01-16 00:53:06 +0000
@@ -755,14 +755,15 @@
             })
         search = graph._make_breadth_first_searcher(['head'])
         # At the start, nothing has been seen, to its all excluded:
-        self.assertEqual((set(['head']), set(['head'])), search.get_recipe())
+        self.assertEqual((set(['head']), set(['head']), 0),
+            search.get_recipe())
         self.assertEqual(set(), search.seen)
         # using next:
         expected = [
-            (set(['head']), (set(['head']), set(['child'])), None, None),
-            (set(['head', 'child']), (set(['head']), set([NULL_REVISION])),
+            (set(['head']), (set(['head']), set(['child']), 1), None, None),
+            (set(['head', 'child']), (set(['head']), set([NULL_REVISION]), 2),
              None, None),
-            (set(['head', 'child', NULL_REVISION]), (set(['head']), set()),
+            (set(['head', 'child', NULL_REVISION]), (set(['head']), set(), 3),
              None, None),
             ]
         self.assertSeenAndRecipes(expected, search, search.next)
@@ -782,8 +783,9 @@
         search = graph._make_breadth_first_searcher([])
         # Starting with nothing and adding a search works:
         search.start_searching(['head'])
-        # At the start, nothing has been seen, to its all excluded:
-        self.assertEqual((set(['head']), set(['child'])), search.get_recipe())
+        # head has been seen:
+        self.assertEqual((set(['head']), set(['child']), 1),
+            search.get_recipe())
         self.assertEqual(set(['head']), search.seen)
         # using next:
         expected = [
@@ -791,14 +793,14 @@
             # - otherhead counts as seen immediately when start_searching is
             # called.
             (set(['head', 'child', 'otherhead']),
-             (set(['head', 'otherhead']), set(['child', 'otherchild'])),
+             (set(['head', 'otherhead']), set(['child', 'otherchild']), 2),
              ['otherhead'], ['child']),
             (set(['head', 'child', 'otherhead', 'otherchild']),
-             (set(['head', 'otherhead']), set(['child', 'excluded'])),
+             (set(['head', 'otherhead']), set(['child', 'excluded']), 3),
              None, None),
-            # stop searchind otherexcluded now
+            # stop searching excluded now
             (set(['head', 'child', 'otherhead', 'otherchild', 'excluded']),
-             (set(['head', 'otherhead']), set(['child', 'excluded'])),
+             (set(['head', 'otherhead']), set(['child', 'excluded']), 3),
              None, ['excluded']),
             ]
         self.assertSeenAndRecipes(expected, search, search.next)
@@ -817,10 +819,10 @@
         # using next:
         expected = [
             (set(['head']),
-             (set(['head']), set(['ghost', 'child'])),
+             (set(['head']), set(['ghost', 'child']), 1),
              None, None),
             (set(['head', 'child', 'ghost']),
-             (set(['head']), set([NULL_REVISION, 'ghost'])),
+             (set(['head']), set([NULL_REVISION, 'ghost']), 2),
              None, None),
             ]
         self.assertSeenAndRecipes(expected, search, search.next)
@@ -838,16 +840,66 @@
         # using next:
         expected = [
             (set(['head', 'ghost']),
-             (set(['head', 'ghost']), set(['child', 'ghost'])),
+             (set(['head', 'ghost']), set(['child', 'ghost']), 1),
              ['ghost'], None),
             (set(['head', 'child', 'ghost']),
-             (set(['head', 'ghost']), 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)
+             (set(['head', 'ghost']), set([NULL_REVISION, 'ghost']), 2),
+             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)
+
+    def test_breadth_first_revision_count_includes_NULL_REVISION(self):
+        graph = self.make_graph({
+            'head':[NULL_REVISION],
+            NULL_REVISION:[],
+            })
+        search = graph._make_breadth_first_searcher(['head'])
+        # using next:
+        expected = [
+            (set(['head']),
+             (set(['head']), set([NULL_REVISION]), 1),
+             None, None),
+            (set(['head', NULL_REVISION]),
+             (set(['head']), set([]), 2),
+             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)
+
+    def test_breadth_first_search_get_recipe_after_StopIteration(self):
+        # StopIteration should not invalid anything..
+        graph = self.make_graph({
+            'head':[NULL_REVISION],
+            NULL_REVISION:[],
+            })
+        search = graph._make_breadth_first_searcher(['head'])
+        # using next:
+        expected = [
+            (set(['head']),
+             (set(['head']), set([NULL_REVISION]), 1),
+             None, None),
+            (set(['head', 'ghost', NULL_REVISION]),
+             (set(['head', 'ghost']), set(['ghost']), 2),
+             ['ghost'], None),
+            ]
+        self.assertSeenAndRecipes(expected, search, search.next)
+        self.assertRaises(StopIteration, search.next)
+        self.assertEqual(set(['head', 'ghost', NULL_REVISION]), search.seen)
+        self.assertEqual((set(['ghost', 'head']), set(['ghost']), 2),
+            search.get_recipe())
+        # using next_with_ghosts:
+        search = graph._make_breadth_first_searcher(['head'])
+        self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
+        self.assertRaises(StopIteration, search.next)
+        self.assertEqual(set(['head', 'ghost', NULL_REVISION]), search.seen)
+        self.assertEqual((set(['ghost', 'head']), set(['ghost']), 2),
+            search.get_recipe())
+
 
 
 class TestCachingParentsProvider(tests.TestCase):



More information about the bazaar-commits mailing list