403
403
def added(self, tree, file_id):
404
404
entry = tree.inventory[file_id]
405
405
path = tree.id2path(file_id)
406
return (file_id, path, True, (False, True), (None, entry.parent_id),
406
return (file_id, (None, path), True, (False, True), (None, entry.parent_id),
407
407
(None, entry.name), (None, entry.kind),
408
408
(None, entry.executable))
410
410
def content_changed(self, tree, file_id):
411
411
entry = tree.inventory[file_id]
412
412
path = tree.id2path(file_id)
413
return (file_id, path, True, (True, True), (entry.parent_id, entry.parent_id),
413
return (file_id, (path, path), True, (True, True), (entry.parent_id, entry.parent_id),
414
414
(entry.name, entry.name), (entry.kind, entry.kind),
415
415
(entry.executable, entry.executable))
418
418
old_entry = from_tree.inventory[file_id]
419
419
new_entry = to_tree.inventory[file_id]
420
420
path = to_tree.id2path(file_id)
421
return (file_id, path, True, (True, True), (old_entry.parent_id, new_entry.parent_id),
421
from_path = from_tree.id2path(file_id)
422
return (file_id, (from_path, path), True, (True, True), (old_entry.parent_id, new_entry.parent_id),
422
423
(old_entry.name, new_entry.name), (old_entry.kind, new_entry.kind),
423
424
(old_entry.executable, new_entry.executable))
425
def missing(self, file_id, path, parent_id, kind):
426
_, basename = os.path.split(path)
427
return (file_id, path, True, (True, True), (parent_id, parent_id),
428
(basename, basename), (kind, None), (False, False))
426
def missing(self, file_id, from_path, to_path, parent_id, kind):
427
_, from_basename = os.path.split(from_path)
428
_, to_basename = os.path.split(to_path)
429
# missing files have both paths, but no kind.
430
return (file_id, (from_path, to_path), True, (True, True),
431
(parent_id, parent_id),
432
(from_basename, to_basename), (kind, None), (False, False))
430
434
def deleted(self, tree, file_id):
431
435
entry = tree.inventory[file_id]
432
436
path = tree.id2path(file_id)
433
return (file_id, path, True, (True, False), (entry.parent_id, None),
437
return (file_id, (path, None), True, (True, False), (entry.parent_id, None),
434
438
(entry.name, None), (entry.kind, None),
435
439
(entry.executable, None))
439
443
to_entry = to_tree.inventory[file_id]
440
444
from_path = from_tree.id2path(file_id)
441
445
to_path = to_tree.id2path(file_id)
442
return (file_id, to_path, content_changed, (True, True),
446
return (file_id, (from_path, to_path), content_changed, (True, True),
443
447
(from_entry.parent_id, to_entry.parent_id),
444
448
(from_entry.name, to_entry.name),
445
449
(from_entry.kind, to_entry.kind),
451
455
name = entry.name
452
456
kind = entry.kind
453
457
executable = entry.executable
454
return (file_id, tree.id2path(file_id), False, (True, True),
458
path = tree.id2path(file_id)
459
return (file_id, (path, path), False, (True, True),
455
460
(parent, parent), (name, name), (kind, kind),
456
461
(executable, executable))
459
464
"""Create an unversioned result."""
460
465
_, basename = os.path.split(path)
461
466
kind = file_kind(tree.abspath(path))
462
return (None, path, True, (False, False), (None, None),
467
return (None, (None, path), True, (False, False), (None, None),
463
468
(None, basename), (None, kind),
534
539
def deleted(file_id):
535
540
entry = tree1.inventory[file_id]
536
541
path = tree1.id2path(file_id)
537
return (file_id, path, True, (True, False),
542
return (file_id, (path, None), True, (True, False),
538
543
(entry.parent_id, None),
539
544
(entry.name, None), (entry.kind, None),
540
545
(entry.executable, None))
541
expected_results = sorted([self.added(tree2, 'empty-root-id'),
542
deleted('root-id'), deleted('a-id'),
543
deleted('b-id'), deleted('c-id')])
546
expected_results = sorted([
547
self.added(tree2, 'empty-root-id'),
548
deleted('root-id'), deleted('a-id'),
549
deleted('b-id'), deleted('c-id')])
546
552
self.assertEqual(
554
560
tree2 = self.get_tree_no_parents_abc_content_2(tree2)
555
561
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
556
562
root_id = tree1.path2id('')
557
self.assertEqual([('a-id', 'a', True, (True, True),
558
(root_id, root_id), ('a', 'a'),
559
('file', 'file'), (False, False))],
563
self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
564
(root_id, root_id), ('a', 'a'),
565
('file', 'file'), (False, False))],
560
566
self.do_iter_changes(tree1, tree2))
562
568
def test_meta_modification(self):
565
571
tree1 = self.get_tree_no_parents_abc_content(tree1)
566
572
tree2 = self.get_tree_no_parents_abc_content_3(tree2)
567
573
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
568
self.assertEqual([('c-id', 'b/c', False, (True, True),
569
('b-id', 'b-id'), ('c', 'c'), ('file', 'file'),
574
self.assertEqual([('c-id', ('b/c', 'b/c'), False, (True, True),
575
('b-id', 'b-id'), ('c', 'c'), ('file', 'file'),
571
577
self.do_iter_changes(tree1, tree2))
591
597
tree2 = self.get_tree_no_parents_abc_content_4(tree2)
592
598
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
593
599
root_id = tree1.path2id('')
594
self.assertEqual([('a-id', 'd', False, (True, True),
595
(root_id, root_id), ('a', 'd'), ('file', 'file'),
600
self.assertEqual([('a-id', ('a', 'd'), False, (True, True),
601
(root_id, root_id), ('a', 'd'), ('file', 'file'),
597
603
self.do_iter_changes(tree1, tree2))
599
605
def test_file_rename_and_modification(self):
603
609
tree2 = self.get_tree_no_parents_abc_content_5(tree2)
604
610
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
605
611
root_id = tree1.path2id('')
606
self.assertEqual([('a-id', 'd', True, (True, True),
607
(root_id, root_id), ('a', 'd'), ('file', 'file'),
612
self.assertEqual([('a-id', ('a', 'd'), True, (True, True),
613
(root_id, root_id), ('a', 'd'), ('file', 'file'),
608
614
(False, False))],
609
615
self.do_iter_changes(tree1, tree2))
615
621
tree2 = self.get_tree_no_parents_abc_content_6(tree2)
616
622
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
617
623
root_id = tree1.path2id('')
618
self.assertEqual([('c-id', 'e', False, (True, True),
619
('b-id', root_id), ('c', 'e'), ('file', 'file'),
624
self.assertEqual([('c-id', ('b/c', 'e'), False, (True, True),
625
('b-id', root_id), ('c', 'e'), ('file', 'file'),
621
627
self.do_iter_changes(tree1, tree2))
623
629
def test_missing_in_target(self):
632
638
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
633
639
root_id = tree1.path2id('')
634
640
expected = sorted([
635
self.missing('a-id', 'a', root_id, 'file'),
636
self.missing('b-id', 'b', root_id, 'directory'),
637
self.missing('c-id', 'b/c', 'b-id', 'file'),
641
self.missing('a-id', 'a', 'a', root_id, 'file'),
642
self.missing('b-id', 'b', 'b', root_id, 'directory'),
643
self.missing('c-id', 'b/c', 'b/c', 'b-id', 'file'),
645
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
647
def test_missing_and_renamed(self):
648
tree1 = self.make_branch_and_tree('tree1')
649
tree2 = self.make_to_branch_and_tree('tree2')
650
self.build_tree(['tree1/file'])
651
tree1.add(['file'], ['file-id'])
652
self.build_tree(['tree2/directory/'])
653
tree2.add(['directory'], ['file-id'])
654
os.rmdir('tree2/directory')
655
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
657
self.addCleanup(tree1.unlock)
659
self.addCleanup(tree2.unlock)
660
root_id = tree1.path2id('')
662
self.missing('file-id', 'file', 'directory', root_id, 'file'),
639
664
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
651
676
tree2.lock_read()
652
677
self.addCleanup(tree2.unlock)
653
678
self.assertEqual(sorted([self.unchanged(tree1, root_id),
654
self.unchanged(tree1, 'b-id'), ('a-id', 'd', True, (True, True),
655
(root_id, root_id), ('a', 'd'), ('file', 'file'),
679
self.unchanged(tree1, 'b-id'),
680
('a-id', ('a', 'd'), True, (True, True),
681
(root_id, root_id), ('a', 'd'), ('file', 'file'),
656
682
(False, False)), self.unchanged(tree1, 'c-id')]),
657
683
self.do_iter_changes(tree1, tree2, include_unchanged=True))
900
926
if f_id.endswith('_f-id'))
901
927
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
903
def test_trees_with_missing_dir(self):
929
def test_trees_with_deleted_dir(self):
904
930
tree1 = self.make_branch_and_tree('tree1')
905
931
tree2 = self.make_to_branch_and_tree('tree2')
906
932
self.build_tree(['tree1/a', 'tree1/b/', 'tree1/b/c',