370
370
self.assertEqual({'rev-id-1':(['foo\n', 'bar\n'], sha1sum)}, contents)
372
372
raw_contents = list(data.read_records_iter_raw(records))
373
self.assertEqual([('rev-id-1', gz_txt)], raw_contents)
373
self.assertEqual([('rev-id-1', gz_txt, sha1sum)], raw_contents)
375
375
def test_not_enough_lines(self):
376
376
sha1sum = sha.new('foo\n').hexdigest()
388
388
# read_records_iter_raw won't detect that sort of mismatch/corruption
389
389
raw_contents = list(data.read_records_iter_raw(records))
390
self.assertEqual([('rev-id-1', gz_txt)], raw_contents)
390
self.assertEqual([('rev-id-1', gz_txt, sha1sum)], raw_contents)
392
392
def test_too_many_lines(self):
393
393
sha1sum = sha.new('foo\nbar\n').hexdigest()
406
406
# read_records_iter_raw won't detect that sort of mismatch/corruption
407
407
raw_contents = list(data.read_records_iter_raw(records))
408
self.assertEqual([('rev-id-1', gz_txt)], raw_contents)
408
self.assertEqual([('rev-id-1', gz_txt, sha1sum)], raw_contents)
410
410
def test_mismatched_version_id(self):
411
411
sha1sum = sha.new('foo\nbar\n').hexdigest()
1293
1293
self.assertEquals(origins[1], ('text-1', 'b\n'))
1294
1294
self.assertEquals(origins[2], ('text-1', 'c\n'))
1296
def _test_join_with_factories(self, k1_factory, k2_factory):
1297
k1 = make_file_knit('test1', get_transport('.'), factory=k1_factory, create=True)
1298
k1.add_lines('text-a', [], ['a1\n', 'a2\n', 'a3\n'])
1299
k1.add_lines('text-b', ['text-a'], ['a1\n', 'b2\n', 'a3\n'])
1300
k1.add_lines('text-c', [], ['c1\n', 'c2\n', 'c3\n'])
1301
k1.add_lines('text-d', ['text-c'], ['c1\n', 'd2\n', 'd3\n'])
1302
k1.add_lines('text-m', ['text-b', 'text-d'], ['a1\n', 'b2\n', 'd3\n'])
1303
k2 = make_file_knit('test2', get_transport('.'), factory=k2_factory, create=True)
1304
count = k2.join(k1, version_ids=['text-m'])
1305
self.assertEquals(count, 5)
1306
self.assertTrue(k2.has_version('text-a'))
1307
self.assertTrue(k2.has_version('text-c'))
1308
origins = k2.annotate('text-m')
1309
self.assertEquals(origins[0], ('text-a', 'a1\n'))
1310
self.assertEquals(origins[1], ('text-b', 'b2\n'))
1311
self.assertEquals(origins[2], ('text-d', 'd3\n'))
1313
def test_knit_join_plain_to_plain(self):
1314
"""Test joining a plain knit with a plain knit."""
1315
self._test_join_with_factories(KnitPlainFactory(), KnitPlainFactory())
1317
def test_knit_join_anno_to_anno(self):
1318
"""Test joining an annotated knit with an annotated knit."""
1319
self._test_join_with_factories(None, None)
1321
def test_knit_join_anno_to_plain(self):
1322
"""Test joining an annotated knit with a plain knit."""
1323
self._test_join_with_factories(None, KnitPlainFactory())
1325
def test_knit_join_plain_to_anno(self):
1326
"""Test joining a plain knit with an annotated knit."""
1327
self._test_join_with_factories(KnitPlainFactory(), None)
1329
1296
def test_reannotate(self):
1330
1297
k1 = make_file_knit('knit1', get_transport('.'),
1331
1298
factory=KnitAnnotateFactory(), create=True)
1337
1304
k2 = make_file_knit('test2', get_transport('.'),
1338
1305
factory=KnitAnnotateFactory(), create=True)
1339
k2.join(k1, version_ids=['text-b'])
1306
k2.insert_record_stream(k1.get_record_stream(k1.versions(),
1307
'unordered', False))
1342
1310
k1.add_lines('text-X', ['text-b'], ['a\n', 'b\n'])
1346
1314
k2.add_lines('text-Y', ['text-b'], ['b\n', 'c\n'])
1348
1316
# test-c will have index 3
1349
k1.join(k2, version_ids=['text-c'])
1317
k1.insert_record_stream(k2.get_record_stream(['text-c'],
1318
'unordered', False))
1351
1320
lines = k1.get_lines('text-c')
1352
1321
self.assertEquals(lines, ['z\n', 'c\n'])
1505
1474
for plan_line, expected_line in zip(plan, AB_MERGE):
1506
1475
self.assertEqual(plan_line, expected_line)
1478
class GetDataStreamTests(KnitTests):
1479
"""Tests for get_data_stream."""
1508
1481
def test_get_stream_empty(self):
1509
1482
"""Get a data stream for an empty knit file."""
1510
1483
k1 = self.make_test_knit()
1696
1669
bytes = reader_callable(length)
1697
1670
self.assertRecordContentEqual(k1, version_id, bytes)
1673
class InsertDataStreamTests(KnitTests):
1674
"""Tests for insert_data_stream."""
1699
1676
def assertKnitFilesEqual(self, knit1, knit2):
1700
1677
"""Assert that the contents of the index and data files of two knits are
1867
1844
errors.KnitDataStreamUnknown,
1868
1845
target.insert_data_stream, data_stream)
1870
def test_insert_data_stream_bug_208418(self):
1847
def test_bug_208418(self):
1871
1848
"""You can insert a stream with an incompatible format, even when:
1872
1849
* the stream has a line-delta record,
1873
1850
* whose parent is in the target, also stored as a line-delta
1897
1874
target.insert_data_stream(data_stream)
1898
1875
# No errors should have been raised.
1901
# * test that a stream of "already present version, then new version"
1902
# inserts correctly.
1877
def test_line_delta_record_into_non_delta_knit(self):
1878
# Make a data stream with a line-delta record
1879
source = self.make_test_knit(name='source', delta=True)
1880
base_lines = split_lines(TEXT_1)
1881
source.add_lines('version-1', [], base_lines)
1882
source.add_lines('version-2', ['version-1'], base_lines + ['a\n'])
1883
# The second record should be a delta.
1884
self.assertEqual('line-delta', source._index.get_method('version-2'))
1885
data_stream = source.get_data_stream(['version-1', 'version-2'])
1887
# Insert the stream into a non-delta knit.
1888
target = self.make_test_knit(name='target', delta=False)
1889
target.insert_data_stream(data_stream)
1891
# Both versions are fulltexts in the target
1892
self.assertEqual('fulltext', target._index.get_method('version-1'))
1893
self.assertEqual('fulltext', target._index.get_method('version-2'))
1896
class DataStreamTests(KnitTests):
1905
1898
def assertMadeStreamKnit(self, source_knit, versions, target_knit):
1906
1899
"""Assert that a knit made from a stream is as expected."""
2793
2786
target_knit = self.make_test_knit(name='annotated', annotate=True)
2794
2787
source_knit.add_lines("A", [], ["Foo\n"])
2795
2788
# Give the target A, so we can try to thunk across to it.
2796
target_knit.join(source_knit)
2789
target_knit.insert_record_stream(source_knit.get_record_stream(['A'],
2790
'unordered', False))
2797
2791
index, access = self.get_index_access(target_knit,
2798
2792
source_knit.get_data_stream([]))
2799
2793
raw_data = list(access.get_raw_records([(True, "A", None, None)]))[0]