~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

resolve conflicts against trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os
20
20
 
21
21
from bzrlib import (
 
22
    config,
22
23
    errors,
23
24
    graph,
24
25
    inventory,
117
118
        finally:
118
119
            tree.unlock()
119
120
 
 
121
    def test_commit_lossy(self):
 
122
        tree = self.make_branch_and_tree(".")
 
123
        tree.lock_write()
 
124
        try:
 
125
            builder = tree.branch.get_commit_builder([], lossy=True)
 
126
            list(builder.record_iter_changes(tree, tree.last_revision(),
 
127
                tree.iter_changes(tree.basis_tree())))
 
128
            builder.finish_inventory()
 
129
            rev_id = builder.commit('foo bar blah')
 
130
        finally:
 
131
            tree.unlock()
 
132
        rev = tree.branch.repository.get_revision(rev_id)
 
133
        self.assertEqual('foo bar blah', rev.message)
 
134
 
120
135
    def test_commit_message(self):
121
136
        tree = self.make_branch_and_tree(".")
122
137
        tree.lock_write()
226
241
        try:
227
242
            self.build_tree(['foo'])
228
243
            tree.add('foo', 'foo-id')
 
244
            builder = tree.branch.get_commit_builder([])
 
245
            if not builder.supports_record_entry_contents:
 
246
                raise tests.TestNotApplicable("CommitBuilder doesn't support "
 
247
                    "record_entry_contents")
229
248
            entry = tree.inventory['foo-id']
230
 
            builder = tree.branch.get_commit_builder([])
231
 
            if not builder.supports_record_entry_contents:
232
 
                raise tests.TestNotApplicable("CommitBuilder doesn't support "
233
 
                    "record_entry_contents")
234
249
            self.assertRaises(errors.RootMissing,
235
250
                builder.record_entry_contents, entry, [], 'foo', tree,
236
251
                    tree.path_content_summary('foo'))
289
304
            # pointless commit.
290
305
            self.assertFalse(builder.any_changes())
291
306
            builder.finish_inventory()
292
 
            new_root = tree.branch.repository.get_inventory(
293
 
                builder._new_revision_id).root
 
307
            builder_tree = builder.revision_tree()
 
308
            new_root_id = builder_tree.get_root_id()
 
309
            new_root_revision = builder_tree.get_file_revision(new_root_id)
294
310
            if tree.branch.repository.supports_rich_root():
295
311
                # We should not have seen a new root revision
296
 
                self.assertEqual(old_revision_id, new_root.revision)
 
312
                self.assertEqual(old_revision_id, new_root_revision)
297
313
            else:
298
314
                # We should see a new root revision
299
 
                self.assertNotEqual(old_revision_id, new_root.revision)
 
315
                self.assertNotEqual(old_revision_id, new_root_revision)
300
316
        finally:
301
317
            builder.abort()
302
318
            tree.unlock()
520
536
        basis_tree = tree.basis_tree()
521
537
        basis_tree.lock_read()
522
538
        self.addCleanup(basis_tree.unlock)
523
 
        self.assertEqual(rev_id, basis_tree.inventory.root.revision)
 
539
        self.assertEqual(rev_id,
 
540
            basis_tree.get_file_revision(basis_tree.get_root_id()))
524
541
 
525
542
    def _get_revtrees(self, tree, revision_ids):
526
543
        tree.lock_read()
540
557
        rev1 = tree.commit('')
541
558
        rev2 = tree.commit('')
542
559
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
543
 
        self.assertEqual(rev1, tree1.inventory.root.revision)
 
560
        self.assertEqual(rev1, tree1.get_file_revision(tree1.get_root_id()))
544
561
        if tree.branch.repository.supports_rich_root():
545
 
            self.assertEqual(rev1, tree2.inventory.root.revision)
 
562
            self.assertEqual(rev1,
 
563
                tree2.get_file_revision(tree2.get_root_id()))
546
564
        else:
547
 
            self.assertEqual(rev2, tree2.inventory.root.revision)
 
565
            self.assertEqual(rev2,
 
566
                tree2.get_file_revision(tree2.get_root_id()))
548
567
 
549
568
    def _add_commit_check_unchanged(self, tree, name, mini_commit=None):
550
569
        tree.add([name], [name + 'id'])
557
576
            mini_commit = self.mini_commit
558
577
        rev2 = mini_commit(tree, name, name, False, False)
559
578
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
560
 
        self.assertEqual(rev1, tree1.inventory[file_id].revision)
561
 
        self.assertEqual(rev1, tree2.inventory[file_id].revision)
 
579
        self.assertEqual(rev1, tree1.get_file_revision(file_id))
 
580
        self.assertEqual(rev1, tree2.get_file_revision(file_id))
562
581
        expected_graph = {}
563
582
        expected_graph[(file_id, rev1)] = ()
564
583
        self.assertFileGraph(expected_graph, tree, (file_id, rev1))
587
606
        tree.add(['dir/content'], ['contentid'])
588
607
        rev2 = tree.commit('')
589
608
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
590
 
        self.assertEqual(rev1, tree1.inventory['dirid'].revision)
591
 
        self.assertEqual(rev1, tree2.inventory['dirid'].revision)
 
609
        self.assertEqual(rev1, tree1.get_file_revision('dirid'))
 
610
        self.assertEqual(rev1, tree2.get_file_revision('dirid'))
592
611
        file_id = 'dirid'
593
612
        expected_graph = {}
594
613
        expected_graph[(file_id, rev1)] = ()
797
816
        rev2 = mini_commit(tree, name, tree.id2path(file_id),
798
817
            expect_fs_hash=expect_fs_hash)
799
818
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
800
 
        self.assertEqual(rev1, tree1.inventory[file_id].revision)
801
 
        self.assertEqual(rev2, tree2.inventory[file_id].revision)
 
819
        self.assertEqual(rev1, tree1.get_file_revision(file_id))
 
820
        self.assertEqual(rev2, tree2.get_file_revision(file_id))
802
821
        expected_graph = {}
803
822
        expected_graph[(file_id, rev1)] = ()
804
823
        expected_graph[(file_id, rev2)] = ((file_id, rev1),)
919
938
            parent_tree = tree.basis_tree()
920
939
            parent_tree.lock_read()
921
940
            self.addCleanup(parent_tree.unlock)
922
 
            parent_invs = [parent_tree.inventory]
 
941
            parent_trees = [parent_tree]
923
942
            for parent_id in parent_ids[1:]:
924
 
                parent_invs.append(tree.branch.repository.revision_tree(
925
 
                    parent_id).inventory)
 
943
                parent_trees.append(tree.branch.repository.revision_tree(
 
944
                    parent_id))
926
945
            changes = list(tree.iter_changes(parent_tree))
927
946
            result = list(builder.record_iter_changes(tree, parent_ids[0],
928
947
                changes))
977
996
        # (closest to a public per-file graph API we have today)
978
997
        tree.lock_read()
979
998
        self.addCleanup(tree.unlock)
980
 
        g = dict(graph.Graph(tree.branch.repository.texts).iter_ancestry([tip]))
 
999
        g = dict(tree.branch.repository.get_file_graph().iter_ancestry([tip]))
981
1000
        self.assertEqual(expected_graph, g)
982
1001
 
983
1002
    def test_last_modified_revision_after_content_file_changes(self):
1058
1077
        rev4 = mini_commit(tree1, 'new_' + name, 'new_' + name,
1059
1078
            expect_fs_hash=expect_fs_hash)
1060
1079
        tree3, = self._get_revtrees(tree1, [rev4])
1061
 
        self.assertEqual(rev4, tree3.inventory[name + 'id'].revision)
 
1080
        self.assertEqual(rev4, tree3.get_file_revision(name + 'id'))
1062
1081
        file_id = name + 'id'
1063
1082
        expected_graph = {}
1064
1083
        expected_graph[(file_id, rev1)] = ()
1124
1143
            rev3 = mini_commit(in_tree, name, 'new_' + name, False,
1125
1144
                delta_against_basis=changed_in_tree)
1126
1145
            tree3, = self._get_revtrees(in_tree, [rev2])
1127
 
            self.assertEqual(rev2, tree3.inventory[name + 'id'].revision)
 
1146
            self.assertEqual(rev2, tree3.get_file_revision(name + 'id'))
1128
1147
            file_id = name + 'id'
1129
1148
            expected_graph = {}
1130
1149
            expected_graph[(file_id, rev1)] = ()
1156
1175
        rev3 = mini_commit(tree1, None, 'name', False)
1157
1176
        tree3, = self._get_revtrees(tree1, [rev2])
1158
1177
        # in rev2, name should be only changed in rev2
1159
 
        self.assertEqual(rev2, tree3.inventory[file_id].revision)
 
1178
        self.assertEqual(rev2, tree3.get_file_revision(file_id))
1160
1179
        expected_graph = {}
1161
1180
        expected_graph[(file_id, rev2)] = ()
1162
1181
        self.assertFileGraph(expected_graph, tree1, (file_id, rev2))
1361
1380
        # Ensure that when no username is available but a committer is
1362
1381
        # supplied, commit works.
1363
1382
        self.overrideEnv('EMAIL', None)
 
1383
        self.overrideEnv('BZR_EMAIL', None)
 
1384
        # Also, make sure that it's not inferred from mailname.
 
1385
        self.overrideAttr(config, '_auto_user_id',
 
1386
            lambda: (None, None))
1364
1387
        tree = self.make_branch_and_tree(".")
1365
1388
        tree.lock_write()
1366
1389
        try: