Rev 104: Hook things up a bit better. in http://bzr.arbash-meinel.com/branches/bzr/history_db/trunk
John Arbash Meinel
john at arbash-meinel.com
Wed Apr 21 21:46:53 BST 2010
At http://bzr.arbash-meinel.com/branches/bzr/history_db/trunk
------------------------------------------------------------
revno: 104
revision-id: john at arbash-meinel.com-20100421204645-v5g8j0e5yedx94mj
parent: john at arbash-meinel.com-20100421202914-7n1bxltjw0e42bdf
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Wed 2010-04-21 15:46:45 -0500
message:
Hook things up a bit better.
Make sure we delete the history.db file between tests (ensure isolation).
Start raising exceptions rather than silently giving bad results.
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2010-04-21 20:29:14 +0000
+++ b/__init__.py 2010-04-21 20:46:45 +0000
@@ -400,7 +400,7 @@
"""
t0 = time.clock()
query = _get_querier(self)
- if query is None:
+ 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.
trace.mutter('history_db falling back to original'
=== modified file 'history_db.py'
--- a/history_db.py 2010-04-21 20:29:14 +0000
+++ b/history_db.py 2010-04-21 20:46:45 +0000
@@ -25,6 +25,7 @@
import time
from bzrlib import (
+ errors,
lru_cache,
revision,
static_tuple,
@@ -35,6 +36,21 @@
from bzrlib.plugins.history_db import schema
+class TipNotImported(errors.BzrError):
+ """Raised when a Branch tip has not been imported.
+
+ So we can't actually give a valid response.
+ """
+
+ _fmt = ('Branch %(branch)s\'s tip revision %(revision)s has'
+ ' not been imported')
+
+ def __init__(self, branch, revision):
+ errors.BzrError.__init__(self)
+ self.branch = branch
+ self.revision = revision
+
+
NULL_PARENTS = (revision.NULL_REVISION,)
@@ -1169,6 +1185,7 @@
self._cursor = None
self._branch = a_branch
self._branch_tip_rev_id = a_branch.last_revision()
+ self._branch_tip_db_id = self._get_db_id(self._branch_tip_rev_id)
self._stats = defaultdict(lambda: 0)
def _get_cursor(self):
@@ -1180,10 +1197,13 @@
return self._cursor
def _get_db_id(self, revision_id):
- db_res = self._get_cursor().execute(
- 'SELECT db_id FROM revision'
- ' WHERE revision_id = ?',
- [revision_id]).fetchone()
+ try:
+ db_res = self._get_cursor().execute(
+ 'SELECT db_id FROM revision'
+ ' WHERE revision_id = ?',
+ [revision_id]).fetchone()
+ except dbapi2.OperationalError:
+ return None
if db_res is None:
return None
return db_res[0]
@@ -1281,8 +1301,9 @@
def get_dotted_revno_range(self, revision_id):
"""Determine the dotted revno, using the range info, etc."""
t = time.time()
- tip_db_id = self._get_db_id(self._branch_tip_rev_id)
- rev_db_id = self._get_db_id(revision_id)
+ tip_db_id = self._branch_tip_db_id
+ if tip_db_id is not None:
+ raise TipNotImported(self._branch, self._branch_tip_rev_id)
revno = None
while tip_db_id is not None:
self._stats['num_steps'] += 1
@@ -1318,7 +1339,9 @@
"""Determine the dotted revno, using the range info, etc."""
cursor = self._get_cursor()
t = time.time()
- tip_db_id = self._get_db_id(self._branch_tip_rev_id)
+ tip_db_id = self._branch_tip_db_id
+ if tip_db_id is None:
+ raise TipNotImported(self._branch, self._branch_tip_rev_id)
db_ids = set()
db_id_to_rev_id = {}
for rev_id in revision_ids:
@@ -1690,6 +1713,8 @@
"""
t = time.time()
tip_db_id = self._get_db_id(self._branch_tip_rev_id)
+ if tip_db_id is None:
+ raise ValueError('tip not imported')
if start_revision_id is not None:
start_db_id = self._get_db_id(start_revision_id)
else:
=== modified file 'test_hooks.py'
--- a/test_hooks.py 2010-04-21 20:29:14 +0000
+++ b/test_hooks.py 2010-04-21 20:46:45 +0000
@@ -16,6 +16,8 @@
"""Test the hook interfaces"""
+import os
+
from bzrlib import (
errors,
osutils,
@@ -39,11 +41,18 @@
merge_sorted = [('B', 0, (2,), False), ('A', 0, (1,), True)]
return b, merge_sorted
+ def get_history_db_path(self):
+ p = osutils.getcwd() + '/history.db'
+ def remove():
+ if os.path.isfile(p):
+ os.remove(p)
+ self.addCleanup(remove)
+ return p
+
def test__get_history_db_path(self):
b = self.make_branch('test')
self.assertIs(None, history_db._get_history_db_path(b))
- cwd = osutils.getcwd()
- history_db_path = cwd + '/history.db'
+ history_db_path = self.get_history_db_path()
b.get_config().set_user_option('history_db_path', history_db_path)
self.assertEqual(history_db_path, history_db._get_history_db_path(b))
@@ -54,8 +63,8 @@
self.assertEqual(merge_sorted,
list(history_db._history_db_iter_merge_sorted_revisions(b)))
- def test_iter_merge_sorted_not_cached(self):
- history_db_path = osutils.getcwd() + '/history.db'
+ def test_iter_merge_sorted_no_init(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)
# Without filling out the cache, it should still give correct results
@@ -64,9 +73,11 @@
# 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']))
def test_iter_merge_sorted_cached(self):
- history_db_path = osutils.getcwd() + '/history.db'
+ 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)
importer = history_db._mod_history_db.Importer(history_db_path, b)
More information about the bazaar-commits
mailing list