~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robert Collins
  • Date: 2006-09-08 04:20:58 UTC
  • mto: (1852.16.2 Tree.walkdirs)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: robertc@robertcollins.net-20060908042058-af4fe4c3b2424159
Implement WorkingTree interface conformance tests for
WorkingTree.revision_tree. As part of this, refactor the basis_tree method
to use revision_tree to access the cached basis inventory.
(Robert Collins, Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
400
400
        If the left most parent is a ghost then the returned tree will be an
401
401
        empty tree - one obtained by calling repository.revision_tree(None).
402
402
        """
403
 
        try:
404
 
            revision_id = self.get_parent_ids()[0]
405
 
        except IndexError:
 
403
        revision_id = self.last_revision()
 
404
        if revision_id is None:
406
405
            # no parents, return an empty revision tree.
407
406
            # in the future this should return the tree for
408
407
            # 'empty:' - the implicit root empty tree.
409
408
            return self.branch.repository.revision_tree(None)
410
 
        else:
411
 
            try:
412
 
                xml = self.read_basis_inventory()
413
 
                inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
414
 
                inv.root.revision = revision_id
415
 
            except NoSuchFile:
416
 
                inv = None
417
 
            if inv is not None and inv.revision_id == revision_id:
418
 
                return bzrlib.tree.RevisionTree(self.branch.repository, inv,
419
 
                                                revision_id)
 
409
        try:
 
410
            return self.revision_tree(revision_id)
 
411
        except errors.NoSuchRevision:
 
412
            pass
420
413
        # No cached copy available, retrieve from the repository.
421
414
        # FIXME? RBC 20060403 should we cache the inventory locally
422
415
        # at this point ?
1523
1516
            resolve(self, filenames, ignore_misses=True)
1524
1517
        return conflicts
1525
1518
 
 
1519
    def revision_tree(self, revision_id):
 
1520
        """See Tree.revision_tree.
 
1521
 
 
1522
        WorkingTree can supply revision_trees for the basis revision only
 
1523
        because there is only one cached inventory in the bzr directory.
 
1524
        """
 
1525
        if revision_id == self.last_revision():
 
1526
            try:
 
1527
                xml = self.read_basis_inventory()
 
1528
            except NoSuchFile:
 
1529
                pass
 
1530
            else:
 
1531
                inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
 
1532
                # Fixup old inventory serialization that has a missing root
 
1533
                # revision_id attribute.
 
1534
                inv.root.revision = revision_id
 
1535
                # dont use the repository revision_tree api because we want
 
1536
                # to supply the inventory.
 
1537
                if inv.revision_id == revision_id:
 
1538
                    return bzrlib.tree.RevisionTree(self.branch.repository,
 
1539
                        inv, revision_id)
 
1540
        # raise if there was no inventory, or if we read the wrong inventory.
 
1541
        raise errors.NoSuchRevisionInTree(self, revision_id)
 
1542
 
1526
1543
    # XXX: This method should be deprecated in favour of taking in a proper
1527
1544
    # new Inventory object.
1528
1545
    @needs_write_lock