~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
        tree2.set_root_id(tree1.get_root_id())
51
51
        tree1 = self.get_tree_no_parents_no_content(tree1)
52
52
        tree2 = self.get_tree_no_parents_no_content(tree2)
53
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
53
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
54
54
        d = self.intertree_class(tree1, tree2).compare()
55
55
        self.assertEqual([], d.added)
56
56
        self.assertEqual([], d.modified)
64
64
        tree2.set_root_id(tree1.get_root_id())
65
65
        tree1 = self.get_tree_no_parents_no_content(tree1)
66
66
        tree2 = self.get_tree_no_parents_abc_content(tree2)
67
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
67
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
68
68
        d = self.intertree_class(tree1, tree2).compare()
69
69
        self.assertEqual([('a', 'a-id', 'file'),
70
70
                          ('b', 'b-id', 'directory'),
94
94
        # default intertree, but may perform a commit for other tree types,
95
95
        # which may reduce the validity of the test. XXX: Think about how to
96
96
        # address this.
97
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
97
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
98
98
        d = self.intertree_class(tree1, tree2).compare()
99
99
        self.assertEqual([], d.added)
100
100
        self.assertEqual([], d.modified)
108
108
        tree2.set_root_id(tree1.get_root_id())
109
109
        tree1 = self.get_tree_no_parents_abc_content(tree1)
110
110
        tree2 = self.get_tree_no_parents_no_content(tree2)
111
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
111
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
112
112
        d = self.intertree_class(tree1, tree2).compare()
113
113
        self.assertEqual([], d.added)
114
114
        self.assertEqual([], d.modified)
125
125
        tree2.set_root_id(tree1.get_root_id())
126
126
        tree1 = self.get_tree_no_parents_abc_content(tree1)
127
127
        tree2 = self.get_tree_no_parents_abc_content_2(tree2)
128
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
128
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
129
129
        d = self.intertree_class(tree1, tree2).compare()
130
130
        self.assertEqual([], d.added)
131
131
        self.assertEqual([('a', 'a-id', 'file', True, False)], d.modified)
139
139
        tree2.set_root_id(tree1.get_root_id())
140
140
        tree1 = self.get_tree_no_parents_abc_content(tree1)
141
141
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
142
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
142
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
143
143
        d = self.intertree_class(tree1, tree2).compare()
144
144
        self.assertEqual([], d.added)
145
145
        self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified)
153
153
        tree2.set_root_id(tree1.get_root_id())
154
154
        tree1 = self.get_tree_no_parents_abc_content(tree1)
155
155
        tree2 = self.get_tree_no_parents_abc_content_4(tree2)
156
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
156
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
157
157
        d = self.intertree_class(tree1, tree2).compare()
158
158
        self.assertEqual([], d.added)
159
159
        self.assertEqual([], d.modified)
167
167
        tree2.set_root_id(tree1.get_root_id())
168
168
        tree1 = self.get_tree_no_parents_abc_content(tree1)
169
169
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
170
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
170
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
171
171
        d = self.intertree_class(tree1, tree2).compare()
172
172
        self.assertEqual([], d.added)
173
173
        self.assertEqual([], d.modified)
181
181
        tree2.set_root_id(tree1.get_root_id())
182
182
        tree1 = self.get_tree_no_parents_abc_content(tree1)
183
183
        tree2 = self.get_tree_no_parents_abc_content_6(tree2)
184
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
184
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
185
185
        d = self.intertree_class(tree1, tree2).compare()
186
186
        self.assertEqual([], d.added)
187
187
        self.assertEqual([], d.modified)
195
195
        tree2.set_root_id(tree1.get_root_id())
196
196
        tree1 = self.get_tree_no_parents_no_content(tree1)
197
197
        tree2 = self.get_tree_no_parents_abc_content(tree2)
198
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
198
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
199
199
        d = self.intertree_class(tree1, tree2).compare(specific_files=['a'])
200
200
        self.assertEqual([('a', 'a-id', 'file')], d.added)
201
201
        self.assertEqual([], d.modified)
208
208
        tree2 = self.make_to_branch_and_tree('2')
209
209
        tree1 = self.get_tree_no_parents_no_content(tree1)
210
210
        tree2 = self.get_tree_no_parents_abc_content(tree2)
211
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
211
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
212
212
        d = self.intertree_class(tree1, tree2).compare(
213
213
            specific_files=['a', 'b/c'])
214
214
        self.assertEqual(
225
225
        tree2 = self.make_to_branch_and_tree('2')
226
226
        tree1 = self.get_tree_no_parents_no_content(tree1)
227
227
        tree2 = self.get_tree_no_parents_abc_content(tree2)
228
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
228
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
229
229
        d = self.intertree_class(tree1, tree2).compare(specific_files=['b'])
230
230
        self.assertEqual(
231
231
            [('b', 'b-id', 'directory'),('b/c', 'c-id', 'file')],
241
241
        tree2 = self.make_to_branch_and_tree('2')
242
242
        tree1 = self.get_tree_no_parents_abc_content(tree1)
243
243
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
244
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
244
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
245
245
        d = self.intertree_class(tree1, tree2).compare(want_unchanged=True)
246
246
        self.assertEqual([], d.added)
247
247
        self.assertEqual([], d.modified)
257
257
        tree2 = self.make_to_branch_and_tree('2')
258
258
        tree1 = self.get_tree_no_parents_abc_content(tree1)
259
259
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
260
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
260
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
261
261
        d = self.intertree_class(tree1, tree2).compare(specific_files=['b'])
262
262
        # the type of tree-3 does not matter - it is used as a lookup, not
263
263
        # a dispatch. XXX: For dirstate it does speak to the optimisability of
292
292
        tree2 = self.make_to_branch_and_tree('2')
293
293
        tree1 = self.get_tree_no_parents_no_content(tree1)
294
294
        tree2 = self.get_tree_no_parents_abc_content(tree2)
295
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
295
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
296
296
        self.assertRaises(errors.PathsNotVersionedError, 
297
297
            self.intertree_class(tree1, tree2).compare,
298
298
            specific_files=['d'],
307
307
        tree1.add(['a', 'c'], ['a-id', 'c-id'])
308
308
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
309
309
 
310
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
310
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
311
311
        d = self.intertree_class(tree1, tree2).compare()
312
312
        self.assertEqual([], d.added)
313
313
        self.assertEqual([(u'a', 'a-id', 'file', True, False),
327
327
            links_supported = True
328
328
        else:
329
329
            links_supported = False
330
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
330
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
331
331
        d = self.intertree_class(tree1, tree2).compare(want_unversioned=True)
332
332
        self.assertEqual([], d.added)
333
333
        self.assertEqual([], d.modified)
367
367
 
368
368
        Read lock them, and add the unlock to the cleanup.
369
369
        """
370
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
370
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
371
371
        tree1.lock_read()
372
372
        self.addCleanup(tree1.unlock)
373
373
        tree2.lock_read()
429
429
        tree2 = self.make_to_branch_and_tree('2')
430
430
        tree1 = self.get_tree_no_parents_no_content(tree1)
431
431
        tree2 = self.get_tree_no_parents_no_content(tree2)
432
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
432
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
433
433
        self.assertEqual([], self.do_iter_changes(tree1, tree2))
434
434
 
435
435
    def added(self, tree, file_id):
436
 
        entry = tree.inventory[file_id]
437
 
        path = tree.id2path(file_id)
 
436
        path, entry = self.get_path_entry(tree, file_id)
438
437
        return (file_id, (None, path), True, (False, True), (None, entry.parent_id),
439
438
                (None, entry.name), (None, entry.kind),
440
439
                (None, entry.executable))
441
440
 
 
441
    @staticmethod
 
442
    def get_path_entry(tree, file_id):
 
443
        iterator = tree.iter_entries_by_dir(specific_file_ids=[file_id])
 
444
        return iterator.next()
 
445
 
442
446
    def content_changed(self, tree, file_id):
443
 
        entry = tree.inventory[file_id]
444
 
        path = tree.id2path(file_id)
445
 
        return (file_id, (path, path), True, (True, True), (entry.parent_id, entry.parent_id),
 
447
        path, entry = self.get_path_entry(tree, file_id)
 
448
        return (file_id, (path, path), True, (True, True),
 
449
                (entry.parent_id, entry.parent_id),
446
450
                (entry.name, entry.name), (entry.kind, entry.kind),
447
451
                (entry.executable, entry.executable))
448
452
 
449
453
    def kind_changed(self, from_tree, to_tree, file_id):
450
 
        old_entry = from_tree.inventory[file_id]
451
 
        new_entry = to_tree.inventory[file_id]
452
 
        path = to_tree.id2path(file_id)
453
 
        from_path = from_tree.id2path(file_id)
454
 
        return (file_id, (from_path, path), True, (True, True), (old_entry.parent_id, new_entry.parent_id),
455
 
                (old_entry.name, new_entry.name), (old_entry.kind, new_entry.kind),
 
454
        from_path, old_entry = self.get_path_entry(from_tree, file_id)
 
455
        path, new_entry = self.get_path_entry(to_tree, file_id)
 
456
        return (file_id, (from_path, path), True, (True, True),
 
457
                (old_entry.parent_id, new_entry.parent_id),
 
458
                (old_entry.name, new_entry.name),
 
459
                (old_entry.kind, new_entry.kind),
456
460
                (old_entry.executable, new_entry.executable))
457
461
 
458
462
    def missing(self, file_id, from_path, to_path, parent_id, kind):
471
475
                (entry.executable, None))
472
476
 
473
477
    def renamed(self, from_tree, to_tree, file_id, content_changed):
474
 
        from_entry = from_tree.inventory[file_id]
475
 
        to_entry = to_tree.inventory[file_id]
476
 
        from_path = from_tree.id2path(file_id)
477
 
        to_path = to_tree.id2path(file_id)
 
478
        from_path, from_entry = self.get_path_entry(from_tree, file_id)
 
479
        to_path, to_entry = self.get_path_entry(to_tree, file_id)
478
480
        return (file_id, (from_path, to_path), content_changed, (True, True),
479
481
            (from_entry.parent_id, to_entry.parent_id),
480
482
            (from_entry.name, to_entry.name),
482
484
            (from_entry.executable, to_entry.executable))
483
485
 
484
486
    def unchanged(self, tree, file_id):
485
 
        entry = tree.inventory[file_id]
 
487
        path, entry = self.get_path_entry(tree, file_id)
486
488
        parent = entry.parent_id
487
489
        name = entry.name
488
490
        kind = entry.kind
489
491
        executable = entry.executable
490
 
        path = tree.id2path(file_id)
491
492
        return (file_id, (path, path), False, (True, True),
492
493
               (parent, parent), (name, name), (kind, kind),
493
494
               (executable, executable))
495
496
    def unversioned(self, tree, path):
496
497
        """Create an unversioned result."""
497
498
        _, basename = os.path.split(path)
498
 
        kind = file_kind(tree.abspath(path))
 
499
        kind = tree._comparison_data(None, path)[0]
499
500
        return (None, (None, path), True, (False, False), (None, None),
500
501
                (None, basename), (None, kind),
501
502
                (None, False))
593
594
        tree2 = self.make_to_branch_and_tree('2')
594
595
        tree1 = self.get_tree_no_parents_abc_content(tree1)
595
596
        tree2 = self.get_tree_no_parents_abc_content_2(tree2)
596
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
597
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
597
598
        root_id = tree1.path2id('')
598
599
        self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
599
600
                           (root_id, root_id), ('a', 'a'),
605
606
        tree2 = self.make_to_branch_and_tree('2')
606
607
        tree1 = self.get_tree_no_parents_abc_content(tree1)
607
608
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
608
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
609
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
609
610
        self.assertEqual([('c-id', ('b/c', 'b/c'), False, (True, True),
610
611
                           ('b-id', 'b-id'), ('c', 'c'), ('file', 'file'),
611
612
                          (False, True))],
621
622
        self.build_tree(['1/a-empty/', '2/a-empty/'])
622
623
        tree1.add(['a-empty'], ['a-empty'])
623
624
        tree2.add(['a-empty'], ['a-empty'])
624
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
625
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
625
626
        expected = []
626
627
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
627
628
 
630
631
        tree2 = self.make_to_branch_and_tree('2')
631
632
        tree1 = self.get_tree_no_parents_abc_content(tree1)
632
633
        tree2 = self.get_tree_no_parents_abc_content_4(tree2)
633
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
634
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
634
635
        root_id = tree1.path2id('')
635
636
        self.assertEqual([('a-id', ('a', 'd'), False, (True, True),
636
637
                           (root_id, root_id), ('a', 'd'), ('file', 'file'),
642
643
        tree2 = self.make_to_branch_and_tree('2')
643
644
        tree1 = self.get_tree_no_parents_abc_content(tree1)
644
645
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
645
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
646
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
646
647
        root_id = tree1.path2id('')
647
648
        self.assertEqual([('a-id', ('a', 'd'), True, (True, True),
648
649
                           (root_id, root_id), ('a', 'd'), ('file', 'file'),
654
655
        tree2 = self.make_to_branch_and_tree('2')
655
656
        tree1 = self.get_tree_no_parents_abc_content(tree1)
656
657
        tree2 = self.get_tree_no_parents_abc_content_6(tree2)
657
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
658
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
658
659
        root_id = tree1.path2id('')
659
660
        self.assertEqual([('c-id', ('b/c', 'e'), False, (True, True),
660
661
                           ('b-id', root_id), ('c', 'e'), ('file', 'file'),
670
671
        os.unlink('2/a')
671
672
        shutil.rmtree('2/b')
672
673
        # TODO ? have a symlink here?
673
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
674
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
674
675
        root_id = tree1.path2id('')
675
676
        expected = sorted([
676
677
            self.missing('a-id', 'a', 'a', root_id, 'file'),
973
974
        tree2 = self.make_to_branch_and_tree('tree2')
974
975
        tree2.set_root_id(tree1.get_root_id())
975
976
        self.build_tree(['tree2/dir/', 'tree2/dir/file'])
976
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
977
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
977
978
        expected = [
978
979
            self.unversioned(tree2, 'dir'),
979
980
            ]