~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

Merge in knit repository use of knits - still not a stable format, but can be experimented with.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
                            sha_strings,
37
37
                            sha_string,
38
38
                            )
 
39
from bzrlib.store.revision.text import TextRevisionStore
39
40
from bzrlib.store.text import TextStore
40
 
from bzrlib.store.weave import WeaveStore
 
41
from bzrlib.store.versioned import WeaveStore
41
42
from bzrlib.symbol_versioning import *
42
43
from bzrlib.trace import mutter
43
 
from bzrlib.transactions import PassThroughTransaction
 
44
from bzrlib.transactions import WriteTransaction
44
45
from bzrlib.transport import get_transport
45
46
from bzrlib.transport.local import LocalTransport
46
47
from bzrlib.weave import Weave
47
 
from bzrlib.weavefile import read_weave, write_weave
48
48
from bzrlib.xml4 import serializer_v4
49
49
from bzrlib.xml5 import serializer_v5
50
50
 
551
551
            self.open_workingtree().clone(result, basis=basis_tree)
552
552
        except errors.NotLocalUrl:
553
553
            # make a new one, this format always has to have one.
554
 
            WorkingTreeFormat2().initialize(result)
 
554
            try:
 
555
                WorkingTreeFormat2().initialize(result)
 
556
            except errors.NotLocalUrl:
 
557
                # but we canot do it for remote trees.
 
558
                pass
555
559
        return result
556
560
 
557
561
    def create_branch(self):
1267
1271
                self.bzrdir.transport.mkdir('weaves')
1268
1272
        except errors.NoSuchFile:
1269
1273
            self.bzrdir.transport.mkdir('weaves')
 
1274
        # deliberately not a WeaveFile as we want to build it up slowly.
1270
1275
        self.inv_weave = Weave('inventory')
1271
1276
        # holds in-memory weaves for all files
1272
1277
        self.text_weaves = {}
1319
1324
        controlweaves = WeaveStore(self.bzrdir.transport, prefixed=False)
1320
1325
        weave_transport = self.bzrdir.transport.clone('weaves')
1321
1326
        weaves = WeaveStore(weave_transport, prefixed=False)
1322
 
        transaction = PassThroughTransaction()
 
1327
        transaction = WriteTransaction()
1323
1328
 
1324
 
        controlweaves.put_weave('inventory', self.inv_weave, transaction)
1325
 
        i = 0
1326
1329
        try:
 
1330
            i = 0
1327
1331
            for file_id, file_weave in self.text_weaves.items():
1328
1332
                self.pb.update('writing weave', i, len(self.text_weaves))
1329
 
                weaves.put_weave(file_id, file_weave, transaction)
 
1333
                weaves._put_weave(file_id, file_weave, transaction)
1330
1334
                i += 1
 
1335
            self.pb.update('inventory', 0, 1)
 
1336
            controlweaves._put_weave('inventory', self.inv_weave, transaction)
 
1337
            self.pb.update('inventory', 1, 1)
1331
1338
        finally:
1332
1339
            self.pb.clear()
1333
1340
 
1337
1344
        self.bzrdir.transport.mkdir('revision-store')
1338
1345
        revision_transport = self.bzrdir.transport.clone('revision-store')
1339
1346
        # TODO permissions
1340
 
        revision_store = TextStore(revision_transport,
1341
 
                                   prefixed=False,
1342
 
                                   compressed=True)
 
1347
        _revision_store = TextRevisionStore(TextStore(revision_transport,
 
1348
                                                      prefixed=False,
 
1349
                                                      compressed=True))
1343
1350
        try:
 
1351
            transaction = bzrlib.transactions.WriteTransaction()
1344
1352
            for i, rev_id in enumerate(self.converted_revs):
1345
1353
                self.pb.update('write revision', i, len(self.converted_revs))
1346
 
                rev_tmp = StringIO()
1347
 
                serializer_v5.write_revision(self.revisions[rev_id], rev_tmp)
1348
 
                rev_tmp.seek(0)
1349
 
                revision_store.add(rev_tmp, rev_id)
 
1354
                _revision_store.add_revision(self.revisions[rev_id], transaction)
1350
1355
        finally:
1351
1356
            self.pb.clear()
1352
1357
            
1358
1363
        self.pb.update('loading revision',
1359
1364
                       len(self.revisions),
1360
1365
                       len(self.known_revisions))
1361
 
        if not self.branch.repository.revision_store.has_id(rev_id):
 
1366
        if not self.branch.repository.has_revision(rev_id):
1362
1367
            self.pb.clear()
1363
1368
            self.pb.note('revision {%s} not present in branch; '
1364
1369
                         'will be converted as a ghost',
1365
1370
                         rev_id)
1366
1371
            self.absent_revisions.add(rev_id)
1367
1372
        else:
1368
 
            rev_xml = self.branch.repository.revision_store.get(rev_id).read()
1369
 
            rev = serializer_v4.read_revision_from_string(rev_xml)
 
1373
            rev = self.branch.repository._revision_store.get_revision(rev_id,
 
1374
                self.branch.repository.get_transaction())
1370
1375
            for parent_id in rev.parent_ids:
1371
1376
                self.known_revisions.add(parent_id)
1372
1377
                self.to_read.append(parent_id)
1410
1415
                    (file_id, rev.revision_id)
1411
1416
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
1412
1417
        new_inv_sha1 = sha_string(new_inv_xml)
1413
 
        self.inv_weave.add(rev.revision_id, 
1414
 
                           present_parents,
1415
 
                           new_inv_xml.splitlines(True),
1416
 
                           new_inv_sha1)
 
1418
        self.inv_weave.add_lines(rev.revision_id, 
 
1419
                                 present_parents,
 
1420
                                 new_inv_xml.splitlines(True))
1417
1421
        rev.inventory_sha1 = new_inv_sha1
1418
1422
 
1419
1423
    def _convert_revision_contents(self, rev, inv, present_parents):
1464
1468
            if ie._unchanged(previous_ie):
1465
1469
                ie.revision = previous_ie.revision
1466
1470
                return
1467
 
        parent_indexes = map(w.lookup, previous_revisions)
1468
1471
        if ie.has_text():
1469
1472
            text = self.branch.repository.text_store.get(ie.text_id)
1470
1473
            file_lines = text.readlines()
1471
1474
            assert sha_strings(file_lines) == ie.text_sha1
1472
1475
            assert sum(map(len, file_lines)) == ie.text_size
1473
 
            w.add(rev_id, parent_indexes, file_lines, ie.text_sha1)
 
1476
            w.add_lines(rev_id, previous_revisions, file_lines)
1474
1477
            self.text_count += 1
1475
1478
        else:
1476
 
            w.add(rev_id, parent_indexes, [], None)
 
1479
            w.add_lines(rev_id, previous_revisions, [])
1477
1480
        ie.revision = rev_id
1478
1481
 
1479
1482
    def _make_order(self):