Merge lp:~jelmer/brz/sort-changes into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/sort-changes
Merge into: lp:brz
Diff against target: 321 lines (+50/-38)
3 files modified
breezy/delta.py (+3/-1)
breezy/tests/per_intertree/test_compare.py (+42/-35)
breezy/transform.py (+5/-2)
To merge this branch: bzr merge lp:~jelmer/brz/sort-changes
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+353368@code.launchpad.net

Commit message

Fix sorting of changes in some tests on Python 3.

Description of the change

Fix sorting of changes in some tests on Python 3.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Thanks! See inline nit about where to put key functions.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/delta.py'
--- breezy/delta.py 2018-08-03 02:26:35 +0000
+++ breezy/delta.py 2018-08-20 21:52:41 +0000
@@ -165,7 +165,9 @@
165 delta.removed.sort()165 delta.removed.sort()
166 delta.added.sort()166 delta.added.sort()
167 delta.renamed.sort()167 delta.renamed.sort()
168 delta.missing.sort()168 def missing_key(change):
169 return (change[0] or '', change[1])
170 delta.missing.sort(key=missing_key)
169 # TODO: jam 20060529 These lists shouldn't need to be sorted171 # TODO: jam 20060529 These lists shouldn't need to be sorted
170 # since we added them in alphabetical order.172 # since we added them in alphabetical order.
171 delta.modified.sort()173 delta.modified.sort()
172174
=== modified file 'breezy/tests/per_intertree/test_compare.py'
--- breezy/tests/per_intertree/test_compare.py 2018-08-02 01:10:26 +0000
+++ breezy/tests/per_intertree/test_compare.py 2018-08-20 21:52:41 +0000
@@ -47,6 +47,15 @@
47# that should just be the default for these tests, by changing47# that should just be the default for these tests, by changing
48# make_branch_and_tree. mbp 2007030748# make_branch_and_tree. mbp 20070307
4949
50
51def _change_key(change):
52 """Return a valid key for sorting Tree.iter_changes entries."""
53 (file_id, paths, content_changed, versioned, parent, name, kind,
54 executable) = change
55 return (file_id or b'', (paths[0] or '', paths[1] or ''), versioned,
56 parent, name, kind, executable)
57
58
50class TestCompare(TestCaseWithTwoTrees):59class TestCompare(TestCaseWithTwoTrees):
5160
52 def _make_abc_tree(self, tree):61 def _make_abc_tree(self, tree):
@@ -414,8 +423,8 @@
414 :param left_changes: A list of the output from iter_changes.423 :param left_changes: A list of the output from iter_changes.
415 :param right_changes: A list of the output from iter_changes.424 :param right_changes: A list of the output from iter_changes.
416 """425 """
417 left_changes = sorted(left_changes)426 left_changes = self.sorted(left_changes)
418 right_changes = sorted(right_changes)427 right_changes = self.sorted(right_changes)
419 if left_changes == right_changes:428 if left_changes == right_changes:
420 return429 return
421 # setify to get item by item differences, but we can only do this430 # setify to get item by item differences, but we can only do this
@@ -448,15 +457,10 @@
448 :param **extra_args: Extra args to pass to iter_changes. This is not457 :param **extra_args: Extra args to pass to iter_changes. This is not
449 inspected by this test helper.458 inspected by this test helper.
450 """459 """
451 tree1.lock_read()460 with tree1.lock_read(), tree2.lock_read():
452 tree2.lock_read()
453 try:
454 # sort order of output is not strictly defined461 # sort order of output is not strictly defined
455 return sorted(self.intertree_class(tree1, tree2)462 return self.sorted(self.intertree_class(tree1, tree2)
456 .iter_changes(**extra_args))463 .iter_changes(**extra_args))
457 finally:
458 tree1.unlock()
459 tree2.unlock()
460464
461 def check_has_changes(self, expected, tree1, tree2):465 def check_has_changes(self, expected, tree1, tree2):
462 # has_changes is defined for mutable trees only466 # has_changes is defined for mutable trees only
@@ -623,13 +627,16 @@
623 (None, basename), (None, kind),627 (None, basename), (None, kind),
624 (None, False))628 (None, False))
625629
630 def sorted(self, changes):
631 return sorted(changes, key=_change_key)
632
626 def test_empty_to_abc_content(self):633 def test_empty_to_abc_content(self):
627 tree1 = self.make_branch_and_tree('1')634 tree1 = self.make_branch_and_tree('1')
628 tree2 = self.make_to_branch_and_tree('2')635 tree2 = self.make_to_branch_and_tree('2')
629 tree1 = self.get_tree_no_parents_no_content(tree1)636 tree1 = self.get_tree_no_parents_no_content(tree1)
630 tree2 = self.get_tree_no_parents_abc_content(tree2)637 tree2 = self.get_tree_no_parents_abc_content(tree2)
631 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)638 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
632 expected_results = sorted([639 expected_results = self.sorted([
633 self.added(tree2, b'root-id'),640 self.added(tree2, b'root-id'),
634 self.added(tree2, b'a-id'),641 self.added(tree2, b'a-id'),
635 self.added(tree2, b'b-id'),642 self.added(tree2, b'b-id'),
@@ -653,7 +660,7 @@
653 tree1 = self.get_tree_no_parents_no_content(tree1)660 tree1 = self.get_tree_no_parents_no_content(tree1)
654 tree2 = self.get_tree_no_parents_abc_content(tree2)661 tree2 = self.get_tree_no_parents_abc_content(tree2)
655 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)662 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
656 expected_results = sorted([663 expected_results = self.sorted([
657 self.added(tree2, b'root-id'),664 self.added(tree2, b'root-id'),
658 self.added(tree2, b'a-id'),665 self.added(tree2, b'a-id'),
659 self.added(tree2, b'b-id'),666 self.added(tree2, b'b-id'),
@@ -669,7 +676,7 @@
669 tree2 = self.get_tree_no_parents_abc_content(tree2)676 tree2 = self.get_tree_no_parents_abc_content(tree2)
670 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)677 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
671 self.assertEqual(678 self.assertEqual(
672 sorted([self.added(tree2, b'root-id'),679 self.sorted([self.added(tree2, b'root-id'),
673 self.added(tree2, b'a-id'),680 self.added(tree2, b'a-id'),
674 self.deleted(tree1, b'empty-root-id')]),681 self.deleted(tree1, b'empty-root-id')]),
675 self.do_iter_changes(tree1, tree2, specific_files=['a']))682 self.do_iter_changes(tree1, tree2, specific_files=['a']))
@@ -702,7 +709,7 @@
702 tree1 = self.get_tree_no_parents_no_content(tree1)709 tree1 = self.get_tree_no_parents_no_content(tree1)
703 tree2 = self.get_tree_no_parents_abc_content(tree2)710 tree2 = self.get_tree_no_parents_abc_content(tree2)
704 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)711 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
705 expected_result = sorted([self.added(tree2, b'root-id'),712 expected_result = self.sorted([self.added(tree2, b'root-id'),
706 self.added(tree2, b'a-id'), self.added(tree2, b'b-id'),713 self.added(tree2, b'a-id'), self.added(tree2, b'b-id'),
707 self.added(tree2, b'c-id'), self.deleted(tree1, b'empty-root-id')])714 self.added(tree2, b'c-id'), self.deleted(tree1, b'empty-root-id')])
708 self.assertEqual(expected_result,715 self.assertEqual(expected_result,
@@ -714,7 +721,7 @@
714 tree1 = self.get_tree_no_parents_abc_content(tree1)721 tree1 = self.get_tree_no_parents_abc_content(tree1)
715 tree2 = self.get_tree_no_parents_no_content(tree2)722 tree2 = self.get_tree_no_parents_no_content(tree2)
716 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)723 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
717 expected_results = sorted([724 expected_results = self.sorted([
718 self.added(tree2, b'empty-root-id'),725 self.added(tree2, b'empty-root-id'),
719 self.deleted(tree1, b'root-id'), self.deleted(tree1, b'a-id'),726 self.deleted(tree1, b'root-id'), self.deleted(tree1, b'a-id'),
720 self.deleted(tree1, b'b-id'), self.deleted(tree1, b'c-id')])727 self.deleted(tree1, b'b-id'), self.deleted(tree1, b'c-id')])
@@ -1047,7 +1054,7 @@
1047 tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)1054 tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1048 self.not_applicable_if_missing_in('a', tree2)1055 self.not_applicable_if_missing_in('a', tree2)
1049 self.not_applicable_if_missing_in('b', tree2)1056 self.not_applicable_if_missing_in('b', tree2)
1050 expected = sorted([1057 expected = self.sorted([
1051 self.missing(b'a-id', 'a', 'a', b'root-id', 'file'),1058 self.missing(b'a-id', 'a', 'a', b'root-id', 'file'),
1052 self.missing(b'b-id', 'b', 'b', b'root-id', 'directory'),1059 self.missing(b'b-id', 'b', 'b', b'root-id', 'directory'),
1053 self.missing(b'c-id', 'b/c', 'b/c', b'b-id', 'file'),1060 self.missing(b'c-id', 'b/c', 'b/c', b'b-id', 'file'),
@@ -1067,7 +1074,7 @@
1067 self.not_applicable_if_missing_in('directory', tree2)1074 self.not_applicable_if_missing_in('directory', tree2)
10681075
1069 root_id = tree1.path2id('')1076 root_id = tree1.path2id('')
1070 expected = sorted([1077 expected = self.sorted([
1071 self.missing(b'file-id', 'file', 'directory', root_id, 'file'),1078 self.missing(b'file-id', 'file', 'directory', root_id, 'file'),
1072 ])1079 ])
1073 self.assertEqual(expected, self.do_iter_changes(tree1, tree2))1080 self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
@@ -1217,7 +1224,7 @@
12171224
1218 # We should ignore the fact that 'b' exists in tree-21225 # We should ignore the fact that 'b' exists in tree-2
1219 # because the want_unversioned parameter was not given.1226 # because the want_unversioned parameter was not given.
1220 expected = sorted([1227 expected = self.sorted([
1221 self.content_changed(tree2, b'a-id'),1228 self.content_changed(tree2, b'a-id'),
1222 self.content_changed(tree2, b'c-id'),1229 self.content_changed(tree2, b'c-id'),
1223 ])1230 ])
@@ -1242,7 +1249,7 @@
1242 ]1249 ]
1243 if links_supported:1250 if links_supported:
1244 expected.append(self.unversioned(tree2, 'link'))1251 expected.append(self.unversioned(tree2, 'link'))
1245 expected = sorted(expected)1252 expected = self.sorted(expected)
1246 self.assertEqual(expected, self.do_iter_changes(tree1, tree2,1253 self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
1247 want_unversioned=True))1254 want_unversioned=True))
12481255
@@ -1265,7 +1272,7 @@
1265 if links_supported:1272 if links_supported:
1266 expected.append(self.unversioned(tree2, 'link'))1273 expected.append(self.unversioned(tree2, 'link'))
1267 specific_files.append('link')1274 specific_files.append('link')
1268 expected = sorted(expected)1275 expected = self.sorted(expected)
1269 self.assertEqual(expected, self.do_iter_changes(tree1, tree2,1276 self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
1270 specific_files=specific_files, require_versioned=False,1277 specific_files=specific_files, require_versioned=False,
1271 want_unversioned=True))1278 want_unversioned=True))
@@ -1310,7 +1317,7 @@
1310 expected.append(self.renamed(tree1, tree2, b'link-id', False))1317 expected.append(self.renamed(tree1, tree2, b'link-id', False))
1311 expected.append(self.unversioned(tree2, 'link'))1318 expected.append(self.unversioned(tree2, 'link'))
1312 specific_files.append('link')1319 specific_files.append('link')
1313 expected = sorted(expected)1320 expected = self.sorted(expected)
1314 # run once with, and once without specific files, to catch1321 # run once with, and once without specific files, to catch
1315 # potentially different code paths.1322 # potentially different code paths.
1316 self.assertEqual(expected, self.do_iter_changes(tree1, tree2,1323 self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
@@ -1351,7 +1358,7 @@
13511358
1352 self.assertEqual([], self.do_iter_changes(tree1, tree2,1359 self.assertEqual([], self.do_iter_changes(tree1, tree2,
1353 want_unversioned=True))1360 want_unversioned=True))
1354 expected = sorted([1361 expected = self.sorted([
1355 self.unchanged(tree2, tree2.get_root_id()),1362 self.unchanged(tree2, tree2.get_root_id()),
1356 self.unchanged(tree2, b'a-id'),1363 self.unchanged(tree2, b'a-id'),
1357 self.unchanged(tree2, b'b-id'),1364 self.unchanged(tree2, b'b-id'),
@@ -1436,7 +1443,7 @@
1436 self.kind_changed(tree1, tree2, b'todir'),1443 self.kind_changed(tree1, tree2, b'todir'),
1437 self.kind_changed(tree1, tree2, b'tofile'),1444 self.kind_changed(tree1, tree2, b'tofile'),
1438 ]1445 ]
1439 expected = sorted(expected)1446 expected = self.sorted(expected)
1440 self.assertEqual(expected,1447 self.assertEqual(expected,
1441 self.do_iter_changes(tree1, tree2, include_unchanged=True,1448 self.do_iter_changes(tree1, tree2, include_unchanged=True,
1442 want_unversioned=True))1449 want_unversioned=True))
@@ -1455,7 +1462,7 @@
1455 self.kind_changed(tree1, tree2, b'todir'),1462 self.kind_changed(tree1, tree2, b'todir'),
1456 self.kind_changed(tree1, tree2, b'tofile'),1463 self.kind_changed(tree1, tree2, b'tofile'),
1457 ]1464 ]
1458 expected = sorted(expected)1465 expected = self.sorted(expected)
1459 # we should get back just the changed links. We pass in 'unchanged' to1466 # we should get back just the changed links. We pass in 'unchanged' to
1460 # make sure that it is correctly not returned - and neither is the1467 # make sure that it is correctly not returned - and neither is the
1461 # unknown path 'unknown' which it points at.1468 # unknown path 'unknown' which it points at.
@@ -1466,13 +1473,13 @@
14661473
1467 def test_tree_with_special_names(self):1474 def test_tree_with_special_names(self):
1468 tree1, tree2, paths, path_ids = self.make_tree_with_special_names()1475 tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
1469 expected = sorted(self.added(tree2, f_id) for f_id in path_ids)1476 expected = self.sorted(self.added(tree2, f_id) for f_id in path_ids)
1470 self.assertEqual(expected, self.do_iter_changes(tree1, tree2))1477 self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1471 self.check_has_changes(True, tree1, tree2)1478 self.check_has_changes(True, tree1, tree2)
14721479
1473 def test_trees_with_special_names(self):1480 def test_trees_with_special_names(self):
1474 tree1, tree2, paths, path_ids = self.make_trees_with_special_names()1481 tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
1475 expected = sorted(self.content_changed(tree2, f_id) for f_id in path_ids1482 expected = self.sorted(self.content_changed(tree2, f_id) for f_id in path_ids
1476 if f_id.endswith(b'_f-id'))1483 if f_id.endswith(b'_f-id'))
1477 self.assertEqual(expected, self.do_iter_changes(tree1, tree2))1484 self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1478 self.check_has_changes(True, tree1, tree2)1485 self.check_has_changes(True, tree1, tree2)
@@ -1650,7 +1657,7 @@
16501657
1651 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)1658 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
16521659
1653 expected = sorted([1660 expected = self.sorted([
1654 self.unchanged(tree1, root_id),1661 self.unchanged(tree1, root_id),
1655 self.unchanged(tree1, a_id),1662 self.unchanged(tree1, a_id),
1656 self.unchanged(tree1, subfile_id),1663 self.unchanged(tree1, subfile_id),
@@ -1661,7 +1668,7 @@
1661 include_unchanged=True))1668 include_unchanged=True))
16621669
1663 # We should also be able to select just a subset1670 # We should also be able to select just a subset
1664 expected = sorted([1671 expected = self.sorted([
1665 self.unchanged(tree1, a_id),1672 self.unchanged(tree1, a_id),
1666 self.unchanged(tree1, subfile_id),1673 self.unchanged(tree1, subfile_id),
1667 ])1674 ])
@@ -1693,7 +1700,7 @@
1693 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)1700 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1694 self.not_applicable_if_cannot_represent_unversioned(tree2)1701 self.not_applicable_if_cannot_represent_unversioned(tree2)
16951702
1696 expected = sorted([1703 expected = self.sorted([
1697 self.unversioned(tree2, u'\u03b1/unknown_dir'),1704 self.unversioned(tree2, u'\u03b1/unknown_dir'),
1698 self.unversioned(tree2, u'\u03b1/unknown_file'),1705 self.unversioned(tree2, u'\u03b1/unknown_file'),
1699 self.unversioned(tree2, u'\u03c9-unknown_root_file'),1706 self.unversioned(tree2, u'\u03c9-unknown_root_file'),
@@ -1710,7 +1717,7 @@
1710 self.check_has_changes(False, tree1, tree2)1717 self.check_has_changes(False, tree1, tree2)
17111718
1712 # We should also be able to select just a subset1719 # We should also be able to select just a subset
1713 expected = sorted([1720 expected = self.sorted([
1714 self.unversioned(tree2, u'\u03b1/unknown_dir'),1721 self.unversioned(tree2, u'\u03b1/unknown_dir'),
1715 self.unversioned(tree2, u'\u03b1/unknown_file'),1722 self.unversioned(tree2, u'\u03b1/unknown_file'),
1716 ])1723 ])
@@ -1745,7 +1752,7 @@
1745 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)1752 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1746 self.not_applicable_if_cannot_represent_unversioned(tree2)1753 self.not_applicable_if_cannot_represent_unversioned(tree2)
17471754
1748 expected = sorted([1755 expected = self.sorted([
1749 self.unversioned(tree2, u'a/file'),1756 self.unversioned(tree2, u'a/file'),
1750 self.unversioned(tree2, u'a/dir'),1757 self.unversioned(tree2, u'a/dir'),
1751 ])1758 ])
@@ -1780,7 +1787,7 @@
17801787
1781 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)1788 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
17821789
1783 expected = sorted([1790 expected = self.sorted([
1784 self.deleted(tree1, b'a-id'),1791 self.deleted(tree1, b'a-id'),
1785 self.deleted(tree1, b'd-id'),1792 self.deleted(tree1, b'd-id'),
1786 self.renamed(tree1, tree2, b'b-id', False),1793 self.renamed(tree1, tree2, b'b-id', False),
@@ -1814,14 +1821,14 @@
1814 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)1821 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1815 self.not_applicable_if_cannot_represent_unversioned(tree2)1822 self.not_applicable_if_cannot_represent_unversioned(tree2)
18161823
1817 expected = sorted([1824 expected = self.sorted([
1818 self.deleted(tree1, b'b-id'),1825 self.deleted(tree1, b'b-id'),
1819 self.unversioned(tree2, 'b'),1826 self.unversioned(tree2, 'b'),
1820 ])1827 ])
1821 self.assertEqual(expected,1828 self.assertEqual(expected,
1822 self.do_iter_changes(tree1, tree2,1829 self.do_iter_changes(tree1, tree2,
1823 want_unversioned=True))1830 want_unversioned=True))
1824 expected = sorted([1831 expected = self.sorted([
1825 self.deleted(tree1, b'b-id'),1832 self.deleted(tree1, b'b-id'),
1826 ])1833 ])
1827 self.assertEqual(expected,1834 self.assertEqual(expected,
@@ -1854,7 +1861,7 @@
18541861
1855 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)1862 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
18561863
1857 expected = sorted([1864 expected = self.sorted([
1858 self.renamed(tree1, tree2, b'b1-id', False),1865 self.renamed(tree1, tree2, b'b1-id', False),
1859 self.renamed(tree1, tree2, b'c1-id', False),1866 self.renamed(tree1, tree2, b'c1-id', False),
1860 self.added(tree2, b'b2-id'),1867 self.added(tree2, b'b2-id'),
@@ -1888,7 +1895,7 @@
1888 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)1895 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1889 self.not_applicable_if_missing_in('a', tree2)1896 self.not_applicable_if_missing_in('a', tree2)
18901897
1891 expected = sorted([1898 expected = self.sorted([
1892 self.missing(b'a-id', 'a', 'a', tree2.get_root_id(), 'file'),1899 self.missing(b'a-id', 'a', 'a', tree2.get_root_id(), 'file'),
1893 self.unversioned(tree2, 'a2'),1900 self.unversioned(tree2, 'a2'),
1894 ])1901 ])
18951902
=== modified file 'breezy/transform.py'
--- breezy/transform.py 2018-08-07 20:43:32 +0000
+++ breezy/transform.py 2018-08-20 21:52:41 +0000
@@ -1960,8 +1960,11 @@
1960 path = self._tree_id_paths[parent_id]1960 path = self._tree_id_paths[parent_id]
1961 except KeyError:1961 except KeyError:
1962 return1962 return
1963 entry = next(self._tree.iter_entries_by_dir(1963 try:
1964 specific_files=[path]))[1]1964 entry = next(self._tree.iter_entries_by_dir(
1965 specific_files=[path]))[1]
1966 except StopIteration:
1967 return
1965 children = getattr(entry, 'children', {})1968 children = getattr(entry, 'children', {})
1966 for child in children:1969 for child in children:
1967 childpath = joinpath(path, child)1970 childpath = joinpath(path, child)

Subscribers

People subscribed via source and target branches