493
493
parents = [last_rev]
494
other_parents = self.pending_merges()
495
return parents + other_parents
495
merges_file = self._control_files.get_utf8('pending-merges')
499
for l in merges_file.readlines():
500
parents.append(l.rstrip('\n'))
497
503
def get_root_id(self):
498
504
"""Return the id of this trees root"""
532
538
if revision_id is None:
533
539
transform_tree(tree, self)
535
# TODO now merge from tree.last_revision to revision
541
# TODO now merge from tree.last_revision to revision (to preserve
542
# user local changes)
536
543
transform_tree(tree, self)
537
tree.set_last_revision(revision_id)
544
tree.set_parent_ids([revision_id])
539
546
@needs_write_lock
540
547
def commit(self, message=None, revprops=None, *args, **kwargs):
693
700
def add_pending_merge(self, *revision_ids):
694
701
# TODO: Perhaps should check at this point that the
695
702
# history of the revision is actually present?
696
p = self.pending_merges()
697
existing_parents = self.get_parent_ids()
703
parents = self.get_parent_ids()
699
705
for rev_id in revision_ids:
702
if rev_id in existing_parents:
706
if rev_id in parents:
708
parents.append(rev_id)
707
self.set_pending_merges(p)
711
self.set_parent_ids(parents, allow_leftmost_as_ghost=True)
710
714
def pending_merges(self):
713
717
These are revisions that have been merged into the working
714
718
directory but not yet committed.
717
merges_file = self._control_files.get_utf8('pending-merges')
721
for l in merges_file.readlines():
722
p.append(l.rstrip('\n'))
720
return self.get_parent_ids()[1:]
725
722
@needs_write_lock
726
723
def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
735
732
:param revision_ids: The revision_ids to set as the parent ids of this
736
733
working tree. Any of these may be ghosts.
739
for rev_id in revision_ids:
742
(rev_id, self.branch.repository.revision_tree(rev_id)))
743
except errors.RevisionNotPresent:
744
trees.append((rev_id, None))
745
self.set_parent_trees(trees,
746
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
735
if len(revision_ids) > 0:
736
leftmost_id = revision_ids[0]
737
if (not allow_leftmost_as_ghost and not
738
self.branch.repository.has_revision(leftmost_id)):
739
raise errors.GhostRevisionUnusableHere(leftmost_id)
740
self.set_last_revision(leftmost_id)
742
self.set_last_revision(None)
743
merges = revision_ids[1:]
744
self._control_files.put_utf8('pending-merges', '\n'.join(merges))
748
746
@needs_write_lock
749
747
def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
753
751
If tree is None, then that element is treated as an unreachable
754
752
parent tree - i.e. a ghost.
756
if len(parents_list) > 0:
757
leftmost_id = parents_list[0][0]
758
if (not allow_leftmost_as_ghost and not
759
self.branch.repository.has_revision(leftmost_id)):
760
raise errors.GhostRevisionUnusableHere(leftmost_id)
761
self.set_last_revision(leftmost_id)
763
self.set_last_revision(None)
764
merges = parents_list[1:]
765
self.set_pending_merges([revid for revid, tree in merges])
754
# parent trees are not used in current format trees, delegate to
756
self.set_parent_ids([rev for (rev, tree) in parents_list],
757
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
767
759
@needs_write_lock
768
760
def set_pending_merges(self, rev_list):
769
if self.last_revision() is None:
770
new_last_list = rev_list[:1]
771
rev_list = rev_list[1:]
773
self.set_last_revision(new_last_list[0])
774
self._control_files.put_utf8('pending-merges', '\n'.join(rev_list))
761
parents = self.get_parent_ids()
762
leftmost = parents[:1]
763
new_parents = leftmost + rev_list
764
self.set_parent_ids(new_parents)
776
766
@needs_write_lock
777
767
def set_merge_modified(self, modified_hashes):
1092
1082
repository = self.branch.repository
1093
1083
pb = bzrlib.ui.ui_factory.nested_progress_bar()
1085
new_basis_tree = self.branch.basis_tree()
1095
1086
merge_inner(self.branch,
1096
self.branch.basis_tree(),
1102
self.set_last_revision(self.branch.last_revision())
1093
# TODO - dedup parents list with things merged by pull ?
1094
# reuse the revisiontree we merged against to set the new
1096
parent_trees = [(self.branch.last_revision(), new_basis_tree)]
1097
# we have to pull the merge trees out again, because
1098
# merge_inner has set the ids. - this corner is not yet
1099
# layered well enough to prevent double handling.
1100
merges = self.get_parent_ids()[1:]
1101
parent_trees.extend([
1102
(parent, repository.revision_tree(parent)) for
1104
self.set_parent_trees(parent_trees)
1105
1107
source.unlock()
1422
1424
old_tree = self.basis_tree()
1423
1425
conflicts = revert(self, old_tree, filenames, backups, pb)
1424
1426
if not len(filenames):
1425
self.set_pending_merges([])
1427
self.set_parent_ids(self.get_parent_ids()[:1])
1428
1430
resolve(self, filenames, ignore_misses=True)
1520
1522
this_tree=self)
1521
# when we have set_parent_ids/set_parent_trees we can
1522
# set the pending merge from old tip here if needed. We cant
1523
# set a pending merge for old tip until we've changed the
1524
# primary parent because it will typically have the same value.
1526
self.set_last_revision(self.branch.last_revision())
1528
if old_tip is not None:
1529
self.add_pending_merge(old_tip)
1523
# TODO - dedup parents list with things merged by pull ?
1524
# reuse the tree we've updated to to set the basis:
1525
parent_trees = [(self.branch.last_revision(), to_tree)]
1526
merges = self.get_parent_ids()[1:]
1527
# Ideally we ask the tree for the trees here, that way the working
1528
# tree can decide whether to give us teh entire tree or give us a
1529
# lazy initialised tree. dirstate for instance will have the trees
1530
# in ram already, whereas a last-revision + basis-inventory tree
1531
# will not, but also does not need them when setting parents.
1532
for parent in merges:
1533
parent_trees.append(
1534
(parent, self.branch.repository.revision_tree(parent)))
1535
if old_tip is not None:
1536
parent_trees.append(
1537
(old_tip, self.branch.repository.revision_tree(old_tip)))
1538
self.set_parent_trees(parent_trees)
1531
1540
# the working tree had the same last-revision as the master
1532
1541
# branch did. We may still have pivot local work from the local
1533
1542
# branch into old_tip:
1534
1543
if old_tip is not None:
1535
self.add_pending_merge(old_tip)
1544
self.add_parent_tree_id(old_tip)
1536
1545
if old_tip and old_tip != self.last_revision():
1537
1546
# our last revision was not the prior branch last revision
1538
1547
# and we have converted that last revision to a pending merge.
1825
1834
_bzrdir=a_bzrdir)
1826
1835
wt._write_inventory(inv)
1827
1836
wt.set_root_id(inv.root.file_id)
1828
wt.set_last_revision(revision)
1829
wt.set_pending_merges([])
1830
build_tree(wt.basis_tree(), wt)
1837
basis_tree = branch.repository.revision_tree(revision)
1838
wt.set_parent_trees([(revision, basis_tree)])
1839
build_tree(basis_tree, wt)
1833
1842
def __init__(self):
1908
1917
wt._write_inventory(inv)
1909
1918
wt.set_root_id(inv.root.file_id)
1910
wt.set_last_revision(revision_id)
1911
wt.set_pending_merges([])
1912
build_tree(wt.basis_tree(), wt)
1919
basis_tree = branch.repository.revision_tree(revision_id)
1920
wt.set_parent_trees([(revision_id, basis_tree)])
1921
build_tree(basis_tree, wt)
1915
1924
control_files.unlock()