~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Patch Queue Manager
  • Date: 2011-11-28 16:04:45 UTC
  • mfrom: (6313.1.4 trim-working-tree)
  • Revision ID: pqm@pqm.ubuntu.com-20111128160445-5ndgnqjd0vggze3d
(jelmer) Move control-files-related code from WorkingTree to
 InventoryWorkingTree. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
172
172
 
173
173
    def __init__(self, basedir='.',
174
174
                 branch=DEPRECATED_PARAMETER,
175
 
                 _control_files=None,
176
175
                 _internal=False,
 
176
                 _transport=None,
177
177
                 _format=None,
178
178
                 _bzrdir=None):
179
179
        """Construct a WorkingTree instance. This is not a public API.
192
192
        else:
193
193
            self._branch = self.bzrdir.open_branch()
194
194
        self.basedir = realpath(basedir)
195
 
        self._control_files = _control_files
196
 
        self._transport = self._control_files._transport
 
195
        self._transport = _transport
197
196
        self._rules_searcher = None
198
197
        self.views = self._make_views()
199
198
 
237
236
 
238
237
        This will probe the repository for its lock as well.
239
238
        """
240
 
        self._control_files.break_lock()
241
 
        self.branch.break_lock()
 
239
        raise NotImplementedError(self.break_lock)
242
240
 
243
241
    def requires_rich_root(self):
244
242
        return self._format.requires_rich_root
741
739
 
742
740
    @needs_tree_write_lock
743
741
    def set_merge_modified(self, modified_hashes):
744
 
        def iter_stanzas():
745
 
            for file_id, hash in modified_hashes.iteritems():
746
 
                yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
747
 
                    hash=hash)
748
 
        self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
 
742
        """Set the merge modified hashes."""
 
743
        raise NotImplementedError(self.set_merge_modified)
749
744
 
750
745
    def _sha_from_stat(self, path, stat_result):
751
746
        """Get a sha digest from the tree's stat cache.
757
752
        """
758
753
        return None
759
754
 
760
 
    def _put_rio(self, filename, stanzas, header):
761
 
        self._must_be_locked()
762
 
        my_file = _mod_rio.rio_file(stanzas, header)
763
 
        self._transport.put_file(filename, my_file,
764
 
            mode=self.bzrdir._get_file_mode())
765
 
 
766
755
    @needs_write_lock # because merge pulls data into the branch.
767
756
    def merge_from_branch(self, branch, to_revision=None, from_revision=None,
768
757
                          merge_type=None, force=False):
1148
1137
        return _mod_revision.ensure_null(self.branch.last_revision())
1149
1138
 
1150
1139
    def is_locked(self):
1151
 
        return self._control_files.is_locked()
1152
 
 
1153
 
    def _must_be_locked(self):
1154
 
        if not self.is_locked():
1155
 
            raise errors.ObjectNotLocked(self)
 
1140
        """Check if this tree is locked."""
 
1141
        raise NotImplementedError(self.is_locked)
1156
1142
 
1157
1143
    def lock_read(self):
1158
1144
        """Lock the tree for reading.
1161
1147
 
1162
1148
        :return: A bzrlib.lock.LogicalLockResult.
1163
1149
        """
1164
 
        if not self.is_locked():
1165
 
            self._reset_data()
1166
 
        self.branch.lock_read()
1167
 
        try:
1168
 
            self._control_files.lock_read()
1169
 
            return LogicalLockResult(self.unlock)
1170
 
        except:
1171
 
            self.branch.unlock()
1172
 
            raise
 
1150
        raise NotImplementedError(self.lock_read)
1173
1151
 
1174
1152
    def lock_tree_write(self):
1175
1153
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
1176
1154
 
1177
1155
        :return: A bzrlib.lock.LogicalLockResult.
1178
1156
        """
1179
 
        if not self.is_locked():
1180
 
            self._reset_data()
1181
 
        self.branch.lock_read()
1182
 
        try:
1183
 
            self._control_files.lock_write()
1184
 
            return LogicalLockResult(self.unlock)
1185
 
        except:
1186
 
            self.branch.unlock()
1187
 
            raise
 
1157
        raise NotImplementedError(self.lock_tree_write)
1188
1158
 
1189
1159
    def lock_write(self):
1190
1160
        """See MutableTree.lock_write, and WorkingTree.unlock.
1191
1161
 
1192
1162
        :return: A bzrlib.lock.LogicalLockResult.
1193
1163
        """
1194
 
        if not self.is_locked():
1195
 
            self._reset_data()
1196
 
        self.branch.lock_write()
1197
 
        try:
1198
 
            self._control_files.lock_write()
1199
 
            return LogicalLockResult(self.unlock)
1200
 
        except:
1201
 
            self.branch.unlock()
1202
 
            raise
 
1164
        raise NotImplementedError(self.lock_write)
1203
1165
 
1204
1166
    def get_physical_lock_status(self):
1205
 
        return self._control_files.get_physical_lock_status()
1206
 
 
1207
 
    def _reset_data(self):
1208
 
        """Reset transient data that cannot be revalidated."""
1209
 
        raise NotImplementedError(self._reset_data)
 
1167
        raise NotImplementedError(self.get_physical_lock_status)
1210
1168
 
1211
1169
    def set_last_revision(self, new_revision):
1212
1170
        """Change the last revision in the working tree."""
1788
1746
        :param branch: A branch to override probing for the branch.
1789
1747
        """
1790
1748
        super(InventoryWorkingTree, self).__init__(basedir=basedir,
1791
 
            branch=branch, _control_files=_control_files, _internal=_internal,
1792
 
            _format=_format, _bzrdir=_bzrdir)
 
1749
            branch=branch, _transport=_control_files._transport,
 
1750
            _internal=_internal, _format=_format, _bzrdir=_bzrdir)
1793
1751
 
 
1752
        self._control_files = _control_files
1794
1753
        self._detect_case_handling()
1795
1754
 
1796
1755
        if _inventory is None:
1835
1794
    def _deserialize(selt, in_file):
1836
1795
        return xml5.serializer_v5.read_inventory(in_file)
1837
1796
 
 
1797
    def break_lock(self):
 
1798
        """Break a lock if one is present from another instance.
 
1799
 
 
1800
        Uses the ui factory to ask for confirmation if the lock may be from
 
1801
        an active process.
 
1802
 
 
1803
        This will probe the repository for its lock as well.
 
1804
        """
 
1805
        self._control_files.break_lock()
 
1806
        self.branch.break_lock()
 
1807
 
 
1808
    def is_locked(self):
 
1809
        return self._control_files.is_locked()
 
1810
 
 
1811
    def _must_be_locked(self):
 
1812
        if not self.is_locked():
 
1813
            raise errors.ObjectNotLocked(self)
 
1814
 
 
1815
    def lock_read(self):
 
1816
        """Lock the tree for reading.
 
1817
 
 
1818
        This also locks the branch, and can be unlocked via self.unlock().
 
1819
 
 
1820
        :return: A bzrlib.lock.LogicalLockResult.
 
1821
        """
 
1822
        if not self.is_locked():
 
1823
            self._reset_data()
 
1824
        self.branch.lock_read()
 
1825
        try:
 
1826
            self._control_files.lock_read()
 
1827
            return LogicalLockResult(self.unlock)
 
1828
        except:
 
1829
            self.branch.unlock()
 
1830
            raise
 
1831
 
 
1832
    def lock_tree_write(self):
 
1833
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
 
1834
 
 
1835
        :return: A bzrlib.lock.LogicalLockResult.
 
1836
        """
 
1837
        if not self.is_locked():
 
1838
            self._reset_data()
 
1839
        self.branch.lock_read()
 
1840
        try:
 
1841
            self._control_files.lock_write()
 
1842
            return LogicalLockResult(self.unlock)
 
1843
        except:
 
1844
            self.branch.unlock()
 
1845
            raise
 
1846
 
 
1847
    def lock_write(self):
 
1848
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
1849
 
 
1850
        :return: A bzrlib.lock.LogicalLockResult.
 
1851
        """
 
1852
        if not self.is_locked():
 
1853
            self._reset_data()
 
1854
        self.branch.lock_write()
 
1855
        try:
 
1856
            self._control_files.lock_write()
 
1857
            return LogicalLockResult(self.unlock)
 
1858
        except:
 
1859
            self.branch.unlock()
 
1860
            raise
 
1861
 
 
1862
    def get_physical_lock_status(self):
 
1863
        return self._control_files.get_physical_lock_status()
 
1864
 
1838
1865
    @needs_tree_write_lock
1839
1866
    def _write_inventory(self, inv):
1840
1867
        """Write inventory as the current inventory."""
2259
2286
                       for key, line in annotator.annotate_flat(this_key)]
2260
2287
        return annotations
2261
2288
 
 
2289
    def _put_rio(self, filename, stanzas, header):
 
2290
        self._must_be_locked()
 
2291
        my_file = _mod_rio.rio_file(stanzas, header)
 
2292
        self._transport.put_file(filename, my_file,
 
2293
            mode=self.bzrdir._get_file_mode())
 
2294
 
 
2295
    @needs_tree_write_lock
 
2296
    def set_merge_modified(self, modified_hashes):
 
2297
        def iter_stanzas():
 
2298
            for file_id, hash in modified_hashes.iteritems():
 
2299
                yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
 
2300
                    hash=hash)
 
2301
        self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
 
2302
 
2262
2303
    @needs_read_lock
2263
2304
    def merge_modified(self):
2264
2305
        """Return a dictionary of files modified by a merge.