/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/per_repository/test_commit_builder.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
 
50
50
    def test_finish_inventory_record_iter_changes(self):
51
51
        tree = self.make_branch_and_tree(".")
52
 
        tree.lock_write()
53
 
        try:
 
52
        with tree.lock_write():
54
53
            builder = tree.branch.get_commit_builder([])
55
54
            try:
56
55
                list(builder.record_iter_changes(tree, tree.last_revision(),
57
 
                    tree.iter_changes(tree.basis_tree())))
 
56
                                                 tree.iter_changes(tree.basis_tree())))
58
57
                builder.finish_inventory()
59
58
            except:
60
59
                builder.abort()
61
60
                raise
62
61
            repo = tree.branch.repository
63
62
            repo.commit_write_group()
64
 
        finally:
65
 
            tree.unlock()
66
63
 
67
64
    def test_abort_record_iter_changes(self):
68
65
        tree = self.make_branch_and_tree(".")
69
 
        tree.lock_write()
70
 
        try:
 
66
        with tree.lock_write():
71
67
            builder = tree.branch.get_commit_builder([])
72
68
            try:
73
69
                basis = tree.basis_tree()
77
73
                builder.finish_inventory()
78
74
            finally:
79
75
                builder.abort()
80
 
        finally:
81
 
            tree.unlock()
82
76
 
83
77
    def test_commit_lossy(self):
84
78
        tree = self.make_branch_and_tree(".")
85
 
        tree.lock_write()
86
 
        try:
 
79
        with tree.lock_write():
87
80
            builder = tree.branch.get_commit_builder([], lossy=True)
88
81
            list(builder.record_iter_changes(tree, tree.last_revision(),
89
 
                tree.iter_changes(tree.basis_tree())))
 
82
                                             tree.iter_changes(tree.basis_tree())))
90
83
            builder.finish_inventory()
91
84
            rev_id = builder.commit('foo bar blah')
92
 
        finally:
93
 
            tree.unlock()
94
85
        rev = tree.branch.repository.get_revision(rev_id)
95
86
        self.assertEqual('foo bar blah', rev.message)
96
87
 
97
88
    def test_commit_message(self):
98
89
        tree = self.make_branch_and_tree(".")
99
 
        tree.lock_write()
100
 
        try:
 
90
        with tree.lock_write():
101
91
            builder = tree.branch.get_commit_builder([])
102
92
            list(builder.record_iter_changes(tree, tree.last_revision(),
103
 
                tree.iter_changes(tree.basis_tree())))
 
93
                                             tree.iter_changes(tree.basis_tree())))
104
94
            builder.finish_inventory()
105
95
            rev_id = builder.commit('foo bar blah')
106
 
        finally:
107
 
            tree.unlock()
108
96
        rev = tree.branch.repository.get_revision(rev_id)
109
97
        self.assertEqual('foo bar blah', rev.message)
110
98
 
111
99
    def test_updates_branch(self):
112
100
        tree = self.make_branch_and_tree(".")
113
 
        tree.lock_write()
114
 
        try:
 
101
        with tree.lock_write():
115
102
            builder = tree.branch.get_commit_builder([])
116
103
            list(builder.record_iter_changes(tree, tree.last_revision(),
117
 
                tree.iter_changes(tree.basis_tree())))
 
104
                                             tree.iter_changes(tree.basis_tree())))
118
105
            builder.finish_inventory()
119
106
            will_update_branch = builder.updates_branch
120
107
            rev_id = builder.commit('might update the branch')
121
 
        finally:
122
 
            tree.unlock()
123
108
        actually_updated_branch = (tree.branch.last_revision() == rev_id)
124
109
        self.assertEqual(actually_updated_branch, will_update_branch)
125
110
 
126
111
    def test_commit_with_revision_id_record_iter_changes(self):
127
112
        tree = self.make_branch_and_tree(".")
128
 
        tree.lock_write()
129
 
        try:
 
113
        with tree.lock_write():
130
114
            # use a unicode revision id to test more corner cases.
131
115
            # The repository layer is meant to handle this.
132
116
            revision_id = u'\xc8abc'.encode('utf8')
133
117
            try:
134
118
                try:
135
119
                    builder = tree.branch.get_commit_builder([],
136
 
                        revision_id=revision_id)
 
120
                                                             revision_id=revision_id)
137
121
                except errors.NonAsciiRevisionId:
138
122
                    revision_id = b'abc'
139
123
                    builder = tree.branch.get_commit_builder([],
140
 
                        revision_id=revision_id)
 
124
                                                             revision_id=revision_id)
141
125
            except repository.CannotSetRevisionId:
142
126
                # This format doesn't support supplied revision ids
143
127
                return
144
128
            self.assertFalse(builder.random_revid)
145
129
            try:
146
130
                list(builder.record_iter_changes(tree, tree.last_revision(),
147
 
                    tree.iter_changes(tree.basis_tree())))
 
131
                                                 tree.iter_changes(tree.basis_tree())))
148
132
                builder.finish_inventory()
149
133
            except:
150
134
                builder.abort()
151
135
                raise
152
136
            self.assertEqual(revision_id, builder.commit('foo bar'))
153
 
        finally:
154
 
            tree.unlock()
155
137
        self.assertTrue(tree.branch.repository.has_revision(revision_id))
156
138
        # the revision id must be set on the inventory when saving it. This
157
139
        # does not precisely test that - a repository that wants to can add it
158
140
        # on deserialisation, but thats all the current contract guarantees
159
141
        # anyway.
160
 
        self.assertEqual(revision_id,
 
142
        self.assertEqual(
 
143
            revision_id,
161
144
            tree.branch.repository.revision_tree(revision_id).get_revision_id())
162
145
 
163
146
    def test_commit_without_root_errors(self):
164
147
        tree = self.make_branch_and_tree(".")
165
 
        tree.lock_write()
166
 
        try:
 
148
        with tree.lock_write():
167
149
            builder = tree.branch.get_commit_builder([])
 
150
 
168
151
            def do_commit():
169
152
                try:
170
153
                    list(builder.record_iter_changes(
176
159
                else:
177
160
                    builder.commit("msg")
178
161
            self.assertRaises(errors.RootMissing, do_commit)
179
 
        finally:
180
 
            tree.unlock()
181
162
 
182
163
    def test_commit_unchanged_root_record_iter_changes(self):
183
164
        tree = self.make_branch_and_tree(".")
209
190
        tree.add(["foo"])
210
191
        foo_id = tree.path2id('foo')
211
192
        rev_id = tree.commit("added foo")
212
 
        tree.lock_write()
213
 
        try:
 
193
        with tree.lock_write():
214
194
            builder = tree.branch.get_commit_builder([rev_id])
215
195
            try:
216
196
                delete_change = (foo_id, ('foo', None), True, (True, False),
217
 
                    (tree.path2id(''), None), ('foo', None), ('file', None),
218
 
                    (False, None))
 
197
                                 (tree.path2id(''), None), ('foo',
 
198
                                                            None), ('file', None),
 
199
                                 (False, None))
219
200
                list(builder.record_iter_changes(tree, rev_id,
220
 
                    [delete_change]))
 
201
                                                 [delete_change]))
221
202
                self.assertEqual(("foo", None, foo_id, None),
222
 
                    builder.get_basis_delta()[0])
 
203
                                 builder.get_basis_delta()[0])
223
204
                self.assertTrue(builder.any_changes())
224
205
                builder.finish_inventory()
225
206
                rev_id2 = builder.commit('delete foo')
226
207
            except:
227
208
                builder.abort()
228
209
                raise
229
 
        finally:
230
 
            tree.unlock()
231
210
        rev_tree = builder.revision_tree()
232
211
        rev_tree.lock_read()
233
212
        self.addCleanup(rev_tree.unlock)
235
214
 
236
215
    def test_revision_tree_record_iter_changes(self):
237
216
        tree = self.make_branch_and_tree(".")
238
 
        tree.lock_write()
239
 
        try:
 
217
        with tree.lock_write():
240
218
            builder = tree.branch.get_commit_builder([])
241
219
            try:
242
220
                list(builder.record_iter_changes(tree,
243
 
                    _mod_revision.NULL_REVISION,
244
 
                    tree.iter_changes(tree.basis_tree())))
 
221
                                                 _mod_revision.NULL_REVISION,
 
222
                                                 tree.iter_changes(tree.basis_tree())))
245
223
                builder.finish_inventory()
246
224
                rev_id = builder.commit('foo bar')
247
225
            except:
252
230
            # the RevisionTree api.
253
231
            self.assertEqual(rev_id, rev_tree.get_revision_id())
254
232
            self.assertEqual((), tuple(rev_tree.get_parent_ids()))
255
 
        finally:
256
 
            tree.unlock()
257
233
 
258
234
    def test_root_entry_has_revision(self):
259
235
        # test the root revision created and put in the basis
266
242
        basis_tree = tree.basis_tree()
267
243
        basis_tree.lock_read()
268
244
        self.addCleanup(basis_tree.unlock)
269
 
        self.assertEqual(rev_id,
270
 
            basis_tree.get_file_revision(u'', basis_tree.get_root_id()))
 
245
        self.assertEqual(rev_id, basis_tree.get_file_revision(u''))
271
246
 
272
247
    def _get_revtrees(self, tree, revision_ids):
273
 
        tree.lock_read()
274
 
        try:
 
248
        with tree.lock_read():
275
249
            trees = list(tree.branch.repository.revision_trees(revision_ids))
276
250
            for _tree in trees:
277
251
                _tree.lock_read()
278
252
                self.addCleanup(_tree.unlock)
279
253
            return trees
280
 
        finally:
281
 
            tree.unlock()
282
254
 
283
255
    def test_last_modified_revision_after_commit_root_unchanged(self):
284
256
        # commiting without changing the root does not change the
299
271
 
300
272
    def _commit_check_unchanged(self, tree, name, file_id):
301
273
        rev1 = tree.commit('rev1')
302
 
        rev2 = self.mini_commit_record_iter_changes(tree, name, name, False, False)
 
274
        rev2 = self.mini_commit_record_iter_changes(
 
275
            tree, name, name, False, False)
303
276
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
304
277
        self.assertEqual(rev1, tree1.get_file_revision(name))
305
278
        self.assertEqual(rev1, tree2.get_file_revision(name))
312
285
        tree = self.make_branch_and_tree('.')
313
286
        if not tree.has_versioned_directories():
314
287
            raise tests.TestNotApplicable(
315
 
                    'Format does not support versioned directories')
 
288
                'Format does not support versioned directories')
316
289
        self.build_tree(['dir/'])
317
290
        self._add_commit_check_unchanged(tree, 'dir')
318
291
 
355
328
        try:
356
329
            tree.add_reference(subtree)
357
330
            self._commit_check_unchanged(tree, 'reference',
358
 
                subtree.get_root_id())
 
331
                                         subtree.get_root_id())
359
332
        except errors.UnsupportedOperation:
360
333
            return
361
334
 
362
335
    def _add_commit_renamed_check_changed(self, tree, name,
363
 
        expect_fs_hash=False):
 
336
                                          expect_fs_hash=False):
364
337
        def rename():
365
338
            tree.rename_one(name, 'new_' + name)
366
339
        self._add_commit_change_check_changed(tree,
367
 
                (name, 'new_' + name), rename,
368
 
            expect_fs_hash=expect_fs_hash)
 
340
                                              (name, 'new_' + name), rename,
 
341
                                              expect_fs_hash=expect_fs_hash)
369
342
 
370
343
    def _commit_renamed_check_changed(self, tree, name,
371
 
        expect_fs_hash=False):
 
344
                                      expect_fs_hash=False):
372
345
        def rename():
373
346
            tree.rename_one(name, 'new_' + name)
374
347
        self._commit_change_check_changed(tree, [name, 'new_' + name],
375
 
                rename, expect_fs_hash=expect_fs_hash)
 
348
                                          rename, expect_fs_hash=expect_fs_hash)
376
349
 
377
350
    def test_last_modified_revision_after_rename_dir_changes(self):
378
351
        # renaming a dir changes the last modified.
379
352
        tree = self.make_branch_and_tree('.')
380
353
        if not tree.has_versioned_directories():
381
354
            raise tests.TestNotApplicable(
382
 
                    'Format does not support versioned directories')
 
355
                'Format does not support versioned directories')
383
356
        self.build_tree(['dir/'])
384
357
        self._add_commit_renamed_check_changed(tree, 'dir')
385
358
 
388
361
        tree = self.make_branch_and_tree('.')
389
362
        self.build_tree(['file'])
390
363
        self._add_commit_renamed_check_changed(tree, 'file',
391
 
            expect_fs_hash=True)
 
364
                                               expect_fs_hash=True)
392
365
 
393
366
    def test_last_modified_revision_after_rename_link_changes(self):
394
367
        # renaming a link changes the last modified.
409
382
            return
410
383
 
411
384
    def _add_commit_reparent_check_changed(self, tree, name,
412
 
        expect_fs_hash=False):
 
385
                                           expect_fs_hash=False):
413
386
        self.build_tree(['newparent/'])
414
387
        tree.add(['newparent'])
 
388
 
415
389
        def reparent():
416
390
            tree.rename_one(name, 'newparent/new_' + name)
417
391
        self._add_commit_change_check_changed(
418
 
                tree, (name, 'newparent/new_' + name), reparent,
 
392
            tree, (name, 'newparent/new_' + name), reparent,
419
393
            expect_fs_hash=expect_fs_hash)
420
394
 
421
395
    def test_last_modified_revision_after_reparent_dir_changes(self):
423
397
        tree = self.make_branch_and_tree('.')
424
398
        if not tree.has_versioned_directories():
425
399
            raise tests.TestNotApplicable(
426
 
                    'Format does not support versioned directories')
 
400
                'Format does not support versioned directories')
427
401
        self.build_tree(['dir/'])
428
402
        self._add_commit_reparent_check_changed(tree, 'dir')
429
403
 
432
406
        tree = self.make_branch_and_tree('.')
433
407
        self.build_tree(['file'])
434
408
        self._add_commit_reparent_check_changed(tree, 'file',
435
 
            expect_fs_hash=True)
 
409
                                                expect_fs_hash=True)
436
410
 
437
411
    def test_last_modified_revision_after_reparent_link_changes(self):
438
412
        # reparenting a link changes the last modified.
442
416
        self._add_commit_reparent_check_changed(tree, 'link')
443
417
 
444
418
    def _add_commit_change_check_changed(self, tree, names, changer,
445
 
            expect_fs_hash=False):
 
419
                                         expect_fs_hash=False):
446
420
        tree.add([names[0]])
447
421
        self.assertTrue(tree.is_versioned(names[0]))
448
422
        self._commit_change_check_changed(
454
428
        rev1 = tree.commit('rev1')
455
429
        changer()
456
430
        rev2 = self.mini_commit_record_iter_changes(
457
 
                tree, names[0], names[1], expect_fs_hash=expect_fs_hash)
 
431
            tree, names[0], names[1], expect_fs_hash=expect_fs_hash)
458
432
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
459
433
        self.assertEqual(rev1, tree1.get_file_revision(names[0]))
460
434
        self.assertEqual(rev2, tree2.get_file_revision(names[1]))
465
439
        self.assertFileGraph(expected_graph, tree, (file_id, rev2))
466
440
 
467
441
    def mini_commit_record_iter_changes(self, tree, name, new_name,
468
 
        records_version=True, delta_against_basis=True, expect_fs_hash=False):
 
442
                                        records_version=True,
 
443
                                        delta_against_basis=True,
 
444
                                        expect_fs_hash=False):
469
445
        """Perform a miniature commit looking for record entry results.
470
446
 
471
447
        This version uses the record_iter_changes interface.
490
466
                with parent_tree.lock_read():
491
467
                    changes = list(tree.iter_changes(parent_tree))
492
468
                result = list(builder.record_iter_changes(tree, parent_ids[0],
493
 
                    changes))
 
469
                                                          changes))
494
470
                file_id = tree.path2id(new_name)
495
471
                self.assertIsNot(None, file_id)
496
472
                if isinstance(tree, inventorytree.InventoryTree):
501
477
                        tree_file_stat[0].close()
502
478
                        self.assertLength(1, result)
503
479
                        result = result[0]
504
 
                        self.assertEqual(result[:2], (file_id, new_name))
505
 
                        self.assertEqual(result[2][0], tree.get_file_sha1(new_name))
506
 
                        self.assertEqualStat(result[2][1], tree_file_stat[1])
 
480
                        self.assertEqual(result[0], new_name)
 
481
                        self.assertEqual(
 
482
                            result[1][0], tree.get_file_sha1(new_name))
 
483
                        self.assertEqualStat(result[1][1], tree_file_stat[1])
507
484
                    else:
508
485
                        self.assertEqual([], result)
509
486
                builder.finish_inventory()
510
487
                if tree.branch.repository._format.supports_full_versioned_files:
511
488
                    inv_key = (builder._new_revision_id,)
512
489
                    inv_sha1 = tree.branch.repository.inventories.get_sha1s(
513
 
                                    [inv_key])[inv_key]
 
490
                        [inv_key])[inv_key]
514
491
                    self.assertEqual(inv_sha1, builder.inv_sha1)
515
492
                rev2 = builder.commit('rev2')
516
493
            except BaseException:
519
496
            delta = builder.get_basis_delta()
520
497
            delta_dict = dict((change[2], change) for change in delta)
521
498
            if tree.branch.repository._format.records_per_file_revision:
522
 
                version_recorded = (file_id in delta_dict and
523
 
                    delta_dict[file_id][3] is not None and
524
 
                    delta_dict[file_id][3].revision == rev2)
 
499
                version_recorded = (file_id in delta_dict
 
500
                                    and delta_dict[file_id][3] is not None
 
501
                                    and delta_dict[file_id][3].revision == rev2)
525
502
                if records_version:
526
503
                    self.assertTrue(version_recorded)
527
504
                else:
528
505
                    self.assertFalse(version_recorded)
529
506
 
530
507
            revtree = builder.revision_tree()
531
 
            new_entry = next(revtree.iter_entries_by_dir(specific_files=[new_name]))[1]
 
508
            new_entry = next(revtree.iter_entries_by_dir(
 
509
                specific_files=[new_name]))[1]
532
510
 
533
511
            if delta_against_basis:
534
512
                if tree.supports_rename_tracking() or name == new_name:
555
533
        # altering a file changes the last modified.
556
534
        tree = self.make_branch_and_tree('.')
557
535
        self.build_tree(['file'])
 
536
 
558
537
        def change_file():
559
538
            tree.put_file_bytes_non_atomic('file', b'new content')
560
539
        self._add_commit_change_check_changed(tree, ('file', 'file'), change_file,
561
 
            expect_fs_hash=True)
 
540
                                              expect_fs_hash=True)
562
541
 
563
542
    def _test_last_mod_rev_after_content_link_changes(
564
 
        self, link, target, newtarget):
 
543
            self, link, target, newtarget):
565
544
        # changing a link changes the last modified.
566
545
        self.requireFeature(features.SymlinkFeature)
567
546
        tree = self.make_branch_and_tree('.')
568
547
        os.symlink(target, link)
 
548
 
569
549
        def change_link():
570
550
            os.unlink(link)
571
551
            os.symlink(newtarget, link)
599
579
        rev2 = self._rename_in_tree(tree1, name, 'rev2')
600
580
        rev3 = self._rename_in_tree(tree2, name, 'rev3')
601
581
        tree1.merge_from_branch(tree2.branch)
602
 
        rev4 = self.mini_commit_record_iter_changes(tree1, 'new_' + name, 'new_' + name,
 
582
        rev4 = self.mini_commit_record_iter_changes(
 
583
            tree1, 'new_' + name, 'new_' + name,
603
584
            expect_fs_hash=expect_fs_hash,
604
585
            delta_against_basis=tree1.supports_rename_tracking())
605
586
        tree3, = self._get_revtrees(tree1, [rev4])
609
590
            expected_graph[(file_id, rev1)] = ()
610
591
            expected_graph[(file_id, rev2)] = ((file_id, rev1),)
611
592
            expected_graph[(file_id, rev3)] = ((file_id, rev1),)
612
 
            expected_graph[(file_id, rev4)] = ((file_id, rev2), (file_id, rev3),)
 
593
            expected_graph[(file_id, rev4)] = (
 
594
                (file_id, rev2), (file_id, rev3),)
613
595
        else:
614
596
            self.assertEqual(rev2, tree3.get_file_revision('new_' + name))
615
597
            expected_graph[(file_id, rev4)] = ()
620
602
        tree1 = self.make_branch_and_tree('t1')
621
603
        if not tree1.has_versioned_directories():
622
604
            raise tests.TestNotApplicable(
623
 
                    'Format does not support versioned directories')
 
605
                'Format does not support versioned directories')
624
606
        self.build_tree(['t1/dir/'])
625
607
        self._commit_sprout_rename_merge(tree1, 'dir')
626
608
 
648
630
        # change on the other side to merge back
649
631
        rev2 = self._rename_in_tree(tree2, name, 'rev2')
650
632
        tree1.merge_from_branch(tree2.branch)
 
633
 
651
634
        def _check_graph(in_tree, changed_in_tree):
652
635
            rev3 = self.mini_commit_record_iter_changes(
653
 
                    in_tree, name, 'new_' + name, False,
654
 
                    delta_against_basis=changed_in_tree)
 
636
                in_tree, name, 'new_' + name, False,
 
637
                delta_against_basis=changed_in_tree)
655
638
            tree3, = self._get_revtrees(in_tree, [rev2])
656
 
            self.assertEqual(
657
 
                    rev2,
658
 
                    tree3.get_file_revision('new_' + name, file_id))
 
639
            self.assertEqual(rev2, tree3.get_file_revision('new_' + name))
659
640
            expected_graph = {}
660
641
            expected_graph[(file_id, rev1)] = ()
661
642
            expected_graph[(file_id, rev2)] = ((file_id, rev1),)
695
676
        tree1 = self.make_branch_and_tree('t1')
696
677
        if not tree1.has_versioned_directories():
697
678
            raise tests.TestNotApplicable(
698
 
                    'Format does not support versioned directories')
 
679
                'Format does not support versioned directories')
699
680
        self.build_tree(['t1/dir/'])
700
681
        self._commit_sprout_rename_merge_converged(tree1, 'dir')
701
682
 
717
698
        tree1 = self.make_branch_and_tree('t1')
718
699
        if not tree1.has_versioned_directories():
719
700
            raise tests.TestNotApplicable(
720
 
                    'Format does not support versioned directories')
 
701
                'Format does not support versioned directories')
721
702
        self._commit_sprout_make_merge(tree1, self.make_dir)
722
703
 
723
704
    def test_last_modified_revision_after_merge_new_file_unchanged(self):
744
725
        tree = self.make_branch_and_tree(name)
745
726
        if not tree.branch.repository._format.rich_root_data:
746
727
            raise tests.TestNotApplicable(
747
 
                    'format does not support rich roots')
 
728
                'format does not support rich roots')
748
729
        tree.commit('foo')
749
730
        return tree
750
731
 
761
742
            make_after(path)
762
743
 
763
744
        self._add_commit_change_check_changed(tree, (path, path), change_kind,
764
 
            expect_fs_hash=expect_fs_hash)
 
745
                                              expect_fs_hash=expect_fs_hash)
765
746
 
766
747
    def test_last_modified_dir_file(self):
767
748
        if not self.repository_format.supports_versioned_directories:
771
752
                'format does not support versioned directories')
772
753
        try:
773
754
            self._check_kind_change(self.make_dir, self.make_file,
774
 
                expect_fs_hash=True)
 
755
                                    expect_fs_hash=True)
775
756
        except errors.UnsupportedKindChange:
776
757
            raise tests.TestSkipped(
777
758
                "tree does not support changing entry kind from "
792
773
 
793
774
    def test_last_modified_link_file(self):
794
775
        self._check_kind_change(self.make_link, self.make_file,
795
 
            expect_fs_hash=True)
 
776
                                expect_fs_hash=True)
796
777
 
797
778
    def test_last_modified_link_dir(self):
798
779
        if not self.repository_format.supports_versioned_directories:
820
801
        branch.repository.lock_write()
821
802
        self.addCleanup(branch.repository.unlock)
822
803
        self.assertRaises(ValueError, branch.repository.get_commit_builder,
823
 
            branch, [], branch.get_config_stack(),
824
 
            revprops={'invalid': u'property\rwith\r\ninvalid chars'})
 
804
                          branch, [], branch.get_config_stack(),
 
805
                          revprops={'invalid': u'property\rwith\r\ninvalid chars'})
825
806
 
826
807
    def test_commit_builder_commit_with_invalid_message(self):
827
808
        branch = self.make_branch('.')
828
809
        branch.repository.lock_write()
829
810
        self.addCleanup(branch.repository.unlock)
830
811
        builder = branch.repository.get_commit_builder(branch, [],
831
 
            branch.get_config_stack())
 
812
                                                       branch.get_config_stack())
832
813
        self.addCleanup(branch.repository.abort_write_group)
833
814
        self.assertRaises(ValueError, builder.commit,
834
 
            u'Invalid\r\ncommit message\r\n')
 
815
                          u'Invalid\r\ncommit message\r\n')
835
816
 
836
817
    def test_non_ascii_str_committer_rejected(self):
837
818
        """Ensure an error is raised on a non-ascii byte string committer"""
839
820
        branch.repository.lock_write()
840
821
        self.addCleanup(branch.repository.unlock)
841
822
        self.assertRaises(UnicodeDecodeError,
842
 
            branch.repository.get_commit_builder,
843
 
            branch, [], branch.get_config_stack(),
844
 
            committer=b"Erik B\xe5gfors <erik@example.com>")
 
823
                          branch.repository.get_commit_builder,
 
824
                          branch, [], branch.get_config_stack(),
 
825
                          committer=b"Erik B\xe5gfors <erik@example.com>")
845
826
 
846
827
    def test_stacked_repositories_reject_commit_builder(self):
847
828
        # As per bug 375013, committing to stacked repositories is currently
857
838
        self.addCleanup(repo_local.lock_write().unlock)
858
839
        if not repo_local._format.supports_chks:
859
840
            self.assertRaises(errors.BzrError, repo_local.get_commit_builder,
860
 
                branch, [], branch.get_config_stack())
 
841
                              branch, [], branch.get_config_stack())
861
842
        else:
862
843
            builder = repo_local.get_commit_builder(branch, [],
863
844
                                                    branch.get_config_stack())
870
851
        self.overrideEnv('BRZ_EMAIL', None)
871
852
        # Also, make sure that it's not inferred from mailname.
872
853
        self.overrideAttr(config, '_auto_user_id',
873
 
            lambda: (None, None))
 
854
                          lambda: (None, None))
874
855
        tree = self.make_branch_and_tree(".")
875
 
        tree.lock_write()
876
 
        try:
 
856
        with tree.lock_write():
877
857
            # Make sure no username is available.
878
858
            self.assertRaises(config.NoWhoami, tree.branch.get_commit_builder,
879
859
                              [])
881
861
                [], committer='me@example.com')
882
862
            try:
883
863
                list(builder.record_iter_changes(tree, tree.last_revision(),
884
 
                    tree.iter_changes(tree.basis_tree())))
 
864
                                                 tree.iter_changes(tree.basis_tree())))
885
865
                builder.finish_inventory()
886
866
            except:
887
867
                builder.abort()
888
868
                raise
889
869
            repo = tree.branch.repository
890
870
            repo.commit_write_group()
891
 
        finally:
892
 
            tree.unlock()