~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-01-13 05:14:24 UTC
  • mfrom: (3936.1.3 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090113051424-nrk3zkfe09h46i9y
(mbp) merge 1.11 and advance to 1.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    symbol_versioning,
32
32
    )
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
345
345
        """
346
346
        raise NotImplementedError(self.get_symlink_target)
347
347
 
 
348
    def get_canonical_inventory_paths(self, paths):
 
349
        """Like get_canonical_inventory_path() but works on multiple items.
 
350
 
 
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
 
354
        insensitively.
 
355
        """
 
356
        return list(self._yield_canonical_inventory_paths(paths))
 
357
 
 
358
    def get_canonical_inventory_path(self, path):
 
359
        """Returns the first inventory item that case-insensitively matches path.
 
360
 
 
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.
 
364
 
 
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
 
367
        form.
 
368
 
 
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.
 
371
 
 
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.
 
375
        """
 
376
        return self._yield_canonical_inventory_paths([path]).next()
 
377
 
 
378
    def _yield_canonical_inventory_paths(self, paths):
 
379
        for path in paths:
 
380
            # First, if the path as specified exists exactly, just use it.
 
381
            if self.path2id(path) is not None:
 
382
                yield path
 
383
                continue
 
384
            # go walkin...
 
385
            cur_id = self.get_root_id()
 
386
            cur_path = ''
 
387
            bit_iter = iter(path.split("/"))
 
388
            for elt in bit_iter:
 
389
                lelt = elt.lower()
 
390
                for child in self.iter_children(cur_id):
 
391
                    try:
 
392
                        child_base = os.path.basename(self.id2path(child))
 
393
                        if child_base.lower() == lelt:
 
394
                            cur_id = child
 
395
                            cur_path = osutils.pathjoin(cur_path, child_base)
 
396
                            break
 
397
                    except NoSuchId:
 
398
                        # before a change is committed we can see this error...
 
399
                        continue
 
400
                else:
 
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))
 
404
                    break
 
405
            yield cur_path
 
406
        # all done.
 
407
 
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)