1
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
# TODO: remove unittest dependency; put that stuff inside the test suite
23
25
from copy import deepcopy
26
from cStringIO import StringIO
25
from cStringIO import StringIO
28
from stat import S_ISDIR
26
29
from unittest import TestSuite
39
42
from bzrlib.store.revision.text import TextRevisionStore
40
43
from bzrlib.store.text import TextStore
41
44
from bzrlib.store.versioned import WeaveStore
42
from bzrlib.symbol_versioning import *
43
45
from bzrlib.trace import mutter
44
46
from bzrlib.transactions import WriteTransaction
45
47
from bzrlib.transport import get_transport
93
95
if not allow_unsupported and not format.is_supported():
94
96
# see open_downlevel to open legacy branches.
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'])
97
raise errors.UnsupportedFormatError(format=format)
101
99
def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
102
100
"""Clone this bzrdir and its contents to url verbatim.
303
301
that child class desires.
305
303
bzrdir = BzrDir.create(base)
306
return bzrdir.create_repository()
304
return bzrdir.create_repository(shared)
309
307
def create_standalone_workingtree(base):
972
970
"""Return the .bzrdir style transport present at URL."""
974
972
format_string = transport.get(".bzr/branch-format").read()
973
except errors.NoSuchFile:
974
raise errors.NotBranchError(path=transport.base)
975
977
return klass._formats[format_string]
976
except errors.NoSuchFile:
977
raise errors.NotBranchError(path=transport.base)
979
raise errors.UnknownFormatError(format_string)
979
raise errors.UnknownFormatError(format=format_string)
982
982
def get_default_format(klass):
1379
class ScratchDir(BzrDir6):
1380
"""Special test class: a bzrdir that cleans up itself..
1382
>>> d = ScratchDir()
1383
>>> base = d.transport.base
1386
>>> b.transport.__del__()
1391
def __init__(self, files=[], dirs=[], transport=None):
1392
"""Make a test branch.
1394
This creates a temporary directory and runs init-tree in it.
1396
If any files are listed, they are created in the working copy.
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()
1407
super(ScratchDir, self).__init__(transport, BzrDirFormat6())
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
1416
self._transport.mkdir(d)
1419
self._transport.put(f, 'content of %s' % f)
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)
1430
... orig.base == clone.base
1433
>>> os.listdir(clone.base)
1434
[u'.bzr', u'file1', u'file2']
1436
from shutil import copytree
1437
from bzrlib.osutils import mkdtemp
1440
copytree(self.base, base, symlinks=True)
1442
transport=bzrlib.transport.local.ScratchTransport(base))
1445
1379
class Converter(object):
1446
1380
"""Converts a disk format object from one format to another."""
1623
1557
def _store_new_weave(self, rev, inv, present_parents):
1624
1558
# the XML is now updated with text versions
1628
if ie.kind == 'root_directory':
1560
entries = inv.iter_entries()
1562
for path, ie in entries:
1630
1563
assert hasattr(ie, 'revision'), \
1631
1564
'no revision on {%s} in {%s}' % \
1632
1565
(file_id, rev.revision_id)
1645
1578
mutter('converting texts of revision {%s}',
1647
1580
parent_invs = map(self._load_updated_inventory, present_parents)
1581
entries = inv.iter_entries()
1583
for path, ie in entries:
1650
1584
self._convert_file_version(rev, ie, parent_invs)
1652
1586
def _convert_file_version(self, rev, ie, parent_invs):