Merge lp:~jelmer/brz/get-canonical-path into lp:brz

Proposed by Jelmer Vernooij on 2018-09-29
Status: Merged
Approved by: Jelmer Vernooij on 2018-10-13
Approved revision: 7132
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 2018-09-29 Approve on 2018-10-13
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.
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
1=== modified file 'breezy/tests/test_tree.py'
2--- breezy/tests/test_tree.py 2018-07-26 22:12:29 +0000
3+++ breezy/tests/test_tree.py 2018-09-29 23:00:39 +0000
4@@ -29,6 +29,7 @@
5 FileTimestampUnavailable,
6 InterTree,
7 find_previous_paths,
8+ get_canonical_path,
9 )
10
11
12@@ -461,3 +462,44 @@
13
14 self.assertEqual({'c': 'b', 'b': None},
15 find_previous_paths(tree2, tree1, ['b', 'c']))
16+
17+
18+class GetCanonicalPath(TestCaseWithTransport):
19+
20+ def test_existing_case(self):
21+ # Test that we can find a file from a path with different case
22+ tree = self.make_branch_and_tree('tree')
23+ self.build_tree(['tree/b'])
24+ tree.add(['b'])
25+ self.assertEqual(
26+ 'b',
27+ get_canonical_path(tree, 'b', lambda x: x.lower()))
28+ self.assertEqual(
29+ 'b',
30+ get_canonical_path(tree, 'B', lambda x: x.lower()))
31+
32+ def test_nonexistant_preserves_case(self):
33+ tree = self.make_branch_and_tree('tree')
34+ self.assertEqual(
35+ 'b',
36+ get_canonical_path(tree, 'b', lambda x: x.lower()))
37+ self.assertEqual(
38+ 'B',
39+ get_canonical_path(tree, 'B', lambda x: x.lower()))
40+
41+ def test_in_directory_with_case(self):
42+ tree = self.make_branch_and_tree('tree')
43+ self.build_tree(['tree/a/', 'tree/a/b'])
44+ tree.add(['a', 'a/b'])
45+ self.assertEqual(
46+ 'a/b',
47+ get_canonical_path(tree, 'a/b', lambda x: x.lower()))
48+ self.assertEqual(
49+ 'a/b',
50+ get_canonical_path(tree, 'A/B', lambda x: x.lower()))
51+ self.assertEqual(
52+ 'a/b',
53+ get_canonical_path(tree, 'A/b', lambda x: x.lower()))
54+ self.assertEqual(
55+ 'a/C',
56+ get_canonical_path(tree, 'A/C', lambda x: x.lower()))
57
58=== modified file 'breezy/tree.py'
59--- breezy/tree.py 2018-09-14 14:35:18 +0000
60+++ breezy/tree.py 2018-09-29 23:00:39 +0000
61@@ -1375,14 +1375,14 @@
62 :return: The canonical path
63 """
64 # go walkin...
65- cur_id = self.get_root_id()
66+ cur_id = tree.get_root_id()
67 cur_path = ''
68 bit_iter = iter(path.split("/"))
69 for elt in bit_iter:
70 lelt = normalize(elt)
71 new_path = None
72 try:
73- for child in self.iter_child_entries(cur_path, cur_id):
74+ for child in tree.iter_child_entries(cur_path, cur_id):
75 try:
76 if child.name == elt:
77 # if we found an exact match, we can stop now; if

Subscribers

People subscribed via source and target branches