~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
# TODO: Can we move specific formats into separate modules to make this file
29
29
# smaller?
30
30
 
31
 
from copy import deepcopy
32
31
from cStringIO import StringIO
33
32
import os
 
33
 
 
34
from bzrlib.lazy_import import lazy_import
 
35
lazy_import(globals(), """
 
36
from copy import deepcopy
34
37
from stat import S_ISDIR
35
 
from unittest import TestSuite
 
38
import unittest
36
39
 
37
40
import bzrlib
38
 
import bzrlib.errors as errors
39
 
from bzrlib.lockable_files import LockableFiles, TransportLock
40
 
from bzrlib.lockdir import LockDir
 
41
from bzrlib import (
 
42
    errors,
 
43
    lockable_files,
 
44
    lockdir,
 
45
    revision as _mod_revision,
 
46
    urlutils,
 
47
    xml4,
 
48
    xml5,
 
49
    )
41
50
from bzrlib.osutils import (
42
 
                            abspath,
43
 
                            pathjoin,
44
 
                            safe_unicode,
45
 
                            sha_strings,
46
 
                            sha_string,
47
 
                            )
48
 
import bzrlib.revision
 
51
    safe_unicode,
 
52
    sha_strings,
 
53
    sha_string,
 
54
    )
49
55
from bzrlib.store.revision.text import TextRevisionStore
50
56
from bzrlib.store.text import TextStore
51
57
from bzrlib.store.versioned import WeaveStore
52
 
from bzrlib.trace import mutter
53
58
from bzrlib.transactions import WriteTransaction
54
59
from bzrlib.transport import get_transport
 
60
from bzrlib.weave import Weave
 
61
""")
 
62
 
 
63
from bzrlib.trace import mutter
55
64
from bzrlib.transport.local import LocalTransport
56
 
import bzrlib.urlutils as urlutils
57
 
from bzrlib.weave import Weave
58
 
from bzrlib.xml4 import serializer_v4
59
 
import bzrlib.xml5
60
65
 
61
66
 
62
67
class BzrDir(object):
188
193
    def _make_tail(self, url):
189
194
        head, tail = urlutils.split(url)
190
195
        if tail and tail != '.':
191
 
            t = bzrlib.transport.get_transport(head)
 
196
            t = get_transport(head)
192
197
            try:
193
198
                t.mkdir(tail)
194
199
            except errors.FileExists:
210
215
                    "not one of %r" % cls)
211
216
        head, tail = urlutils.split(base)
212
217
        if tail and tail != '.':
213
 
            t = bzrlib.transport.get_transport(head)
 
218
            t = get_transport(head)
214
219
            try:
215
220
                t.mkdir(tail)
216
221
            except errors.FileExists:
690
695
    def __init__(self, _transport, _format):
691
696
        """See BzrDir.__init__."""
692
697
        super(BzrDirPreSplitOut, self).__init__(_transport, _format)
693
 
        assert self._format._lock_class == TransportLock
 
698
        assert self._format._lock_class == lockable_files.TransportLock
694
699
        assert self._format._lock_file_name == 'branch-lock'
695
 
        self._control_files = LockableFiles(self.get_branch_transport(None),
 
700
        self._control_files = lockable_files.LockableFiles(
 
701
                                            self.get_branch_transport(None),
696
702
                                            self._format._lock_file_name,
697
703
                                            self._format._lock_class)
698
704
 
742
748
        # done on this format anyway. So - acceptable wart.
743
749
        result = self.open_workingtree()
744
750
        if revision_id is not None:
745
 
            if revision_id == bzrlib.revision.NULL_REVISION:
 
751
            if revision_id == _mod_revision.NULL_REVISION:
746
752
                result.set_parent_ids([])
747
753
            else:
748
754
                result.set_parent_ids([revision_id])
915
921
 
916
922
    def _get_mkdir_mode(self):
917
923
        """Figure out the mode to use when creating a bzrdir subdir."""
918
 
        temp_control = LockableFiles(self.transport, '', TransportLock)
 
924
        temp_control = lockable_files.LockableFiles(self.transport, '',
 
925
                                     lockable_files.TransportLock)
919
926
        return temp_control._dir_mode
920
927
 
921
928
    def get_branch_transport(self, branch_format):
1097
1104
        """Initialize a new bzrdir in the base directory of a Transport."""
1098
1105
        # Since we don't have a .bzr directory, inherit the
1099
1106
        # mode from the root directory
1100
 
        temp_control = LockableFiles(transport, '', TransportLock)
 
1107
        temp_control = lockable_files.LockableFiles(transport,
 
1108
                            '', lockable_files.TransportLock)
1101
1109
        temp_control._transport.mkdir('.bzr',
1102
1110
                                      # FIXME: RBC 20060121 don't peek under
1103
1111
                                      # the covers
1112
1120
                      ('branch-format', self.get_format_string()),
1113
1121
                      ]
1114
1122
        # NB: no need to escape relative paths that are url safe.
1115
 
        control_files = LockableFiles(control, self._lock_file_name, 
1116
 
                                      self._lock_class)
 
1123
        control_files = lockable_files.LockableFiles(control,
 
1124
                            self._lock_file_name, self._lock_class)
1117
1125
        control_files.create_lock()
1118
1126
        control_files.lock_write()
1119
1127
        try:
1222
1230
    removed in format 5; write support for this format has been removed.
1223
1231
    """
1224
1232
 
1225
 
    _lock_class = TransportLock
 
1233
    _lock_class = lockable_files.TransportLock
1226
1234
 
1227
1235
    def get_format_string(self):
1228
1236
        """See BzrDirFormat.get_format_string()."""
1272
1280
       Unhashed stores in the repository.
1273
1281
    """
1274
1282
 
1275
 
    _lock_class = TransportLock
 
1283
    _lock_class = lockable_files.TransportLock
1276
1284
 
1277
1285
    def get_format_string(self):
1278
1286
        """See BzrDirFormat.get_format_string()."""
1331
1339
     - Format 6 repositories [always]
1332
1340
    """
1333
1341
 
1334
 
    _lock_class = TransportLock
 
1342
    _lock_class = lockable_files.TransportLock
1335
1343
 
1336
1344
    def get_format_string(self):
1337
1345
        """See BzrDirFormat.get_format_string()."""
1391
1399
     - Format 7 repositories [optional]
1392
1400
    """
1393
1401
 
1394
 
    _lock_class = LockDir
 
1402
    _lock_class = lockdir.LockDir
1395
1403
 
1396
1404
    def get_converter(self, format=None):
1397
1405
        """See BzrDirFormat.get_converter()."""
1451
1459
        self._formats = formats
1452
1460
    
1453
1461
    def adapt(self, test):
1454
 
        result = TestSuite()
 
1462
        result = unittest.TestSuite()
1455
1463
        for format in self._formats:
1456
1464
            new_test = deepcopy(test)
1457
1465
            new_test.transport_server = self._transport_server
1555
1563
        self.bzrdir.transport.delete_tree('text-store')
1556
1564
 
1557
1565
    def _convert_working_inv(self):
1558
 
        inv = serializer_v4.read_inventory(self.branch.control_files.get('inventory'))
1559
 
        new_inv_xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
 
1566
        inv = xml4.serializer_v4.read_inventory(
 
1567
                    self.branch.control_files.get('inventory'))
 
1568
        new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
1560
1569
        # FIXME inventory is a working tree change.
1561
1570
        self.branch.control_files.put('inventory', StringIO(new_inv_xml))
1562
1571
 
1588
1597
                                                      prefixed=False,
1589
1598
                                                      compressed=True))
1590
1599
        try:
1591
 
            transaction = bzrlib.transactions.WriteTransaction()
 
1600
            transaction = WriteTransaction()
1592
1601
            for i, rev_id in enumerate(self.converted_revs):
1593
1602
                self.pb.update('write revision', i, len(self.converted_revs))
1594
1603
                _revision_store.add_revision(self.revisions[rev_id], transaction)
1620
1629
    def _load_old_inventory(self, rev_id):
1621
1630
        assert rev_id not in self.converted_revs
1622
1631
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
1623
 
        inv = serializer_v4.read_inventory_from_string(old_inv_xml)
 
1632
        inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
1624
1633
        inv.revision_id = rev_id
1625
1634
        rev = self.revisions[rev_id]
1626
1635
        if rev.inventory_sha1:
1631
1640
    def _load_updated_inventory(self, rev_id):
1632
1641
        assert rev_id in self.converted_revs
1633
1642
        inv_xml = self.inv_weave.get_text(rev_id)
1634
 
        inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(inv_xml)
 
1643
        inv = xml5.serializer_v5.read_inventory_from_string(inv_xml)
1635
1644
        return inv
1636
1645
 
1637
1646
    def _convert_one_rev(self, rev_id):
1653
1662
                assert getattr(ie, 'revision', None) is not None, \
1654
1663
                    'no revision on {%s} in {%s}' % \
1655
1664
                    (file_id, rev.revision_id)
1656
 
        new_inv_xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
 
1665
        new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
1657
1666
        new_inv_sha1 = sha_string(new_inv_xml)
1658
1667
        self.inv_weave.add_lines(rev.revision_id, 
1659
1668
                                 present_parents,
1871
1880
    def make_lock(self, name):
1872
1881
        """Make a lock for the new control dir name."""
1873
1882
        self.step('Make %s lock' % name)
1874
 
        ld = LockDir(self.bzrdir.transport, 
1875
 
                     '%s/lock' % name,
1876
 
                     file_modebits=self.file_mode,
1877
 
                     dir_modebits=self.dir_mode)
 
1883
        ld = lockdir.LockDir(self.bzrdir.transport,
 
1884
                             '%s/lock' % name,
 
1885
                             file_modebits=self.file_mode,
 
1886
                             dir_modebits=self.dir_mode)
1878
1887
        ld.create()
1879
1888
 
1880
1889
    def move_entry(self, new_dir, entry):