/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

Merge from bzr.dev and newer set-last-revision changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
394
394
        return pathjoin(self.basedir, filename)
395
395
    
396
396
    def basis_tree(self):
397
 
        """Return RevisionTree for the current last revision."""
 
397
        """Return RevisionTree for the current last revision.
 
398
        
 
399
        If the left most parent is a ghost then the returned tree will be an
 
400
        empty tree - one obtained by calling repository.revision_tree(None).
 
401
        """
398
402
        revision_id = self.last_revision()
399
403
        if revision_id is not None:
400
404
            try:
415
419
            # its a ghost.
416
420
            if self.branch.repository.has_revision(revision_id):
417
421
                raise
418
 
            # the basis tree is a ghost
 
422
            # the basis tree is a ghost so return an empty tree.
419
423
            return self.branch.repository.revision_tree(None)
420
424
 
421
425
    @staticmethod
1491
1495
        Do a 'normal' merge of the old branch basis if it is relevant.
1492
1496
        """
1493
1497
        old_tip = self.branch.update()
1494
 
        try:
1495
 
            result = 0
1496
 
            if self.last_revision() != self.branch.last_revision():
1497
 
                # merge tree state up to new branch tip.
1498
 
                basis = self.basis_tree()
1499
 
                to_tree = self.branch.basis_tree()
1500
 
                result += merge_inner(self.branch,
1501
 
                                      to_tree,
1502
 
                                      basis,
1503
 
                                      this_tree=self)
 
1498
        # here if old_tip is not None, it is the old tip of the branch before
 
1499
        # it was updated from the master branch. This should become a pending
 
1500
        # merge in the working tree to preserve the user existing work.  we
 
1501
        # cant set that until we update the working trees last revision to be
 
1502
        # one from the new branch, because it will just get absorbed by the
 
1503
        # parent de-duplication logic.
 
1504
        # 
 
1505
        # We MUST save it even if an error occurs, because otherwise the users
 
1506
        # local work is unreferenced and will appear to have been lost.
 
1507
        # 
 
1508
        result = 0
 
1509
        if self.last_revision() != self.branch.last_revision():
 
1510
            # merge tree state up to new branch tip.
 
1511
            basis = self.basis_tree()
 
1512
            to_tree = self.branch.basis_tree()
 
1513
            result += merge_inner(self.branch,
 
1514
                                  to_tree,
 
1515
                                  basis,
 
1516
                                  this_tree=self)
 
1517
            # when we have set_parent_ids/set_parent_trees we can
 
1518
            # set the pending merge from old tip here if needed.  We cant
 
1519
            # set a pending merge for old tip until we've changed the
 
1520
            # primary parent because it will typically have the same value.
 
1521
            try:
1504
1522
                self.set_last_revision(self.branch.last_revision())
1505
 
            if old_tip and old_tip != self.last_revision():
1506
 
                # our last revision was not the prior branch last revision
1507
 
                # and we have converted that last revision to a pending merge.
1508
 
                # base is somewhere between the branch tip now
1509
 
                # and the now pending merge
1510
 
                from bzrlib.revision import common_ancestor
1511
 
                try:
1512
 
                    base_rev_id = common_ancestor(self.branch.last_revision(),
1513
 
                                                  old_tip,
1514
 
                                                  self.branch.repository)
1515
 
                except errors.NoCommonAncestor:
1516
 
                    base_rev_id = None
1517
 
                base_tree = self.branch.repository.revision_tree(base_rev_id)
1518
 
                other_tree = self.branch.repository.revision_tree(old_tip)
1519
 
                result += merge_inner(self.branch,
1520
 
                                      other_tree,
1521
 
                                      base_tree,
1522
 
                                      this_tree=self)
1523
 
            return result
1524
 
        finally:
 
1523
            finally:
 
1524
                if old_tip is not None:
 
1525
                    self.add_pending_merge(old_tip)
 
1526
        else:
 
1527
            # the working tree had the same last-revision as the master
 
1528
            # branch did. We may still have pivot local work from the local
 
1529
            # branch into old_tip:
1525
1530
            if old_tip is not None:
1526
1531
                self.add_pending_merge(old_tip)
 
1532
        if old_tip and old_tip != self.last_revision():
 
1533
            # our last revision was not the prior branch last revision
 
1534
            # and we have converted that last revision to a pending merge.
 
1535
            # base is somewhere between the branch tip now
 
1536
            # and the now pending merge
 
1537
            from bzrlib.revision import common_ancestor
 
1538
            try:
 
1539
                base_rev_id = common_ancestor(self.branch.last_revision(),
 
1540
                                              old_tip,
 
1541
                                              self.branch.repository)
 
1542
            except errors.NoCommonAncestor:
 
1543
                base_rev_id = None
 
1544
            base_tree = self.branch.repository.revision_tree(base_rev_id)
 
1545
            other_tree = self.branch.repository.revision_tree(old_tip)
 
1546
            result += merge_inner(self.branch,
 
1547
                                  other_tree,
 
1548
                                  base_tree,
 
1549
                                  this_tree=self)
 
1550
        return result
1527
1551
 
1528
1552
    @needs_write_lock
1529
1553
    def _write_inventory(self, inv):