~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/intertree_implementations/test_compare.py

  • Committer: Vincent Ladeuil
  • Date: 2009-07-10 08:33:11 UTC
  • mfrom: (4503.1.3 tree-has-changes)
  • mto: This revision was merged to the branch mainline in revision 4525.
  • Revision ID: v.ladeuil+lp@free.fr-20090710083311-ulnr2ic6lvevjr3a
Quicker check for changes in mutable trees

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from bzrlib import (
23
23
    errors,
 
24
    mutabletree,
24
25
    tests,
25
26
    workingtree_4,
26
27
    )
367
368
            tree1.unlock()
368
369
            tree2.unlock()
369
370
 
 
371
    def check_has_changes(self, expected, tree1, tree2):
 
372
        # has_changes is defined for mutable trees only
 
373
        print '\nt1, t2: %r, %r' % (type(tree1), type(tree2))
 
374
        if not isinstance(tree2, mutabletree.MutableTree):
 
375
            if isinstance(tree1, mutabletree.MutableTree):
 
376
                # Let's switch the trees since has_changes() is commutative
 
377
                # (where we can apply it)
 
378
                tree2, tree1 = tree1, tree2
 
379
            else:
 
380
                # Neither tree can be used
 
381
                return
 
382
        tree1.lock_read()
 
383
        tree2.lock_read()
 
384
        try:
 
385
            return tree2.has_changes(tree1)
 
386
        finally:
 
387
            tree1.unlock()
 
388
            tree2.unlock()
 
389
 
370
390
    def mutable_trees_to_locked_test_trees(self, tree1, tree2):
371
391
        """Convert the working trees into test trees.
372
392
 
436
456
        tree2 = self.get_tree_no_parents_no_content(tree2)
437
457
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
438
458
        self.assertEqual([], self.do_iter_changes(tree1, tree2))
 
459
        self.check_has_changes(False, tree1, tree2)
439
460
 
440
461
    def added(self, tree, file_id):
441
462
        path, entry = self.get_path_entry(tree, file_id)
519
540
            self.added(tree2, 'c-id'),
520
541
            self.deleted(tree1, 'empty-root-id')])
521
542
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
 
543
        self.check_has_changes(True, tree1, tree2)
522
544
 
523
545
    def test_empty_specific_files(self):
524
546
        tree1 = self.make_branch_and_tree('1')
542
564
            self.added(tree2, 'c-id'),
543
565
            self.deleted(tree1, 'empty-root-id')])
544
566
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
 
567
        self.check_has_changes(True, tree1, tree2)
545
568
 
546
569
    def test_empty_to_abc_content_a_only(self):
547
570
        tree1 = self.make_branch_and_tree('1')
593
616
        self.assertEqual(
594
617
            expected_results,
595
618
            self.do_iter_changes(tree1, tree2))
 
619
        self.check_has_changes(True, tree1, tree2)
596
620
 
597
621
    def test_content_modification(self):
598
622
        tree1 = self.make_branch_and_tree('1')
605
629
                           (root_id, root_id), ('a', 'a'),
606
630
                           ('file', 'file'), (False, False))],
607
631
                         self.do_iter_changes(tree1, tree2))
 
632
        self.check_has_changes(True, tree1, tree2)
608
633
 
609
634
    def test_meta_modification(self):
610
635
        tree1 = self.make_branch_and_tree('1')
834
859
            self.content_changed(tree2, 'c-id'),
835
860
            ])
836
861
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
 
862
        self.check_has_changes(True, tree1, tree2)
837
863
 
838
864
    def test_unversioned_paths_in_tree(self):
839
865
        tree1 = self.make_branch_and_tree('tree1')
1051
1077
        self.assertEqual(expected,
1052
1078
            self.do_iter_changes(tree1, tree2, include_unchanged=True,
1053
1079
                want_unversioned=True))
 
1080
        self.check_has_changes(True, tree1, tree2)
1054
1081
 
1055
1082
    def test_versioned_symlinks_specific_files(self):
1056
1083
        self.requireFeature(tests.SymlinkFeature)
1072
1099
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
1073
1100
            specific_files=['added', 'changed', 'fromdir', 'fromfile',
1074
1101
            'removed', 'unchanged', 'todir', 'tofile']))
 
1102
        self.check_has_changes(True, tree1, tree2)
1075
1103
 
1076
1104
    def test_tree_with_special_names(self):
1077
1105
        tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
1078
1106
        expected = sorted(self.added(tree2, f_id) for f_id in path_ids)
1079
1107
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
 
1108
        self.check_has_changes(True, tree1, tree2)
1080
1109
 
1081
1110
    def test_trees_with_special_names(self):
1082
1111
        tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
1083
1112
        expected = sorted(self.content_changed(tree2, f_id) for f_id in path_ids
1084
1113
                          if f_id.endswith('_f-id'))
1085
1114
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
 
1115
        self.check_has_changes(True, tree1, tree2)
1086
1116
 
1087
1117
    def test_trees_with_deleted_dir(self):
1088
1118
        tree1 = self.make_branch_and_tree('tree1')
1106
1136
            self.deleted(tree1, 'e-id'),
1107
1137
            ])
1108
1138
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
 
1139
        self.check_has_changes(True, tree1, tree2)
1109
1140
 
1110
1141
    def test_added_unicode(self):
1111
1142
        tree1 = self.make_branch_and_tree('tree1')
1134
1165
        self.assertEqual([self.added(tree2, added_id)],
1135
1166
                         self.do_iter_changes(tree1, tree2,
1136
1167
                                              specific_files=[u'\u03b1']))
 
1168
        self.check_has_changes(True, tree1, tree2)
1137
1169
 
1138
1170
    def test_deleted_unicode(self):
1139
1171
        tree1 = self.make_branch_and_tree('tree1')
1162
1194
        self.assertEqual([self.deleted(tree1, deleted_id)],
1163
1195
                         self.do_iter_changes(tree1, tree2,
1164
1196
                                              specific_files=[u'\u03b1']))
 
1197
        self.check_has_changes(True, tree1, tree2)
1165
1198
 
1166
1199
    def test_modified_unicode(self):
1167
1200
        tree1 = self.make_branch_and_tree('tree1')
1191
1224
        self.assertEqual([self.content_changed(tree1, mod_id)],
1192
1225
                         self.do_iter_changes(tree1, tree2,
1193
1226
                                              specific_files=[u'\u03b1']))
 
1227
        self.check_has_changes(True, tree1, tree2)
1194
1228
 
1195
1229
    def test_renamed_unicode(self):
1196
1230
        tree1 = self.make_branch_and_tree('tree1')
1221
1255
        self.assertEqual([self.renamed(tree1, tree2, rename_id, False)],
1222
1256
                         self.do_iter_changes(tree1, tree2,
1223
1257
                                              specific_files=[u'\u03b1']))
 
1258
        self.check_has_changes(True, tree1, tree2)
1224
1259
 
1225
1260
    def test_unchanged_unicode(self):
1226
1261
        tree1 = self.make_branch_and_tree('tree1')
1309
1344
                                              want_unversioned=True))
1310
1345
        self.assertEqual([], # Without want_unversioned we should get nothing
1311
1346
                         self.do_iter_changes(tree1, tree2))
 
1347
        self.check_has_changes(False, tree1, tree2)
1312
1348
 
1313
1349
        # We should also be able to select just a subset
1314
1350
        expected = sorted([
1389
1425
            ])
1390
1426
        self.assertEqual(expected,
1391
1427
                         self.do_iter_changes(tree1, tree2))
 
1428
        self.check_has_changes(True, tree1, tree2)
1392
1429
 
1393
1430
    def test_deleted_and_unknown(self):
1394
1431
        """Test a file marked removed, but still present on disk."""