/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tree.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-09-14 22:58:47 UTC
  • mfrom: (7104.3.4 brz-git-renames)
  • Revision ID: breezy.the.bot@gmail.com-20180914225847-0qnfeylaf94259b0
Some refactoring around get_canonical_inventory_paths.

* Drop the 'inventory' bit since it doesn't apply to non-inventory trees
* Move to working trees; canonicalization currently only matters there, where
  files can be stored on case-insensitive (VFAT) or normalizing filesystems
  (i.e. Mac OS X)
* Run tests against all working tree formats, including Git, not just InventoryTree ones

This fixes 'bzr mv' and 'bzr rename' for Git.

Merged from https://code.launchpad.net/~jelmer/brz/brz-git-renames/+merge/354952

Show diffs side-by-side

added added

removed removed

Lines of Context:
1364
1364
        return to_tree.id2path(file_id)
1365
1365
    except errors.NoSuchId:
1366
1366
        return None
 
1367
 
 
1368
 
 
1369
def get_canonical_path(tree, path, normalize):
 
1370
    """Find the canonical path of an item, ignoring case.
 
1371
 
 
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
 
1376
    """
 
1377
    # go walkin...
 
1378
    cur_id = self.get_root_id()
 
1379
    cur_path = ''
 
1380
    bit_iter = iter(path.split("/"))
 
1381
    for elt in bit_iter:
 
1382
        lelt = normalize(elt)
 
1383
        new_path = None
 
1384
        try:
 
1385
            for child in self.iter_child_entries(cur_path, cur_id):
 
1386
                try:
 
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
 
1391
                        # later.
 
1392
                        cur_id = child.file_id
 
1393
                        new_path = osutils.pathjoin(cur_path, child.name)
 
1394
                        break
 
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...
 
1400
                    continue
 
1401
        except errors.NotADirectory:
 
1402
            pass
 
1403
        if new_path:
 
1404
            cur_path = new_path
 
1405
        else:
 
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))
 
1409
            break
 
1410
    return cur_path