~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: John Arbash Meinel
  • Date: 2006-06-18 02:21:57 UTC
  • mfrom: (1787 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1794.
  • Revision ID: john@arbash-meinel.com-20060618022157-6e33aa9b67c25e4f
[merge] bzr.dev 1787

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
23
from copy import deepcopy
 
24
import os
26
25
from cStringIO import StringIO
27
 
import os
28
 
from stat import S_ISDIR
29
26
from unittest import TestSuite
30
27
 
31
28
import bzrlib
42
39
from bzrlib.store.revision.text import TextRevisionStore
43
40
from bzrlib.store.text import TextStore
44
41
from bzrlib.store.versioned import WeaveStore
 
42
from bzrlib.symbol_versioning import *
45
43
from bzrlib.trace import mutter
46
44
from bzrlib.transactions import WriteTransaction
47
45
from bzrlib.transport import get_transport
94
92
        """
95
93
        if not allow_unsupported and not format.is_supported():
96
94
            # see open_downlevel to open legacy branches.
97
 
            raise errors.UnsupportedFormatError(format=format)
 
95
            raise errors.UnsupportedFormatError(
 
96
                    'sorry, format %s not supported' % format,
 
97
                    ['use a different bzr version',
 
98
                     'or remove the .bzr directory'
 
99
                     ' and "bzr init" again'])
98
100
 
99
101
    def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
100
102
        """Clone this bzrdir and its contents to url verbatim.
970
972
        """Return the .bzrdir style transport present at URL."""
971
973
        try:
972
974
            format_string = transport.get(".bzr/branch-format").read()
 
975
            return klass._formats[format_string]
973
976
        except errors.NoSuchFile:
974
977
            raise errors.NotBranchError(path=transport.base)
975
 
 
976
 
        try:
977
 
            return klass._formats[format_string]
978
978
        except KeyError:
979
 
            raise errors.UnknownFormatError(format=format_string)
 
979
            raise errors.UnknownFormatError(format_string)
980
980
 
981
981
    @classmethod
982
982
    def get_default_format(klass):
1376
1376
        return result
1377
1377
 
1378
1378
 
 
1379
class ScratchDir(BzrDir6):
 
1380
    """Special test class: a bzrdir that cleans up itself..
 
1381
 
 
1382
    >>> d = ScratchDir()
 
1383
    >>> base = d.transport.base
 
1384
    >>> isdir(base)
 
1385
    True
 
1386
    >>> b.transport.__del__()
 
1387
    >>> isdir(base)
 
1388
    False
 
1389
    """
 
1390
 
 
1391
    def __init__(self, files=[], dirs=[], transport=None):
 
1392
        """Make a test branch.
 
1393
 
 
1394
        This creates a temporary directory and runs init-tree in it.
 
1395
 
 
1396
        If any files are listed, they are created in the working copy.
 
1397
        """
 
1398
        if transport is None:
 
1399
            transport = bzrlib.transport.local.ScratchTransport()
 
1400
            # local import for scope restriction
 
1401
            BzrDirFormat6().initialize(transport.base)
 
1402
            super(ScratchDir, self).__init__(transport, BzrDirFormat6())
 
1403
            self.create_repository()
 
1404
            self.create_branch()
 
1405
            self.create_workingtree()
 
1406
        else:
 
1407
            super(ScratchDir, self).__init__(transport, BzrDirFormat6())
 
1408
 
 
1409
        # BzrBranch creates a clone to .bzr and then forgets about the
 
1410
        # original transport. A ScratchTransport() deletes itself and
 
1411
        # everything underneath it when it goes away, so we need to
 
1412
        # grab a local copy to prevent that from happening
 
1413
        self._transport = transport
 
1414
 
 
1415
        for d in dirs:
 
1416
            self._transport.mkdir(d)
 
1417
            
 
1418
        for f in files:
 
1419
            self._transport.put(f, 'content of %s' % f)
 
1420
 
 
1421
    def clone(self):
 
1422
        """
 
1423
        >>> orig = ScratchDir(files=["file1", "file2"])
 
1424
        >>> os.listdir(orig.base)
 
1425
        [u'.bzr', u'file1', u'file2']
 
1426
        >>> clone = orig.clone()
 
1427
        >>> if os.name != 'nt':
 
1428
        ...   os.path.samefile(orig.base, clone.base)
 
1429
        ... else:
 
1430
        ...   orig.base == clone.base
 
1431
        ...
 
1432
        False
 
1433
        >>> os.listdir(clone.base)
 
1434
        [u'.bzr', u'file1', u'file2']
 
1435
        """
 
1436
        from shutil import copytree
 
1437
        from bzrlib.osutils import mkdtemp
 
1438
        base = mkdtemp()
 
1439
        os.rmdir(base)
 
1440
        copytree(self.base, base, symlinks=True)
 
1441
        return ScratchDir(
 
1442
            transport=bzrlib.transport.local.ScratchTransport(base))
 
1443
 
 
1444
 
1379
1445
class Converter(object):
1380
1446
    """Converts a disk format object from one format to another."""
1381
1447