~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

Test the disk layout of format3 working trees.

Show diffs side-by-side

added added

removed removed

Lines of Context:
187
187
    not listed in the Inventory and vice versa.
188
188
    """
189
189
 
190
 
    def __init__(self, basedir='.', branch=None, _inventory=None, _control_files=None, _internal=False, _format=None):
 
190
    def __init__(self, basedir='.',
 
191
                 branch=None,
 
192
                 _inventory=None,
 
193
                 _control_files=None,
 
194
                 _internal=False,
 
195
                 _format=None,
 
196
                 _bzrdir=None):
191
197
        """Construct a WorkingTree for basedir.
192
198
 
193
199
        If the branch is not supplied, it is opened automatically.
196
202
        would be meaningless).
197
203
        """
198
204
        self._format = _format
 
205
        self.bzrdir = _bzrdir
199
206
        if not _internal:
200
207
            # created via open etc.
201
208
            wt = WorkingTree.open(basedir)
205
212
            self._hashcache = wt._hashcache
206
213
            self._set_inventory(wt._inventory)
207
214
            self._format = wt._format
 
215
            self.bzrdir = wt.bzrdir
208
216
        from bzrlib.hashcache import HashCache
209
217
        from bzrlib.trace import note, mutter
210
218
        assert isinstance(basedir, basestring), \
218
226
        self.branch = branch
219
227
        self.basedir = realpath(basedir)
220
228
        # if branch is at our basedir and is a format 6 or less
221
 
        if (isinstance(self._format, WorkingTreeFormat2)
222
 
            # might be able to share control object
223
 
            and self.branch.base.split('/')[-2] == self.basedir.split('/')[-1]):
 
229
        if isinstance(self._format, WorkingTreeFormat2):
 
230
            # share control object
224
231
            self._control_files = self.branch.control_files
225
232
        elif _control_files is not None:
226
233
            assert False, "not done yet"
227
234
#            self._control_files = _control_files
228
235
        else:
229
 
            # FIXME old format use the bzrdir control files.
 
236
            # only ready for format 3
 
237
            assert isinstance(self._format, WorkingTreeFormat3)
230
238
            self._control_files = LockableFiles(
231
 
                get_transport(self.basedir).clone(bzrlib.BZRDIR), 'branch-lock')
 
239
                self.bzrdir.get_workingtree_transport(None),
 
240
                'lock')
232
241
 
233
242
        # update the whole cache up front and write to disk if anything changed;
234
243
        # in the future we might want to do this more selectively
236
245
        # if needed, or, when the cache sees a change, append it to the hash
237
246
        # cache file, and have the parser take the most recent entry for a
238
247
        # given path only.
239
 
        hc = self._hashcache = HashCache(basedir, self._control_files._file_mode)
 
248
        cache_filename = self.bzrdir.get_workingtree_transport(None).abspath('stat-cache')
 
249
        hc = self._hashcache = HashCache(basedir, cache_filename, self._control_files._file_mode)
240
250
        hc.read()
241
251
        # is this scan needed ? it makes things kinda slow.
242
252
        hc.scan()
1218
1228
                         branch,
1219
1229
                         inv,
1220
1230
                         _internal=True,
1221
 
                         _format=self)
 
1231
                         _format=self,
 
1232
                         _bzrdir=a_bzrdir)
1222
1233
        wt._write_inventory(inv)
1223
1234
        wt.set_root_id(inv.root.file_id)
1224
1235
        wt.set_last_revision(revision)
1225
1236
        wt.set_pending_merges([])
1226
1237
        wt.revert([])
1227
 
        wt.bzrdir = a_bzrdir
1228
1238
        return wt
1229
1239
 
1230
1240
    def __init__(self):
1242
1252
            raise NotImplementedError
1243
1253
        if not isinstance(a_bzrdir.transport, LocalTransport):
1244
1254
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1245
 
        result = WorkingTree(a_bzrdir.root_transport.base, _internal=True, _format=self)
1246
 
        result.bzrdir = a_bzrdir
1247
 
        return result
 
1255
        return WorkingTree(a_bzrdir.root_transport.base,
 
1256
                           _internal=True,
 
1257
                           _format=self,
 
1258
                           _bzrdir=a_bzrdir)
1248
1259
 
1249
1260
 
1250
1261
class WorkingTreeFormat3(WorkingTreeFormat):
1272
1283
                         branch,
1273
1284
                         inv,
1274
1285
                         _internal=True,
1275
 
                         _format=self)
 
1286
                         _format=self,
 
1287
                         _bzrdir=a_bzrdir)
1276
1288
        wt._write_inventory(inv)
1277
1289
        wt.set_root_id(inv.root.file_id)
1278
1290
        wt.set_last_revision(revision)
1279
1291
        wt.set_pending_merges([])
1280
1292
        wt.revert([])
1281
 
        wt.bzrdir = a_bzrdir
1282
1293
        return wt
1283
1294
 
1284
1295
    def __init__(self):
1296
1307
            raise NotImplementedError
1297
1308
        if not isinstance(a_bzrdir.transport, LocalTransport):
1298
1309
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1299
 
        result = WorkingTree(a_bzrdir.root_transport.base, _internal=True, _format=self)
1300
 
        result.bzrdir = a_bzrdir
1301
 
        return result
 
1310
        return WorkingTree(a_bzrdir.root_transport.base,
 
1311
                           _internal=True,
 
1312
                           _format=self,
 
1313
                           _bzrdir=a_bzrdir)
1302
1314
 
1303
1315
 
1304
1316
# formats which have no format string are not discoverable