/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

review comment application - paired with Martin.

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
1420
1424
        Do a 'normal' merge of the old branch basis if it is relevant.
1421
1425
        """
1422
1426
        old_tip = self.branch.update()
1423
 
        try:
1424
 
            result = 0
1425
 
            if self.last_revision() != self.branch.last_revision():
1426
 
                # merge tree state up to new branch tip.
1427
 
                basis = self.basis_tree()
1428
 
                to_tree = self.branch.basis_tree()
1429
 
                result += merge_inner(self.branch,
1430
 
                                      to_tree,
1431
 
                                      basis,
1432
 
                                      this_tree=self)
 
1427
        # here if old_tip is not None, it is the old tip of the branch before
 
1428
        # it was updated from the master branch. This should become a pending
 
1429
        # merge in the working tree to preserve the user existing work.  we
 
1430
        # cant set that until we update the working trees last revision to be
 
1431
        # one from the new branch, because it will just get absorbed by the
 
1432
        # parent de-duplication logic.
 
1433
        # 
 
1434
        # We MUST save it even if an error occurs, because otherwise the users
 
1435
        # local work is unreferenced and will appear to have been lost.
 
1436
        # 
 
1437
        result = 0
 
1438
        if self.last_revision() != self.branch.last_revision():
 
1439
            # merge tree state up to new branch tip.
 
1440
            basis = self.basis_tree()
 
1441
            to_tree = self.branch.basis_tree()
 
1442
            result += merge_inner(self.branch,
 
1443
                                  to_tree,
 
1444
                                  basis,
 
1445
                                  this_tree=self)
 
1446
            # when we have set_parent_ids/set_parent_trees we can
 
1447
            # set the pending merge from old tip here if needed.  We cant
 
1448
            # set a pending merge for old tip until we've changed the
 
1449
            # primary parent because it will typically have the same value.
 
1450
            try:
1433
1451
                self.set_last_revision(self.branch.last_revision())
1434
 
            if old_tip and old_tip != self.last_revision():
1435
 
                # our last revision was not the prior branch last revision
1436
 
                # and we have converted that last revision to a pending merge.
1437
 
                # base is somewhere between the branch tip now
1438
 
                # and the now pending merge
1439
 
                from bzrlib.revision import common_ancestor
1440
 
                try:
1441
 
                    base_rev_id = common_ancestor(self.branch.last_revision(),
1442
 
                                                  old_tip,
1443
 
                                                  self.branch.repository)
1444
 
                except errors.NoCommonAncestor:
1445
 
                    base_rev_id = None
1446
 
                base_tree = self.branch.repository.revision_tree(base_rev_id)
1447
 
                other_tree = self.branch.repository.revision_tree(old_tip)
1448
 
                result += merge_inner(self.branch,
1449
 
                                      other_tree,
1450
 
                                      base_tree,
1451
 
                                      this_tree=self)
1452
 
            return result
1453
 
        finally:
 
1452
            finally:
 
1453
                if old_tip is not None:
 
1454
                    self.add_pending_merge(old_tip)
 
1455
        else:
 
1456
            # the working tree had the same last-revision as the master
 
1457
            # branch did. We may still have pivot local work from the local
 
1458
            # branch into old_tip:
1454
1459
            if old_tip is not None:
1455
1460
                self.add_pending_merge(old_tip)
 
1461
        if old_tip and old_tip != self.last_revision():
 
1462
            # our last revision was not the prior branch last revision
 
1463
            # and we have converted that last revision to a pending merge.
 
1464
            # base is somewhere between the branch tip now
 
1465
            # and the now pending merge
 
1466
            from bzrlib.revision import common_ancestor
 
1467
            try:
 
1468
                base_rev_id = common_ancestor(self.branch.last_revision(),
 
1469
                                              old_tip,
 
1470
                                              self.branch.repository)
 
1471
            except errors.NoCommonAncestor:
 
1472
                base_rev_id = None
 
1473
            base_tree = self.branch.repository.revision_tree(base_rev_id)
 
1474
            other_tree = self.branch.repository.revision_tree(old_tip)
 
1475
            result += merge_inner(self.branch,
 
1476
                                  other_tree,
 
1477
                                  base_tree,
 
1478
                                  this_tree=self)
 
1479
        return result
1456
1480
 
1457
1481
    @needs_write_lock
1458
1482
    def _write_inventory(self, inv):