/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 breezy/workingtree.py

Remove uses of needs_write_lock.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
from . import (
64
64
    osutils,
65
65
    )
66
 
from .decorators import needs_write_lock
67
66
from .i18n import gettext
68
67
from . import mutabletree
69
68
from .mutabletree import needs_tree_write_lock
548
547
                    if e.errno == errno.ENOENT:
549
548
                        raise errors.NoSuchFile(fullpath)
550
549
 
551
 
    @needs_write_lock
552
550
    def add_parent_tree_id(self, revision_id, allow_leftmost_as_ghost=False):
553
551
        """Add revision_id as a parent.
554
552
 
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.
562
560
        """
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)
566
565
 
567
566
    @needs_tree_write_lock
568
567
    def add_parent_tree(self, parent_tuple, allow_leftmost_as_ghost=False):
719
718
        """
720
719
        return None
721
720
 
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().
732
730
        """
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(
746
 
            merger.other_rev_id)
747
 
        merger.other_branch = branch
748
 
        if from_revision is None:
749
 
            merger.find_base()
750
 
        else:
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
757
 
        else:
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()
763
 
        merger.set_pending()
764
 
        return conflicts
 
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(
 
745
                merger.other_rev_id)
 
746
            merger.other_branch = branch
 
747
            if from_revision is None:
 
748
                merger.find_base()
 
749
            else:
 
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
 
756
            else:
 
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()
 
762
            merger.set_pending()
 
763
            return conflicts
765
764
 
766
765
    def merge_modified(self):
767
766
        """Return a dictionary of files modified by a merge.
775
774
        """
776
775
        raise NotImplementedError(self.merge_modified)
777
776
 
778
 
    @needs_write_lock
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')
787
 
        return file_id
 
783
        with self.lock_write():
 
784
            os.mkdir(self.abspath(path))
 
785
            self.add(path, file_id, 'directory')
 
786
            return file_id
788
787
 
789
788
    def get_symlink_target(self, file_id, path=None):
790
789
        if path is not None:
934
933
        """
935
934
        raise NotImplementedError(self.unversion)
936
935
 
937
 
    @needs_write_lock
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)
985
983
            return count
986
984
 
987
 
    @needs_write_lock
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')
991
 
        try:
992
 
            stream.write(bytes)
993
 
        finally:
994
 
            stream.close()
 
987
        with self.lock_write():
 
988
            stream = file(self.id2abspath(file_id), 'wb')
 
989
            try:
 
990
                stream.write(bytes)
 
991
            finally:
 
992
                stream.close()
995
993
 
996
994
    def extras(self):
997
995
        """Yield all unversioned files in this WorkingTree.
1262
1260
                basis_tree.unlock()
1263
1261
        return conflicts
1264
1262
 
1265
 
    @needs_write_lock
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)
1270
 
        try:
1271
 
            if not shelf_creator.shelve_all():
1272
 
                return
1273
 
            self.branch.store_uncommitted(shelf_creator)
1274
 
            shelf_creator.transform()
1275
 
        finally:
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)
 
1268
            try:
 
1269
                if not shelf_creator.shelve_all():
 
1270
                    return
 
1271
                self.branch.store_uncommitted(shelf_creator)
 
1272
                shelf_creator.transform()
 
1273
            finally:
 
1274
                shelf_creator.finalize()
 
1275
            note('Uncommitted changes stored in branch "%s".', self.branch.nick)
1278
1276
 
1279
 
    @needs_write_lock
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:
1284
 
            return
1285
 
        try:
1286
 
            merger = unshelver.make_merger()
1287
 
            merger.ignore_zero = True
1288
 
            merger.do_merge()
1289
 
            self.branch.store_uncommitted(None)
1290
 
        finally:
1291
 
            unshelver.finalize()
 
1279
        with self.lock_write():
 
1280
            unshelver = self.branch.get_unshelver(self)
 
1281
            if unshelver is None:
 
1282
                return
 
1283
            try:
 
1284
                merger = unshelver.make_merger()
 
1285
                merger.ignore_zero = True
 
1286
                merger.do_merge()
 
1287
                self.branch.store_uncommitted(None)
 
1288
            finally:
 
1289
                unshelver.finalize()
1292
1290
 
1293
1291
    def revision_tree(self, revision_id):
1294
1292
        """See Tree.revision_tree.