/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-12 20:16:43 UTC
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20060912201643-66a32bc419a28c6f
Shave off another 40ms by demand loading branch and bzrdir

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
directories.
21
21
"""
22
22
 
23
 
# TODO: remove unittest dependency; put that stuff inside the test suite
24
 
 
25
 
from copy import deepcopy
26
23
from cStringIO import StringIO
27
24
import os
 
25
 
 
26
from bzrlib.lazy_import import lazy_import
 
27
lazy_import(globals(), """
 
28
from copy import deepcopy
28
29
from stat import S_ISDIR
29
 
from unittest import TestSuite
 
30
import unittest
30
31
 
31
32
import bzrlib
32
 
import bzrlib.errors as errors
33
 
from bzrlib.lockable_files import LockableFiles, TransportLock
34
 
from bzrlib.lockdir import LockDir
 
33
from bzrlib import (
 
34
    errors,
 
35
    lockable_files,
 
36
    lockdir,
 
37
    urlutils,
 
38
    )
35
39
from bzrlib.osutils import (
36
 
                            abspath,
37
 
                            pathjoin,
38
 
                            safe_unicode,
39
 
                            sha_strings,
40
 
                            sha_string,
41
 
                            )
 
40
    safe_unicode,
 
41
    sha_strings,
 
42
    sha_string,
 
43
    )
42
44
import bzrlib.revision
43
45
from bzrlib.store.revision.text import TextRevisionStore
44
46
from bzrlib.store.text import TextStore
45
47
from bzrlib.store.versioned import WeaveStore
46
 
from bzrlib.trace import mutter
47
48
from bzrlib.transactions import WriteTransaction
48
49
from bzrlib.transport import get_transport
49
 
from bzrlib.transport.local import LocalTransport
50
 
import bzrlib.urlutils as urlutils
51
50
from bzrlib.weave import Weave
52
51
from bzrlib.xml4 import serializer_v4
53
52
import bzrlib.xml5
 
53
""")
 
54
 
 
55
from bzrlib.trace import mutter
 
56
from bzrlib.transport.local import LocalTransport
54
57
 
55
58
 
56
59
class BzrDir(object):
177
180
    def _make_tail(self, url):
178
181
        head, tail = urlutils.split(url)
179
182
        if tail and tail != '.':
180
 
            t = bzrlib.transport.get_transport(head)
 
183
            t = get_transport(head)
181
184
            try:
182
185
                t.mkdir(tail)
183
186
            except errors.FileExists:
199
202
                    "not one of %r" % cls)
200
203
        head, tail = urlutils.split(base)
201
204
        if tail and tail != '.':
202
 
            t = bzrlib.transport.get_transport(head)
 
205
            t = get_transport(head)
203
206
            try:
204
207
                t.mkdir(tail)
205
208
            except errors.FileExists:
635
638
    def __init__(self, _transport, _format):
636
639
        """See BzrDir.__init__."""
637
640
        super(BzrDirPreSplitOut, self).__init__(_transport, _format)
638
 
        assert self._format._lock_class == TransportLock
 
641
        assert self._format._lock_class == lockable_files.TransportLock
639
642
        assert self._format._lock_file_name == 'branch-lock'
640
 
        self._control_files = LockableFiles(self.get_branch_transport(None),
 
643
        self._control_files = lockable_files.LockableFiles(
 
644
                                            self.get_branch_transport(None),
641
645
                                            self._format._lock_file_name,
642
646
                                            self._format._lock_class)
643
647
 
840
844
 
841
845
    def _get_mkdir_mode(self):
842
846
        """Figure out the mode to use when creating a bzrdir subdir."""
843
 
        temp_control = LockableFiles(self.transport, '', TransportLock)
 
847
        temp_control = lockable_files.LockableFiles(self.transport, '',
 
848
                                     lockable_files.TransportLock)
844
849
        return temp_control._dir_mode
845
850
 
846
851
    def get_branch_transport(self, branch_format):
1022
1027
        """Initialize a new bzrdir in the base directory of a Transport."""
1023
1028
        # Since we don't have a .bzr directory, inherit the
1024
1029
        # mode from the root directory
1025
 
        temp_control = LockableFiles(transport, '', TransportLock)
 
1030
        temp_control = lockable_files.LockableFiles(transport,
 
1031
                            '', lockable_files.TransportLock)
1026
1032
        temp_control._transport.mkdir('.bzr',
1027
1033
                                      # FIXME: RBC 20060121 don't peek under
1028
1034
                                      # the covers
1037
1043
                      ('branch-format', self.get_format_string()),
1038
1044
                      ]
1039
1045
        # NB: no need to escape relative paths that are url safe.
1040
 
        control_files = LockableFiles(control, self._lock_file_name, 
1041
 
                                      self._lock_class)
 
1046
        control_files = lockable_files.LockableFiles(control,
 
1047
                            self._lock_file_name, self._lock_class)
1042
1048
        control_files.create_lock()
1043
1049
        control_files.lock_write()
1044
1050
        try:
1143
1149
    removed in format 5; write support for this format has been removed.
1144
1150
    """
1145
1151
 
1146
 
    _lock_class = TransportLock
 
1152
    _lock_class = lockable_files.TransportLock
1147
1153
 
1148
1154
    def get_format_string(self):
1149
1155
        """See BzrDirFormat.get_format_string()."""
1193
1199
       Unhashed stores in the repository.
1194
1200
    """
1195
1201
 
1196
 
    _lock_class = TransportLock
 
1202
    _lock_class = lockable_files.TransportLock
1197
1203
 
1198
1204
    def get_format_string(self):
1199
1205
        """See BzrDirFormat.get_format_string()."""
1252
1258
     - Format 6 repositories [always]
1253
1259
    """
1254
1260
 
1255
 
    _lock_class = TransportLock
 
1261
    _lock_class = lockable_files.TransportLock
1256
1262
 
1257
1263
    def get_format_string(self):
1258
1264
        """See BzrDirFormat.get_format_string()."""
1312
1318
     - Format 7 repositories [optional]
1313
1319
    """
1314
1320
 
1315
 
    _lock_class = LockDir
 
1321
    _lock_class = lockdir.LockDir
1316
1322
 
1317
1323
    def get_converter(self, format=None):
1318
1324
        """See BzrDirFormat.get_converter()."""
1372
1378
        self._formats = formats
1373
1379
    
1374
1380
    def adapt(self, test):
1375
 
        result = TestSuite()
 
1381
        result = unittest.TestSuite()
1376
1382
        for format in self._formats:
1377
1383
            new_test = deepcopy(test)
1378
1384
            new_test.transport_server = self._transport_server
1509
1515
                                                      prefixed=False,
1510
1516
                                                      compressed=True))
1511
1517
        try:
1512
 
            transaction = bzrlib.transactions.WriteTransaction()
 
1518
            transaction = WriteTransaction()
1513
1519
            for i, rev_id in enumerate(self.converted_revs):
1514
1520
                self.pb.update('write revision', i, len(self.converted_revs))
1515
1521
                _revision_store.add_revision(self.revisions[rev_id], transaction)
1791
1797
    def make_lock(self, name):
1792
1798
        """Make a lock for the new control dir name."""
1793
1799
        self.step('Make %s lock' % name)
1794
 
        ld = LockDir(self.bzrdir.transport, 
1795
 
                     '%s/lock' % name,
1796
 
                     file_modebits=self.file_mode,
1797
 
                     dir_modebits=self.dir_mode)
 
1800
        ld = lockdir.LockDir(self.bzrdir.transport,
 
1801
                             '%s/lock' % name,
 
1802
                             file_modebits=self.file_mode,
 
1803
                             dir_modebits=self.dir_mode)
1798
1804
        ld.create()
1799
1805
 
1800
1806
    def move_entry(self, new_dir, entry):