Rev 2597: Trivial index reading. in http://people.ubuntu.com/~robertc/baz2.0/repository
Robert Collins
robertc at robertcollins.net
Thu Jul 12 14:43:42 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/repository
------------------------------------------------------------
revno: 2597
revision-id: robertc at robertcollins.net-20070712134339-c5vx9dbdb9n22zte
parent: robertc at robertcollins.net-20070712131738-ns8lo0xowgwvf2wo
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Thu 2007-07-12 23:43:39 +1000
message:
Trivial index reading.
modified:
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/index.py index.py-20070712131115-lolkarso50vjr64s-1
bzrlib/tests/test_errors.py test_errors.py-20060210110251-41aba2deddf936a8
bzrlib/tests/test_index.py test_index.py-20070712131115-lolkarso50vjr64s-2
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2007-07-05 22:42:07 +0000
+++ b/bzrlib/errors.py 2007-07-12 13:43:39 +0000
@@ -1552,6 +1552,16 @@
self.msg = msg
+class MissingKey(BzrError):
+
+ _fmt = "The key %(key)s is not present in %(thing)s."
+
+ def __init__(self, thing, key):
+ BzrError.__init__(self)
+ self.thing = thing
+ self.key = key
+
+
class MissingText(BzrError):
_fmt = ("Branch %(base)s is missing revision"
@@ -1564,7 +1574,6 @@
self.text_revision = text_revision
self.file_id = file_id
-
class DuplicateFileId(BzrError):
_fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py 2007-07-12 13:17:38 +0000
+++ b/bzrlib/index.py 2007-07-12 13:43:39 +0000
@@ -18,6 +18,7 @@
from cStringIO import StringIO
+from bzrlib import errors
_SIGNATURE = "Bazaar Graph Index 1\n"
@@ -27,3 +28,41 @@
def finish(self):
return StringIO(_SIGNATURE + '\n')
+
+
+class GraphIndex(object):
+ """An index for data with embedded graphs.
+
+ """
+
+ def __init__(self, transport, name):
+ """Open an index called name on transport.
+
+ :param transport: A bzrlib.transport.Transport.
+ :param name: A path to provide to transport API calls.
+ """
+ self._transport = transport
+ self._name = name
+
+ def iter_all_entries(self):
+ """Iterate over all keys within the index.
+
+ :return: An iterable of (key, reference_lists, value). There is no
+ defined order for the result iteration - it will be in the most
+ efficient order for the index.
+ """
+ return []
+
+ def iter_entries(self, keys):
+ """Iterate over keys within the index.
+
+ :param keys: An iterable providing the keys to be retrieved.
+ :return: An iterable of (key, reference_lists, value). There is no
+ defined order for the result iteration - it will be in the most
+ efficient order for the index.
+ """
+ if not keys:
+ return
+ if False:
+ yield None
+ raise errors.MissingKey(self, keys[0])
=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py 2007-07-05 22:42:07 +0000
+++ b/bzrlib/tests/test_errors.py 2007-07-12 13:43:39 +0000
@@ -93,6 +93,11 @@
" known method in options: ['bad', 'no-eol']",
str(error))
+ def test_missing_key(self):
+ error = errors.MissingKey('container', 'a key')
+ self.assertEqualDiff("The key a key is not present in container.",
+ str(error))
+
def test_medium_not_connected(self):
error = errors.MediumNotConnected("a medium")
self.assertEqualDiff(
=== modified file 'bzrlib/tests/test_index.py'
--- a/bzrlib/tests/test_index.py 2007-07-12 13:17:38 +0000
+++ b/bzrlib/tests/test_index.py 2007-07-12 13:43:39 +0000
@@ -16,7 +16,8 @@
"""Tests for indices."""
-from bzrlib.index import GraphIndexBuilder
+from bzrlib import errors
+from bzrlib.index import GraphIndexBuilder, GraphIndex
from bzrlib.tests import TestCaseWithMemoryTransport
@@ -28,3 +29,20 @@
contents = stream.read()
self.assertEqual("Bazaar Graph Index 1\n\n", contents)
+
+class TestGraphIndex(TestCaseWithMemoryTransport):
+
+ def make_index(self):
+ builder = GraphIndexBuilder()
+ stream = builder.finish()
+ trans = self.get_transport()
+ trans.put('index', stream.read())
+ return GraphIndex(trans, 'index')
+
+ def test_iter_all_entries_empty(self):
+ index = self.make_index()
+ self.assertEqual([], list(index.iter_all_entries()))
+
+ def test_iter_missing_entry_empty(self):
+ index = self.make_index()
+ self.assertRaises(errors.MissingKey, list, index.iter_entries(['a']))
More information about the bazaar-commits
mailing list