Rev 2628: Implement a get_graph for a new KnitGraphIndex that will implement a KnitIndex on top of the GraphIndex API. in http://people.ubuntu.com/~robertc/baz2.0/repository
Robert Collins
robertc at robertcollins.net
Fri Jul 13 16:46:57 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/repository
------------------------------------------------------------
revno: 2628
revision-id: robertc at robertcollins.net-20070713154654-5x2rsbcf5k8nt2n4
parent: robertc at robertcollins.net-20070713151747-6q0y5y1lbsw7hstn
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Sat 2007-07-14 01:46:54 +1000
message:
Implement a get_graph for a new KnitGraphIndex that will implement a KnitIndex on top of the GraphIndex API.
modified:
bzrlib/knit.py knit.py-20051212171256-f056ac8f0fbe1bd9
bzrlib/tests/test_knit.py test_knit.py-20051212171302-95d4c00dd5f11f2b
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py 2007-07-13 15:17:47 +0000
+++ b/bzrlib/knit.py 2007-07-13 15:46:54 +0000
@@ -1167,6 +1167,7 @@
self._filename, self.HEADER, mode=self._file_mode)
def get_graph(self):
+ """Return a list of the node:parents lists from this knit index."""
return [(vid, idx[4]) for vid, idx in self._cache.iteritems()]
def get_ancestry(self, versions, topo_sorted=True):
@@ -1318,6 +1319,22 @@
raise RevisionNotPresent(version_id, self._filename)
+class KnitGraphIndex(object):
+ """A knit index that builds on GraphIndex."""
+
+ def __init__(self, graph_index):
+ """Construct a KnitGraphIndex on a graph_index.
+
+ :param graph_index: An implementation of bzrlib.index.GraphIndex.
+ """
+ self._graph_index = graph_index
+
+ def get_graph(self):
+ """Return a list of the node:parents lists from this knit index."""
+ return [(key, refs[0]) for (key, refs, value) in
+ self._graph_index.iter_all_entries()]
+
+
class _KnitData(_KnitComponentFile):
"""Contents of the knit data file"""
=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py 2007-07-13 15:17:47 +0000
+++ b/bzrlib/tests/test_knit.py 2007-07-13 15:46:54 +0000
@@ -36,6 +36,7 @@
from bzrlib.index import *
from bzrlib.knit import (
KnitContent,
+ KnitGraphIndex,
KnitVersionedFile,
KnitPlainFactory,
KnitAnnotateFactory,
@@ -846,14 +847,14 @@
class KnitTests(TestCaseWithTransport):
"""Class containing knit test helper routines."""
- def make_test_knit(self, annotate=False, delay_create=False):
+ def make_test_knit(self, annotate=False, delay_create=False, index=None):
if not annotate:
factory = KnitPlainFactory()
else:
factory = None
return KnitVersionedFile('test', get_transport('.'), access_mode='w',
factory=factory, create=True,
- delay_create=delay_create)
+ delay_create=delay_create, index=index)
class BasicKnitTests(KnitTests):
@@ -1526,3 +1527,33 @@
t.put_bytes('test.kndx', '# not really a knit header\n\n')
self.assertRaises(KnitHeaderError, self.make_test_knit)
+
+
+class TestGraphIndexKnit(KnitTests):
+ """Tests for knits using a GraphIndex rather than a KnitIndex."""
+
+ def make_g_index(self, name, ref_lists=0, nodes=[]):
+ builder = GraphIndexBuilder(ref_lists)
+ for node, references, value in nodes:
+ builder.add_node(node, references, value)
+ stream = builder.finish()
+ trans = self.get_transport()
+ trans.put_file(name, stream)
+ return GraphIndex(trans, name)
+
+ def test_get_graph(self):
+ # build a complex graph across several indices.
+ index1 = self.make_g_index('1', 1, [
+ ('tip', (['parent'], ), ''),
+ ('tail', ([], ), '')])
+ index2 = self.make_g_index('2', 1, [
+ ('parent', (['tail', 'ghost'], ), ''),
+ ('separate', ([], ), '')])
+ combined_index = CombinedGraphIndex([index1, index2])
+ index = KnitGraphIndex(combined_index)
+ self.assertEqual(set([
+ ('tip', ('parent', )),
+ ('tail', ()),
+ ('parent', ('tail', 'ghost')),
+ ('separate', ()),
+ ]), set(index.get_graph()))
More information about the bazaar-commits
mailing list