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:
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
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
1079
for l_filename, l_trans_id in\
1080
self._limbo_children_names[parent].iteritems():
1081
if l_trans_id == trans_id:
1083
if l_filename.lower() == filename.lower():
1086
use_direct_path = True
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
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
1062
def _generate_limbo_path(self, trans_id):
1063
"""Generate a limbo path using the trans_id as the relative path.
1065
This is suitable as a fallback, and when the transform should not be
1066
sensitive to the path encoding of the limbo directory.
1068
self._needs_rename.add(trans_id)
1069
return pathjoin(self._limbodir, trans_id)
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)
1408
1381
yield self.trans_id_tree_path(childpath)
1383
def _generate_limbo_path(self, trans_id):
1384
"""Generate a limbo path using the final path if possible.
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.
1390
If the final path cannot be used, falls back to using the trans_id as
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
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
1413
for l_filename, l_trans_id in\
1414
self._limbo_children_names[parent].iteritems():
1415
if l_trans_id == trans_id:
1417
if l_filename.lower() == filename.lower():
1420
use_direct_path = True
1422
if not use_direct_path:
1423
return DiskTreeTransform._generate_limbo_path(self, trans_id)
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
1410
1431
def apply(self, no_conflicts=False, precomputed_delta=None, _mover=None):
1411
1432
"""Apply all changes to the inventory and filesystem.