Rev 2639: Implement KnitGraphIndex.get_method. in http://people.ubuntu.com/~robertc/baz2.0/repository
Robert Collins
robertc at robertcollins.net
Fri Jul 13 21:06:37 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/repository
------------------------------------------------------------
revno: 2639
revision-id: robertc at robertcollins.net-20070713200634-hvhse33adl211oa7
parent: robertc at robertcollins.net-20070713200224-0rowyzto11en8zfd
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Sat 2007-07-14 06:06:34 +1000
message:
Implement KnitGraphIndex.get_method.
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 19:00:02 +0000
+++ b/bzrlib/knit.py 2007-07-13 20:06:34 +0000
@@ -1316,12 +1316,14 @@
class KnitGraphIndex(object):
"""A knit index that builds on GraphIndex."""
- def __init__(self, graph_index):
+ def __init__(self, graph_index, deltas=False):
"""Construct a KnitGraphIndex on a graph_index.
:param graph_index: An implementation of bzrlib.index.GraphIndex.
+ :param deltas: Allow delta-compressed records.
"""
self._graph_index = graph_index
+ self._deltas = deltas
def get_ancestry(self, versions, topo_sorted=True):
"""See VersionedFile.get_ancestry."""
@@ -1397,11 +1399,12 @@
def get_method(self, version_id):
"""Return compression method of specified version."""
- fulltext = self._get_node(version_id)[2][0] == 'F'
- if fulltext:
+ if not self._deltas:
return 'fulltext'
+ if len(self._get_node(version_id)[1][1]):
+ return 'line-delta'
else:
- return 'line-delta'
+ return 'fulltext'
def _get_node(self, version_id):
return list(self._graph_index.iter_entries([version_id]))[0]
=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py 2007-07-13 19:00:02 +0000
+++ b/bzrlib/tests/test_knit.py 2007-07-13 20:06:34 +0000
@@ -1519,16 +1519,29 @@
trans.put_file(name, stream)
return GraphIndex(trans, name)
- def two_graph_index(self):
+ def two_graph_index(self, deltas=False):
+ """Build a two-graph index.
+
+ :param deltas: If true, use underlying indices with two node-ref
+ lists and 'parent' set to a delta-compressed against tail.
+ """
# build a complex graph across several indices.
- index1 = self.make_g_index('1', 1, [
- ('tip', (['parent'], ), 'F0 100'),
- ('tail', ([], ), '')])
- index2 = self.make_g_index('2', 1, [
- ('parent', (['tail', 'ghost'], ), 'L100 78'),
- ('separate', ([], ), '')])
+ if deltas:
+ index1 = self.make_g_index('1', 2, [
+ ('tip', (['parent'], [], ), ' 0 100'),
+ ('tail', ([], []), '')])
+ index2 = self.make_g_index('2', 2, [
+ ('parent', (['tail', 'ghost'], ['tail']), ' 100 78'),
+ ('separate', ([], []), '')])
+ else:
+ index1 = self.make_g_index('1', 1, [
+ ('tip', (['parent'], ), ' 0 100'),
+ ('tail', ([], ), '')])
+ index2 = self.make_g_index('2', 1, [
+ ('parent', (['tail', 'ghost'], ), ' 100 78'),
+ ('separate', ([], ), '')])
combined_index = CombinedGraphIndex([index1, index2])
- return KnitGraphIndex(combined_index)
+ return KnitGraphIndex(combined_index, deltas=deltas)
def two_graph_index_no_ghosts(self):
# build a complex graph across several indices.
@@ -1618,11 +1631,17 @@
self.assertEqual((0, 100), index.get_position('tip'))
self.assertEqual((100, 78), index.get_position('parent'))
- def test_get_method(self):
- index = self.two_graph_index()
+ def test_get_method_deltas(self):
+ index = self.two_graph_index(deltas=True)
self.assertEqual('fulltext', index.get_method('tip'))
self.assertEqual('line-delta', index.get_method('parent'))
+ def test_get_method_no_deltas(self):
+ # check that the parent-history lookup is ignored with deltas=False.
+ index = self.two_graph_index(deltas=False)
+ self.assertEqual('fulltext', index.get_method('tip'))
+ self.assertEqual('fulltext', index.get_method('parent'))
+
## --- mutating tests for later ---
#
# def test_add_version
More information about the bazaar-commits
mailing list