Merge lp:~jelmer/brz/get-canonical-path 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/get-canonical-path
Merge into: lp:brz
Diff against target: 77 lines (+44/-2)
2 files modified
breezy/tests/test_tree.py (+42/-0)
breezy/tree.py (+2/-2)
To merge this branch: bzr merge lp:~jelmer/brz/get-canonical-path
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+355879@code.launchpad.net

Commit message

Fix get_canonical_path and add some basic tests for it.

Description of the change

Fix get_canonical_path and add some basic tests for it.

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

Looks good, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/tests/test_tree.py'
--- breezy/tests/test_tree.py 2018-07-26 22:12:29 +0000
+++ breezy/tests/test_tree.py 2018-09-29 23:00:39 +0000
@@ -29,6 +29,7 @@
29 FileTimestampUnavailable,29 FileTimestampUnavailable,
30 InterTree,30 InterTree,
31 find_previous_paths,31 find_previous_paths,
32 get_canonical_path,
32 )33 )
3334
3435
@@ -461,3 +462,44 @@
461462
462 self.assertEqual({'c': 'b', 'b': None},463 self.assertEqual({'c': 'b', 'b': None},
463 find_previous_paths(tree2, tree1, ['b', 'c']))464 find_previous_paths(tree2, tree1, ['b', 'c']))
465
466
467class GetCanonicalPath(TestCaseWithTransport):
468
469 def test_existing_case(self):
470 # Test that we can find a file from a path with different case
471 tree = self.make_branch_and_tree('tree')
472 self.build_tree(['tree/b'])
473 tree.add(['b'])
474 self.assertEqual(
475 'b',
476 get_canonical_path(tree, 'b', lambda x: x.lower()))
477 self.assertEqual(
478 'b',
479 get_canonical_path(tree, 'B', lambda x: x.lower()))
480
481 def test_nonexistant_preserves_case(self):
482 tree = self.make_branch_and_tree('tree')
483 self.assertEqual(
484 'b',
485 get_canonical_path(tree, 'b', lambda x: x.lower()))
486 self.assertEqual(
487 'B',
488 get_canonical_path(tree, 'B', lambda x: x.lower()))
489
490 def test_in_directory_with_case(self):
491 tree = self.make_branch_and_tree('tree')
492 self.build_tree(['tree/a/', 'tree/a/b'])
493 tree.add(['a', 'a/b'])
494 self.assertEqual(
495 'a/b',
496 get_canonical_path(tree, 'a/b', lambda x: x.lower()))
497 self.assertEqual(
498 'a/b',
499 get_canonical_path(tree, 'A/B', lambda x: x.lower()))
500 self.assertEqual(
501 'a/b',
502 get_canonical_path(tree, 'A/b', lambda x: x.lower()))
503 self.assertEqual(
504 'a/C',
505 get_canonical_path(tree, 'A/C', lambda x: x.lower()))
464506
=== modified file 'breezy/tree.py'
--- breezy/tree.py 2018-09-14 14:35:18 +0000
+++ breezy/tree.py 2018-09-29 23:00:39 +0000
@@ -1375,14 +1375,14 @@
1375 :return: The canonical path1375 :return: The canonical path
1376 """1376 """
1377 # go walkin...1377 # go walkin...
1378 cur_id = self.get_root_id()1378 cur_id = tree.get_root_id()
1379 cur_path = ''1379 cur_path = ''
1380 bit_iter = iter(path.split("/"))1380 bit_iter = iter(path.split("/"))
1381 for elt in bit_iter:1381 for elt in bit_iter:
1382 lelt = normalize(elt)1382 lelt = normalize(elt)
1383 new_path = None1383 new_path = None
1384 try:1384 try:
1385 for child in self.iter_child_entries(cur_path, cur_id):1385 for child in tree.iter_child_entries(cur_path, cur_id):
1386 try:1386 try:
1387 if child.name == elt:1387 if child.name == elt:
1388 # if we found an exact match, we can stop now; if1388 # if we found an exact match, we can stop now; if

Subscribers

People subscribed via source and target branches