Rev 2619: Test missing end lines with non-empty indices. in http://people.ubuntu.com/~robertc/baz2.0/repository
Robert Collins
robertc at robertcollins.net
Fri Jul 13 11:29:25 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/repository
------------------------------------------------------------
revno: 2619
revision-id: robertc at robertcollins.net-20070713102922-v3ge2itsa8460o6i
parent: robertc at robertcollins.net-20070713092112-n7b71oko7t9pn0am
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Fri 2007-07-13 20:29:22 +1000
message:
Test missing end lines with non-empty indices.
modified:
bzrlib/index.py index.py-20070712131115-lolkarso50vjr64s-1
bzrlib/tests/test_index.py test_index.py-20070712131115-lolkarso50vjr64s-2
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py 2007-07-13 09:03:17 +0000
+++ b/bzrlib/index.py 2007-07-13 10:29:22 +0000
@@ -188,7 +188,35 @@
defined order for the result iteration - it will be in the most
efficient order for the index.
"""
- return []
+ stream = self._transport.get(self._name)
+ self._read_prefix(stream)
+ line_count = 0
+ keys_by_offset = {}
+ trailers = 0
+ pos = stream.tell()
+ for line in stream.readlines():
+ if line == '\n':
+ trailers += 1
+ continue
+ key, absent, references, value = line[:-1].split('\0')
+ keys_by_offset[pos] = (key, absent, references, value)
+ for key, absent, references, value in keys_by_offset.values():
+ yield (key, (), value)
+ if trailers != 1:
+ # there must be one line - the empty trailer line.
+ raise errors.BadIndexData(self)
+
+ def _read_prefix(self, stream):
+ signature = stream.read(len(self._signature()))
+ if not signature == self._signature():
+ raise errors.BadIndexFormatSignature(self._name, GraphIndex)
+ options_line = stream.readline()
+ if not options_line.startswith(_OPTION_NODE_REFS):
+ raise errors.BadIndexOptions(self)
+ try:
+ self.node_ref_lists = int(options_line[len(_OPTION_NODE_REFS):-1])
+ except ValueError:
+ raise errors.BadIndexOptions(self)
def iter_entries(self, keys):
"""Iterate over keys within the index.
@@ -210,21 +238,6 @@
def validate(self):
"""Validate that everything in the index can be accessed."""
- stream = self._transport.get(self._name)
- signature = stream.read(len(self._signature()))
- if not signature == self._signature():
- raise errors.BadIndexFormatSignature(self._name, GraphIndex)
- options_line = stream.readline()
- if not options_line.startswith(_OPTION_NODE_REFS):
- raise errors.BadIndexOptions(self)
- try:
- node_ref_lists = int(options_line[len(_OPTION_NODE_REFS):-1])
- except ValueError:
- raise errors.BadIndexOptions(self)
- line_count = 0
- for line in stream.readlines():
- # validate the line
- line_count += 1
- if line_count < 1:
- # there must be one line - the empty trailer line.
- raise errors.BadIndexData(self)
+ # iter_all validates completely at the moment, so just do that.
+ for node in self.iter_all_entries():
+ pass
=== modified file 'bzrlib/tests/test_index.py'
--- a/bzrlib/tests/test_index.py 2007-07-13 09:21:12 +0000
+++ b/bzrlib/tests/test_index.py 2007-07-13 10:29:22 +0000
@@ -219,7 +219,7 @@
class TestGraphIndex(TestCaseWithMemoryTransport):
def make_index(self, ref_lists=0, nodes=[]):
- builder = GraphIndexBuilder()
+ builder = GraphIndexBuilder(ref_lists)
for node, references, value in nodes:
builder.add_node(node, references, value)
stream = builder.finish()
@@ -236,6 +236,11 @@
index = self.make_index()
self.assertEqual([], list(index.iter_all_entries()))
+ def test_iter_all_entries_simple(self):
+ index = self.make_index(nodes=[('name', (), 'data')])
+ self.assertEqual([('name', (), 'data')],
+ list(index.iter_all_entries()))
+
def test_iter_nothing_empty(self):
index = self.make_index()
self.assertEqual([], list(index.iter_entries([])))
@@ -259,7 +264,7 @@
trans.put_bytes('index', new_content)
self.assertRaises(errors.BadIndexOptions, index.validate)
- def test_validate_missing_end_line(self):
+ def test_validate_missing_end_line_empty(self):
index = self.make_index(2)
trans = self.get_transport()
content = trans.get_bytes('index')
@@ -267,6 +272,14 @@
trans.put_bytes('index', content[:-1])
self.assertRaises(errors.BadIndexData, index.validate)
+ def test_validate_missing_end_line_nonempty(self):
+ index = self.make_index(2, [('key', ([], []), '')])
+ trans = self.get_transport()
+ content = trans.get_bytes('index')
+ # truncate the last byte
+ trans.put_bytes('index', content[:-1])
+ self.assertRaises(errors.BadIndexData, index.validate)
+
def test_validate_empty(self):
index = self.make_index()
index.validate()
More information about the bazaar-commits
mailing list