1364
1364
return to_tree.id2path(file_id)
1365
1365
except errors.NoSuchId:
1369
def get_canonical_path(tree, path, normalize):
1370
"""Find the canonical path of an item, ignoring case.
1372
:param tree: Tree to traverse
1373
:param path: Case-insensitive path to look up
1374
:param normalize: Function to normalize a filename for comparison
1375
:return: The canonical path
1378
cur_id = self.get_root_id()
1380
bit_iter = iter(path.split("/"))
1381
for elt in bit_iter:
1382
lelt = normalize(elt)
1385
for child in self.iter_child_entries(cur_path, cur_id):
1387
if child.name == elt:
1388
# if we found an exact match, we can stop now; if
1389
# we found an approximate match we need to keep
1390
# searching because there might be an exact match
1392
cur_id = child.file_id
1393
new_path = osutils.pathjoin(cur_path, child.name)
1395
elif normalize(child.name) == lelt:
1396
cur_id = child.file_id
1397
new_path = osutils.pathjoin(cur_path, child.name)
1398
except errors.NoSuchId:
1399
# before a change is committed we can see this error...
1401
except errors.NotADirectory:
1406
# got to the end of this directory and no entries matched.
1407
# Return what matched so far, plus the rest as specified.
1408
cur_path = osutils.pathjoin(cur_path, elt, *list(bit_iter))