33
33
from bzrlib.decorators import needs_read_lock
34
from bzrlib.errors import BzrError, BzrCheckError
34
from bzrlib.errors import BzrError, BzrCheckError, NoSuchId
35
35
from bzrlib import errors
36
36
from bzrlib.inventory import Inventory, InventoryFile
37
37
from bzrlib.inter import InterObject
346
346
raise NotImplementedError(self.get_symlink_target)
348
def get_canonical_inventory_paths(self, paths):
349
"""Like get_canonical_inventory_path() but works on multiple items.
351
:param paths: A sequence of paths relative to the root of the tree.
352
:return: A list of paths, with each item the corresponding input path
353
adjusted to account for existing elements that match case
356
return list(self._yield_canonical_inventory_paths(paths))
358
def get_canonical_inventory_path(self, path):
359
"""Returns the first inventory item that case-insensitively matches path.
361
If a path matches exactly, it is returned. If no path matches exactly
362
but more than one path matches case-insensitively, it is implementation
363
defined which is returned.
365
If no path matches case-insensitively, the input path is returned, but
366
with as many path entries that do exist changed to their canonical
369
If you need to resolve many names from the same tree, you should
370
use get_canonical_inventory_paths() to avoid O(N) behaviour.
372
:param path: A paths relative to the root of the tree.
373
:return: The input path adjusted to account for existing elements
374
that match case insensitively.
376
return self._yield_canonical_inventory_paths([path]).next()
378
def _yield_canonical_inventory_paths(self, paths):
380
# First, if the path as specified exists exactly, just use it.
381
if self.path2id(path) is not None:
385
cur_id = self.get_root_id()
387
bit_iter = iter(path.split("/"))
390
for child in self.iter_children(cur_id):
392
child_base = os.path.basename(self.id2path(child))
393
if child_base.lower() == lelt:
395
cur_path = osutils.pathjoin(cur_path, child_base)
398
# before a change is committed we can see this error...
401
# got to the end of this directory and no entries matched.
402
# Return what matched so far, plus the rest as specified.
403
cur_path = osutils.pathjoin(cur_path, elt, *list(bit_iter))
348
408
def get_root_id(self):
349
409
"""Return the file_id for the root of this tree."""
350
410
raise NotImplementedError(self.get_root_id)