Rev 105: Update rev_id=>dotted so that it also imports if necessary. in http://bzr.arbash-meinel.com/branches/bzr/history_db/trunk

John Arbash Meinel john at arbash-meinel.com
Wed Apr 21 22:07:46 BST 2010


At http://bzr.arbash-meinel.com/branches/bzr/history_db/trunk

------------------------------------------------------------
revno: 105
revision-id: john at arbash-meinel.com-20100421210738-121p9mv2tokku564
parent: john at arbash-meinel.com-20100421204645-v5g8j0e5yedx94mj
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Wed 2010-04-21 16:07:38 -0500
message:
  Update rev_id=>dotted so that it also imports if necessary.
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2010-04-21 20:46:45 +0000
+++ b/__init__.py	2010-04-21 21:07:38 +0000
@@ -400,6 +400,8 @@
     """
     t0 = time.clock()
     query = _get_querier(self)
+    if query is not None:
+        query.ensure_branch_tip()
     if query is None or query._branch_tip_db_id is None:
         # TODO: Consider other cases where we may want to fall back, like
         #       special arguments, etc that we don't handle well yet.
@@ -454,7 +456,9 @@
         return revno
     t0 = time.clock()
     query = _get_querier(self)
-    if query is None:
+    if query is not None:
+        query.ensure_branch_tip()
+    if query is None or query._branch_tip_db_id is None:
         trace.mutter('history_db falling back to original'
                      'revision_id => dotted_revno')
         return _orig_do_rev_id_to_dotted(self, revision_id)

=== modified file 'history_db.py'
--- a/history_db.py	2010-04-21 20:46:45 +0000
+++ b/history_db.py	2010-04-21 21:07:38 +0000
@@ -1188,6 +1188,25 @@
         self._branch_tip_db_id = self._get_db_id(self._branch_tip_rev_id)
         self._stats = defaultdict(lambda: 0)
 
+    def ensure_branch_tip(self):
+        """Ensure that the branch tip has been imported.
+
+        This will run Importer if it has not.
+        """
+        if self._branch_tip_db_id is not None:
+            # It has been imported
+            return
+        if self._cursor is not None:
+            self._db_conn.close()
+            self._cursor = None
+        importer = Importer(self._db_path, self._branch,
+                            tip_revision_id=self._branch_tip_rev_id,
+                            incremental=True)
+        importer.do_import()
+        self._db_conn = importer._db_conn
+        self._cursor = importer._cursor
+        self._branch_tip_db_id = self._get_db_id(self._branch_tip_rev_id)
+
     def _get_cursor(self):
         if self._cursor is not None:
             return self._cursor

=== modified file 'test_hooks.py'
--- a/test_hooks.py	2010-04-21 20:46:45 +0000
+++ b/test_hooks.py	2010-04-21 21:07:38 +0000
@@ -70,11 +70,10 @@
         # Without filling out the cache, it should still give correct results
         self.assertEqual(merge_sorted,
                 list(history_db._history_db_iter_merge_sorted_revisions(b)))
-        # TODO: It should populate the cache before running, so check that the
-        #       cache is filled
         self.assertIsNot(None, b._history_db_querier)
-        # self.assertEqual({'B': (2,)},
-        #             b._history_db_querier.get_dotted_revno_range_multi(['B']))
+        self.assertIsNot(None, b._history_db_querier._branch_tip_db_id)
+        self.assertEqual({'B': (2,)},
+                    b._history_db_querier.get_dotted_revno_range_multi(['B']))
 
     def test_iter_merge_sorted_cached(self):
         history_db_path = self.get_history_db_path()
@@ -87,3 +86,10 @@
         self.assertEqual(merge_sorted,
                 list(history_db._history_db_iter_merge_sorted_revisions(b)))
         self.assertIsNot(None, b._history_db_querier)
+
+    def test_rev_to_dotted_not_imported(self):
+        history_db_path = self.get_history_db_path()
+        b, merge_sorted = self.make_simple_history_branch()
+        b.get_config().set_user_option('history_db_path', history_db_path)
+        self.assertEqual((2,),
+                history_db._history_db_revision_id_to_dotted_revno(b, 'B'))



More information about the bazaar-commits mailing list