1
# Copyright (C) 2005-2013, 2016 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
from io import BytesIO
27
revision as _mod_revision,
35
from ..bundle.apply_bundle import install_bundle, merge_bundle
36
from ..bundle.bundle_data import BundleTree
37
from ..bundle.serializer import write_bundle, read_bundle, v09, v4
38
from ..bundle.serializer.v08 import BundleSerializerV08
39
from ..bundle.serializer.v09 import BundleSerializerV09
40
from ..bundle.serializer.v4 import BundleSerializerV4
41
from ..bzr import knitrepo
46
from ..transform import TreeTransform
49
def get_text(vf, key):
50
"""Get the fulltext for a given revision id that is present in the vf"""
51
stream = vf.get_record_stream([key], 'unordered', True)
53
return record.get_bytes_as('fulltext')
56
def get_inventory_text(repo, revision_id):
57
"""Get the fulltext for the inventory at revision id"""
58
with repo.lock_read():
59
return get_text(repo.inventories, (revision_id,))
62
class MockTree(object):
65
from ..bzr.inventory import InventoryDirectory, ROOT_ID
67
self.paths = {ROOT_ID: ""}
68
self.ids = {"": ROOT_ID}
70
self.root = InventoryDirectory(ROOT_ID, '', None)
72
inventory = property(lambda x: x)
73
root_inventory = property(lambda x: x)
75
def get_root_id(self):
76
return self.root.file_id
78
def all_file_ids(self):
79
return set(self.paths.keys())
81
def all_versioned_paths(self):
82
return set(self.paths.values())
84
def is_executable(self, path):
85
# Not all the files are executable.
88
def __getitem__(self, file_id):
89
if file_id == self.root.file_id:
92
return self.make_entry(file_id, self.paths[file_id])
94
def get_entry_by_path(self, path):
95
return self[self.path2id(path)]
97
def parent_id(self, file_id):
98
parent_dir = os.path.dirname(self.paths[file_id])
101
return self.ids[parent_dir]
103
def iter_entries(self):
104
for path, file_id in self.ids.items():
105
yield path, self[file_id]
107
def kind(self, path):
108
if path in self.contents:
114
def make_entry(self, file_id, path):
115
from ..bzr.inventory import (InventoryFile, InventoryDirectory,
117
if not isinstance(file_id, bytes):
118
raise TypeError(file_id)
119
name = os.path.basename(path)
120
kind = self.kind(path)
121
parent_id = self.parent_id(file_id)
122
text_sha_1, text_size = self.contents_stats(path)
123
if kind == 'directory':
124
ie = InventoryDirectory(file_id, name, parent_id)
126
ie = InventoryFile(file_id, name, parent_id)
127
ie.text_sha1 = text_sha_1
128
ie.text_size = text_size
129
elif kind == 'symlink':
130
ie = InventoryLink(file_id, name, parent_id)
132
raise errors.BzrError('unknown kind %r' % kind)
135
def add_dir(self, file_id, path):
136
if not isinstance(file_id, bytes):
137
raise TypeError(file_id)
138
self.paths[file_id] = path
139
self.ids[path] = file_id
141
def add_file(self, file_id, path, contents):
142
if not isinstance(file_id, bytes):
143
raise TypeError(file_id)
144
self.add_dir(file_id, path)
145
self.contents[path] = contents
147
def path2id(self, path):
148
return self.ids.get(path)
150
def id2path(self, file_id):
151
return self.paths.get(file_id)
153
def has_id(self, file_id):
154
return self.id2path(file_id) is not None
156
def get_file(self, path):
159
result.write(self.contents[path])
161
raise errors.NoSuchFile(path)
165
def get_file_revision(self, path):
166
return self.inventory.get_entry_by_path(path).revision
168
def get_file_size(self, path):
169
return self.inventory.get_entry_by_path(path).text_size
171
def get_file_sha1(self, path, file_id=None):
172
return self.inventory.get_entry_by_path(path).text_sha1
174
def contents_stats(self, path):
175
if path not in self.contents:
177
text_sha1 = osutils.sha_file(self.get_file(path))
178
return text_sha1, len(self.contents[path])
181
class BTreeTester(tests.TestCase):
182
"""A simple unittest tester for the BundleTree class."""
184
def make_tree_1(self):
186
mtree.add_dir(b"a", "grandparent")
187
mtree.add_dir(b"b", "grandparent/parent")
188
mtree.add_file(b"c", "grandparent/parent/file", b"Hello\n")
189
mtree.add_dir(b"d", "grandparent/alt_parent")
190
return BundleTree(mtree, b''), mtree
192
def test_renames(self):
193
"""Ensure that file renames have the proper effect on children"""
194
btree = self.make_tree_1()[0]
195
self.assertEqual(btree.old_path("grandparent"), "grandparent")
196
self.assertEqual(btree.old_path("grandparent/parent"),
197
"grandparent/parent")
198
self.assertEqual(btree.old_path("grandparent/parent/file"),
199
"grandparent/parent/file")
201
self.assertEqual(btree.id2path(b"a"), "grandparent")
202
self.assertEqual(btree.id2path(b"b"), "grandparent/parent")
203
self.assertEqual(btree.id2path(b"c"), "grandparent/parent/file")
205
self.assertEqual(btree.path2id("grandparent"), b"a")
206
self.assertEqual(btree.path2id("grandparent/parent"), b"b")
207
self.assertEqual(btree.path2id("grandparent/parent/file"), b"c")
209
self.assertIs(btree.path2id("grandparent2"), None)
210
self.assertIs(btree.path2id("grandparent2/parent"), None)
211
self.assertIs(btree.path2id("grandparent2/parent/file"), None)
213
btree.note_rename("grandparent", "grandparent2")
214
self.assertIs(btree.old_path("grandparent"), None)
215
self.assertIs(btree.old_path("grandparent/parent"), None)
216
self.assertIs(btree.old_path("grandparent/parent/file"), None)
218
self.assertEqual(btree.id2path(b"a"), "grandparent2")
219
self.assertEqual(btree.id2path(b"b"), "grandparent2/parent")
220
self.assertEqual(btree.id2path(b"c"), "grandparent2/parent/file")
222
self.assertEqual(btree.path2id("grandparent2"), b"a")
223
self.assertEqual(btree.path2id("grandparent2/parent"), b"b")
224
self.assertEqual(btree.path2id("grandparent2/parent/file"), b"c")
226
self.assertTrue(btree.path2id("grandparent") is None)
227
self.assertTrue(btree.path2id("grandparent/parent") is None)
228
self.assertTrue(btree.path2id("grandparent/parent/file") is None)
230
btree.note_rename("grandparent/parent", "grandparent2/parent2")
231
self.assertEqual(btree.id2path(b"a"), "grandparent2")
232
self.assertEqual(btree.id2path(b"b"), "grandparent2/parent2")
233
self.assertEqual(btree.id2path(b"c"), "grandparent2/parent2/file")
235
self.assertEqual(btree.path2id("grandparent2"), b"a")
236
self.assertEqual(btree.path2id("grandparent2/parent2"), b"b")
237
self.assertEqual(btree.path2id("grandparent2/parent2/file"), b"c")
239
self.assertTrue(btree.path2id("grandparent2/parent") is None)
240
self.assertTrue(btree.path2id("grandparent2/parent/file") is None)
242
btree.note_rename("grandparent/parent/file",
243
"grandparent2/parent2/file2")
244
self.assertEqual(btree.id2path(b"a"), "grandparent2")
245
self.assertEqual(btree.id2path(b"b"), "grandparent2/parent2")
246
self.assertEqual(btree.id2path(b"c"), "grandparent2/parent2/file2")
248
self.assertEqual(btree.path2id("grandparent2"), b"a")
249
self.assertEqual(btree.path2id("grandparent2/parent2"), b"b")
250
self.assertEqual(btree.path2id("grandparent2/parent2/file2"), b"c")
252
self.assertTrue(btree.path2id("grandparent2/parent2/file") is None)
254
def test_moves(self):
255
"""Ensure that file moves have the proper effect on children"""
256
btree = self.make_tree_1()[0]
257
btree.note_rename("grandparent/parent/file",
258
"grandparent/alt_parent/file")
259
self.assertEqual(btree.id2path(b"c"), "grandparent/alt_parent/file")
260
self.assertEqual(btree.path2id("grandparent/alt_parent/file"), b"c")
261
self.assertTrue(btree.path2id("grandparent/parent/file") is None)
263
def unified_diff(self, old, new):
265
diff.internal_diff("old", old, "new", new, out)
269
def make_tree_2(self):
270
btree = self.make_tree_1()[0]
271
btree.note_rename("grandparent/parent/file",
272
"grandparent/alt_parent/file")
273
self.assertTrue(btree.id2path(b"e") is None)
274
self.assertFalse(btree.is_versioned("grandparent/parent/file"))
275
btree.note_id(b"e", "grandparent/parent/file")
279
"""File/inventory adds"""
280
btree = self.make_tree_2()
281
add_patch = self.unified_diff([], [b"Extra cheese\n"])
282
btree.note_patch("grandparent/parent/file", add_patch)
283
btree.note_id(b'f', 'grandparent/parent/symlink', kind='symlink')
284
btree.note_target('grandparent/parent/symlink', 'venus')
285
self.adds_test(btree)
287
def adds_test(self, btree):
288
self.assertEqual(btree.id2path(b"e"), "grandparent/parent/file")
289
self.assertEqual(btree.path2id("grandparent/parent/file"), b"e")
290
with btree.get_file("grandparent/parent/file") as f:
291
self.assertEqual(f.read(), b"Extra cheese\n")
293
btree.get_symlink_target('grandparent/parent/symlink'), 'venus')
295
def test_adds2(self):
296
"""File/inventory adds, with patch-compatibile renames"""
297
btree = self.make_tree_2()
298
btree.contents_by_id = False
299
add_patch = self.unified_diff([b"Hello\n"], [b"Extra cheese\n"])
300
btree.note_patch("grandparent/parent/file", add_patch)
301
btree.note_id(b'f', 'grandparent/parent/symlink', kind='symlink')
302
btree.note_target('grandparent/parent/symlink', 'venus')
303
self.adds_test(btree)
305
def make_tree_3(self):
306
btree, mtree = self.make_tree_1()
307
mtree.add_file(b"e", "grandparent/parent/topping", b"Anchovies\n")
308
btree.note_rename("grandparent/parent/file",
309
"grandparent/alt_parent/file")
310
btree.note_rename("grandparent/parent/topping",
311
"grandparent/alt_parent/stopping")
314
def get_file_test(self, btree):
315
with btree.get_file(btree.id2path(b"e")) as f:
316
self.assertEqual(f.read(), b"Lemon\n")
317
with btree.get_file(btree.id2path(b"c")) as f:
318
self.assertEqual(f.read(), b"Hello\n")
320
def test_get_file(self):
321
"""Get file contents"""
322
btree = self.make_tree_3()
323
mod_patch = self.unified_diff([b"Anchovies\n"], [b"Lemon\n"])
324
btree.note_patch("grandparent/alt_parent/stopping", mod_patch)
325
self.get_file_test(btree)
327
def test_get_file2(self):
328
"""Get file contents, with patch-compatible renames"""
329
btree = self.make_tree_3()
330
btree.contents_by_id = False
331
mod_patch = self.unified_diff([], [b"Lemon\n"])
332
btree.note_patch("grandparent/alt_parent/stopping", mod_patch)
333
mod_patch = self.unified_diff([], [b"Hello\n"])
334
btree.note_patch("grandparent/alt_parent/file", mod_patch)
335
self.get_file_test(btree)
337
def test_delete(self):
339
btree = self.make_tree_1()[0]
340
with btree.get_file(btree.id2path(b"c")) as f:
341
self.assertEqual(f.read(), b"Hello\n")
342
btree.note_deletion("grandparent/parent/file")
343
self.assertTrue(btree.id2path(b"c") is None)
344
self.assertFalse(btree.is_versioned("grandparent/parent/file"))
346
def sorted_ids(self, tree):
347
ids = sorted(tree.all_file_ids())
350
def test_iteration(self):
351
"""Ensure that iteration through ids works properly"""
352
btree = self.make_tree_1()[0]
353
self.assertEqual(self.sorted_ids(btree),
354
[inventory.ROOT_ID, b'a', b'b', b'c', b'd'])
355
btree.note_deletion("grandparent/parent/file")
356
btree.note_id(b"e", "grandparent/alt_parent/fool", kind="directory")
357
btree.note_last_changed("grandparent/alt_parent/fool",
359
self.assertEqual(self.sorted_ids(btree),
360
[inventory.ROOT_ID, b'a', b'b', b'd', b'e'])
363
class BundleTester1(tests.TestCaseWithTransport):
365
def test_mismatched_bundle(self):
366
format = bzrdir.BzrDirMetaFormat1()
367
format.repository_format = knitrepo.RepositoryFormatKnit3()
368
serializer = BundleSerializerV08('0.8')
369
b = self.make_branch('.', format=format)
370
self.assertRaises(errors.IncompatibleBundleFormat, serializer.write,
371
b.repository, [], {}, BytesIO())
373
def test_matched_bundle(self):
374
"""Don't raise IncompatibleBundleFormat for knit2 and bundle0.9"""
375
format = bzrdir.BzrDirMetaFormat1()
376
format.repository_format = knitrepo.RepositoryFormatKnit3()
377
serializer = BundleSerializerV09('0.9')
378
b = self.make_branch('.', format=format)
379
serializer.write(b.repository, [], {}, BytesIO())
381
def test_mismatched_model(self):
382
"""Try copying a bundle from knit2 to knit1"""
383
format = bzrdir.BzrDirMetaFormat1()
384
format.repository_format = knitrepo.RepositoryFormatKnit3()
385
source = self.make_branch_and_tree('source', format=format)
386
source.commit('one', rev_id=b'one-id')
387
source.commit('two', rev_id=b'two-id')
389
write_bundle(source.branch.repository, b'two-id', b'null:', text,
393
format = bzrdir.BzrDirMetaFormat1()
394
format.repository_format = knitrepo.RepositoryFormatKnit1()
395
target = self.make_branch('target', format=format)
396
self.assertRaises(errors.IncompatibleRevision, install_bundle,
397
target.repository, read_bundle(text))
400
class BundleTester(object):
402
def bzrdir_format(self):
403
format = bzrdir.BzrDirMetaFormat1()
404
format.repository_format = knitrepo.RepositoryFormatKnit1()
407
def make_branch_and_tree(self, path, format=None):
409
format = self.bzrdir_format()
410
return tests.TestCaseWithTransport.make_branch_and_tree(
413
def make_branch(self, path, format=None):
415
format = self.bzrdir_format()
416
return tests.TestCaseWithTransport.make_branch(self, path, format)
418
def create_bundle_text(self, base_rev_id, rev_id):
419
bundle_txt = BytesIO()
420
rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
421
bundle_txt, format=self.format)
423
self.assertEqual(bundle_txt.readline(),
424
b'# Bazaar revision bundle v%s\n' % self.format.encode('ascii'))
425
self.assertEqual(bundle_txt.readline(), b'#\n')
427
rev = self.b1.repository.get_revision(rev_id)
428
self.assertEqual(bundle_txt.readline().decode('utf-8'),
431
return bundle_txt, rev_ids
433
def get_valid_bundle(self, base_rev_id, rev_id, checkout_dir=None):
434
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
435
Make sure that the text generated is valid, and that it
436
can be applied against the base, and generate the same information.
438
:return: The in-memory bundle
440
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
442
# This should also validate the generated bundle
443
bundle = read_bundle(bundle_txt)
444
repository = self.b1.repository
445
for bundle_rev in bundle.real_revisions:
446
# These really should have already been checked when we read the
447
# bundle, since it computes the sha1 hash for the revision, which
448
# only will match if everything is okay, but lets be explicit about
450
branch_rev = repository.get_revision(bundle_rev.revision_id)
451
for a in ('inventory_sha1', 'revision_id', 'parent_ids',
452
'timestamp', 'timezone', 'message', 'committer',
453
'parent_ids', 'properties'):
454
self.assertEqual(getattr(branch_rev, a),
455
getattr(bundle_rev, a))
456
self.assertEqual(len(branch_rev.parent_ids),
457
len(bundle_rev.parent_ids))
458
self.assertEqual(rev_ids,
459
[r.revision_id for r in bundle.real_revisions])
460
self.valid_apply_bundle(base_rev_id, bundle, checkout_dir=checkout_dir)
464
def get_invalid_bundle(self, base_rev_id, rev_id):
465
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
466
Munge the text so that it's invalid.
468
:return: The in-memory bundle
470
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
471
new_text = bundle_txt.getvalue().replace(b'executable:no',
473
bundle_txt = BytesIO(new_text)
474
bundle = read_bundle(bundle_txt)
475
self.valid_apply_bundle(base_rev_id, bundle)
478
def test_non_bundle(self):
479
self.assertRaises(errors.NotABundle,
480
read_bundle, BytesIO(b'#!/bin/sh\n'))
482
def test_malformed(self):
483
self.assertRaises(errors.BadBundle, read_bundle,
484
BytesIO(b'# Bazaar revision bundle v'))
486
def test_crlf_bundle(self):
488
read_bundle(BytesIO(b'# Bazaar revision bundle v0.8\r\n'))
489
except errors.BadBundle:
490
# It is currently permitted for bundles with crlf line endings to
491
# make read_bundle raise a BadBundle, but this should be fixed.
492
# Anything else, especially NotABundle, is an error.
495
def get_checkout(self, rev_id, checkout_dir=None):
496
"""Get a new tree, with the specified revision in it.
499
if checkout_dir is None:
500
checkout_dir = osutils.mkdtemp(prefix='test-branch-', dir='.')
502
if not os.path.exists(checkout_dir):
503
os.mkdir(checkout_dir)
504
tree = self.make_branch_and_tree(checkout_dir)
506
ancestors = write_bundle(self.b1.repository, rev_id, b'null:', s,
509
self.assertIsInstance(s.getvalue(), bytes)
510
install_bundle(tree.branch.repository, read_bundle(s))
511
for ancestor in ancestors:
512
old = self.b1.repository.revision_tree(ancestor)
513
new = tree.branch.repository.revision_tree(ancestor)
517
# Check that there aren't any inventory level changes
518
delta = new.changes_from(old)
519
self.assertFalse(delta.has_changed(),
520
'Revision %s not copied correctly.'
523
# Now check that the file contents are all correct
524
for path in old.all_versioned_paths():
526
old_file = old.get_file(path)
527
except errors.NoSuchFile:
530
old_file.read(), new.get_file(path).read())
534
if not _mod_revision.is_null(rev_id):
535
tree.branch.generate_revision_history(rev_id)
537
delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
538
self.assertFalse(delta.has_changed(),
539
'Working tree has modifications: %s' % delta)
542
def valid_apply_bundle(self, base_rev_id, info, checkout_dir=None):
543
"""Get the base revision, apply the changes, and make
544
sure everything matches the builtin branch.
546
to_tree = self.get_checkout(base_rev_id, checkout_dir=checkout_dir)
549
self._valid_apply_bundle(base_rev_id, info, to_tree)
553
def _valid_apply_bundle(self, base_rev_id, info, to_tree):
554
original_parents = to_tree.get_parent_ids()
555
repository = to_tree.branch.repository
556
original_parents = to_tree.get_parent_ids()
557
self.assertIs(repository.has_revision(base_rev_id), True)
558
for rev in info.real_revisions:
559
self.assertTrue(not repository.has_revision(rev.revision_id),
560
'Revision {%s} present before applying bundle'
562
merge_bundle(info, to_tree, True, merge.Merge3Merger, False, False)
564
for rev in info.real_revisions:
565
self.assertTrue(repository.has_revision(rev.revision_id),
566
'Missing revision {%s} after applying bundle'
569
self.assertTrue(to_tree.branch.repository.has_revision(info.target))
570
# Do we also want to verify that all the texts have been added?
572
self.assertEqual(original_parents + [info.target],
573
to_tree.get_parent_ids())
575
rev = info.real_revisions[-1]
576
base_tree = self.b1.repository.revision_tree(rev.revision_id)
577
to_tree = to_tree.branch.repository.revision_tree(rev.revision_id)
579
# TODO: make sure the target tree is identical to base tree
580
# we might also check the working tree.
582
base_files = list(base_tree.list_files())
583
to_files = list(to_tree.list_files())
584
self.assertEqual(len(base_files), len(to_files))
585
for base_file, to_file in zip(base_files, to_files):
586
self.assertEqual(base_file, to_file)
588
for path, status, kind, entry in base_files:
589
# Check that the meta information is the same
591
base_tree.get_file_size(path),
592
to_tree.get_file_size(to_tree.id2path(entry.file_id)))
594
base_tree.get_file_sha1(path, entry.file_id),
595
to_tree.get_file_sha1(to_tree.id2path(entry.file_id)))
596
# Check that the contents are the same
597
# This is pretty expensive
598
# self.assertEqual(base_tree.get_file(fileid).read(),
599
# to_tree.get_file(fileid).read())
601
def test_bundle(self):
602
self.tree1 = self.make_branch_and_tree('b1')
603
self.b1 = self.tree1.branch
605
self.build_tree_contents([('b1/one', b'one\n')])
606
self.tree1.add('one', b'one-id')
607
self.tree1.set_root_id(b'root-id')
608
self.tree1.commit('add one', rev_id=b'a@cset-0-1')
610
bundle = self.get_valid_bundle(b'null:', b'a@cset-0-1')
612
# Make sure we can handle files with spaces, tabs, other
615
'b1/with space.txt', 'b1/dir/', 'b1/dir/filein subdir.c', 'b1/dir/WithCaps.txt', 'b1/dir/ pre space', 'b1/sub/', 'b1/sub/sub/', 'b1/sub/sub/nonempty.txt'
617
self.build_tree_contents([('b1/sub/sub/emptyfile.txt', b''),
618
('b1/dir/nolastnewline.txt', b'bloop')])
619
tt = TreeTransform(self.tree1)
620
tt.new_file('executable', tt.root, [b'#!/bin/sh\n'], b'exe-1', True)
622
# have to fix length of file-id so that we can predictably rewrite
623
# a (length-prefixed) record containing it later.
624
self.tree1.add('with space.txt', b'withspace-id')
626
'dir', 'dir/filein subdir.c', 'dir/WithCaps.txt', 'dir/ pre space', 'dir/nolastnewline.txt', 'sub', 'sub/sub', 'sub/sub/nonempty.txt', 'sub/sub/emptyfile.txt'
628
self.tree1.commit('add whitespace', rev_id=b'a@cset-0-2')
630
bundle = self.get_valid_bundle(b'a@cset-0-1', b'a@cset-0-2')
632
# Check a rollup bundle
633
bundle = self.get_valid_bundle(b'null:', b'a@cset-0-2')
637
['sub/sub/nonempty.txt', 'sub/sub/emptyfile.txt', 'sub/sub'
639
tt = TreeTransform(self.tree1)
640
trans_id = tt.trans_id_tree_path('executable')
641
tt.set_executability(False, trans_id)
643
self.tree1.commit('removed', rev_id=b'a@cset-0-3')
645
bundle = self.get_valid_bundle(b'a@cset-0-2', b'a@cset-0-3')
646
self.assertRaises((errors.TestamentMismatch,
647
errors.VersionedFileInvalidChecksum,
648
errors.BadBundle), self.get_invalid_bundle,
649
b'a@cset-0-2', b'a@cset-0-3')
650
# Check a rollup bundle
651
bundle = self.get_valid_bundle(b'null:', b'a@cset-0-3')
653
# Now move the directory
654
self.tree1.rename_one('dir', 'sub/dir')
655
self.tree1.commit('rename dir', rev_id=b'a@cset-0-4')
657
bundle = self.get_valid_bundle(b'a@cset-0-3', b'a@cset-0-4')
658
# Check a rollup bundle
659
bundle = self.get_valid_bundle(b'null:', b'a@cset-0-4')
662
with open('b1/sub/dir/WithCaps.txt', 'ab') as f:
663
f.write(b'\nAdding some text\n')
664
with open('b1/sub/dir/ pre space', 'ab') as f:
666
b'\r\nAdding some\r\nDOS format lines\r\n')
667
with open('b1/sub/dir/nolastnewline.txt', 'ab') as f:
669
self.tree1.rename_one('sub/dir/ pre space',
671
self.tree1.commit('Modified files', rev_id=b'a@cset-0-5')
672
bundle = self.get_valid_bundle(b'a@cset-0-4', b'a@cset-0-5')
674
self.tree1.rename_one('sub/dir/WithCaps.txt', 'temp')
675
self.tree1.rename_one('with space.txt', 'WithCaps.txt')
676
self.tree1.rename_one('temp', 'with space.txt')
677
self.tree1.commit(u'swap filenames', rev_id=b'a@cset-0-6',
679
bundle = self.get_valid_bundle(b'a@cset-0-5', b'a@cset-0-6')
680
other = self.get_checkout(b'a@cset-0-5')
681
tree1_inv = get_inventory_text(self.tree1.branch.repository,
683
tree2_inv = get_inventory_text(other.branch.repository,
685
self.assertEqualDiff(tree1_inv, tree2_inv)
686
other.rename_one('sub/dir/nolastnewline.txt', 'sub/nolastnewline.txt')
687
other.commit('rename file', rev_id=b'a@cset-0-6b')
688
self.tree1.merge_from_branch(other.branch)
689
self.tree1.commit(u'Merge', rev_id=b'a@cset-0-7',
691
bundle = self.get_valid_bundle(b'a@cset-0-6', b'a@cset-0-7')
693
def _test_symlink_bundle(self, link_name, link_target, new_link_target):
696
self.requireFeature(features.SymlinkFeature)
697
self.tree1 = self.make_branch_and_tree('b1')
698
self.b1 = self.tree1.branch
700
tt = TreeTransform(self.tree1)
701
tt.new_symlink(link_name, tt.root, link_target, link_id)
703
self.tree1.commit('add symlink', rev_id=b'l@cset-0-1')
704
bundle = self.get_valid_bundle(b'null:', b'l@cset-0-1')
705
if getattr(bundle, 'revision_tree', None) is not None:
706
# Not all bundle formats supports revision_tree
707
bund_tree = bundle.revision_tree(self.b1.repository, b'l@cset-0-1')
709
link_target, bund_tree.get_symlink_target(link_name))
711
tt = TreeTransform(self.tree1)
712
trans_id = tt.trans_id_tree_path(link_name)
713
tt.adjust_path('link2', tt.root, trans_id)
714
tt.delete_contents(trans_id)
715
tt.create_symlink(new_link_target, trans_id)
717
self.tree1.commit('rename and change symlink', rev_id=b'l@cset-0-2')
718
bundle = self.get_valid_bundle(b'l@cset-0-1', b'l@cset-0-2')
719
if getattr(bundle, 'revision_tree', None) is not None:
720
# Not all bundle formats supports revision_tree
721
bund_tree = bundle.revision_tree(self.b1.repository, b'l@cset-0-2')
722
self.assertEqual(new_link_target,
723
bund_tree.get_symlink_target('link2'))
725
tt = TreeTransform(self.tree1)
726
trans_id = tt.trans_id_tree_path('link2')
727
tt.delete_contents(trans_id)
728
tt.create_symlink('jupiter', trans_id)
730
self.tree1.commit('just change symlink target', rev_id=b'l@cset-0-3')
731
bundle = self.get_valid_bundle(b'l@cset-0-2', b'l@cset-0-3')
733
tt = TreeTransform(self.tree1)
734
trans_id = tt.trans_id_tree_path('link2')
735
tt.delete_contents(trans_id)
737
self.tree1.commit('Delete symlink', rev_id=b'l@cset-0-4')
738
bundle = self.get_valid_bundle(b'l@cset-0-3', b'l@cset-0-4')
740
def test_symlink_bundle(self):
741
self._test_symlink_bundle('link', 'bar/foo', 'mars')
743
def test_unicode_symlink_bundle(self):
744
self.requireFeature(features.UnicodeFilenameFeature)
745
self._test_symlink_bundle(u'\N{Euro Sign}link',
746
u'bar/\N{Euro Sign}foo',
747
u'mars\N{Euro Sign}')
749
def test_binary_bundle(self):
750
self.tree1 = self.make_branch_and_tree('b1')
751
self.b1 = self.tree1.branch
752
tt = TreeTransform(self.tree1)
755
tt.new_file('file', tt.root, [
756
b'\x00\n\x00\r\x01\n\x02\r\xff'], b'binary-1')
757
tt.new_file('file2', tt.root, [b'\x01\n\x02\r\x03\n\x04\r\xff'],
760
self.tree1.commit('add binary', rev_id=b'b@cset-0-1')
761
self.get_valid_bundle(b'null:', b'b@cset-0-1')
764
tt = TreeTransform(self.tree1)
765
trans_id = tt.trans_id_tree_path('file')
766
tt.delete_contents(trans_id)
768
self.tree1.commit('delete binary', rev_id=b'b@cset-0-2')
769
self.get_valid_bundle(b'b@cset-0-1', b'b@cset-0-2')
772
tt = TreeTransform(self.tree1)
773
trans_id = tt.trans_id_tree_path('file2')
774
tt.adjust_path('file3', tt.root, trans_id)
775
tt.delete_contents(trans_id)
776
tt.create_file([b'file\rcontents\x00\n\x00'], trans_id)
778
self.tree1.commit('rename and modify binary', rev_id=b'b@cset-0-3')
779
self.get_valid_bundle(b'b@cset-0-2', b'b@cset-0-3')
782
tt = TreeTransform(self.tree1)
783
trans_id = tt.trans_id_tree_path('file3')
784
tt.delete_contents(trans_id)
785
tt.create_file([b'\x00file\rcontents'], trans_id)
787
self.tree1.commit('just modify binary', rev_id=b'b@cset-0-4')
788
self.get_valid_bundle(b'b@cset-0-3', b'b@cset-0-4')
791
self.get_valid_bundle(b'null:', b'b@cset-0-4')
793
def test_last_modified(self):
794
self.tree1 = self.make_branch_and_tree('b1')
795
self.b1 = self.tree1.branch
796
tt = TreeTransform(self.tree1)
797
tt.new_file('file', tt.root, [b'file'], b'file')
799
self.tree1.commit('create file', rev_id=b'a@lmod-0-1')
801
tt = TreeTransform(self.tree1)
802
trans_id = tt.trans_id_tree_path('file')
803
tt.delete_contents(trans_id)
804
tt.create_file([b'file2'], trans_id)
806
self.tree1.commit('modify text', rev_id=b'a@lmod-0-2a')
808
other = self.get_checkout(b'a@lmod-0-1')
809
tt = TreeTransform(other)
810
trans_id = tt.trans_id_tree_path('file2')
811
tt.delete_contents(trans_id)
812
tt.create_file([b'file2'], trans_id)
814
other.commit('modify text in another tree', rev_id=b'a@lmod-0-2b')
815
self.tree1.merge_from_branch(other.branch)
816
self.tree1.commit(u'Merge', rev_id=b'a@lmod-0-3',
818
self.tree1.commit(u'Merge', rev_id=b'a@lmod-0-4')
819
bundle = self.get_valid_bundle(b'a@lmod-0-2a', b'a@lmod-0-4')
821
def test_hide_history(self):
822
self.tree1 = self.make_branch_and_tree('b1')
823
self.b1 = self.tree1.branch
825
with open('b1/one', 'wb') as f:
827
self.tree1.add('one')
828
self.tree1.commit('add file', rev_id=b'a@cset-0-1')
829
with open('b1/one', 'wb') as f:
831
self.tree1.commit('modify', rev_id=b'a@cset-0-2')
832
with open('b1/one', 'wb') as f:
834
self.tree1.commit('modify', rev_id=b'a@cset-0-3')
835
bundle_file = BytesIO()
836
rev_ids = write_bundle(self.tree1.branch.repository, b'a@cset-0-3',
837
b'a@cset-0-1', bundle_file, format=self.format)
838
self.assertNotContainsRe(bundle_file.getvalue(), b'\btwo\b')
839
self.assertContainsRe(self.get_raw(bundle_file), b'one')
840
self.assertContainsRe(self.get_raw(bundle_file), b'three')
842
def test_bundle_same_basis(self):
843
"""Ensure using the basis as the target doesn't cause an error"""
844
self.tree1 = self.make_branch_and_tree('b1')
845
self.tree1.commit('add file', rev_id=b'a@cset-0-1')
846
bundle_file = BytesIO()
847
rev_ids = write_bundle(self.tree1.branch.repository, b'a@cset-0-1',
848
b'a@cset-0-1', bundle_file)
851
def get_raw(bundle_file):
852
return bundle_file.getvalue()
854
def test_unicode_bundle(self):
855
self.requireFeature(features.UnicodeFilenameFeature)
856
# Handle international characters
858
f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
860
self.tree1 = self.make_branch_and_tree('b1')
861
self.b1 = self.tree1.branch
864
u'With international man of mystery\n'
865
u'William Dod\xe9\n').encode('utf-8'))
868
self.tree1.add([u'with Dod\N{Euro Sign}'], [b'withdod-id'])
869
self.tree1.commit(u'i18n commit from William Dod\xe9',
870
rev_id=b'i18n-1', committer=u'William Dod\xe9')
873
bundle = self.get_valid_bundle(b'null:', b'i18n-1')
876
f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
877
f.write(u'Modified \xb5\n'.encode('utf8'))
879
self.tree1.commit(u'modified', rev_id=b'i18n-2')
881
bundle = self.get_valid_bundle(b'i18n-1', b'i18n-2')
884
self.tree1.rename_one(u'with Dod\N{Euro Sign}', u'B\N{Euro Sign}gfors')
885
self.tree1.commit(u'renamed, the new i18n man', rev_id=b'i18n-3',
886
committer=u'Erik B\xe5gfors')
888
bundle = self.get_valid_bundle(b'i18n-2', b'i18n-3')
891
self.tree1.remove([u'B\N{Euro Sign}gfors'])
892
self.tree1.commit(u'removed', rev_id=b'i18n-4')
894
bundle = self.get_valid_bundle(b'i18n-3', b'i18n-4')
897
bundle = self.get_valid_bundle(b'null:', b'i18n-4')
899
def test_whitespace_bundle(self):
900
if sys.platform in ('win32', 'cygwin'):
901
raise tests.TestSkipped('Windows doesn\'t support filenames'
902
' with tabs or trailing spaces')
903
self.tree1 = self.make_branch_and_tree('b1')
904
self.b1 = self.tree1.branch
906
self.build_tree(['b1/trailing space '])
907
self.tree1.add(['trailing space '])
908
# TODO: jam 20060701 Check for handling files with '\t' characters
909
# once we actually support them
912
self.tree1.commit('funky whitespace', rev_id=b'white-1')
914
bundle = self.get_valid_bundle(b'null:', b'white-1')
917
with open('b1/trailing space ', 'ab') as f:
918
f.write(b'add some text\n')
919
self.tree1.commit('add text', rev_id=b'white-2')
921
bundle = self.get_valid_bundle(b'white-1', b'white-2')
924
self.tree1.rename_one('trailing space ', ' start and end space ')
925
self.tree1.commit('rename', rev_id=b'white-3')
927
bundle = self.get_valid_bundle(b'white-2', b'white-3')
930
self.tree1.remove([' start and end space '])
931
self.tree1.commit('removed', rev_id=b'white-4')
933
bundle = self.get_valid_bundle(b'white-3', b'white-4')
935
# Now test a complet roll-up
936
bundle = self.get_valid_bundle(b'null:', b'white-4')
938
def test_alt_timezone_bundle(self):
939
self.tree1 = self.make_branch_and_memory_tree('b1')
940
self.b1 = self.tree1.branch
941
builder = treebuilder.TreeBuilder()
943
self.tree1.lock_write()
944
builder.start_tree(self.tree1)
945
builder.build(['newfile'])
946
builder.finish_tree()
948
# Asia/Colombo offset = 5 hours 30 minutes
949
self.tree1.commit('non-hour offset timezone', rev_id=b'tz-1',
950
timezone=19800, timestamp=1152544886.0)
952
bundle = self.get_valid_bundle(b'null:', b'tz-1')
954
rev = bundle.revisions[0]
955
self.assertEqual('Mon 2006-07-10 20:51:26.000000000 +0530', rev.date)
956
self.assertEqual(19800, rev.timezone)
957
self.assertEqual(1152544886.0, rev.timestamp)
960
def test_bundle_root_id(self):
961
self.tree1 = self.make_branch_and_tree('b1')
962
self.b1 = self.tree1.branch
963
self.tree1.commit('message', rev_id=b'revid1')
964
bundle = self.get_valid_bundle(b'null:', b'revid1')
965
tree = self.get_bundle_tree(bundle, b'revid1')
966
root_revision = tree.get_file_revision(u'')
967
self.assertEqual(b'revid1', root_revision)
969
def test_install_revisions(self):
970
self.tree1 = self.make_branch_and_tree('b1')
971
self.b1 = self.tree1.branch
972
self.tree1.commit('message', rev_id=b'rev2a')
973
bundle = self.get_valid_bundle(b'null:', b'rev2a')
974
branch2 = self.make_branch('b2')
975
self.assertFalse(branch2.repository.has_revision(b'rev2a'))
976
target_revision = bundle.install_revisions(branch2.repository)
977
self.assertTrue(branch2.repository.has_revision(b'rev2a'))
978
self.assertEqual(b'rev2a', target_revision)
980
def test_bundle_empty_property(self):
981
"""Test serializing revision properties with an empty value."""
982
tree = self.make_branch_and_memory_tree('tree')
984
self.addCleanup(tree.unlock)
985
tree.add([''], [b'TREE_ROOT'])
986
tree.commit('One', revprops={u'one': 'two',
987
u'empty': ''}, rev_id=b'rev1')
988
self.b1 = tree.branch
989
bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
990
bundle = read_bundle(bundle_sio)
991
revision_info = bundle.revisions[0]
992
self.assertEqual(b'rev1', revision_info.revision_id)
993
rev = revision_info.as_revision()
994
self.assertEqual({'branch-nick': 'tree', 'empty': '', 'one': 'two'},
997
def test_bundle_sorted_properties(self):
998
"""For stability the writer should write properties in sorted order."""
999
tree = self.make_branch_and_memory_tree('tree')
1001
self.addCleanup(tree.unlock)
1003
tree.add([''], [b'TREE_ROOT'])
1004
tree.commit('One', rev_id=b'rev1',
1005
revprops={u'a': '4', u'b': '3', u'c': '2', u'd': '1'})
1006
self.b1 = tree.branch
1007
bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
1008
bundle = read_bundle(bundle_sio)
1009
revision_info = bundle.revisions[0]
1010
self.assertEqual(b'rev1', revision_info.revision_id)
1011
rev = revision_info.as_revision()
1012
self.assertEqual({'branch-nick': 'tree', 'a': '4', 'b': '3', 'c': '2',
1013
'd': '1'}, rev.properties)
1015
def test_bundle_unicode_properties(self):
1016
"""We should be able to round trip a non-ascii property."""
1017
tree = self.make_branch_and_memory_tree('tree')
1019
self.addCleanup(tree.unlock)
1021
tree.add([''], [b'TREE_ROOT'])
1022
# Revisions themselves do not require anything about revision property
1023
# keys, other than that they are a basestring, and do not contain
1025
# However, Testaments assert than they are str(), and thus should not
1027
tree.commit('One', rev_id=b'rev1',
1028
revprops={u'omega': u'\u03a9', u'alpha': u'\u03b1'})
1029
self.b1 = tree.branch
1030
bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
1031
bundle = read_bundle(bundle_sio)
1032
revision_info = bundle.revisions[0]
1033
self.assertEqual(b'rev1', revision_info.revision_id)
1034
rev = revision_info.as_revision()
1035
self.assertEqual({'branch-nick': 'tree', 'omega': u'\u03a9',
1036
'alpha': u'\u03b1'}, rev.properties)
1038
def test_bundle_with_ghosts(self):
1039
tree = self.make_branch_and_tree('tree')
1040
self.b1 = tree.branch
1041
self.build_tree_contents([('tree/file', b'content1')])
1044
self.build_tree_contents([('tree/file', b'content2')])
1045
tree.add_parent_tree_id(b'ghost')
1046
tree.commit('rev2', rev_id=b'rev2')
1047
bundle = self.get_valid_bundle(b'null:', b'rev2')
1049
def make_simple_tree(self, format=None):
1050
tree = self.make_branch_and_tree('b1', format=format)
1051
self.b1 = tree.branch
1052
self.build_tree(['b1/file'])
1056
def test_across_serializers(self):
1057
tree = self.make_simple_tree('knit')
1058
tree.commit('hello', rev_id=b'rev1')
1059
tree.commit('hello', rev_id=b'rev2')
1060
bundle = read_bundle(self.create_bundle_text(b'null:', b'rev2')[0])
1061
repo = self.make_repository('repo', format='dirstate-with-subtree')
1062
bundle.install_revisions(repo)
1063
inv_text = repo._get_inventory_xml(b'rev2')
1064
self.assertNotContainsRe(inv_text, b'format="5"')
1065
self.assertContainsRe(inv_text, b'format="7"')
1067
def make_repo_with_installed_revisions(self):
1068
tree = self.make_simple_tree('knit')
1069
tree.commit('hello', rev_id=b'rev1')
1070
tree.commit('hello', rev_id=b'rev2')
1071
bundle = read_bundle(self.create_bundle_text(b'null:', b'rev2')[0])
1072
repo = self.make_repository('repo', format='dirstate-with-subtree')
1073
bundle.install_revisions(repo)
1076
def test_across_models(self):
1077
repo = self.make_repo_with_installed_revisions()
1078
inv = repo.get_inventory(b'rev2')
1079
self.assertEqual(b'rev2', inv.root.revision)
1080
root_id = inv.root.file_id
1082
self.addCleanup(repo.unlock)
1083
self.assertEqual({(root_id, b'rev1'): (),
1084
(root_id, b'rev2'): ((root_id, b'rev1'),)},
1085
repo.texts.get_parent_map([(root_id, b'rev1'), (root_id, b'rev2')]))
1087
def test_inv_hash_across_serializers(self):
1088
repo = self.make_repo_with_installed_revisions()
1089
recorded_inv_sha1 = repo.get_revision(b'rev2').inventory_sha1
1090
xml = repo._get_inventory_xml(b'rev2')
1091
self.assertEqual(osutils.sha_string(xml), recorded_inv_sha1)
1093
def test_across_models_incompatible(self):
1094
tree = self.make_simple_tree('dirstate-with-subtree')
1095
tree.commit('hello', rev_id=b'rev1')
1096
tree.commit('hello', rev_id=b'rev2')
1098
bundle = read_bundle(self.create_bundle_text(b'null:', b'rev1')[0])
1099
except errors.IncompatibleBundleFormat:
1100
raise tests.TestSkipped("Format 0.8 doesn't work with knit3")
1101
repo = self.make_repository('repo', format='knit')
1102
bundle.install_revisions(repo)
1104
bundle = read_bundle(self.create_bundle_text(b'null:', b'rev2')[0])
1105
self.assertRaises(errors.IncompatibleRevision,
1106
bundle.install_revisions, repo)
1108
def test_get_merge_request(self):
1109
tree = self.make_simple_tree()
1110
tree.commit('hello', rev_id=b'rev1')
1111
tree.commit('hello', rev_id=b'rev2')
1112
bundle = read_bundle(self.create_bundle_text(b'null:', b'rev1')[0])
1113
result = bundle.get_merge_request(tree.branch.repository)
1114
self.assertEqual((None, b'rev1', 'inapplicable'), result)
1116
def test_with_subtree(self):
1117
tree = self.make_branch_and_tree('tree',
1118
format='dirstate-with-subtree')
1119
self.b1 = tree.branch
1120
subtree = self.make_branch_and_tree('tree/subtree',
1121
format='dirstate-with-subtree')
1123
tree.commit('hello', rev_id=b'rev1')
1125
bundle = read_bundle(self.create_bundle_text(b'null:', b'rev1')[0])
1126
except errors.IncompatibleBundleFormat:
1127
raise tests.TestSkipped("Format 0.8 doesn't work with knit3")
1128
if isinstance(bundle, v09.BundleInfo09):
1129
raise tests.TestSkipped("Format 0.9 doesn't work with subtrees")
1130
repo = self.make_repository('repo', format='knit')
1131
self.assertRaises(errors.IncompatibleRevision,
1132
bundle.install_revisions, repo)
1133
repo2 = self.make_repository('repo2', format='dirstate-with-subtree')
1134
bundle.install_revisions(repo2)
1136
def test_revision_id_with_slash(self):
1137
self.tree1 = self.make_branch_and_tree('tree')
1138
self.b1 = self.tree1.branch
1140
self.tree1.commit('Revision/id/with/slashes', rev_id=b'rev/id')
1142
raise tests.TestSkipped(
1143
"Repository doesn't support revision ids with slashes")
1144
bundle = self.get_valid_bundle(b'null:', b'rev/id')
1146
def test_skip_file(self):
1147
"""Make sure we don't accidentally write to the wrong versionedfile"""
1148
self.tree1 = self.make_branch_and_tree('tree')
1149
self.b1 = self.tree1.branch
1150
# rev1 is not present in bundle, done by fetch
1151
self.build_tree_contents([('tree/file2', b'contents1')])
1152
self.tree1.add('file2', b'file2-id')
1153
self.tree1.commit('rev1', rev_id=b'reva')
1154
self.build_tree_contents([('tree/file3', b'contents2')])
1155
# rev2 is present in bundle, and done by fetch
1156
# having file1 in the bunle causes file1's versionedfile to be opened.
1157
self.tree1.add('file3', b'file3-id')
1158
rev2 = self.tree1.commit('rev2')
1159
# Updating file2 should not cause an attempt to add to file1's vf
1160
target = self.tree1.controldir.sprout('target').open_workingtree()
1161
self.build_tree_contents([('tree/file2', b'contents3')])
1162
self.tree1.commit('rev3', rev_id=b'rev3')
1163
bundle = self.get_valid_bundle(b'reva', b'rev3')
1164
if getattr(bundle, 'get_bundle_reader', None) is None:
1165
raise tests.TestSkipped('Bundle format cannot provide reader')
1167
(f, r) for b, m, k, r, f in bundle.get_bundle_reader().iter_records()
1170
{(b'file2-id', b'rev3'), (b'file3-id', rev2)}, file_ids)
1171
bundle.install_revisions(target.branch.repository)
1174
class V08BundleTester(BundleTester, tests.TestCaseWithTransport):
1178
def test_bundle_empty_property(self):
1179
"""Test serializing revision properties with an empty value."""
1180
tree = self.make_branch_and_memory_tree('tree')
1182
self.addCleanup(tree.unlock)
1183
tree.add([''], [b'TREE_ROOT'])
1184
tree.commit('One', revprops={u'one': 'two',
1185
u'empty': ''}, rev_id=b'rev1')
1186
self.b1 = tree.branch
1187
bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
1188
self.assertContainsRe(bundle_sio.getvalue(),
1190
b'# branch-nick: tree\n'
1194
bundle = read_bundle(bundle_sio)
1195
revision_info = bundle.revisions[0]
1196
self.assertEqual(b'rev1', revision_info.revision_id)
1197
rev = revision_info.as_revision()
1198
self.assertEqual({'branch-nick': 'tree', 'empty': '', 'one': 'two'},
1201
def get_bundle_tree(self, bundle, revision_id):
1202
repository = self.make_repository('repo')
1203
return bundle.revision_tree(repository, b'revid1')
1205
def test_bundle_empty_property_alt(self):
1206
"""Test serializing revision properties with an empty value.
1208
Older readers had a bug when reading an empty property.
1209
They assumed that all keys ended in ': \n'. However they would write an
1210
empty value as ':\n'. This tests make sure that all newer bzr versions
1211
can handle th second form.
1213
tree = self.make_branch_and_memory_tree('tree')
1215
self.addCleanup(tree.unlock)
1216
tree.add([''], [b'TREE_ROOT'])
1217
tree.commit('One', revprops={u'one': 'two',
1218
u'empty': ''}, rev_id=b'rev1')
1219
self.b1 = tree.branch
1220
bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
1221
txt = bundle_sio.getvalue()
1222
loc = txt.find(b'# empty: ') + len(b'# empty:')
1223
# Create a new bundle, which strips the trailing space after empty
1224
bundle_sio = BytesIO(txt[:loc] + txt[loc + 1:])
1226
self.assertContainsRe(bundle_sio.getvalue(),
1228
b'# branch-nick: tree\n'
1232
bundle = read_bundle(bundle_sio)
1233
revision_info = bundle.revisions[0]
1234
self.assertEqual(b'rev1', revision_info.revision_id)
1235
rev = revision_info.as_revision()
1236
self.assertEqual({'branch-nick': 'tree', 'empty': '', 'one': 'two'},
1239
def test_bundle_sorted_properties(self):
1240
"""For stability the writer should write properties in sorted order."""
1241
tree = self.make_branch_and_memory_tree('tree')
1243
self.addCleanup(tree.unlock)
1245
tree.add([''], [b'TREE_ROOT'])
1246
tree.commit('One', rev_id=b'rev1',
1247
revprops={u'a': '4', u'b': '3', u'c': '2', u'd': '1'})
1248
self.b1 = tree.branch
1249
bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
1250
self.assertContainsRe(bundle_sio.getvalue(),
1254
b'# branch-nick: tree\n'
1258
bundle = read_bundle(bundle_sio)
1259
revision_info = bundle.revisions[0]
1260
self.assertEqual(b'rev1', revision_info.revision_id)
1261
rev = revision_info.as_revision()
1262
self.assertEqual({'branch-nick': 'tree', 'a': '4', 'b': '3', 'c': '2',
1263
'd': '1'}, rev.properties)
1265
def test_bundle_unicode_properties(self):
1266
"""We should be able to round trip a non-ascii property."""
1267
tree = self.make_branch_and_memory_tree('tree')
1269
self.addCleanup(tree.unlock)
1271
tree.add([''], [b'TREE_ROOT'])
1272
# Revisions themselves do not require anything about revision property
1273
# keys, other than that they are a basestring, and do not contain
1275
# However, Testaments assert than they are str(), and thus should not
1277
tree.commit('One', rev_id=b'rev1',
1278
revprops={u'omega': u'\u03a9', u'alpha': u'\u03b1'})
1279
self.b1 = tree.branch
1280
bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
1281
self.assertContainsRe(bundle_sio.getvalue(),
1283
b'# alpha: \xce\xb1\n'
1284
b'# branch-nick: tree\n'
1285
b'# omega: \xce\xa9\n'
1287
bundle = read_bundle(bundle_sio)
1288
revision_info = bundle.revisions[0]
1289
self.assertEqual(b'rev1', revision_info.revision_id)
1290
rev = revision_info.as_revision()
1291
self.assertEqual({'branch-nick': 'tree', 'omega': u'\u03a9',
1292
'alpha': u'\u03b1'}, rev.properties)
1295
class V09BundleKnit2Tester(V08BundleTester):
1299
def bzrdir_format(self):
1300
format = bzrdir.BzrDirMetaFormat1()
1301
format.repository_format = knitrepo.RepositoryFormatKnit3()
1305
class V09BundleKnit1Tester(V08BundleTester):
1309
def bzrdir_format(self):
1310
format = bzrdir.BzrDirMetaFormat1()
1311
format.repository_format = knitrepo.RepositoryFormatKnit1()
1315
class V4BundleTester(BundleTester, tests.TestCaseWithTransport):
1319
def get_valid_bundle(self, base_rev_id, rev_id, checkout_dir=None):
1320
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
1321
Make sure that the text generated is valid, and that it
1322
can be applied against the base, and generate the same information.
1324
:return: The in-memory bundle
1326
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
1328
# This should also validate the generated bundle
1329
bundle = read_bundle(bundle_txt)
1330
repository = self.b1.repository
1331
for bundle_rev in bundle.real_revisions:
1332
# These really should have already been checked when we read the
1333
# bundle, since it computes the sha1 hash for the revision, which
1334
# only will match if everything is okay, but lets be explicit about
1336
branch_rev = repository.get_revision(bundle_rev.revision_id)
1337
for a in ('inventory_sha1', 'revision_id', 'parent_ids',
1338
'timestamp', 'timezone', 'message', 'committer',
1339
'parent_ids', 'properties'):
1340
self.assertEqual(getattr(branch_rev, a),
1341
getattr(bundle_rev, a))
1342
self.assertEqual(len(branch_rev.parent_ids),
1343
len(bundle_rev.parent_ids))
1344
self.assertEqual(set(rev_ids),
1345
{r.revision_id for r in bundle.real_revisions})
1346
self.valid_apply_bundle(base_rev_id, bundle,
1347
checkout_dir=checkout_dir)
1351
def get_invalid_bundle(self, base_rev_id, rev_id):
1352
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
1353
Munge the text so that it's invalid.
1355
:return: The in-memory bundle
1357
from ..bundle import serializer
1358
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
1359
new_text = self.get_raw(BytesIO(b''.join(bundle_txt)))
1360
new_text = new_text.replace(b'<file file_id="exe-1"',
1361
b'<file executable="y" file_id="exe-1"')
1362
new_text = new_text.replace(b'B260', b'B275')
1363
bundle_txt = BytesIO()
1364
bundle_txt.write(serializer._get_bundle_header('4'))
1365
bundle_txt.write(b'\n')
1366
bundle_txt.write(bz2.compress(new_text))
1368
bundle = read_bundle(bundle_txt)
1369
self.valid_apply_bundle(base_rev_id, bundle)
1372
def create_bundle_text(self, base_rev_id, rev_id):
1373
bundle_txt = BytesIO()
1374
rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
1375
bundle_txt, format=self.format)
1377
self.assertEqual(bundle_txt.readline(),
1378
b'# Bazaar revision bundle v%s\n' % self.format.encode('ascii'))
1379
self.assertEqual(bundle_txt.readline(), b'#\n')
1380
rev = self.b1.repository.get_revision(rev_id)
1382
return bundle_txt, rev_ids
1384
def get_bundle_tree(self, bundle, revision_id):
1385
repository = self.make_repository('repo')
1386
bundle.install_revisions(repository)
1387
return repository.revision_tree(revision_id)
1389
def test_creation(self):
1390
tree = self.make_branch_and_tree('tree')
1391
self.build_tree_contents([('tree/file', b'contents1\nstatic\n')])
1392
tree.add('file', b'fileid-2')
1393
tree.commit('added file', rev_id=b'rev1')
1394
self.build_tree_contents([('tree/file', b'contents2\nstatic\n')])
1395
tree.commit('changed file', rev_id=b'rev2')
1397
serializer = BundleSerializerV4('1.0')
1398
with tree.lock_read():
1399
serializer.write_bundle(
1400
tree.branch.repository, b'rev2', b'null:', s)
1402
tree2 = self.make_branch_and_tree('target')
1403
target_repo = tree2.branch.repository
1404
install_bundle(target_repo, serializer.read(s))
1405
target_repo.lock_read()
1406
self.addCleanup(target_repo.unlock)
1407
# Turn the 'iterators_of_bytes' back into simple strings for comparison
1408
repo_texts = dict((i, b''.join(content)) for i, content
1409
in target_repo.iter_files_bytes(
1410
[(b'fileid-2', b'rev1', '1'),
1411
(b'fileid-2', b'rev2', '2')]))
1412
self.assertEqual({'1': b'contents1\nstatic\n',
1413
'2': b'contents2\nstatic\n'},
1415
rtree = target_repo.revision_tree(b'rev2')
1416
inventory_vf = target_repo.inventories
1417
# If the inventory store has a graph, it must match the revision graph.
1419
[inventory_vf.get_parent_map([(b'rev2',)])[(b'rev2',)]],
1420
[None, ((b'rev1',),)])
1421
self.assertEqual('changed file',
1422
target_repo.get_revision(b'rev2').message)
1425
def get_raw(bundle_file):
1427
line = bundle_file.readline()
1428
line = bundle_file.readline()
1429
lines = bundle_file.readlines()
1430
return bz2.decompress(b''.join(lines))
1432
def test_copy_signatures(self):
1433
tree_a = self.make_branch_and_tree('tree_a')
1435
import breezy.commit as commit
1436
oldstrategy = breezy.gpg.GPGStrategy
1437
branch = tree_a.branch
1438
repo_a = branch.repository
1439
tree_a.commit("base", allow_pointless=True, rev_id=b'A')
1440
self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
1442
from ..bzr.testament import Testament
1443
# monkey patch gpg signing mechanism
1444
breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
1445
new_config = test_commit.MustSignConfig()
1446
commit.Commit(config_stack=new_config).commit(message="base",
1447
allow_pointless=True,
1449
working_tree=tree_a)
1452
return breezy.gpg.LoopbackGPGStrategy(None).sign(text)
1453
self.assertTrue(repo_a.has_signature_for_revision_id(b'B'))
1455
breezy.gpg.GPGStrategy = oldstrategy
1456
tree_b = self.make_branch_and_tree('tree_b')
1457
repo_b = tree_b.branch.repository
1459
serializer = BundleSerializerV4('4')
1460
with tree_a.lock_read():
1461
serializer.write_bundle(
1462
tree_a.branch.repository, b'B', b'null:', s)
1464
install_bundle(repo_b, serializer.read(s))
1465
self.assertTrue(repo_b.has_signature_for_revision_id(b'B'))
1466
self.assertEqual(repo_b.get_signature_text(b'B'),
1467
repo_a.get_signature_text(b'B'))
1469
# ensure repeat installs are harmless
1470
install_bundle(repo_b, serializer.read(s))
1473
class V4_2aBundleTester(V4BundleTester):
1475
def bzrdir_format(self):
1478
def get_invalid_bundle(self, base_rev_id, rev_id):
1479
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
1480
Munge the text so that it's invalid.
1482
:return: The in-memory bundle
1484
from ..bundle import serializer
1485
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
1486
new_text = self.get_raw(BytesIO(b''.join(bundle_txt)))
1487
# We are going to be replacing some text to set the executable bit on a
1488
# file. Make sure the text replacement actually works correctly.
1489
self.assertContainsRe(new_text, b'(?m)B244\n\ni 1\n<inventory')
1490
new_text = new_text.replace(b'<file file_id="exe-1"',
1491
b'<file executable="y" file_id="exe-1"')
1492
new_text = new_text.replace(b'B244', b'B259')
1493
bundle_txt = BytesIO()
1494
bundle_txt.write(serializer._get_bundle_header('4'))
1495
bundle_txt.write(b'\n')
1496
bundle_txt.write(bz2.compress(new_text))
1498
bundle = read_bundle(bundle_txt)
1499
self.valid_apply_bundle(base_rev_id, bundle)
1502
def make_merged_branch(self):
1503
builder = self.make_branch_builder('source')
1504
builder.start_series()
1505
builder.build_snapshot(None, [
1506
('add', ('', b'root-id', 'directory', None)),
1507
('add', ('file', b'file-id', 'file', b'original content\n')),
1508
], revision_id=b'a@cset-0-1')
1509
builder.build_snapshot([b'a@cset-0-1'], [
1510
('modify', ('file', b'new-content\n')),
1511
], revision_id=b'a@cset-0-2a')
1512
builder.build_snapshot([b'a@cset-0-1'], [
1513
('add', ('other-file', b'file2-id', 'file', b'file2-content\n')),
1514
], revision_id=b'a@cset-0-2b')
1515
builder.build_snapshot([b'a@cset-0-2a', b'a@cset-0-2b'], [
1516
('add', ('other-file', b'file2-id', 'file', b'file2-content\n')),
1517
], revision_id=b'a@cset-0-3')
1518
builder.finish_series()
1519
self.b1 = builder.get_branch()
1521
self.addCleanup(self.b1.unlock)
1523
def make_bundle_just_inventories(self, base_revision_id,
1527
writer = v4.BundleWriteOperation(base_revision_id, target_revision_id,
1528
self.b1.repository, sio)
1529
writer.bundle.begin()
1530
writer._add_inventory_mpdiffs_from_serializer(revision_ids)
1535
def test_single_inventory_multiple_parents_as_xml(self):
1536
self.make_merged_branch()
1537
sio = self.make_bundle_just_inventories(b'a@cset-0-1', b'a@cset-0-3',
1539
reader = v4.BundleReader(sio, stream_input=False)
1540
records = list(reader.iter_records())
1541
self.assertEqual(1, len(records))
1542
(bytes, metadata, repo_kind, revision_id,
1543
file_id) = records[0]
1544
self.assertIs(None, file_id)
1545
self.assertEqual(b'a@cset-0-3', revision_id)
1546
self.assertEqual('inventory', repo_kind)
1547
self.assertEqual({b'parents': [b'a@cset-0-2a', b'a@cset-0-2b'],
1548
b'sha1': b'09c53b0c4de0895e11a2aacc34fef60a6e70865c',
1549
b'storage_kind': b'mpdiff',
1551
# We should have an mpdiff that takes some lines from both parents.
1552
self.assertEqualDiff(
1554
b'<inventory format="10" revision_id="a@cset-0-3">\n'
1557
b'c 1 3 3 2\n', bytes)
1559
def test_single_inv_no_parents_as_xml(self):
1560
self.make_merged_branch()
1561
sio = self.make_bundle_just_inventories(b'null:', b'a@cset-0-1',
1563
reader = v4.BundleReader(sio, stream_input=False)
1564
records = list(reader.iter_records())
1565
self.assertEqual(1, len(records))
1566
(bytes, metadata, repo_kind, revision_id,
1567
file_id) = records[0]
1568
self.assertIs(None, file_id)
1569
self.assertEqual(b'a@cset-0-1', revision_id)
1570
self.assertEqual('inventory', repo_kind)
1571
self.assertEqual({b'parents': [],
1572
b'sha1': b'a13f42b142d544aac9b085c42595d304150e31a2',
1573
b'storage_kind': b'mpdiff',
1575
# We should have an mpdiff that takes some lines from both parents.
1576
self.assertEqualDiff(
1578
b'<inventory format="10" revision_id="a@cset-0-1">\n'
1579
b'<directory file_id="root-id" name=""'
1580
b' revision="a@cset-0-1" />\n'
1581
b'<file file_id="file-id" name="file" parent_id="root-id"'
1582
b' revision="a@cset-0-1"'
1583
b' text_sha1="09c2f8647e14e49e922b955c194102070597c2d1"'
1584
b' text_size="17" />\n'
1588
def test_multiple_inventories_as_xml(self):
1589
self.make_merged_branch()
1590
sio = self.make_bundle_just_inventories(b'a@cset-0-1', b'a@cset-0-3',
1591
[b'a@cset-0-2a', b'a@cset-0-2b', b'a@cset-0-3'])
1592
reader = v4.BundleReader(sio, stream_input=False)
1593
records = list(reader.iter_records())
1594
self.assertEqual(3, len(records))
1595
revision_ids = [rev_id for b, m, k, rev_id, f in records]
1596
self.assertEqual([b'a@cset-0-2a', b'a@cset-0-2b', b'a@cset-0-3'],
1598
metadata_2a = records[0][1]
1599
self.assertEqual({b'parents': [b'a@cset-0-1'],
1600
b'sha1': b'1e105886d62d510763e22885eec733b66f5f09bf',
1601
b'storage_kind': b'mpdiff',
1603
metadata_2b = records[1][1]
1604
self.assertEqual({b'parents': [b'a@cset-0-1'],
1605
b'sha1': b'f03f12574bdb5ed2204c28636c98a8547544ccd8',
1606
b'storage_kind': b'mpdiff',
1608
metadata_3 = records[2][1]
1609
self.assertEqual({b'parents': [b'a@cset-0-2a', b'a@cset-0-2b'],
1610
b'sha1': b'09c53b0c4de0895e11a2aacc34fef60a6e70865c',
1611
b'storage_kind': b'mpdiff',
1613
bytes_2a = records[0][0]
1614
self.assertEqualDiff(
1616
b'<inventory format="10" revision_id="a@cset-0-2a">\n'
1620
b'<file file_id="file-id" name="file" parent_id="root-id"'
1621
b' revision="a@cset-0-2a"'
1622
b' text_sha1="50f545ff40e57b6924b1f3174b267ffc4576e9a9"'
1623
b' text_size="12" />\n'
1625
b'c 0 3 3 1\n', bytes_2a)
1626
bytes_2b = records[1][0]
1627
self.assertEqualDiff(
1629
b'<inventory format="10" revision_id="a@cset-0-2b">\n'
1633
b'<file file_id="file2-id" name="other-file" parent_id="root-id"'
1634
b' revision="a@cset-0-2b"'
1635
b' text_sha1="b46c0c8ea1e5ef8e46fc8894bfd4752a88ec939e"'
1636
b' text_size="14" />\n'
1638
b'c 0 3 4 1\n', bytes_2b)
1639
bytes_3 = records[2][0]
1640
self.assertEqualDiff(
1642
b'<inventory format="10" revision_id="a@cset-0-3">\n'
1645
b'c 1 3 3 2\n', bytes_3)
1647
def test_creating_bundle_preserves_chk_pages(self):
1648
self.make_merged_branch()
1649
target = self.b1.controldir.sprout('target',
1650
revision_id=b'a@cset-0-2a').open_branch()
1651
bundle_txt, rev_ids = self.create_bundle_text(b'a@cset-0-2a',
1653
self.assertEqual(set([b'a@cset-0-2b', b'a@cset-0-3']), set(rev_ids))
1654
bundle = read_bundle(bundle_txt)
1656
self.addCleanup(target.unlock)
1657
install_bundle(target.repository, bundle)
1658
inv1 = next(self.b1.repository.inventories.get_record_stream([
1659
(b'a@cset-0-3',)], 'unordered',
1660
True)).get_bytes_as('fulltext')
1661
inv2 = next(target.repository.inventories.get_record_stream([
1662
(b'a@cset-0-3',)], 'unordered',
1663
True)).get_bytes_as('fulltext')
1664
self.assertEqualDiff(inv1, inv2)
1667
class MungedBundleTester(object):
1669
def build_test_bundle(self):
1670
wt = self.make_branch_and_tree('b1')
1672
self.build_tree(['b1/one'])
1674
wt.commit('add one', rev_id=b'a@cset-0-1')
1675
self.build_tree(['b1/two'])
1677
wt.commit('add two', rev_id=b'a@cset-0-2',
1678
revprops={u'branch-nick': 'test'})
1680
bundle_txt = BytesIO()
1681
rev_ids = write_bundle(wt.branch.repository, b'a@cset-0-2',
1682
b'a@cset-0-1', bundle_txt, self.format)
1683
self.assertEqual({b'a@cset-0-2'}, set(rev_ids))
1684
bundle_txt.seek(0, 0)
1687
def check_valid(self, bundle):
1688
"""Check that after whatever munging, the final object is valid."""
1689
self.assertEqual([b'a@cset-0-2'],
1690
[r.revision_id for r in bundle.real_revisions])
1692
def test_extra_whitespace(self):
1693
bundle_txt = self.build_test_bundle()
1695
# Seek to the end of the file
1696
# Adding one extra newline used to give us
1697
# TypeError: float() argument must be a string or a number
1698
bundle_txt.seek(0, 2)
1699
bundle_txt.write(b'\n')
1702
bundle = read_bundle(bundle_txt)
1703
self.check_valid(bundle)
1705
def test_extra_whitespace_2(self):
1706
bundle_txt = self.build_test_bundle()
1708
# Seek to the end of the file
1709
# Adding two extra newlines used to give us
1710
# MalformedPatches: The first line of all patches should be ...
1711
bundle_txt.seek(0, 2)
1712
bundle_txt.write(b'\n\n')
1715
bundle = read_bundle(bundle_txt)
1716
self.check_valid(bundle)
1719
class MungedBundleTesterV09(tests.TestCaseWithTransport, MungedBundleTester):
1723
def test_missing_trailing_whitespace(self):
1724
bundle_txt = self.build_test_bundle()
1726
# Remove a trailing newline, it shouldn't kill the parser
1727
raw = bundle_txt.getvalue()
1728
# The contents of the bundle don't have to be this, but this
1729
# test is concerned with the exact case where the serializer
1730
# creates a blank line at the end, and fails if that
1732
self.assertEqual(b'\n\n', raw[-2:])
1733
bundle_txt = BytesIO(raw[:-1])
1735
bundle = read_bundle(bundle_txt)
1736
self.check_valid(bundle)
1738
def test_opening_text(self):
1739
bundle_txt = self.build_test_bundle()
1741
bundle_txt = BytesIO(
1742
b"Some random\nemail comments\n" + bundle_txt.getvalue())
1744
bundle = read_bundle(bundle_txt)
1745
self.check_valid(bundle)
1747
def test_trailing_text(self):
1748
bundle_txt = self.build_test_bundle()
1750
bundle_txt = BytesIO(
1751
bundle_txt.getvalue() + b"Some trailing\nrandom\ntext\n")
1753
bundle = read_bundle(bundle_txt)
1754
self.check_valid(bundle)
1757
class MungedBundleTesterV4(tests.TestCaseWithTransport, MungedBundleTester):
1762
class TestBundleWriterReader(tests.TestCase):
1764
def test_roundtrip_record(self):
1766
writer = v4.BundleWriter(fileobj)
1768
writer.add_info_record({b'foo': b'bar'})
1769
writer._add_record(b"Record body", {b'parents': [b'1', b'3'],
1770
b'storage_kind': b'fulltext'}, 'file', b'revid', b'fileid')
1773
reader = v4.BundleReader(fileobj, stream_input=True)
1774
record_iter = reader.iter_records()
1775
record = next(record_iter)
1776
self.assertEqual((None, {b'foo': b'bar', b'storage_kind': b'header'},
1777
'info', None, None), record)
1778
record = next(record_iter)
1779
self.assertEqual((b"Record body", {b'storage_kind': b'fulltext',
1780
b'parents': [b'1', b'3']}, 'file', b'revid', b'fileid'),
1783
def test_roundtrip_record_memory_hungry(self):
1785
writer = v4.BundleWriter(fileobj)
1787
writer.add_info_record({b'foo': b'bar'})
1788
writer._add_record(b"Record body", {b'parents': [b'1', b'3'],
1789
b'storage_kind': b'fulltext'}, 'file', b'revid', b'fileid')
1792
reader = v4.BundleReader(fileobj, stream_input=False)
1793
record_iter = reader.iter_records()
1794
record = next(record_iter)
1795
self.assertEqual((None, {b'foo': b'bar', b'storage_kind': b'header'},
1796
'info', None, None), record)
1797
record = next(record_iter)
1798
self.assertEqual((b"Record body", {b'storage_kind': b'fulltext',
1799
b'parents': [b'1', b'3']}, 'file', b'revid', b'fileid'),
1802
def test_encode_name(self):
1803
self.assertEqual(b'revision/rev1',
1804
v4.BundleWriter.encode_name('revision', b'rev1'))
1805
self.assertEqual(b'file/rev//1/file-id-1',
1806
v4.BundleWriter.encode_name('file', b'rev/1', b'file-id-1'))
1807
self.assertEqual(b'info',
1808
v4.BundleWriter.encode_name('info', None, None))
1810
def test_decode_name(self):
1811
self.assertEqual(('revision', b'rev1', None),
1812
v4.BundleReader.decode_name(b'revision/rev1'))
1813
self.assertEqual(('file', b'rev/1', b'file-id-1'),
1814
v4.BundleReader.decode_name(b'file/rev//1/file-id-1'))
1815
self.assertEqual(('info', None, None),
1816
v4.BundleReader.decode_name(b'info'))
1818
def test_too_many_names(self):
1820
writer = v4.BundleWriter(fileobj)
1822
writer.add_info_record({b'foo': b'bar'})
1823
writer._container.add_bytes_record(b'blah', [(b'two', ), (b'names', )])
1826
record_iter = v4.BundleReader(fileobj).iter_records()
1827
record = next(record_iter)
1828
self.assertEqual((None, {b'foo': b'bar', b'storage_kind': b'header'},
1829
'info', None, None), record)
1830
self.assertRaises(errors.BadBundle, next, record_iter)