~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: John Arbash Meinel
  • Date: 2008-05-05 20:42:38 UTC
  • mfrom: (3406 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3407.
  • Revision ID: john@arbash-meinel.com-20080505204238-598hf62krc3wwcin
merge bzr.dev, resolve NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    bzrdir,
26
26
    delta,
27
27
    errors,
28
 
    inventory
 
28
    inventory,
 
29
    revision as _mod_revision,
29
30
    )
30
31
""")
31
32
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
1359
1360
            yield self.trans_id_tree_path(childpath)
1360
1361
 
1361
1362
 
1362
 
class _PreviewTree(object):
 
1363
class _PreviewTree(tree.Tree):
1363
1364
    """Partial implementation of Tree to support show_diff_trees"""
1364
1365
 
1365
1366
    def __init__(self, transform):
1366
1367
        self._transform = transform
 
1368
        self._final_paths = FinalPaths(transform)
 
1369
 
 
1370
    def _changes(self, file_id):
 
1371
        for changes in self._transform.iter_changes():
 
1372
            if changes[0] == file_id:
 
1373
                return changes
 
1374
 
 
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])
 
1381
 
 
1382
    def _get_file_revision(self, file_id, vf, tree_revision):
 
1383
        return self._transform._tree._get_file_revision(file_id, vf,
 
1384
                                                        tree_revision)
 
1385
 
 
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)
1367
1390
 
1368
1391
    def lock_read(self):
1369
1392
        # Perhaps in theory, this should lock the TreeTransform?
1372
1395
    def unlock(self):
1373
1396
        pass
1374
1397
 
 
1398
    @property
 
1399
    def inventory(self):
 
1400
        """This Tree does not use inventory as its backing data."""
 
1401
        raise NotImplementedError(_PreviewTree.inventory)
 
1402
 
 
1403
    def get_root_id(self):
 
1404
        return self._transform.final_file_id(self._transform.root)
 
1405
 
 
1406
    def all_file_ids(self):
 
1407
        return self._transform._tree.all_file_ids()
 
1408
 
 
1409
    def __iter__(self):
 
1410
        return iter(self.all_file_ids())
 
1411
 
 
1412
    def paths2ids(self, specific_files, trees=None, require_versioned=False):
 
1413
        """See Tree.paths2ids"""
 
1414
        to_find = set(specific_files)
 
1415
        result = set()
 
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))
 
1423
        return result
 
1424
 
 
1425
    def path2id(self, path):
 
1426
        return self._transform._tree.path2id(path)
 
1427
 
 
1428
    def id2path(self, file_id):
 
1429
        trans_id = self._transform.trans_id_file_id(file_id)
 
1430
        try:
 
1431
            return self._final_paths._determine_path(trans_id)
 
1432
        except NoFinalPath:
 
1433
            raise errors.NoSuchId(self, file_id)
 
1434
 
 
1435
    def iter_entries_by_dir(self, specific_file_ids=None):
 
1436
        return self._transform._tree.iter_entries_by_dir(specific_file_ids)
 
1437
 
 
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)
 
1441
 
 
1442
    def stored_kind(self, file_id):
 
1443
        return self._transform._tree.stored_kind(file_id)
 
1444
 
 
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
 
1450
 
 
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)
 
1455
        else:
 
1456
            return None
 
1457
 
 
1458
    def get_file_sha1(self, file_id, path=None, stat_value=None):
 
1459
        return self._transform._tree.get_file_sha1(file_id)
 
1460
 
 
1461
    def is_executable(self, file_id, path=None):
 
1462
        return self._transform._tree.is_executable(file_id, path)
 
1463
 
 
1464
    def path_content_summary(self, path):
 
1465
        return self._transform._tree.path_content_summary(path)
 
1466
 
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()
1393
1485
 
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)
1397
 
 
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
1403
 
 
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')
1409
1493
 
 
1494
    def get_file_text(self, file_id):
 
1495
        text_file = self.get_file(file_id)
 
1496
        try:
 
1497
            return text_file.read()
 
1498
        finally:
 
1499
            text_file.close()
 
1500
 
 
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)
 
1505
 
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)
1415
1513
 
1416
 
    def paths2ids(self, specific_files, trees=None, require_versioned=False):
1417
 
        """See Tree.paths2ids"""
1418
 
        return 'not_empty'
 
1514
    def list_files(self, include_root=False):
 
1515
        return self._transform._tree.list_files(include_root)
 
1516
 
 
1517
    def walkdirs(self, prefix=""):
 
1518
        return self._transform._tree.walkdirs(prefix)
 
1519
 
 
1520
    def get_parent_ids(self):
 
1521
        return self._transform._tree.get_parent_ids()
 
1522
 
 
1523
    def get_revision_tree(self, revision_id):
 
1524
        return self._transform._tree.get_revision_tree(revision_id)
1419
1525
 
1420
1526
 
1421
1527
def joinpath(parent, child):