~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-16 01:25:46 UTC
  • mfrom: (2071 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2080.
  • Revision ID: john@arbash-meinel.com-20061016012546-d01a0740671b4d73
[merge] 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:
341
346
        """
342
347
        raise NotImplementedError(self.create_workingtree)
343
348
 
 
349
    def destroy_workingtree(self):
 
350
        """Destroy the working tree at this BzrDir.
 
351
 
 
352
        Formats that do not support this may raise UnsupportedOperation.
 
353
        """
 
354
        raise NotImplementedError(self.destroy_workingtree)
 
355
 
 
356
    def destroy_workingtree_metadata(self):
 
357
        """Destroy the control files for the working tree at this BzrDir.
 
358
 
 
359
        The contents of working tree files are not affected.
 
360
        Formats that do not support this may raise UnsupportedOperation.
 
361
        """
 
362
        raise NotImplementedError(self.destroy_workingtree_metadata)
 
363
 
344
364
    def find_repository(self):
345
365
        """Find the repository that should be used for a_bzrdir.
346
366
 
675
695
    def __init__(self, _transport, _format):
676
696
        """See BzrDir.__init__."""
677
697
        super(BzrDirPreSplitOut, self).__init__(_transport, _format)
678
 
        assert self._format._lock_class == TransportLock
 
698
        assert self._format._lock_class == lockable_files.TransportLock
679
699
        assert self._format._lock_file_name == 'branch-lock'
680
 
        self._control_files = LockableFiles(self.get_branch_transport(None),
 
700
        self._control_files = lockable_files.LockableFiles(
 
701
                                            self.get_branch_transport(None),
681
702
                                            self._format._lock_file_name,
682
703
                                            self._format._lock_class)
683
704
 
727
748
        # done on this format anyway. So - acceptable wart.
728
749
        result = self.open_workingtree()
729
750
        if revision_id is not None:
730
 
            if revision_id == bzrlib.revision.NULL_REVISION:
 
751
            if revision_id == _mod_revision.NULL_REVISION:
731
752
                result.set_parent_ids([])
732
753
            else:
733
754
                result.set_parent_ids([revision_id])
734
755
        return result
735
756
 
 
757
    def destroy_workingtree(self):
 
758
        """See BzrDir.destroy_workingtree."""
 
759
        raise errors.UnsupportedOperation(self.destroy_workingtree, self)
 
760
 
 
761
    def destroy_workingtree_metadata(self):
 
762
        """See BzrDir.destroy_workingtree_metadata."""
 
763
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata, 
 
764
                                          self)
 
765
 
736
766
    def get_branch_transport(self, branch_format):
737
767
        """See BzrDir.get_branch_transport()."""
738
768
        if branch_format is None:
878
908
        from bzrlib.workingtree import WorkingTreeFormat
879
909
        return WorkingTreeFormat.get_default_format().initialize(self, revision_id)
880
910
 
 
911
    def destroy_workingtree(self):
 
912
        """See BzrDir.destroy_workingtree."""
 
913
        wt = self.open_workingtree()
 
914
        repository = wt.branch.repository
 
915
        empty = repository.revision_tree(bzrlib.revision.NULL_REVISION)
 
916
        wt.revert([], old_tree=empty)
 
917
        self.destroy_workingtree_metadata()
 
918
 
 
919
    def destroy_workingtree_metadata(self):
 
920
        self.transport.delete_tree('checkout')
 
921
 
881
922
    def _get_mkdir_mode(self):
882
923
        """Figure out the mode to use when creating a bzrdir subdir."""
883
 
        temp_control = LockableFiles(self.transport, '', TransportLock)
 
924
        temp_control = lockable_files.LockableFiles(self.transport, '',
 
925
                                     lockable_files.TransportLock)
884
926
        return temp_control._dir_mode
885
927
 
886
928
    def get_branch_transport(self, branch_format):
1062
1104
        """Initialize a new bzrdir in the base directory of a Transport."""
1063
1105
        # Since we don't have a .bzr directory, inherit the
1064
1106
        # mode from the root directory
1065
 
        temp_control = LockableFiles(transport, '', TransportLock)
 
1107
        temp_control = lockable_files.LockableFiles(transport,
 
1108
                            '', lockable_files.TransportLock)
1066
1109
        temp_control._transport.mkdir('.bzr',
1067
1110
                                      # FIXME: RBC 20060121 don't peek under
1068
1111
                                      # the covers
1077
1120
                      ('branch-format', self.get_format_string()),
1078
1121
                      ]
1079
1122
        # NB: no need to escape relative paths that are url safe.
1080
 
        control_files = LockableFiles(control, self._lock_file_name, 
1081
 
                                      self._lock_class)
 
1123
        control_files = lockable_files.LockableFiles(control,
 
1124
                            self._lock_file_name, self._lock_class)
1082
1125
        control_files.create_lock()
1083
1126
        control_files.lock_write()
1084
1127
        try:
1187
1230
    removed in format 5; write support for this format has been removed.
1188
1231
    """
1189
1232
 
1190
 
    _lock_class = TransportLock
 
1233
    _lock_class = lockable_files.TransportLock
1191
1234
 
1192
1235
    def get_format_string(self):
1193
1236
        """See BzrDirFormat.get_format_string()."""
1237
1280
       Unhashed stores in the repository.
1238
1281
    """
1239
1282
 
1240
 
    _lock_class = TransportLock
 
1283
    _lock_class = lockable_files.TransportLock
1241
1284
 
1242
1285
    def get_format_string(self):
1243
1286
        """See BzrDirFormat.get_format_string()."""
1296
1339
     - Format 6 repositories [always]
1297
1340
    """
1298
1341
 
1299
 
    _lock_class = TransportLock
 
1342
    _lock_class = lockable_files.TransportLock
1300
1343
 
1301
1344
    def get_format_string(self):
1302
1345
        """See BzrDirFormat.get_format_string()."""
1356
1399
     - Format 7 repositories [optional]
1357
1400
    """
1358
1401
 
1359
 
    _lock_class = LockDir
 
1402
    _lock_class = lockdir.LockDir
1360
1403
 
1361
1404
    def get_converter(self, format=None):
1362
1405
        """See BzrDirFormat.get_converter()."""
1416
1459
        self._formats = formats
1417
1460
    
1418
1461
    def adapt(self, test):
1419
 
        result = TestSuite()
 
1462
        result = unittest.TestSuite()
1420
1463
        for format in self._formats:
1421
1464
            new_test = deepcopy(test)
1422
1465
            new_test.transport_server = self._transport_server
1520
1563
        self.bzrdir.transport.delete_tree('text-store')
1521
1564
 
1522
1565
    def _convert_working_inv(self):
1523
 
        inv = serializer_v4.read_inventory(self.branch.control_files.get('inventory'))
1524
 
        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)
1525
1569
        # FIXME inventory is a working tree change.
1526
1570
        self.branch.control_files.put('inventory', StringIO(new_inv_xml))
1527
1571
 
1553
1597
                                                      prefixed=False,
1554
1598
                                                      compressed=True))
1555
1599
        try:
1556
 
            transaction = bzrlib.transactions.WriteTransaction()
 
1600
            transaction = WriteTransaction()
1557
1601
            for i, rev_id in enumerate(self.converted_revs):
1558
1602
                self.pb.update('write revision', i, len(self.converted_revs))
1559
1603
                _revision_store.add_revision(self.revisions[rev_id], transaction)
1585
1629
    def _load_old_inventory(self, rev_id):
1586
1630
        assert rev_id not in self.converted_revs
1587
1631
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
1588
 
        inv = serializer_v4.read_inventory_from_string(old_inv_xml)
 
1632
        inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
1589
1633
        inv.revision_id = rev_id
1590
1634
        rev = self.revisions[rev_id]
1591
1635
        if rev.inventory_sha1:
1596
1640
    def _load_updated_inventory(self, rev_id):
1597
1641
        assert rev_id in self.converted_revs
1598
1642
        inv_xml = self.inv_weave.get_text(rev_id)
1599
 
        inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(inv_xml)
 
1643
        inv = xml5.serializer_v5.read_inventory_from_string(inv_xml)
1600
1644
        return inv
1601
1645
 
1602
1646
    def _convert_one_rev(self, rev_id):
1618
1662
                assert getattr(ie, 'revision', None) is not None, \
1619
1663
                    'no revision on {%s} in {%s}' % \
1620
1664
                    (file_id, rev.revision_id)
1621
 
        new_inv_xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
 
1665
        new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
1622
1666
        new_inv_sha1 = sha_string(new_inv_xml)
1623
1667
        self.inv_weave.add_lines(rev.revision_id, 
1624
1668
                                 present_parents,
1836
1880
    def make_lock(self, name):
1837
1881
        """Make a lock for the new control dir name."""
1838
1882
        self.step('Make %s lock' % name)
1839
 
        ld = LockDir(self.bzrdir.transport, 
1840
 
                     '%s/lock' % name,
1841
 
                     file_modebits=self.file_mode,
1842
 
                     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)
1843
1887
        ld.create()
1844
1888
 
1845
1889
    def move_entry(self, new_dir, entry):