323
317
return ROOT_PARENT
324
318
return self.trans_id_tree_path(os.path.dirname(path))
326
def create_file(self, contents, trans_id, mode_id=None):
327
"""Schedule creation of a new file.
331
Contents is an iterator of strings, all of which will be written
332
to the target destination.
334
New file takes the permissions of any existing file with that id,
335
unless mode_id is specified.
337
name = self._limbo_name(trans_id)
341
unique_add(self._new_contents, trans_id, 'file')
343
# Clean up the file, it never got registered so
344
# TreeTransform.finalize() won't clean it up.
349
f.writelines(contents)
352
self._set_mode(trans_id, mode_id, S_ISREG)
354
def _set_mode(self, trans_id, mode_id, typefunc):
355
"""Set the mode of new file contents.
356
The mode_id is the existing file to get the mode from (often the same
357
as trans_id). The operation is only performed if there's a mode match
358
according to typefunc.
363
old_path = self._tree_id_paths[mode_id]
367
mode = os.stat(self._tree.abspath(old_path)).st_mode
369
if e.errno in (errno.ENOENT, errno.ENOTDIR):
370
# Either old_path doesn't exist, or the parent of the
371
# target is not a directory (but will be one eventually)
372
# Either way, we know it doesn't exist *right now*
373
# See also bug #248448
378
os.chmod(self._limbo_name(trans_id), mode)
380
def create_hardlink(self, path, trans_id):
381
"""Schedule creation of a hard link"""
382
name = self._limbo_name(trans_id)
386
if e.errno != errno.EPERM:
388
raise errors.HardLinkNotSupported(path)
390
unique_add(self._new_contents, trans_id, 'file')
392
# Clean up the file, it never got registered so
393
# TreeTransform.finalize() won't clean it up.
397
def create_directory(self, trans_id):
398
"""Schedule creation of a new directory.
400
See also new_directory.
402
os.mkdir(self._limbo_name(trans_id))
403
unique_add(self._new_contents, trans_id, 'directory')
405
def create_symlink(self, target, trans_id):
406
"""Schedule creation of a new symbolic link.
408
target is a bytestring.
409
See also new_symlink.
412
os.symlink(target, self._limbo_name(trans_id))
413
unique_add(self._new_contents, trans_id, 'symlink')
416
path = FinalPaths(self).get_path(trans_id)
419
raise UnableCreateSymlink(path=path)
421
def cancel_creation(self, trans_id):
422
"""Cancel the creation of new file contents."""
423
del self._new_contents[trans_id]
424
children = self._limbo_children.get(trans_id)
425
# if this is a limbo directory with children, move them before removing
427
if children is not None:
428
self._rename_in_limbo(children)
429
del self._limbo_children[trans_id]
430
del self._limbo_children_names[trans_id]
431
delete_any(self._limbo_name(trans_id))
433
320
def delete_contents(self, trans_id):
434
321
"""Schedule the contents of a path entry for deletion"""
435
self.tree_kind(trans_id)
436
self._removed_contents.add(trans_id)
322
kind = self.tree_kind(trans_id)
324
self._removed_contents.add(trans_id)
438
326
def cancel_deletion(self, trans_id):
439
327
"""Cancel a scheduled deletion"""
1113
976
def get_preview_tree(self):
1114
977
"""Return a tree representing the result of the transform.
1116
This tree only supports the subset of Tree functionality required
1117
by show_diff_trees. It must only be compared to tt._tree.
979
The tree is a snapshot, and altering the TreeTransform will invalidate
1119
982
return _PreviewTree(self)
1122
class TreeTransform(TreeTransformBase):
984
def commit(self, branch, message, merge_parents=None, strict=False,
985
timestamp=None, timezone=None, committer=None, authors=None,
986
revprops=None, revision_id=None):
987
"""Commit the result of this TreeTransform to a branch.
989
:param branch: The branch to commit to.
990
:param message: The message to attach to the commit.
991
:param merge_parents: Additional parent revision-ids specified by
993
:param strict: If True, abort the commit if there are unversioned
995
:param timestamp: if not None, seconds-since-epoch for the time and
996
date. (May be a float.)
997
:param timezone: Optional timezone for timestamp, as an offset in
999
:param committer: Optional committer in email-id format.
1000
(e.g. "J Random Hacker <jrandom@example.com>")
1001
:param authors: Optional list of authors in email-id format.
1002
:param revprops: Optional dictionary of revision properties.
1003
:param revision_id: Optional revision id. (Specifying a revision-id
1004
may reduce performance for some non-native formats.)
1005
:return: The revision_id of the revision committed.
1007
self._check_malformed()
1009
unversioned = set(self._new_contents).difference(set(self._new_id))
1010
for trans_id in unversioned:
1011
if self.final_file_id(trans_id) is None:
1012
raise errors.StrictCommitFailed()
1014
revno, last_rev_id = branch.last_revision_info()
1015
if last_rev_id == _mod_revision.NULL_REVISION:
1016
if merge_parents is not None:
1017
raise ValueError('Cannot supply merge parents for first'
1021
parent_ids = [last_rev_id]
1022
if merge_parents is not None:
1023
parent_ids.extend(merge_parents)
1024
if self._tree.get_revision_id() != last_rev_id:
1025
raise ValueError('TreeTransform not based on branch basis: %s' %
1026
self._tree.get_revision_id())
1027
revprops = commit.Commit.update_revprops(revprops, branch, authors)
1028
builder = branch.get_commit_builder(parent_ids,
1029
timestamp=timestamp,
1031
committer=committer,
1033
revision_id=revision_id)
1034
preview = self.get_preview_tree()
1035
list(builder.record_iter_changes(preview, last_rev_id,
1036
self.iter_changes()))
1037
builder.finish_inventory()
1038
revision_id = builder.commit(message)
1039
branch.set_last_revision_info(revno + 1, revision_id)
1042
def _text_parent(self, trans_id):
1043
file_id = self.tree_file_id(trans_id)
1045
if file_id is None or self._tree.kind(file_id) != 'file':
1047
except errors.NoSuchFile:
1051
def _get_parents_texts(self, trans_id):
1052
"""Get texts for compression parents of this file."""
1053
file_id = self._text_parent(trans_id)
1056
return (self._tree.get_file_text(file_id),)
1058
def _get_parents_lines(self, trans_id):
1059
"""Get lines for compression parents of this file."""
1060
file_id = self._text_parent(trans_id)
1063
return (self._tree.get_file_lines(file_id),)
1065
def serialize(self, serializer):
1066
"""Serialize this TreeTransform.
1068
:param serializer: A Serialiser like pack.ContainerSerializer.
1070
new_name = dict((k, v.encode('utf-8')) for k, v in
1071
self._new_name.items())
1072
new_executability = dict((k, int(v)) for k, v in
1073
self._new_executability.items())
1074
tree_path_ids = dict((k.encode('utf-8'), v)
1075
for k, v in self._tree_path_ids.items())
1077
'_id_number': self._id_number,
1078
'_new_name': new_name,
1079
'_new_parent': self._new_parent,
1080
'_new_executability': new_executability,
1081
'_new_id': self._new_id,
1082
'_tree_path_ids': tree_path_ids,
1083
'_removed_id': list(self._removed_id),
1084
'_removed_contents': list(self._removed_contents),
1085
'_non_present_ids': self._non_present_ids,
1087
yield serializer.bytes_record(bencode.bencode(attribs),
1089
for trans_id, kind in self._new_contents.items():
1091
lines = osutils.chunks_to_lines(
1092
self._read_file_chunks(trans_id))
1093
parents = self._get_parents_lines(trans_id)
1094
mpdiff = multiparent.MultiParent.from_lines(lines, parents)
1095
content = ''.join(mpdiff.to_patch())
1096
if kind == 'directory':
1098
if kind == 'symlink':
1099
content = self._read_symlink_target(trans_id)
1100
yield serializer.bytes_record(content, ((trans_id, kind),))
1102
def deserialize(self, records):
1103
"""Deserialize a stored TreeTransform.
1105
:param records: An iterable of (names, content) tuples, as per
1106
pack.ContainerPushParser.
1108
names, content = records.next()
1109
attribs = bencode.bdecode(content)
1110
self._id_number = attribs['_id_number']
1111
self._new_name = dict((k, v.decode('utf-8'))
1112
for k, v in attribs['_new_name'].items())
1113
self._new_parent = attribs['_new_parent']
1114
self._new_executability = dict((k, bool(v)) for k, v in
1115
attribs['_new_executability'].items())
1116
self._new_id = attribs['_new_id']
1117
self._r_new_id = dict((v, k) for k, v in self._new_id.items())
1118
self._tree_path_ids = {}
1119
self._tree_id_paths = {}
1120
for bytepath, trans_id in attribs['_tree_path_ids'].items():
1121
path = bytepath.decode('utf-8')
1122
self._tree_path_ids[path] = trans_id
1123
self._tree_id_paths[trans_id] = path
1124
self._removed_id = set(attribs['_removed_id'])
1125
self._removed_contents = set(attribs['_removed_contents'])
1126
self._non_present_ids = attribs['_non_present_ids']
1127
for ((trans_id, kind),), content in records:
1129
mpdiff = multiparent.MultiParent.from_patch(content)
1130
lines = mpdiff.to_lines(self._get_parents_texts(trans_id))
1131
self.create_file(lines, trans_id)
1132
if kind == 'directory':
1133
self.create_directory(trans_id)
1134
if kind == 'symlink':
1135
self.create_symlink(content.decode('utf-8'), trans_id)
1138
class DiskTreeTransform(TreeTransformBase):
1139
"""Tree transform storing its contents on disk."""
1141
def __init__(self, tree, limbodir, pb=None,
1142
case_sensitive=True):
1144
:param tree: The tree that will be transformed, but not necessarily
1146
:param limbodir: A directory where new files can be stored until
1147
they are installed in their proper places
1149
:param case_sensitive: If True, the target of the transform is
1150
case sensitive, not just case preserving.
1152
TreeTransformBase.__init__(self, tree, pb, case_sensitive)
1153
self._limbodir = limbodir
1154
self._deletiondir = None
1155
# A mapping of transform ids to their limbo filename
1156
self._limbo_files = {}
1157
# A mapping of transform ids to a set of the transform ids of children
1158
# that their limbo directory has
1159
self._limbo_children = {}
1160
# Map transform ids to maps of child filename to child transform id
1161
self._limbo_children_names = {}
1162
# List of transform ids that need to be renamed from limbo into place
1163
self._needs_rename = set()
1164
self._creation_mtime = None
1167
"""Release the working tree lock, if held, clean up limbo dir.
1169
This is required if apply has not been invoked, but can be invoked
1172
if self._tree is None:
1175
entries = [(self._limbo_name(t), t, k) for t, k in
1176
self._new_contents.iteritems()]
1177
entries.sort(reverse=True)
1178
for path, trans_id, kind in entries:
1181
delete_any(self._limbodir)
1183
# We don't especially care *why* the dir is immortal.
1184
raise ImmortalLimbo(self._limbodir)
1186
if self._deletiondir is not None:
1187
delete_any(self._deletiondir)
1189
raise errors.ImmortalPendingDeletion(self._deletiondir)
1191
TreeTransformBase.finalize(self)
1193
def _limbo_name(self, trans_id):
1194
"""Generate the limbo name of a file"""
1195
limbo_name = self._limbo_files.get(trans_id)
1196
if limbo_name is None:
1197
limbo_name = self._generate_limbo_path(trans_id)
1198
self._limbo_files[trans_id] = limbo_name
1201
def _generate_limbo_path(self, trans_id):
1202
"""Generate a limbo path using the trans_id as the relative path.
1204
This is suitable as a fallback, and when the transform should not be
1205
sensitive to the path encoding of the limbo directory.
1207
self._needs_rename.add(trans_id)
1208
return pathjoin(self._limbodir, trans_id)
1210
def adjust_path(self, name, parent, trans_id):
1211
previous_parent = self._new_parent.get(trans_id)
1212
previous_name = self._new_name.get(trans_id)
1213
TreeTransformBase.adjust_path(self, name, parent, trans_id)
1214
if (trans_id in self._limbo_files and
1215
trans_id not in self._needs_rename):
1216
self._rename_in_limbo([trans_id])
1217
if previous_parent != parent:
1218
self._limbo_children[previous_parent].remove(trans_id)
1219
if previous_parent != parent or previous_name != name:
1220
del self._limbo_children_names[previous_parent][previous_name]
1222
def _rename_in_limbo(self, trans_ids):
1223
"""Fix limbo names so that the right final path is produced.
1225
This means we outsmarted ourselves-- we tried to avoid renaming
1226
these files later by creating them with their final names in their
1227
final parents. But now the previous name or parent is no longer
1228
suitable, so we have to rename them.
1230
Even for trans_ids that have no new contents, we must remove their
1231
entries from _limbo_files, because they are now stale.
1233
for trans_id in trans_ids:
1234
old_path = self._limbo_files.pop(trans_id)
1235
if trans_id not in self._new_contents:
1237
new_path = self._limbo_name(trans_id)
1238
os.rename(old_path, new_path)
1239
for descendant in self._limbo_descendants(trans_id):
1240
desc_path = self._limbo_files[descendant]
1241
desc_path = new_path + desc_path[len(old_path):]
1242
self._limbo_files[descendant] = desc_path
1244
def _limbo_descendants(self, trans_id):
1245
"""Return the set of trans_ids whose limbo paths descend from this."""
1246
descendants = set(self._limbo_children.get(trans_id, []))
1247
for descendant in list(descendants):
1248
descendants.update(self._limbo_descendants(descendant))
1251
def create_file(self, contents, trans_id, mode_id=None, sha1=None):
1252
"""Schedule creation of a new file.
1256
:param contents: an iterator of strings, all of which will be written
1257
to the target destination.
1258
:param trans_id: TreeTransform handle
1259
:param mode_id: If not None, force the mode of the target file to match
1260
the mode of the object referenced by mode_id.
1261
Otherwise, we will try to preserve mode bits of an existing file.
1262
:param sha1: If the sha1 of this content is already known, pass it in.
1263
We can use it to prevent future sha1 computations.
1265
name = self._limbo_name(trans_id)
1266
f = open(name, 'wb')
1269
unique_add(self._new_contents, trans_id, 'file')
1271
# Clean up the file, it never got registered so
1272
# TreeTransform.finalize() won't clean it up.
1276
f.writelines(contents)
1279
self._set_mtime(name)
1280
self._set_mode(trans_id, mode_id, S_ISREG)
1281
# It is unfortunate we have to use lstat instead of fstat, but we just
1282
# used utime and chmod on the file, so we need the accurate final
1284
if sha1 is not None:
1285
self._observed_sha1s[trans_id] = (sha1, osutils.lstat(name))
1287
def _read_file_chunks(self, trans_id):
1288
cur_file = open(self._limbo_name(trans_id), 'rb')
1290
return cur_file.readlines()
1294
def _read_symlink_target(self, trans_id):
1295
return os.readlink(self._limbo_name(trans_id))
1297
def _set_mtime(self, path):
1298
"""All files that are created get the same mtime.
1300
This time is set by the first object to be created.
1302
if self._creation_mtime is None:
1303
self._creation_mtime = time.time()
1304
os.utime(path, (self._creation_mtime, self._creation_mtime))
1306
def create_hardlink(self, path, trans_id):
1307
"""Schedule creation of a hard link"""
1308
name = self._limbo_name(trans_id)
1312
if e.errno != errno.EPERM:
1314
raise errors.HardLinkNotSupported(path)
1316
unique_add(self._new_contents, trans_id, 'file')
1318
# Clean up the file, it never got registered so
1319
# TreeTransform.finalize() won't clean it up.
1323
def create_directory(self, trans_id):
1324
"""Schedule creation of a new directory.
1326
See also new_directory.
1328
os.mkdir(self._limbo_name(trans_id))
1329
unique_add(self._new_contents, trans_id, 'directory')
1331
def create_symlink(self, target, trans_id):
1332
"""Schedule creation of a new symbolic link.
1334
target is a bytestring.
1335
See also new_symlink.
1338
os.symlink(target, self._limbo_name(trans_id))
1339
unique_add(self._new_contents, trans_id, 'symlink')
1342
path = FinalPaths(self).get_path(trans_id)
1345
raise UnableCreateSymlink(path=path)
1347
def cancel_creation(self, trans_id):
1348
"""Cancel the creation of new file contents."""
1349
del self._new_contents[trans_id]
1350
if trans_id in self._observed_sha1s:
1351
del self._observed_sha1s[trans_id]
1352
children = self._limbo_children.get(trans_id)
1353
# if this is a limbo directory with children, move them before removing
1355
if children is not None:
1356
self._rename_in_limbo(children)
1357
del self._limbo_children[trans_id]
1358
del self._limbo_children_names[trans_id]
1359
delete_any(self._limbo_name(trans_id))
1361
def new_orphan(self, trans_id, parent_id):
1362
# FIXME: There is no tree config, so we use the branch one (it's weird
1363
# to define it this way as orphaning can only occur in a working tree,
1364
# but that's all we have (for now). It will find the option in
1365
# locations.conf or bazaar.conf though) -- vila 20100916
1366
conf = self._tree.branch.get_config()
1367
conf_var_name = 'bzr.transform.orphan_policy'
1368
orphan_policy = conf.get_user_option(conf_var_name)
1369
default_policy = orphaning_registry.default_key
1370
if orphan_policy is None:
1371
orphan_policy = default_policy
1372
if orphan_policy not in orphaning_registry:
1373
trace.warning('%s (from %s) is not a known policy, defaulting '
1374
'to %s' % (orphan_policy, conf_var_name, default_policy))
1375
orphan_policy = default_policy
1376
handle_orphan = orphaning_registry.get(orphan_policy)
1377
handle_orphan(self, trans_id, parent_id)
1380
class OrphaningError(errors.BzrError):
1382
# Only bugs could lead to such exception being seen by the user
1383
internal_error = True
1384
_fmt = "Error while orphaning %s in %s directory"
1386
def __init__(self, orphan, parent):
1387
errors.BzrError.__init__(self)
1388
self.orphan = orphan
1389
self.parent = parent
1392
class OrphaningForbidden(OrphaningError):
1394
_fmt = "Policy: %s doesn't allow creating orphans."
1396
def __init__(self, policy):
1397
errors.BzrError.__init__(self)
1398
self.policy = policy
1401
def move_orphan(tt, orphan_id, parent_id):
1402
"""See TreeTransformBase.new_orphan.
1404
This creates a new orphan in the `bzr-orphans` dir at the root of the
1407
:param tt: The TreeTransform orphaning `trans_id`.
1409
:param orphan_id: The trans id that should be orphaned.
1411
:param parent_id: The orphan parent trans id.
1413
# Add the orphan dir if it doesn't exist
1414
orphan_dir_basename = 'bzr-orphans'
1415
od_id = tt.trans_id_tree_path(orphan_dir_basename)
1416
if tt.final_kind(od_id) is None:
1417
tt.create_directory(od_id)
1418
parent_path = tt._tree_id_paths[parent_id]
1419
# Find a name that doesn't exist yet in the orphan dir
1420
actual_name = tt.final_name(orphan_id)
1421
new_name = tt._available_backup_name(actual_name, od_id)
1422
tt.adjust_path(new_name, od_id, orphan_id)
1423
trace.warning('%s has been orphaned in %s'
1424
% (joinpath(parent_path, actual_name), orphan_dir_basename))
1427
def refuse_orphan(tt, orphan_id, parent_id):
1428
"""See TreeTransformBase.new_orphan.
1430
This refuses to create orphan, letting the caller handle the conflict.
1432
raise OrphaningForbidden('never')
1435
orphaning_registry = registry.Registry()
1436
orphaning_registry.register(
1437
'conflict', refuse_orphan,
1438
'Leave orphans in place and create a conflict on the directory.')
1439
orphaning_registry.register(
1440
'move', move_orphan,
1441
'Move orphans into the bzr-orphans directory.')
1442
orphaning_registry._set_default_key('conflict')
1445
class TreeTransform(DiskTreeTransform):
1123
1446
"""Represent a tree transformation.
1125
1448
This object is designed to support incremental generation of the transform,
1214
TreeTransformBase.__init__(self, tree, limbodir, pb,
1537
# Cache of realpath results, to speed up canonical_path
1538
self._realpaths = {}
1539
# Cache of relpath results, to speed up canonical_path
1541
DiskTreeTransform.__init__(self, tree, limbodir, pb,
1215
1542
tree.case_sensitive)
1216
1543
self._deletiondir = deletiondir
1545
def canonical_path(self, path):
1546
"""Get the canonical tree-relative path"""
1547
# don't follow final symlinks
1548
abs = self._tree.abspath(path)
1549
if abs in self._relpaths:
1550
return self._relpaths[abs]
1551
dirname, basename = os.path.split(abs)
1552
if dirname not in self._realpaths:
1553
self._realpaths[dirname] = os.path.realpath(dirname)
1554
dirname = self._realpaths[dirname]
1555
abs = pathjoin(dirname, basename)
1556
if dirname in self._relpaths:
1557
relpath = pathjoin(self._relpaths[dirname], basename)
1558
relpath = relpath.rstrip('/\\')
1560
relpath = self._tree.relpath(abs)
1561
self._relpaths[abs] = relpath
1564
def tree_kind(self, trans_id):
1565
"""Determine the file kind in the working tree.
1567
:returns: The file kind or None if the file does not exist
1569
path = self._tree_id_paths.get(trans_id)
1573
return file_kind(self._tree.abspath(path))
1574
except errors.NoSuchFile:
1577
def _set_mode(self, trans_id, mode_id, typefunc):
1578
"""Set the mode of new file contents.
1579
The mode_id is the existing file to get the mode from (often the same
1580
as trans_id). The operation is only performed if there's a mode match
1581
according to typefunc.
1586
old_path = self._tree_id_paths[mode_id]
1590
mode = os.stat(self._tree.abspath(old_path)).st_mode
1592
if e.errno in (errno.ENOENT, errno.ENOTDIR):
1593
# Either old_path doesn't exist, or the parent of the
1594
# target is not a directory (but will be one eventually)
1595
# Either way, we know it doesn't exist *right now*
1596
# See also bug #248448
1601
os.chmod(self._limbo_name(trans_id), mode)
1603
def iter_tree_children(self, parent_id):
1604
"""Iterate through the entry's tree children, if any"""
1606
path = self._tree_id_paths[parent_id]
1610
children = os.listdir(self._tree.abspath(path))
1612
if not (osutils._is_error_enotdir(e)
1613
or e.errno in (errno.ENOENT, errno.ESRCH)):
1617
for child in children:
1618
childpath = joinpath(path, child)
1619
if self._tree.is_control_filename(childpath):
1621
yield self.trans_id_tree_path(childpath)
1623
def _generate_limbo_path(self, trans_id):
1624
"""Generate a limbo path using the final path if possible.
1626
This optimizes the performance of applying the tree transform by
1627
avoiding renames. These renames can be avoided only when the parent
1628
directory is already scheduled for creation.
1630
If the final path cannot be used, falls back to using the trans_id as
1633
parent = self._new_parent.get(trans_id)
1634
# if the parent directory is already in limbo (e.g. when building a
1635
# tree), choose a limbo name inside the parent, to reduce further
1637
use_direct_path = False
1638
if self._new_contents.get(parent) == 'directory':
1639
filename = self._new_name.get(trans_id)
1640
if filename is not None:
1641
if parent not in self._limbo_children:
1642
self._limbo_children[parent] = set()
1643
self._limbo_children_names[parent] = {}
1644
use_direct_path = True
1645
# the direct path can only be used if no other file has
1646
# already taken this pathname, i.e. if the name is unused, or
1647
# if it is already associated with this trans_id.
1648
elif self._case_sensitive_target:
1649
if (self._limbo_children_names[parent].get(filename)
1650
in (trans_id, None)):
1651
use_direct_path = True
1653
for l_filename, l_trans_id in\
1654
self._limbo_children_names[parent].iteritems():
1655
if l_trans_id == trans_id:
1657
if l_filename.lower() == filename.lower():
1660
use_direct_path = True
1662
if not use_direct_path:
1663
return DiskTreeTransform._generate_limbo_path(self, trans_id)
1665
limbo_name = pathjoin(self._limbo_files[parent], filename)
1666
self._limbo_children[parent].add(trans_id)
1667
self._limbo_children_names[parent][filename] = trans_id
1218
1671
def apply(self, no_conflicts=False, precomputed_delta=None, _mover=None):
1219
1672
"""Apply all changes to the inventory and filesystem.
2279
2936
merge_modified[file_id] = new_sha1
2281
2938
# preserve the execute bit when backing up
2282
if keep_content and executable[0] == executable[1]:
2283
tt.set_executability(executable[1], trans_id)
2284
elif kind[1] is not None:
2285
raise AssertionError(kind[1])
2286
if versioned == (False, True):
2939
if keep_content and wt_executable == target_executable:
2940
tt.set_executability(target_executable, trans_id)
2941
elif target_kind is not None:
2942
raise AssertionError(target_kind)
2943
if not wt_versioned and target_versioned:
2287
2944
tt.version_file(file_id, trans_id)
2288
if versioned == (True, False):
2945
if wt_versioned and not target_versioned:
2289
2946
tt.unversion_file(trans_id)
2290
if (name[1] is not None and
2291
(name[0] != name[1] or parent[0] != parent[1])):
2292
if name[1] == '' and parent[1] is None:
2947
if (target_name is not None and
2948
(wt_name != target_name or wt_parent != target_parent)):
2949
if target_name == '' and target_parent is None:
2293
2950
parent_trans = ROOT_PARENT
2295
parent_trans = tt.trans_id_file_id(parent[1])
2296
tt.adjust_path(name[1], parent_trans, trans_id)
2297
if executable[0] != executable[1] and kind[1] == "file":
2298
tt.set_executability(executable[1], trans_id)
2299
for (trans_id, mode_id), bytes in target_tree.iter_files_bytes(
2301
tt.create_file(bytes, trans_id, mode_id)
2952
parent_trans = tt.trans_id_file_id(target_parent)
2953
if wt_parent is None and wt_versioned:
2954
tt.adjust_root_path(target_name, parent_trans)
2956
tt.adjust_path(target_name, parent_trans, trans_id)
2957
if wt_executable != target_executable and target_kind == "file":
2958
tt.set_executability(target_executable, trans_id)
2959
if working_tree.supports_content_filtering():
2960
for index, ((trans_id, mode_id), bytes) in enumerate(
2961
target_tree.iter_files_bytes(deferred_files)):
2962
file_id = deferred_files[index][0]
2963
# We're reverting a tree to the target tree so using the
2964
# target tree to find the file path seems the best choice
2965
# here IMO - Ian C 27/Oct/2009
2966
filter_tree_path = target_tree.id2path(file_id)
2967
filters = working_tree._content_filter_stack(filter_tree_path)
2968
bytes = filtered_output_bytes(bytes, filters,
2969
ContentFilterContext(filter_tree_path, working_tree))
2970
tt.create_file(bytes, trans_id, mode_id)
2972
for (trans_id, mode_id), bytes in target_tree.iter_files_bytes(
2974
tt.create_file(bytes, trans_id, mode_id)
2975
tt.fixup_new_roots()
2303
2977
if basis_tree is not None:
2304
2978
basis_tree.unlock()
2305
2979
return merge_modified
2308
def resolve_conflicts(tt, pb=DummyProgress(), pass_func=None):
2982
def resolve_conflicts(tt, pb=None, pass_func=None):
2309
2983
"""Make many conflict-resolution attempts, but die if they fail"""
2310
2984
if pass_func is None:
2311
2985
pass_func = conflict_pass
2312
2986
new_conflicts = set()
2987
pb = ui.ui_factory.nested_progress_bar()
2314
2989
for n in range(10):
2315
2990
pb.update('Resolution pass', n+1, 10)