1359
1360
yield self.trans_id_tree_path(childpath)
1362
class _PreviewTree(object):
1363
class _PreviewTree(tree.Tree):
1363
1364
"""Partial implementation of Tree to support show_diff_trees"""
1365
1366
def __init__(self, transform):
1366
1367
self._transform = transform
1368
self._final_paths = FinalPaths(transform)
1370
def _changes(self, file_id):
1371
for changes in self._transform.iter_changes():
1372
if changes[0] == file_id:
1375
def _content_change(self, file_id):
1376
"""Return True if the content of this file changed"""
1377
changes = self._changes(file_id)
1378
# changes[2] is true if the file content changed. See
1379
# InterTree.iter_changes.
1380
return (changes is not None and changes[2])
1382
def _get_file_revision(self, file_id, vf, tree_revision):
1383
return self._transform._tree._get_file_revision(file_id, vf,
1386
def _stat_limbo_file(self, file_id):
1387
trans_id = self._transform.trans_id_file_id(file_id)
1388
name = self._transform._limbo_name(trans_id)
1389
return os.lstat(name)
1368
1391
def lock_read(self):
1369
1392
# Perhaps in theory, this should lock the TreeTransform?
1372
1395
def unlock(self):
1399
def inventory(self):
1400
"""This Tree does not use inventory as its backing data."""
1401
raise NotImplementedError(_PreviewTree.inventory)
1403
def get_root_id(self):
1404
return self._transform.final_file_id(self._transform.root)
1406
def all_file_ids(self):
1407
return self._transform._tree.all_file_ids()
1410
return iter(self.all_file_ids())
1412
def paths2ids(self, specific_files, trees=None, require_versioned=False):
1413
"""See Tree.paths2ids"""
1414
to_find = set(specific_files)
1416
for (file_id, paths, changed, versioned, parent, name, kind,
1417
executable) in self._transform.iter_changes():
1418
if paths[1] in to_find:
1419
result.append(file_id)
1420
to_find.remove(paths[1])
1421
result.update(self._transform._tree.paths2ids(to_find,
1422
trees=[], require_versioned=require_versioned))
1425
def path2id(self, path):
1426
return self._transform._tree.path2id(path)
1428
def id2path(self, file_id):
1429
trans_id = self._transform.trans_id_file_id(file_id)
1431
return self._final_paths._determine_path(trans_id)
1433
raise errors.NoSuchId(self, file_id)
1435
def iter_entries_by_dir(self, specific_file_ids=None):
1436
return self._transform._tree.iter_entries_by_dir(specific_file_ids)
1438
def kind(self, file_id):
1439
trans_id = self._transform.trans_id_file_id(file_id)
1440
return self._transform.final_kind(trans_id)
1442
def stored_kind(self, file_id):
1443
return self._transform._tree.stored_kind(file_id)
1445
def get_file_mtime(self, file_id, path=None):
1446
"""See Tree.get_file_mtime"""
1447
if not self._content_change(file_id):
1448
return self._transform._tree.get_file_mtime(file_id, path)
1449
return self._stat_limbo_file(file_id).st_mtime
1451
def get_file_size(self, file_id):
1452
"""See Tree.get_file_size"""
1453
if self.kind(file_id) == 'file':
1454
return self._transform._tree.get_file_size(file_id)
1458
def get_file_sha1(self, file_id, path=None, stat_value=None):
1459
return self._transform._tree.get_file_sha1(file_id)
1461
def is_executable(self, file_id, path=None):
1462
return self._transform._tree.is_executable(file_id, path)
1464
def path_content_summary(self, path):
1465
return self._transform._tree.path_content_summary(path)
1375
1467
def iter_changes(self, from_tree, include_unchanged=False,
1376
1468
specific_files=None, pb=None, extra_trees=None,
1377
1469
require_versioned=True, want_unversioned=False):
1391
1483
raise ValueError('want_unversioned is not supported')
1392
1484
return self._transform.iter_changes()
1394
def kind(self, file_id):
1395
trans_id = self._transform.trans_id_file_id(file_id)
1396
return self._transform.final_kind(trans_id)
1398
def get_file_mtime(self, file_id, path=None):
1399
"""See Tree.get_file_mtime"""
1400
trans_id = self._transform.trans_id_file_id(file_id)
1401
name = self._transform._limbo_name(trans_id)
1402
return os.stat(name).st_mtime
1404
def get_file(self, file_id):
1486
def get_file(self, file_id, path=None):
1405
1487
"""See Tree.get_file"""
1488
if not self._content_change(file_id):
1489
return self._transform._tree.get_file(file_id, path)
1406
1490
trans_id = self._transform.trans_id_file_id(file_id)
1407
1491
name = self._transform._limbo_name(trans_id)
1408
1492
return open(name, 'rb')
1494
def get_file_text(self, file_id):
1495
text_file = self.get_file(file_id)
1497
return text_file.read()
1501
def annotate_iter(self, file_id,
1502
default_revision=_mod_revision.CURRENT_REVISION):
1503
return self._transform._tree.annotate_iter(file_id,
1504
default_revision=default_revision)
1410
1506
def get_symlink_target(self, file_id):
1411
1507
"""See Tree.get_symlink_target"""
1508
if not self._content_change(file_id):
1509
return self._transform._tree.get_symlink_target(file_id)
1412
1510
trans_id = self._transform.trans_id_file_id(file_id)
1413
1511
name = self._transform._limbo_name(trans_id)
1414
1512
return os.readlink(name)
1416
def paths2ids(self, specific_files, trees=None, require_versioned=False):
1417
"""See Tree.paths2ids"""
1514
def list_files(self, include_root=False):
1515
return self._transform._tree.list_files(include_root)
1517
def walkdirs(self, prefix=""):
1518
return self._transform._tree.walkdirs(prefix)
1520
def get_parent_ids(self):
1521
return self._transform._tree.get_parent_ids()
1523
def get_revision_tree(self, revision_id):
1524
return self._transform._tree.get_revision_tree(revision_id)
1421
1527
def joinpath(parent, child):