61
83
a transport connected to the directory this bzr was opened from.
87
"""Invoke break_lock on the first object in the bzrdir.
89
If there is a tree, the tree is opened and break_lock() called.
90
Otherwise, branch is tried, and finally repository.
92
# XXX: This seems more like a UI function than something that really
93
# belongs in this class.
95
thing_to_unlock = self.open_workingtree()
96
except (errors.NotLocalUrl, errors.NoWorkingTree):
98
thing_to_unlock = self.open_branch()
99
except errors.NotBranchError:
101
thing_to_unlock = self.open_repository()
102
except errors.NoRepositoryPresent:
104
thing_to_unlock.break_lock()
64
106
def can_convert_format(self):
65
107
"""Return true if this bzrdir is one whose format we can convert from."""
68
def _check_supported(self, format, allow_unsupported):
69
"""Check whether format is a supported format.
71
If allow_unsupported is True, this is a no-op.
110
def check_conversion_target(self, target_format):
111
target_repo_format = target_format.repository_format
112
source_repo_format = self._format.repository_format
113
source_repo_format.check_conversion_target(target_repo_format)
116
def _check_supported(format, allow_unsupported,
117
recommend_upgrade=True,
119
"""Give an error or warning on old formats.
121
:param format: may be any kind of format - workingtree, branch,
124
:param allow_unsupported: If true, allow opening
125
formats that are strongly deprecated, and which may
126
have limited functionality.
128
:param recommend_upgrade: If true (default), warn
129
the user through the ui object that they may wish
130
to upgrade the object.
132
# TODO: perhaps move this into a base Format class; it's not BzrDir
133
# specific. mbp 20070323
73
134
if not allow_unsupported and not format.is_supported():
74
raise errors.UnsupportedFormatError(format)
135
# see open_downlevel to open legacy branches.
136
raise errors.UnsupportedFormatError(format=format)
137
if recommend_upgrade \
138
and getattr(format, 'upgrade_recommended', False):
139
ui.ui_factory.recommend_upgrade(
140
format.get_format_description(),
76
def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
143
def clone(self, url, revision_id=None, force_new_repo=False):
77
144
"""Clone this bzrdir and its contents to url verbatim.
79
146
If urls last component does not exist, it will be created.
114
197
except errors.NotBranchError:
117
self.open_workingtree().clone(result, basis=basis_tree)
200
self.open_workingtree().clone(result)
118
201
except (errors.NoWorkingTree, errors.NotLocalUrl):
122
def _get_basis_components(self, basis):
123
"""Retrieve the basis components that are available at basis."""
125
return None, None, None
127
basis_tree = basis.open_workingtree()
128
basis_branch = basis_tree.branch
129
basis_repo = basis_branch.repository
130
except (errors.NoWorkingTree, errors.NotLocalUrl):
133
basis_branch = basis.open_branch()
134
basis_repo = basis_branch.repository
135
except errors.NotBranchError:
138
basis_repo = basis.open_repository()
139
except errors.NoRepositoryPresent:
141
return basis_repo, basis_branch, basis_tree
205
# TODO: This should be given a Transport, and should chdir up; otherwise
206
# this will open a new connection.
143
207
def _make_tail(self, url):
144
segments = url.split('/')
145
if segments and segments[-1] not in ('', '.'):
146
parent = '/'.join(segments[:-1])
147
t = bzrlib.transport.get_transport(parent)
149
t.mkdir(segments[-1])
150
except errors.FileExists:
208
t = get_transport(url)
212
def create(cls, base, format=None, possible_transports=None):
155
213
"""Create a new BzrDir at the url 'base'.
157
215
This will call the current default formats initialize with base
158
216
as the only parameter.
160
If you need a specific format, consider creating an instance
161
of that and calling initialize().
218
:param format: If supplied, the format of branch to create. If not
219
supplied, the default is used.
220
:param possible_transports: If supplied, a list of transports that
221
can be reused to share a remote connection.
163
segments = base.split('/')
164
if segments and segments[-1] not in ('', '.'):
165
parent = '/'.join(segments[:-1])
166
t = bzrlib.transport.get_transport(parent)
168
t.mkdir(segments[-1])
169
except errors.FileExists:
171
return BzrDirFormat.get_default_format().initialize(safe_unicode(base))
223
if cls is not BzrDir:
224
raise AssertionError("BzrDir.create always creates the default"
225
" format, not one of %r" % cls)
226
t = get_transport(base, possible_transports)
229
format = BzrDirFormat.get_default_format()
230
return format.initialize(base, possible_transports)
173
232
def create_branch(self):
174
233
"""Create a branch in this BzrDir.
394
528
_unsupported is a private parameter to the BzrDir class.
396
530
t = get_transport(base)
397
mutter("trying to open %r with transport %r", base, t)
398
format = BzrDirFormat.find_format(t)
399
if not _unsupported and not format.is_supported():
400
# see open_downlevel to open legacy branches.
401
raise errors.UnsupportedFormatError(
402
'sorry, format %s not supported' % format,
403
['use a different bzr version',
404
'or remove the .bzr directory'
405
' and "bzr init" again'])
406
return format.open(t, _found=True)
531
return BzrDir.open_from_transport(t, _unsupported=_unsupported)
534
def open_from_transport(transport, _unsupported=False,
535
_server_formats=True):
536
"""Open a bzrdir within a particular directory.
538
:param transport: Transport containing the bzrdir.
539
:param _unsupported: private.
541
base = transport.base
543
def find_format(transport):
544
return transport, BzrDirFormat.find_format(
545
transport, _server_formats=_server_formats)
547
def redirected(transport, e, redirection_notice):
548
qualified_source = e.get_source_url()
549
relpath = transport.relpath(qualified_source)
550
if not e.target.endswith(relpath):
551
# Not redirected to a branch-format, not a branch
552
raise errors.NotBranchError(path=e.target)
553
target = e.target[:-len(relpath)]
554
note('%s is%s redirected to %s',
555
transport.base, e.permanently, target)
556
# Let's try with a new transport
557
qualified_target = e.get_target_url()[:-len(relpath)]
558
# FIXME: If 'transport' has a qualifier, this should
559
# be applied again to the new transport *iff* the
560
# schemes used are the same. It's a bit tricky to
561
# verify, so I'll punt for now
563
return get_transport(target)
566
transport, format = do_catching_redirections(find_format,
569
except errors.TooManyRedirections:
570
raise errors.NotBranchError(base)
572
BzrDir._check_supported(format, _unsupported)
573
return format.open(transport, _found=True)
408
575
def open_branch(self, unsupported=False):
409
576
"""Open the branch object at this BzrDir if one is present.
435
603
If there is one and it is either an unrecognised format or an unsupported
436
604
format, UnknownFormatError or UnsupportedFormatError are raised.
437
605
If there is one, it is returned, along with the unused portion of url.
607
:return: The BzrDir that contains the path, and a Unicode path
608
for the rest of the URL.
439
610
# this gets the normalised url back. I.e. '.' -> the full path.
440
611
url = a_transport.base
443
format = BzrDirFormat.find_format(a_transport)
444
return format.open(a_transport), a_transport.relpath(url)
614
result = BzrDir.open_from_transport(a_transport)
615
return result, urlutils.unescape(a_transport.relpath(url))
445
616
except errors.NotBranchError, e:
446
mutter('not a branch in: %r %s', a_transport.base, e)
447
new_t = a_transport.clone('..')
619
new_t = a_transport.clone('..')
620
except errors.InvalidURLJoin:
621
# reached the root, whatever that may be
622
raise errors.NotBranchError(path=url)
448
623
if new_t.base == a_transport.base:
449
624
# reached the root, whatever that may be
450
625
raise errors.NotBranchError(path=url)
451
626
a_transport = new_t
629
def open_containing_tree_or_branch(klass, location):
630
"""Return the branch and working tree contained by a location.
632
Returns (tree, branch, relpath).
633
If there is no tree at containing the location, tree will be None.
634
If there is no branch containing the location, an exception will be
636
relpath is the portion of the path that is contained by the branch.
638
bzrdir, relpath = klass.open_containing(location)
640
tree = bzrdir.open_workingtree()
641
except (errors.NoWorkingTree, errors.NotLocalUrl):
643
branch = bzrdir.open_branch()
646
return tree, branch, relpath
453
648
def open_repository(self, _unsupported=False):
454
649
"""Open the repository object at this BzrDir if one is present.
463
658
raise NotImplementedError(self.open_repository)
465
def open_workingtree(self, _unsupported=False):
660
def open_workingtree(self, _unsupported=False,
661
recommend_upgrade=True):
466
662
"""Open the workingtree object at this BzrDir if one is present.
468
TODO: static convenience version of this?
664
:param recommend_upgrade: Optional keyword parameter, when True (the
665
default), emit through the ui module a recommendation that the user
666
upgrade the working tree when the workingtree being opened is old
667
(but still fully supported).
470
669
raise NotImplementedError(self.open_workingtree)
472
def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
671
def has_branch(self):
672
"""Tell if this bzrdir contains a branch.
674
Note: if you're going to open the branch, you should just go ahead
675
and try, and not ask permission first. (This method just opens the
676
branch and discards it, and that's somewhat expensive.)
681
except errors.NotBranchError:
684
def has_workingtree(self):
685
"""Tell if this bzrdir contains a working tree.
687
This will still raise an exception if the bzrdir has a workingtree that
688
is remote & inaccessible.
690
Note: if you're going to open the working tree, you should just go ahead
691
and try, and not ask permission first. (This method just opens the
692
workingtree and discards it, and that's somewhat expensive.)
695
self.open_workingtree(recommend_upgrade=False)
697
except errors.NoWorkingTree:
700
def _cloning_metadir(self):
701
"""Produce a metadir suitable for cloning with"""
702
result_format = self._format.__class__()
705
branch = self.open_branch()
706
source_repository = branch.repository
707
except errors.NotBranchError:
709
source_repository = self.open_repository()
710
except errors.NoRepositoryPresent:
711
source_repository = None
713
# XXX TODO: This isinstance is here because we have not implemented
714
# the fix recommended in bug # 103195 - to delegate this choice the
716
repo_format = source_repository._format
717
if not isinstance(repo_format, remote.RemoteRepositoryFormat):
718
result_format.repository_format = repo_format
720
# TODO: Couldn't we just probe for the format in these cases,
721
# rather than opening the whole tree? It would be a little
722
# faster. mbp 20070401
723
tree = self.open_workingtree(recommend_upgrade=False)
724
except (errors.NoWorkingTree, errors.NotLocalUrl):
725
result_format.workingtree_format = None
727
result_format.workingtree_format = tree._format.__class__()
728
return result_format, source_repository
730
def cloning_metadir(self):
731
"""Produce a metadir suitable for cloning or sprouting with.
733
These operations may produce workingtrees (yes, even though they're
734
"cloning" something that doesn't have a tree, so a viable workingtree
735
format must be selected.
737
format, repository = self._cloning_metadir()
738
if format._workingtree_format is None:
739
if repository is None:
741
tree_format = repository._format._matchingbzrdir.workingtree_format
742
format.workingtree_format = tree_format.__class__()
745
def checkout_metadir(self):
746
return self.cloning_metadir()
748
def sprout(self, url, revision_id=None, force_new_repo=False,
749
recurse='down', possible_transports=None):
473
750
"""Create a copy of this bzrdir prepared for use as a new line of
510
786
# no repo available, make a new one
511
787
result.create_repository()
512
788
elif source_repository is not None and result_repo is None:
513
# have soure, and want to make a new target repo
514
source_repository.clone(result,
515
revision_id=revision_id,
789
# have source, and want to make a new target repo
790
result_repo = source_repository.sprout(result,
791
revision_id=revision_id)
518
793
# fetch needed content into target.
520
# XXX FIXME RBC 20060214 need tests for this when the basis
522
result_repo.fetch(basis_repo, revision_id=revision_id)
523
result_repo.fetch(source_repository, revision_id=revision_id)
794
if source_repository is not None:
796
# source_repository.copy_content_into(result_repo,
797
# revision_id=revision_id)
798
# so we can override the copy method
799
result_repo.fetch(source_repository, revision_id=revision_id)
524
800
if source_branch is not None:
525
801
source_branch.sprout(result, revision_id=revision_id)
527
803
result.create_branch()
529
self.open_workingtree().clone(result,
530
revision_id=revision_id,
532
except (errors.NoWorkingTree, errors.NotLocalUrl):
533
result.create_workingtree()
804
if isinstance(target_transport, LocalTransport) and (
805
result_repo is None or result_repo.make_working_trees()):
806
wt = result.create_workingtree()
809
if wt.path2id('') is None:
811
wt.set_root_id(self.open_workingtree.get_root_id())
812
except errors.NoWorkingTree:
818
if recurse == 'down':
820
basis = wt.basis_tree()
822
subtrees = basis.iter_references()
823
recurse_branch = wt.branch
824
elif source_branch is not None:
825
basis = source_branch.basis_tree()
827
subtrees = basis.iter_references()
828
recurse_branch = source_branch
833
for path, file_id in subtrees:
834
target = urlutils.join(url, urlutils.escape(path))
835
sublocation = source_branch.reference_parent(file_id, path)
836
sublocation.bzrdir.sprout(target,
837
basis.get_reference_revision(file_id, path),
838
force_new_repo=force_new_repo, recurse=recurse)
840
if basis is not None:
540
848
def __init__(self, _transport, _format):
541
849
"""See BzrDir.__init__."""
542
850
super(BzrDirPreSplitOut, self).__init__(_transport, _format)
543
self._control_files = LockableFiles(self.get_branch_transport(None),
546
def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
851
assert self._format._lock_class == lockable_files.TransportLock
852
assert self._format._lock_file_name == 'branch-lock'
853
self._control_files = lockable_files.LockableFiles(
854
self.get_branch_transport(None),
855
self._format._lock_file_name,
856
self._format._lock_class)
858
def break_lock(self):
859
"""Pre-splitout bzrdirs do not suffer from stale locks."""
860
raise NotImplementedError(self.break_lock)
862
def clone(self, url, revision_id=None, force_new_repo=False):
547
863
"""See BzrDir.clone()."""
548
864
from bzrlib.workingtree import WorkingTreeFormat2
549
865
self._make_tail(url)
550
result = self._format.initialize(url, _cloning=True)
551
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
552
self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
553
self.open_branch().clone(result, revision_id=revision_id)
866
result = self._format._initialize_for_clone(url)
867
self.open_repository().clone(result, revision_id=revision_id)
868
from_branch = self.open_branch()
869
from_branch.clone(result, revision_id=revision_id)
555
self.open_workingtree().clone(result, basis=basis_tree)
871
self.open_workingtree().clone(result)
556
872
except errors.NotLocalUrl:
557
873
# make a new one, this format always has to have one.
558
WorkingTreeFormat2().initialize(result)
875
WorkingTreeFormat2().initialize(result)
876
except errors.NotLocalUrl:
877
# but we cannot do it for remote trees.
878
to_branch = result.open_branch()
879
WorkingTreeFormat2().stub_initialize_remote(to_branch.control_files)
561
882
def create_branch(self):
853
1274
"""Return the ASCII format string that identifies this format."""
854
1275
raise NotImplementedError(self.get_format_string)
1277
def get_format_description(self):
1278
"""Return the short description for this format."""
1279
raise NotImplementedError(self.get_format_description)
856
1281
def get_converter(self, format=None):
857
1282
"""Return the converter to use to convert bzrdirs needing converts.
859
1284
This returns a bzrlib.bzrdir.Converter object.
861
1286
This should return the best upgrader to step this format towards the
862
current default format. In the case of plugins we can/shouold provide
1287
current default format. In the case of plugins we can/should provide
863
1288
some means for them to extend the range of returnable converters.
865
:param format: Optional format to override the default foramt of the
1290
:param format: Optional format to override the default format of the
868
1293
raise NotImplementedError(self.get_converter)
870
def initialize(self, url):
871
"""Create a bzr control dir at this url and return an opened copy."""
1295
def initialize(self, url, possible_transports=None):
1296
"""Create a bzr control dir at this url and return an opened copy.
1298
Subclasses should typically override initialize_on_transport
1299
instead of this method.
1301
return self.initialize_on_transport(get_transport(url,
1302
possible_transports))
1304
def initialize_on_transport(self, transport):
1305
"""Initialize a new bzrdir in the base directory of a Transport."""
872
1306
# Since we don't have a .bzr directory, inherit the
873
1307
# mode from the root directory
874
t = get_transport(url)
875
temp_control = LockableFiles(t, '')
1308
temp_control = lockable_files.LockableFiles(transport,
1309
'', lockable_files.TransportLock)
876
1310
temp_control._transport.mkdir('.bzr',
877
# FIXME: RBC 20060121 dont peek under
1311
# FIXME: RBC 20060121 don't peek under
879
1313
mode=temp_control._dir_mode)
880
1314
file_mode = temp_control._file_mode
881
1315
del temp_control
882
mutter('created control directory in ' + t.base)
883
control = t.clone('.bzr')
884
lock_file = 'branch-lock'
1316
mutter('created control directory in ' + transport.base)
1317
control = transport.clone('.bzr')
885
1318
utf8_files = [('README',
886
1319
"This is a Bazaar-NG control directory.\n"
887
1320
"Do not change any files in this directory.\n"),
888
1321
('branch-format', self.get_format_string()),
890
1323
# NB: no need to escape relative paths that are url safe.
891
control.put(lock_file, StringIO(), mode=file_mode)
892
control_files = LockableFiles(control, lock_file)
1324
control_files = lockable_files.LockableFiles(control,
1325
self._lock_file_name, self._lock_class)
1326
control_files.create_lock()
893
1327
control_files.lock_write()
895
1329
for file, content in utf8_files:
896
1330
control_files.put_utf8(file, content)
898
1332
control_files.unlock()
899
return self.open(t, _found=True)
1333
return self.open(transport, _found=True)
901
1335
def is_supported(self):
902
1336
"""Is this format supported?
1122
1674
def __set_repository_format(self, value):
1123
1675
"""Allow changint the repository format for metadir formats."""
1124
1676
self._repository_format = value
1125
1678
repository_format = property(__return_repository_format, __set_repository_format)
1680
def __get_workingtree_format(self):
1681
if self._workingtree_format is None:
1682
from bzrlib.workingtree import WorkingTreeFormat
1683
self._workingtree_format = WorkingTreeFormat.get_default_format()
1684
return self._workingtree_format
1686
def __set_workingtree_format(self, wt_format):
1687
self._workingtree_format = wt_format
1689
workingtree_format = property(__get_workingtree_format,
1690
__set_workingtree_format)
1693
# Register bzr control format
1694
BzrDirFormat.register_control_format(BzrDirFormat)
1696
# Register bzr formats
1128
1697
BzrDirFormat.register_format(BzrDirFormat4())
1129
1698
BzrDirFormat.register_format(BzrDirFormat5())
1130
BzrDirFormat.register_format(BzrDirMetaFormat1())
1131
__default_format = BzrDirFormat6()
1699
BzrDirFormat.register_format(BzrDirFormat6())
1700
__default_format = BzrDirMetaFormat1()
1132
1701
BzrDirFormat.register_format(__default_format)
1133
BzrDirFormat.set_default_format(__default_format)
1136
class BzrDirTestProviderAdapter(object):
1137
"""A tool to generate a suite testing multiple bzrdir formats at once.
1139
This is done by copying the test once for each transport and injecting
1140
the transport_server, transport_readonly_server, and bzrdir_format
1141
classes into each copy. Each copy is also given a new id() to make it
1145
def __init__(self, transport_server, transport_readonly_server, formats):
1146
self._transport_server = transport_server
1147
self._transport_readonly_server = transport_readonly_server
1148
self._formats = formats
1150
def adapt(self, test):
1151
result = TestSuite()
1152
for format in self._formats:
1153
new_test = deepcopy(test)
1154
new_test.transport_server = self._transport_server
1155
new_test.transport_readonly_server = self._transport_readonly_server
1156
new_test.bzrdir_format = format
1157
def make_new_test_id():
1158
new_id = "%s(%s)" % (new_test.id(), format.__class__.__name__)
1159
return lambda: new_id
1160
new_test.id = make_new_test_id()
1161
result.addTest(new_test)
1165
class ScratchDir(BzrDir6):
1166
"""Special test class: a bzrdir that cleans up itself..
1168
>>> d = ScratchDir()
1169
>>> base = d.transport.base
1172
>>> b.transport.__del__()
1177
def __init__(self, files=[], dirs=[], transport=None):
1178
"""Make a test branch.
1180
This creates a temporary directory and runs init-tree in it.
1182
If any files are listed, they are created in the working copy.
1184
if transport is None:
1185
transport = bzrlib.transport.local.ScratchTransport()
1186
# local import for scope restriction
1187
BzrDirFormat6().initialize(transport.base)
1188
super(ScratchDir, self).__init__(transport, BzrDirFormat6())
1189
self.create_repository()
1190
self.create_branch()
1191
self.create_workingtree()
1193
super(ScratchDir, self).__init__(transport, BzrDirFormat6())
1195
# BzrBranch creates a clone to .bzr and then forgets about the
1196
# original transport. A ScratchTransport() deletes itself and
1197
# everything underneath it when it goes away, so we need to
1198
# grab a local copy to prevent that from happening
1199
self._transport = transport
1202
self._transport.mkdir(d)
1205
self._transport.put(f, 'content of %s' % f)
1209
>>> orig = ScratchDir(files=["file1", "file2"])
1210
>>> os.listdir(orig.base)
1211
[u'.bzr', u'file1', u'file2']
1212
>>> clone = orig.clone()
1213
>>> if os.name != 'nt':
1214
... os.path.samefile(orig.base, clone.base)
1216
... orig.base == clone.base
1219
>>> os.listdir(clone.base)
1220
[u'.bzr', u'file1', u'file2']
1222
from shutil import copytree
1223
from bzrlib.osutils import mkdtemp
1226
copytree(self.base, base, symlinks=True)
1228
transport=bzrlib.transport.local.ScratchTransport(base))
1702
BzrDirFormat._default_format = __default_format
1231
1705
class Converter(object):
1563
2044
# find out whats there
1564
2045
self.step('Finding branch files')
1565
last_revision = self.bzrdir.open_workingtree().last_revision()
2046
last_revision = self.bzrdir.open_branch().last_revision()
1566
2047
bzrcontents = self.bzrdir.transport.list_dir('.')
1567
2048
for name in bzrcontents:
1568
2049
if name.startswith('basis-inventory.'):
1569
2050
self.garbage_inventories.append(name)
1570
2051
# create new directories for repository, working tree and branch
1571
dir_mode = self.bzrdir._control_files._dir_mode
2052
self.dir_mode = self.bzrdir._control_files._dir_mode
1572
2053
self.file_mode = self.bzrdir._control_files._file_mode
1573
2054
repository_names = [('inventory.weave', True),
1574
2055
('revision-store', True),
1575
2056
('weaves', True)]
1576
2057
self.step('Upgrading repository ')
1577
self.bzrdir.transport.mkdir('repository', mode=dir_mode)
2058
self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
1578
2059
self.make_lock('repository')
1579
2060
# we hard code the formats here because we are converting into
1580
2061
# the meta format. The meta format upgrader can take this to a
1581
2062
# future format within each component.
1582
self.put_format('repository', bzrlib.repository.RepositoryFormat7())
2063
self.put_format('repository', RepositoryFormat7())
1583
2064
for entry in repository_names:
1584
2065
self.move_entry('repository', entry)
1586
2067
self.step('Upgrading branch ')
1587
self.bzrdir.transport.mkdir('branch', mode=dir_mode)
2068
self.bzrdir.transport.mkdir('branch', mode=self.dir_mode)
1588
2069
self.make_lock('branch')
1589
self.put_format('branch', bzrlib.branch.BzrBranchFormat5())
2070
self.put_format('branch', BzrBranchFormat5())
1590
2071
branch_files = [('revision-history', True),
1591
2072
('branch-name', True),
1592
2073
('parent', False)]
1593
2074
for entry in branch_files:
1594
2075
self.move_entry('branch', entry)
1596
self.step('Upgrading working tree')
1597
self.bzrdir.transport.mkdir('checkout', mode=dir_mode)
1598
self.make_lock('checkout')
1599
self.put_format('checkout', bzrlib.workingtree.WorkingTreeFormat3())
1600
self.bzrdir.transport.delete_multi(self.garbage_inventories, self.pb)
1601
2077
checkout_files = [('pending-merges', True),
1602
2078
('inventory', True),
1603
2079
('stat-cache', False)]
1604
for entry in checkout_files:
1605
self.move_entry('checkout', entry)
1606
if last_revision is not None:
1607
self.bzrdir._control_files.put_utf8('checkout/last-revision',
1609
self.bzrdir._control_files.put_utf8('branch-format', BzrDirMetaFormat1().get_format_string())
2080
# If a mandatory checkout file is not present, the branch does not have
2081
# a functional checkout. Do not create a checkout in the converted
2083
for name, mandatory in checkout_files:
2084
if mandatory and name not in bzrcontents:
2085
has_checkout = False
2089
if not has_checkout:
2090
self.pb.note('No working tree.')
2091
# If some checkout files are there, we may as well get rid of them.
2092
for name, mandatory in checkout_files:
2093
if name in bzrcontents:
2094
self.bzrdir.transport.delete(name)
2096
from bzrlib.workingtree import WorkingTreeFormat3
2097
self.step('Upgrading working tree')
2098
self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
2099
self.make_lock('checkout')
2101
'checkout', WorkingTreeFormat3())
2102
self.bzrdir.transport.delete_multi(
2103
self.garbage_inventories, self.pb)
2104
for entry in checkout_files:
2105
self.move_entry('checkout', entry)
2106
if last_revision is not None:
2107
self.bzrdir._control_files.put_utf8(
2108
'checkout/last-revision', last_revision)
2109
self.bzrdir._control_files.put_utf8(
2110
'branch-format', BzrDirMetaFormat1().get_format_string())
1610
2111
return BzrDir.open(self.bzrdir.root_transport.base)
1612
2113
def make_lock(self, name):
1613
2114
"""Make a lock for the new control dir name."""
1614
2115
self.step('Make %s lock' % name)
1615
self.bzrdir.transport.put('%s/lock' % name, StringIO(), mode=self.file_mode)
2116
ld = lockdir.LockDir(self.bzrdir.transport,
2118
file_modebits=self.file_mode,
2119
dir_modebits=self.dir_mode)
1617
2122
def move_entry(self, new_dir, entry):
1618
2123
"""Move then entry name into new_dir."""
1656
2161
self.pb.note('starting repository conversion')
1657
2162
converter = CopyConverter(self.target_format.repository_format)
1658
2163
converter.convert(repo, pb)
2165
branch = self.bzrdir.open_branch()
2166
except errors.NotBranchError:
2169
# TODO: conversions of Branch and Tree should be done by
2170
# InterXFormat lookups
2171
# Avoid circular imports
2172
from bzrlib import branch as _mod_branch
2173
if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
2174
self.target_format.get_branch_format().__class__ is
2175
_mod_branch.BzrBranchFormat6):
2176
branch_converter = _mod_branch.Converter5to6()
2177
branch_converter.convert(branch)
2179
tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2180
except (errors.NoWorkingTree, errors.NotLocalUrl):
2183
# TODO: conversions of Branch and Tree should be done by
2184
# InterXFormat lookups
2185
if (isinstance(tree, workingtree.WorkingTree3) and
2186
not isinstance(tree, workingtree_4.WorkingTree4) and
2187
isinstance(self.target_format.workingtree_format,
2188
workingtree_4.WorkingTreeFormat4)):
2189
workingtree_4.Converter3to4().convert(tree)
1659
2190
return to_convert
2193
# This is not in remote.py because it's small, and needs to be registered.
2194
# Putting it in remote.py creates a circular import problem.
2195
# we can make it a lazy object if the control formats is turned into something
2197
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2198
"""Format representing bzrdirs accessed via a smart server"""
2200
def get_format_description(self):
2201
return 'bzr remote bzrdir'
2204
def probe_transport(klass, transport):
2205
"""Return a RemoteBzrDirFormat object if it looks possible."""
2207
client = transport.get_smart_client()
2208
except (NotImplementedError, AttributeError,
2209
errors.TransportNotPossible):
2210
# no smart server, so not a branch for this format type.
2211
raise errors.NotBranchError(path=transport.base)
2213
# Send a 'hello' request in protocol version one, and decline to
2214
# open it if the server doesn't support our required version (2) so
2215
# that the VFS-based transport will do it.
2216
request = client.get_request()
2217
smart_protocol = protocol.SmartClientRequestProtocolOne(request)
2218
server_version = smart_protocol.query_version()
2219
if server_version != 2:
2220
raise errors.NotBranchError(path=transport.base)
2223
def initialize_on_transport(self, transport):
2225
# hand off the request to the smart server
2226
shared_medium = transport.get_shared_medium()
2227
except errors.NoSmartMedium:
2228
# TODO: lookup the local format from a server hint.
2229
local_dir_format = BzrDirMetaFormat1()
2230
return local_dir_format.initialize_on_transport(transport)
2231
client = _SmartClient(shared_medium)
2232
path = client.remote_path_from_transport(transport)
2233
response = _SmartClient(shared_medium).call('BzrDirFormat.initialize',
2235
assert response[0] in ('ok', ), 'unexpected response code %s' % (response,)
2236
return remote.RemoteBzrDir(transport)
2238
def _open(self, transport):
2239
return remote.RemoteBzrDir(transport)
2241
def __eq__(self, other):
2242
if not isinstance(other, RemoteBzrDirFormat):
2244
return self.get_format_description() == other.get_format_description()
2247
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2250
class BzrDirFormatInfo(object):
2252
def __init__(self, native, deprecated, hidden):
2253
self.deprecated = deprecated
2254
self.native = native
2255
self.hidden = hidden
2258
class BzrDirFormatRegistry(registry.Registry):
2259
"""Registry of user-selectable BzrDir subformats.
2261
Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2262
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
2265
def register_metadir(self, key,
2266
repository_format, help, native=True, deprecated=False,
2270
"""Register a metadir subformat.
2272
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2273
by the Repository format.
2275
:param repository_format: The fully-qualified repository format class
2277
:param branch_format: Fully-qualified branch format class name as
2279
:param tree_format: Fully-qualified tree format class name as
2282
# This should be expanded to support setting WorkingTree and Branch
2283
# formats, once BzrDirMetaFormat1 supports that.
2284
def _load(full_name):
2285
mod_name, factory_name = full_name.rsplit('.', 1)
2287
mod = __import__(mod_name, globals(), locals(),
2289
except ImportError, e:
2290
raise ImportError('failed to load %s: %s' % (full_name, e))
2292
factory = getattr(mod, factory_name)
2293
except AttributeError:
2294
raise AttributeError('no factory %s in module %r'
2299
bd = BzrDirMetaFormat1()
2300
if branch_format is not None:
2301
bd.set_branch_format(_load(branch_format))
2302
if tree_format is not None:
2303
bd.workingtree_format = _load(tree_format)
2304
if repository_format is not None:
2305
bd.repository_format = _load(repository_format)
2307
self.register(key, helper, help, native, deprecated, hidden)
2309
def register(self, key, factory, help, native=True, deprecated=False,
2311
"""Register a BzrDirFormat factory.
2313
The factory must be a callable that takes one parameter: the key.
2314
It must produce an instance of the BzrDirFormat when called.
2316
This function mainly exists to prevent the info object from being
2319
registry.Registry.register(self, key, factory, help,
2320
BzrDirFormatInfo(native, deprecated, hidden))
2322
def register_lazy(self, key, module_name, member_name, help, native=True,
2323
deprecated=False, hidden=False):
2324
registry.Registry.register_lazy(self, key, module_name, member_name,
2325
help, BzrDirFormatInfo(native, deprecated, hidden))
2327
def set_default(self, key):
2328
"""Set the 'default' key to be a clone of the supplied key.
2330
This method must be called once and only once.
2332
registry.Registry.register(self, 'default', self.get(key),
2333
self.get_help(key), info=self.get_info(key))
2335
def set_default_repository(self, key):
2336
"""Set the FormatRegistry default and Repository default.
2338
This is a transitional method while Repository.set_default_format
2341
if 'default' in self:
2342
self.remove('default')
2343
self.set_default(key)
2344
format = self.get('default')()
2345
assert isinstance(format, BzrDirMetaFormat1)
2347
def make_bzrdir(self, key):
2348
return self.get(key)()
2350
def help_topic(self, topic):
2351
output = textwrap.dedent("""\
2352
Bazaar directory formats
2353
------------------------
2355
These formats can be used for creating branches, working trees, and
2359
default_help = self.get_help('default')
2361
for key in self.keys():
2362
if key == 'default':
2364
help = self.get_help(key)
2365
if help == default_help:
2366
default_realkey = key
2368
help_pairs.append((key, help))
2370
def wrapped(key, help, info):
2372
help = '(native) ' + help
2373
return ' %s:\n%s\n\n' % (key,
2374
textwrap.fill(help, initial_indent=' ',
2375
subsequent_indent=' '))
2376
output += wrapped('%s/default' % default_realkey, default_help,
2377
self.get_info('default'))
2378
deprecated_pairs = []
2379
for key, help in help_pairs:
2380
info = self.get_info(key)
2383
elif info.deprecated:
2384
deprecated_pairs.append((key, help))
2386
output += wrapped(key, help, info)
2387
if len(deprecated_pairs) > 0:
2388
output += "Deprecated formats\n------------------\n\n"
2389
for key, help in deprecated_pairs:
2390
info = self.get_info(key)
2391
output += wrapped(key, help, info)
2396
format_registry = BzrDirFormatRegistry()
2397
format_registry.register('weave', BzrDirFormat6,
2398
'Pre-0.8 format. Slower than knit and does not'
2399
' support checkouts or shared repositories.',
2401
format_registry.register_metadir('knit',
2402
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2403
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2404
branch_format='bzrlib.branch.BzrBranchFormat5',
2405
tree_format='bzrlib.workingtree.WorkingTreeFormat3')
2406
format_registry.register_metadir('metaweave',
2407
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2408
'Transitional format in 0.8. Slower than knit.',
2409
branch_format='bzrlib.branch.BzrBranchFormat5',
2410
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2412
format_registry.register_metadir('dirstate',
2413
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2414
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2415
'above when accessed over the network.',
2416
branch_format='bzrlib.branch.BzrBranchFormat5',
2417
# this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
2418
# directly from workingtree_4 triggers a circular import.
2419
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2421
format_registry.register_metadir('dirstate-tags',
2422
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2423
help='New in 0.15: Fast local operations and improved scaling for '
2424
'network operations. Additionally adds support for tags.'
2425
' Incompatible with bzr < 0.15.',
2426
branch_format='bzrlib.branch.BzrBranchFormat6',
2427
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2429
format_registry.register_metadir('dirstate-with-subtree',
2430
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2431
help='New in 0.15: Fast local operations and improved scaling for '
2432
'network operations. Additionally adds support for versioning nested '
2433
'bzr branches. Incompatible with bzr < 0.15.',
2434
branch_format='bzrlib.branch.BzrBranchFormat6',
2435
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2438
format_registry.set_default('dirstate')