/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 bzrlib/inventory.py

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
879
879
    def _forget_tree_state(self):
880
880
        self.reference_revision = None 
881
881
 
 
882
    def _unchanged(self, previous_ie):
 
883
        """See InventoryEntry._unchanged."""
 
884
        compatible = super(TreeReference, self)._unchanged(previous_ie)
 
885
        if self.reference_revision != previous_ie.reference_revision:
 
886
            compatible = False
 
887
        return compatible
 
888
 
882
889
 
883
890
class Inventory(object):
884
891
    """Inventory of versioned files in a tree.
1004
1011
                # if we finished all children, pop it off the stack
1005
1012
                stack.pop()
1006
1013
 
1007
 
    def iter_entries_by_dir(self, from_dir=None, specific_file_ids=None):
 
1014
    def iter_entries_by_dir(self, from_dir=None, specific_file_ids=None,
 
1015
        yield_parents=False):
1008
1016
        """Iterate over the entries in a directory first order.
1009
1017
 
1010
1018
        This returns all entries for a directory before returning
1012
1020
        lexicographically sorted order, and is a hybrid between
1013
1021
        depth-first and breadth-first.
1014
1022
 
 
1023
        :param yield_parents: If True, yield the parents from the root leading
 
1024
            down to specific_file_ids that have been requested. This has no
 
1025
            impact if specific_file_ids is None.
1015
1026
        :return: This yields (path, entry) pairs
1016
1027
        """
1017
1028
        if specific_file_ids:
1023
1034
            if self.root is None:
1024
1035
                return
1025
1036
            # Optimize a common case
1026
 
            if specific_file_ids is not None and len(specific_file_ids) == 1:
 
1037
            if (not yield_parents and specific_file_ids is not None and
 
1038
                len(specific_file_ids) == 1):
1027
1039
                file_id = list(specific_file_ids)[0]
1028
1040
                if file_id in self:
1029
1041
                    yield self.id2path(file_id), self[file_id]
1030
1042
                return 
1031
1043
            from_dir = self.root
1032
 
            if (specific_file_ids is None or 
 
1044
            if (specific_file_ids is None or yield_parents or
1033
1045
                self.root.file_id in specific_file_ids):
1034
1046
                yield u'', self.root
1035
1047
        elif isinstance(from_dir, basestring):
1064
1076
                child_relpath = cur_relpath + child_name
1065
1077
 
1066
1078
                if (specific_file_ids is None or 
1067
 
                    child_ie.file_id in specific_file_ids):
 
1079
                    child_ie.file_id in specific_file_ids or
 
1080
                    (yield_parents and child_ie.file_id in parents)):
1068
1081
                    yield child_relpath, child_ie
1069
1082
 
1070
1083
                if child_ie.kind == 'directory':
1371
1384
        This does not move the working file.
1372
1385
        """
1373
1386
        file_id = osutils.safe_file_id(file_id)
 
1387
        new_name = ensure_normalized_name(new_name)
1374
1388
        if not is_valid_name(new_name):
1375
1389
            raise BzrError("not an acceptable filename: %r" % new_name)
1376
1390
 
1418
1432
        file_id = generate_ids.gen_file_id(name)
1419
1433
    else:
1420
1434
        file_id = osutils.safe_file_id(file_id)
1421
 
 
 
1435
    name = ensure_normalized_name(name)
 
1436
    try:
 
1437
        factory = entry_factory[kind]
 
1438
    except KeyError:
 
1439
        raise BzrError("unknown kind %r" % kind)
 
1440
    return factory(file_id, name, parent_id)
 
1441
 
 
1442
 
 
1443
def ensure_normalized_name(name):
 
1444
    """Normalize name.
 
1445
 
 
1446
    :raises InvalidNormalization: When name is not normalized, and cannot be
 
1447
        accessed on this platform by the normalized path.
 
1448
    :return: The NFC/NFKC normalised version of name.
 
1449
    """
1422
1450
    #------- This has been copied to bzrlib.dirstate.DirState.add, please
1423
1451
    # keep them synchronised.
1424
1452
    # we dont import normalized_filename directly because we want to be
1426
1454
    norm_name, can_access = osutils.normalized_filename(name)
1427
1455
    if norm_name != name:
1428
1456
        if can_access:
1429
 
            name = norm_name
 
1457
            return norm_name
1430
1458
        else:
1431
1459
            # TODO: jam 20060701 This would probably be more useful
1432
1460
            #       if the error was raised with the full path
1433
1461
            raise errors.InvalidNormalization(name)
1434
 
 
1435
 
    try:
1436
 
        factory = entry_factory[kind]
1437
 
    except KeyError:
1438
 
        raise BzrError("unknown kind %r" % kind)
1439
 
    return factory(file_id, name, parent_id)
 
1462
    return name
1440
1463
 
1441
1464
 
1442
1465
_NAME_RE = None