746
753
If tree is None, then that element is treated as an unreachable
747
754
parent tree - i.e. a ghost.
749
parent = parents_list[:1]
756
if len(parents_list) > 0:
757
leftmost_id = parents_list[0][0]
751
758
if (not allow_leftmost_as_ghost and not
752
self.branch.repository.has_revision(parent[0][0])):
753
raise errors.GhostRevision(parent[0][0])
754
self.set_last_revision(parent[0][0])
759
self.branch.repository.has_revision(leftmost_id)):
760
raise errors.GhostRevisionUnusableHere(leftmost_id)
761
self.set_last_revision(leftmost_id)
756
763
self.set_last_revision(None)
757
764
merges = parents_list[1:]
1504
1511
Do a 'normal' merge of the old branch basis if it is relevant.
1506
1513
old_tip = self.branch.update()
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,
1517
self.set_last_revision(self.branch.last_revision())
1518
# TODO - dedup parents list with things merged by pull ?
1519
# reuse the tree we've updated to to set the basis:
1520
parent_trees = [(self.branch.last_revision(), to_tree)]
1521
merges = self.get_parent_ids()[1:]
1522
# pull the other trees out of the repository. This could be
1523
# better expressed - for instance by inserting a parent, and
1524
# that would remove duplication.
1525
parent_trees.extend([
1526
(parent, self.branch.repository.revision_tree(parent)) for
1528
self.set_parent_trees(parent_trees)
1529
if old_tip and old_tip != self.last_revision():
1530
# our last revision was not the prior branch last revision
1531
# and we have converted that last revision to a pending merge.
1532
# base is somewhere between the branch tip now
1533
# and the now pending merge
1534
from bzrlib.revision import common_ancestor
1536
base_rev_id = common_ancestor(self.branch.last_revision(),
1538
self.branch.repository)
1539
except errors.NoCommonAncestor:
1541
base_tree = self.branch.repository.revision_tree(base_rev_id)
1542
other_tree = self.branch.repository.revision_tree(old_tip)
1543
result += merge_inner(self.branch,
1514
# here if old_tip is not None, it is the old tip of the branch before
1515
# it was updated from the master branch. This should become a pending
1516
# merge in the working tree to preserve the user existing work. we
1517
# cant set that until we update the working trees last revision to be
1518
# one from the new branch, because it will just get absorbed by the
1519
# parent de-duplication logic.
1521
# We MUST save it even if an error occurs, because otherwise the users
1522
# local work is unreferenced and will appear to have been lost.
1525
if self.last_revision() != self.branch.last_revision():
1526
# merge tree state up to new branch tip.
1527
basis = self.basis_tree()
1528
to_tree = self.branch.basis_tree()
1529
result += merge_inner(self.branch,
1533
# TODO - dedup parents list with things merged by pull ?
1534
# reuse the tree we've updated to to set the basis:
1535
parent_trees = [(self.branch.last_revision(), to_tree)]
1536
merges = self.get_parent_ids()[1:]
1537
# Ideally we ask the tree for the trees here, that way the working
1538
# tree can decide whether to give us teh entire tree or give us a
1539
# lazy initialised tree. dirstate for instance will have the trees
1540
# in ram already, whereas a last-revision + basis-inventory tree
1541
# will not, but also does not need them when setting parents.
1542
for parent in merges:
1543
parent_trees.append(
1544
(parent, self.branch.repository.revision_tree(parent)))
1545
if old_tip is not None:
1546
parent_trees.append(
1547
(old_tip, self.branch.repository.revision_tree(old_tip)))
1548
self.set_parent_trees(parent_trees)
1550
# the working tree had the same last-revision as the master
1551
# branch did. We may still have pivot local work from the local
1552
# branch into old_tip:
1549
1553
if old_tip is not None:
1550
1554
self.add_pending_merge(old_tip)
1555
if old_tip and old_tip != self.last_revision():
1556
# our last revision was not the prior branch last revision
1557
# and we have converted that last revision to a pending merge.
1558
# base is somewhere between the branch tip now
1559
# and the now pending merge
1560
from bzrlib.revision import common_ancestor
1562
base_rev_id = common_ancestor(self.branch.last_revision(),
1564
self.branch.repository)
1565
except errors.NoCommonAncestor:
1567
base_tree = self.branch.repository.revision_tree(base_rev_id)
1568
other_tree = self.branch.repository.revision_tree(old_tip)
1569
result += merge_inner(self.branch,
1552
1575
@needs_write_lock
1553
1576
def _write_inventory(self, inv):