~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Andrew Bennetts
  • Date: 2009-10-26 06:44:40 UTC
  • mfrom: (4634.77.9 2.0)
  • mto: This revision was merged to the branch mainline in revision 4770.
  • Revision ID: andrew.bennetts@canonical.com-20091026064440-06u7tpg7l6sjkh8h
Merge lp:bzr/2.0 into lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1054
1054
    def _limbo_name(self, trans_id):
1055
1055
        """Generate the limbo name of a file"""
1056
1056
        limbo_name = self._limbo_files.get(trans_id)
1057
 
        if limbo_name is not None:
1058
 
            return limbo_name
1059
 
        parent = self._new_parent.get(trans_id)
1060
 
        # if the parent directory is already in limbo (e.g. when building a
1061
 
        # tree), choose a limbo name inside the parent, to reduce further
1062
 
        # renames.
1063
 
        use_direct_path = False
1064
 
        if self._new_contents.get(parent) == 'directory':
1065
 
            filename = self._new_name.get(trans_id)
1066
 
            if filename is not None:
1067
 
                if parent not in self._limbo_children:
1068
 
                    self._limbo_children[parent] = set()
1069
 
                    self._limbo_children_names[parent] = {}
1070
 
                    use_direct_path = True
1071
 
                # the direct path can only be used if no other file has
1072
 
                # already taken this pathname, i.e. if the name is unused, or
1073
 
                # if it is already associated with this trans_id.
1074
 
                elif self._case_sensitive_target:
1075
 
                    if (self._limbo_children_names[parent].get(filename)
1076
 
                        in (trans_id, None)):
1077
 
                        use_direct_path = True
1078
 
                else:
1079
 
                    for l_filename, l_trans_id in\
1080
 
                        self._limbo_children_names[parent].iteritems():
1081
 
                        if l_trans_id == trans_id:
1082
 
                            continue
1083
 
                        if l_filename.lower() == filename.lower():
1084
 
                            break
1085
 
                    else:
1086
 
                        use_direct_path = True
1087
 
 
1088
 
        if use_direct_path:
1089
 
            limbo_name = pathjoin(self._limbo_files[parent], filename)
1090
 
            self._limbo_children[parent].add(trans_id)
1091
 
            self._limbo_children_names[parent][filename] = trans_id
1092
 
        else:
1093
 
            limbo_name = pathjoin(self._limbodir, trans_id)
1094
 
            self._needs_rename.add(trans_id)
1095
 
        self._limbo_files[trans_id] = limbo_name
 
1057
        if limbo_name is None:
 
1058
            limbo_name = self._generate_limbo_path(trans_id)
 
1059
            self._limbo_files[trans_id] = limbo_name
1096
1060
        return limbo_name
1097
1061
 
 
1062
    def _generate_limbo_path(self, trans_id):
 
1063
        """Generate a limbo path using the trans_id as the relative path.
 
1064
 
 
1065
        This is suitable as a fallback, and when the transform should not be
 
1066
        sensitive to the path encoding of the limbo directory.
 
1067
        """
 
1068
        self._needs_rename.add(trans_id)
 
1069
        return pathjoin(self._limbodir, trans_id)
 
1070
 
1098
1071
    def adjust_path(self, name, parent, trans_id):
1099
1072
        previous_parent = self._new_parent.get(trans_id)
1100
1073
        previous_name = self._new_name.get(trans_id)
1407
1380
                continue
1408
1381
            yield self.trans_id_tree_path(childpath)
1409
1382
 
 
1383
    def _generate_limbo_path(self, trans_id):
 
1384
        """Generate a limbo path using the final path if possible.
 
1385
 
 
1386
        This optimizes the performance of applying the tree transform by
 
1387
        avoiding renames.  These renames can be avoided only when the parent
 
1388
        directory is already scheduled for creation.
 
1389
 
 
1390
        If the final path cannot be used, falls back to using the trans_id as
 
1391
        the relpath.
 
1392
        """
 
1393
        parent = self._new_parent.get(trans_id)
 
1394
        # if the parent directory is already in limbo (e.g. when building a
 
1395
        # tree), choose a limbo name inside the parent, to reduce further
 
1396
        # renames.
 
1397
        use_direct_path = False
 
1398
        if self._new_contents.get(parent) == 'directory':
 
1399
            filename = self._new_name.get(trans_id)
 
1400
            if filename is not None:
 
1401
                if parent not in self._limbo_children:
 
1402
                    self._limbo_children[parent] = set()
 
1403
                    self._limbo_children_names[parent] = {}
 
1404
                    use_direct_path = True
 
1405
                # the direct path can only be used if no other file has
 
1406
                # already taken this pathname, i.e. if the name is unused, or
 
1407
                # if it is already associated with this trans_id.
 
1408
                elif self._case_sensitive_target:
 
1409
                    if (self._limbo_children_names[parent].get(filename)
 
1410
                        in (trans_id, None)):
 
1411
                        use_direct_path = True
 
1412
                else:
 
1413
                    for l_filename, l_trans_id in\
 
1414
                        self._limbo_children_names[parent].iteritems():
 
1415
                        if l_trans_id == trans_id:
 
1416
                            continue
 
1417
                        if l_filename.lower() == filename.lower():
 
1418
                            break
 
1419
                    else:
 
1420
                        use_direct_path = True
 
1421
 
 
1422
        if not use_direct_path:
 
1423
            return DiskTreeTransform._generate_limbo_path(self, trans_id)
 
1424
 
 
1425
        limbo_name = pathjoin(self._limbo_files[parent], filename)
 
1426
        self._limbo_children[parent].add(trans_id)
 
1427
        self._limbo_children_names[parent][filename] = trans_id
 
1428
        return limbo_name
 
1429
 
 
1430
 
1410
1431
    def apply(self, no_conflicts=False, precomputed_delta=None, _mover=None):
1411
1432
        """Apply all changes to the inventory and filesystem.
1412
1433