~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Martin Pool
  • Date: 2006-03-09 07:14:10 UTC
  • mfrom: (1600 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1602.
  • Revision ID: mbp@sourcefrog.net-20060309071410-4ab7d54905541c75
[merge] from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
                            sha_strings,
38
38
                            sha_string,
39
39
                            )
 
40
from bzrlib.store.revision.text import TextRevisionStore
40
41
from bzrlib.store.text import TextStore
41
 
from bzrlib.store.weave import WeaveStore
 
42
from bzrlib.store.versioned import WeaveStore
42
43
from bzrlib.symbol_versioning import *
43
44
from bzrlib.trace import mutter
44
 
from bzrlib.transactions import PassThroughTransaction
 
45
from bzrlib.transactions import WriteTransaction
45
46
from bzrlib.transport import get_transport
46
47
from bzrlib.transport.local import LocalTransport
47
48
from bzrlib.weave import Weave
48
 
from bzrlib.weavefile import read_weave, write_weave
49
49
from bzrlib.xml4 import serializer_v4
50
50
from bzrlib.xml5 import serializer_v5
51
51
 
557
557
            self.open_workingtree().clone(result, basis=basis_tree)
558
558
        except errors.NotLocalUrl:
559
559
            # make a new one, this format always has to have one.
560
 
            WorkingTreeFormat2().initialize(result)
 
560
            try:
 
561
                WorkingTreeFormat2().initialize(result)
 
562
            except errors.NotLocalUrl:
 
563
                # but we canot do it for remote trees.
 
564
                pass
561
565
        return result
562
566
 
563
567
    def create_branch(self):
1288
1292
                self.bzrdir.transport.mkdir('weaves')
1289
1293
        except errors.NoSuchFile:
1290
1294
            self.bzrdir.transport.mkdir('weaves')
 
1295
        # deliberately not a WeaveFile as we want to build it up slowly.
1291
1296
        self.inv_weave = Weave('inventory')
1292
1297
        # holds in-memory weaves for all files
1293
1298
        self.text_weaves = {}
1340
1345
        controlweaves = WeaveStore(self.bzrdir.transport, prefixed=False)
1341
1346
        weave_transport = self.bzrdir.transport.clone('weaves')
1342
1347
        weaves = WeaveStore(weave_transport, prefixed=False)
1343
 
        transaction = PassThroughTransaction()
 
1348
        transaction = WriteTransaction()
1344
1349
 
1345
 
        controlweaves.put_weave('inventory', self.inv_weave, transaction)
1346
 
        i = 0
1347
1350
        try:
 
1351
            i = 0
1348
1352
            for file_id, file_weave in self.text_weaves.items():
1349
1353
                self.pb.update('writing weave', i, len(self.text_weaves))
1350
 
                weaves.put_weave(file_id, file_weave, transaction)
 
1354
                weaves._put_weave(file_id, file_weave, transaction)
1351
1355
                i += 1
 
1356
            self.pb.update('inventory', 0, 1)
 
1357
            controlweaves._put_weave('inventory', self.inv_weave, transaction)
 
1358
            self.pb.update('inventory', 1, 1)
1352
1359
        finally:
1353
1360
            self.pb.clear()
1354
1361
 
1358
1365
        self.bzrdir.transport.mkdir('revision-store')
1359
1366
        revision_transport = self.bzrdir.transport.clone('revision-store')
1360
1367
        # TODO permissions
1361
 
        revision_store = TextStore(revision_transport,
1362
 
                                   prefixed=False,
1363
 
                                   compressed=True)
 
1368
        _revision_store = TextRevisionStore(TextStore(revision_transport,
 
1369
                                                      prefixed=False,
 
1370
                                                      compressed=True))
1364
1371
        try:
 
1372
            transaction = bzrlib.transactions.WriteTransaction()
1365
1373
            for i, rev_id in enumerate(self.converted_revs):
1366
1374
                self.pb.update('write revision', i, len(self.converted_revs))
1367
 
                rev_tmp = StringIO()
1368
 
                serializer_v5.write_revision(self.revisions[rev_id], rev_tmp)
1369
 
                rev_tmp.seek(0)
1370
 
                revision_store.add(rev_tmp, rev_id)
 
1375
                _revision_store.add_revision(self.revisions[rev_id], transaction)
1371
1376
        finally:
1372
1377
            self.pb.clear()
1373
1378
            
1379
1384
        self.pb.update('loading revision',
1380
1385
                       len(self.revisions),
1381
1386
                       len(self.known_revisions))
1382
 
        if not self.branch.repository.revision_store.has_id(rev_id):
 
1387
        if not self.branch.repository.has_revision(rev_id):
1383
1388
            self.pb.clear()
1384
1389
            self.pb.note('revision {%s} not present in branch; '
1385
1390
                         'will be converted as a ghost',
1386
1391
                         rev_id)
1387
1392
            self.absent_revisions.add(rev_id)
1388
1393
        else:
1389
 
            rev_xml = self.branch.repository.revision_store.get(rev_id).read()
1390
 
            rev = serializer_v4.read_revision_from_string(rev_xml)
 
1394
            rev = self.branch.repository._revision_store.get_revision(rev_id,
 
1395
                self.branch.repository.get_transaction())
1391
1396
            for parent_id in rev.parent_ids:
1392
1397
                self.known_revisions.add(parent_id)
1393
1398
                self.to_read.append(parent_id)
1431
1436
                    (file_id, rev.revision_id)
1432
1437
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
1433
1438
        new_inv_sha1 = sha_string(new_inv_xml)
1434
 
        self.inv_weave.add(rev.revision_id, 
1435
 
                           present_parents,
1436
 
                           new_inv_xml.splitlines(True),
1437
 
                           new_inv_sha1)
 
1439
        self.inv_weave.add_lines(rev.revision_id, 
 
1440
                                 present_parents,
 
1441
                                 new_inv_xml.splitlines(True))
1438
1442
        rev.inventory_sha1 = new_inv_sha1
1439
1443
 
1440
1444
    def _convert_revision_contents(self, rev, inv, present_parents):
1485
1489
            if ie._unchanged(previous_ie):
1486
1490
                ie.revision = previous_ie.revision
1487
1491
                return
1488
 
        parent_indexes = map(w.lookup, previous_revisions)
1489
1492
        if ie.has_text():
1490
1493
            text = self.branch.repository.text_store.get(ie.text_id)
1491
1494
            file_lines = text.readlines()
1492
1495
            assert sha_strings(file_lines) == ie.text_sha1
1493
1496
            assert sum(map(len, file_lines)) == ie.text_size
1494
 
            w.add(rev_id, parent_indexes, file_lines, ie.text_sha1)
 
1497
            w.add_lines(rev_id, previous_revisions, file_lines)
1495
1498
            self.text_count += 1
1496
1499
        else:
1497
 
            w.add(rev_id, parent_indexes, [], None)
 
1500
            w.add_lines(rev_id, previous_revisions, [])
1498
1501
        ie.revision = rev_id
1499
1502
 
1500
1503
    def _make_order(self):