560
558
added, or the allow_leftmost_as_ghost parameter is set True.
561
559
:param allow_leftmost_as_ghost: Allow the first parent to be a ghost.
563
parents = self.get_parent_ids() + [revision_id]
564
self.set_parent_ids(parents, allow_leftmost_as_ghost=len(parents) > 1
565
or allow_leftmost_as_ghost)
561
with self.lock_write():
562
parents = self.get_parent_ids() + [revision_id]
563
self.set_parent_ids(parents, allow_leftmost_as_ghost=len(parents) > 1
564
or allow_leftmost_as_ghost)
567
566
@needs_tree_write_lock
568
567
def add_parent_tree(self, parent_tuple, allow_leftmost_as_ghost=False):
722
@needs_write_lock # because merge pulls data into the branch.
723
721
def merge_from_branch(self, branch, to_revision=None, from_revision=None,
724
722
merge_type=None, force=False):
725
723
"""Merge from a branch into this working tree.
731
729
branch.last_revision().
733
731
from .merge import Merger, Merge3Merger
734
merger = Merger(self.branch, this_tree=self)
735
# check that there are no local alterations
736
if not force and self.has_changes():
737
raise errors.UncommittedChanges(self)
738
if to_revision is None:
739
to_revision = _mod_revision.ensure_null(branch.last_revision())
740
merger.other_rev_id = to_revision
741
if _mod_revision.is_null(merger.other_rev_id):
742
raise errors.NoCommits(branch)
743
self.branch.fetch(branch, last_revision=merger.other_rev_id)
744
merger.other_basis = merger.other_rev_id
745
merger.other_tree = self.branch.repository.revision_tree(
747
merger.other_branch = branch
748
if from_revision is None:
751
merger.set_base_revision(from_revision, branch)
752
if merger.base_rev_id == merger.other_rev_id:
753
raise errors.PointlessMerge
754
merger.backup_files = False
755
if merge_type is None:
756
merger.merge_type = Merge3Merger
758
merger.merge_type = merge_type
759
merger.set_interesting_files(None)
760
merger.show_base = False
761
merger.reprocess = False
762
conflicts = merger.do_merge()
732
with self.lock_write():
733
merger = Merger(self.branch, this_tree=self)
734
# check that there are no local alterations
735
if not force and self.has_changes():
736
raise errors.UncommittedChanges(self)
737
if to_revision is None:
738
to_revision = _mod_revision.ensure_null(branch.last_revision())
739
merger.other_rev_id = to_revision
740
if _mod_revision.is_null(merger.other_rev_id):
741
raise errors.NoCommits(branch)
742
self.branch.fetch(branch, last_revision=merger.other_rev_id)
743
merger.other_basis = merger.other_rev_id
744
merger.other_tree = self.branch.repository.revision_tree(
746
merger.other_branch = branch
747
if from_revision is None:
750
merger.set_base_revision(from_revision, branch)
751
if merger.base_rev_id == merger.other_rev_id:
752
raise errors.PointlessMerge
753
merger.backup_files = False
754
if merge_type is None:
755
merger.merge_type = Merge3Merger
757
merger.merge_type = merge_type
758
merger.set_interesting_files(None)
759
merger.show_base = False
760
merger.reprocess = False
761
conflicts = merger.do_merge()
766
765
def merge_modified(self):
767
766
"""Return a dictionary of files modified by a merge.
776
775
raise NotImplementedError(self.merge_modified)
779
777
def mkdir(self, path, file_id=None):
780
778
"""See MutableTree.mkdir()."""
781
779
if file_id is None:
782
780
file_id = generate_ids.gen_file_id(os.path.basename(path))
783
781
elif not self.supports_setting_file_ids():
784
782
raise SettingFileIdUnsupported()
785
os.mkdir(self.abspath(path))
786
self.add(path, file_id, 'directory')
783
with self.lock_write():
784
os.mkdir(self.abspath(path))
785
self.add(path, file_id, 'directory')
789
788
def get_symlink_target(self, file_id, path=None):
790
789
if path is not None:
935
934
raise NotImplementedError(self.unversion)
938
936
def pull(self, source, overwrite=False, stop_revision=None,
939
937
change_reporter=None, possible_transports=None, local=False,
940
938
show_base=False):
941
with source.lock_read():
939
with source.lock_read(), self.lock_write():
942
940
old_revision_info = self.branch.last_revision_info()
943
941
basis_tree = self.basis_tree()
944
942
count = self.branch.pull(source, overwrite, stop_revision,
984
982
self.set_parent_trees(parent_trees)
988
985
def put_file_bytes_non_atomic(self, file_id, bytes):
989
986
"""See MutableTree.put_file_bytes_non_atomic."""
990
stream = file(self.id2abspath(file_id), 'wb')
987
with self.lock_write():
988
stream = file(self.id2abspath(file_id), 'wb')
996
994
def extras(self):
997
995
"""Yield all unversioned files in this WorkingTree.
1262
1260
basis_tree.unlock()
1263
1261
return conflicts
1266
1263
def store_uncommitted(self):
1267
1264
"""Store uncommitted changes from the tree in the branch."""
1268
target_tree = self.basis_tree()
1269
shelf_creator = shelf.ShelfCreator(self, target_tree)
1271
if not shelf_creator.shelve_all():
1273
self.branch.store_uncommitted(shelf_creator)
1274
shelf_creator.transform()
1276
shelf_creator.finalize()
1277
note('Uncommitted changes stored in branch "%s".', self.branch.nick)
1265
with self.lock_write():
1266
target_tree = self.basis_tree()
1267
shelf_creator = shelf.ShelfCreator(self, target_tree)
1269
if not shelf_creator.shelve_all():
1271
self.branch.store_uncommitted(shelf_creator)
1272
shelf_creator.transform()
1274
shelf_creator.finalize()
1275
note('Uncommitted changes stored in branch "%s".', self.branch.nick)
1280
1277
def restore_uncommitted(self):
1281
1278
"""Restore uncommitted changes from the branch into the tree."""
1282
unshelver = self.branch.get_unshelver(self)
1283
if unshelver is None:
1286
merger = unshelver.make_merger()
1287
merger.ignore_zero = True
1289
self.branch.store_uncommitted(None)
1291
unshelver.finalize()
1279
with self.lock_write():
1280
unshelver = self.branch.get_unshelver(self)
1281
if unshelver is None:
1284
merger = unshelver.make_merger()
1285
merger.ignore_zero = True
1287
self.branch.store_uncommitted(None)
1289
unshelver.finalize()
1293
1291
def revision_tree(self, revision_id):
1294
1292
"""See Tree.revision_tree.