~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robert Collins
  • Date: 2006-09-10 23:42:17 UTC
  • mto: This revision was merged to the branch mainline in revision 2000.
  • Revision ID: robertc@robertcollins.net-20060910234217-0ae24d8e666d60d6
All WorkingTree methods which write to the tree, but not to the branch
have been converted to use ``needs_tree_write_lock`` rather than 
``needs_write_lock``. Also converted is the revert, conflicts and tree
transform modules. This provides a modest performance improvement on 
metadir style trees, due to the reduce lock-acquisition, and a more
significant performance improvement on lightweight checkouts from 
remote branches, where trivial operations used to pay a significant 
penalty. It also provides the basis for allowing readonly checkouts.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
622
622
            mode = os.lstat(self.abspath(path)).st_mode
623
623
            return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
624
624
 
625
 
    @needs_write_lock
 
625
    @needs_tree_write_lock
626
626
    def add(self, files, ids=None):
627
627
        """Make files versioned.
628
628
 
683
683
 
684
684
        self._write_inventory(inv)
685
685
 
686
 
    @needs_write_lock
 
686
    @needs_tree_write_lock
687
687
    def add_parent_tree_id(self, revision_id, allow_leftmost_as_ghost=False):
688
688
        """Add revision_id as a parent.
689
689
 
699
699
        self.set_parent_ids(parents,
700
700
            allow_leftmost_as_ghost=len(parents) > 1 or allow_leftmost_as_ghost)
701
701
 
702
 
    @needs_write_lock
 
702
    @needs_tree_write_lock
703
703
    def add_parent_tree(self, parent_tuple, allow_leftmost_as_ghost=False):
704
704
        """Add revision_id, tree tuple as a parent.
705
705
 
721
721
        self.set_parent_ids(parent_ids,
722
722
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
723
723
 
724
 
    @needs_write_lock
 
724
    @needs_tree_write_lock
725
725
    def add_pending_merge(self, *revision_ids):
726
726
        # TODO: Perhaps should check at this point that the
727
727
        # history of the revision is actually present?
748
748
        """
749
749
        return self.get_parent_ids()[1:]
750
750
 
751
 
    @needs_write_lock
 
751
    @needs_tree_write_lock
752
752
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
753
753
        """Set the parent ids to revision_ids.
754
754
        
772
772
        merges = revision_ids[1:]
773
773
        self._control_files.put_utf8('pending-merges', '\n'.join(merges))
774
774
 
775
 
    @needs_write_lock
 
775
    @needs_tree_write_lock
776
776
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
777
777
        """Set the parents of the working tree.
778
778
 
785
785
        self.set_parent_ids([rev for (rev, tree) in parents_list],
786
786
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
787
787
 
788
 
    @needs_write_lock
 
788
    @needs_tree_write_lock
789
789
    def set_pending_merges(self, rev_list):
790
790
        parents = self.get_parent_ids()
791
791
        leftmost = parents[:1]
792
792
        new_parents = leftmost + rev_list
793
793
        self.set_parent_ids(new_parents)
794
794
 
795
 
    @needs_write_lock
 
795
    @needs_tree_write_lock
796
796
    def set_merge_modified(self, modified_hashes):
797
797
        def iter_stanzas():
798
798
            for file_id, hash in modified_hashes.iteritems():
799
799
                yield Stanza(file_id=file_id, hash=hash)
800
800
        self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
801
801
 
802
 
    @needs_write_lock
 
802
    @needs_tree_write_lock
803
803
    def _put_rio(self, filename, stanzas, header):
804
804
        my_file = rio_file(stanzas, header)
805
805
        self._control_files.put(filename, my_file)
806
806
 
807
 
    @needs_write_lock
 
807
    @needs_write_lock # because merge pulls data into the branch.
808
808
    def merge_from_branch(self, branch, to_revision=None):
809
809
        """Merge from a branch into this working tree.
810
810
 
988
988
                # if we finished all children, pop it off the stack
989
989
                stack.pop()
990
990
 
991
 
 
992
 
    @needs_write_lock
 
991
    @needs_tree_write_lock
993
992
    def move(self, from_paths, to_name):
994
993
        """Rename files.
995
994
 
1058
1057
        self._write_inventory(inv)
1059
1058
        return result
1060
1059
 
1061
 
    @needs_write_lock
 
1060
    @needs_tree_write_lock
1062
1061
    def rename_one(self, from_rel, to_rel):
1063
1062
        """Rename one file.
1064
1063
 
1117
1116
            if not self.is_ignored(subp):
1118
1117
                yield subp
1119
1118
    
1120
 
    @needs_write_lock
 
1119
    @needs_tree_write_lock
1121
1120
    def unversion(self, file_ids):
1122
1121
        """Remove the file ids in file_ids from the current versioned set.
1123
1122
 
1430
1429
    def _basis_inventory_name(self):
1431
1430
        return 'basis-inventory-cache'
1432
1431
 
1433
 
    @needs_write_lock
 
1432
    @needs_tree_write_lock
1434
1433
    def set_last_revision(self, new_revision):
1435
1434
        """Change the last revision in the working tree."""
1436
1435
        if self._change_last_revision(new_revision):
1498
1497
        self._set_inventory(result)
1499
1498
        return result
1500
1499
 
1501
 
    @needs_write_lock
 
1500
    @needs_tree_write_lock
1502
1501
    def remove(self, files, verbose=False, to_file=None):
1503
1502
        """Remove nominated files from the working inventory..
1504
1503
 
1538
1537
 
1539
1538
        self._write_inventory(inv)
1540
1539
 
1541
 
    @needs_write_lock
 
1540
    @needs_tree_write_lock
1542
1541
    def revert(self, filenames, old_tree=None, backups=True, 
1543
1542
               pb=DummyProgress()):
1544
1543
        from transform import revert
1555
1554
 
1556
1555
    # XXX: This method should be deprecated in favour of taking in a proper
1557
1556
    # new Inventory object.
1558
 
    @needs_write_lock
 
1557
    @needs_tree_write_lock
1559
1558
    def set_inventory(self, new_inventory_list):
1560
1559
        from bzrlib.inventory import (Inventory,
1561
1560
                                      InventoryDirectory,
1578
1577
                raise BzrError("unknown kind %r" % kind)
1579
1578
        self._write_inventory(inv)
1580
1579
 
1581
 
    @needs_write_lock
 
1580
    @needs_tree_write_lock
1582
1581
    def set_root_id(self, file_id):
1583
1582
        """Set the root id for this tree."""
1584
1583
        inv = self.read_working_inventory()
1690
1689
                                  this_tree=self)
1691
1690
        return result
1692
1691
 
1693
 
    @needs_write_lock
 
1692
    @needs_tree_write_lock
1694
1693
    def _write_inventory(self, inv):
1695
1694
        """Write inventory as the current inventory."""
1696
1695
        sio = StringIO()
1794
1793
            self._control_files.put_utf8('last-revision', revision_id)
1795
1794
            return True
1796
1795
 
1797
 
    @needs_write_lock
 
1796
    @needs_tree_write_lock
1798
1797
    def set_conflicts(self, conflicts):
1799
1798
        self._put_rio('conflicts', conflicts.to_stanzas(), 
1800
1799
                      CONFLICT_HEADER_1)
1801
1800
 
1802
 
    @needs_write_lock
 
1801
    @needs_tree_write_lock
1803
1802
    def add_conflicts(self, new_conflicts):
1804
1803
        conflict_set = set(self.conflicts())
1805
1804
        conflict_set.update(set(list(new_conflicts)))