1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""BzrDir logic. The BzrDir is the basic control directory used by bzr.
19
At format 7 this was split out into Branch, Repository and Checkout control
22
Note: This module has a lot of ``open`` functions/methods that return
23
references to in-memory objects. As a rule, there are no matching ``close``
24
methods. To free any associated resources, simply stop referencing the
28
# TODO: Move old formats into a plugin to make this file smaller.
33
from bzrlib.lazy_import import lazy_import
34
lazy_import(globals(), """
35
from stat import S_ISDIR
47
revision as _mod_revision,
58
from bzrlib.osutils import (
61
from bzrlib.smart.client import _SmartClient
62
from bzrlib.store.versioned import WeaveStore
63
from bzrlib.transactions import WriteTransaction
64
from bzrlib.transport import (
65
do_catching_redirections,
69
from bzrlib.weave import Weave
72
from bzrlib.trace import (
84
"""A .bzr control diretory.
86
BzrDir instances let you create or open any of the things that can be
87
found within .bzr - checkouts, branches and repositories.
90
the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
92
a transport connected to the directory this bzr was opened from
93
(i.e. the parent directory holding the .bzr directory).
95
Everything in the bzrdir should have the same file permissions.
99
"""Invoke break_lock on the first object in the bzrdir.
101
If there is a tree, the tree is opened and break_lock() called.
102
Otherwise, branch is tried, and finally repository.
104
# XXX: This seems more like a UI function than something that really
105
# belongs in this class.
107
thing_to_unlock = self.open_workingtree()
108
except (errors.NotLocalUrl, errors.NoWorkingTree):
110
thing_to_unlock = self.open_branch()
111
except errors.NotBranchError:
113
thing_to_unlock = self.open_repository()
114
except errors.NoRepositoryPresent:
116
thing_to_unlock.break_lock()
118
def can_convert_format(self):
119
"""Return true if this bzrdir is one whose format we can convert from."""
122
def check_conversion_target(self, target_format):
123
target_repo_format = target_format.repository_format
124
source_repo_format = self._format.repository_format
125
source_repo_format.check_conversion_target(target_repo_format)
128
def _check_supported(format, allow_unsupported,
129
recommend_upgrade=True,
131
"""Give an error or warning on old formats.
133
:param format: may be any kind of format - workingtree, branch,
136
:param allow_unsupported: If true, allow opening
137
formats that are strongly deprecated, and which may
138
have limited functionality.
140
:param recommend_upgrade: If true (default), warn
141
the user through the ui object that they may wish
142
to upgrade the object.
144
# TODO: perhaps move this into a base Format class; it's not BzrDir
145
# specific. mbp 20070323
146
if not allow_unsupported and not format.is_supported():
147
# see open_downlevel to open legacy branches.
148
raise errors.UnsupportedFormatError(format=format)
149
if recommend_upgrade \
150
and getattr(format, 'upgrade_recommended', False):
151
ui.ui_factory.recommend_upgrade(
152
format.get_format_description(),
155
def clone(self, url, revision_id=None, force_new_repo=False,
156
preserve_stacking=False):
157
"""Clone this bzrdir and its contents to url verbatim.
159
:param url: The url create the clone at. If url's last component does
160
not exist, it will be created.
161
:param revision_id: The tip revision-id to use for any branch or
162
working tree. If not None, then the clone operation may tune
163
itself to download less data.
164
:param force_new_repo: Do not use a shared repository for the target
165
even if one is available.
166
:param preserve_stacking: When cloning a stacked branch, stack the
167
new branch on top of the other branch's stacked-on branch.
169
return self.clone_on_transport(get_transport(url),
170
revision_id=revision_id,
171
force_new_repo=force_new_repo,
172
preserve_stacking=preserve_stacking)
174
def clone_on_transport(self, transport, revision_id=None,
175
force_new_repo=False, preserve_stacking=False,
177
"""Clone this bzrdir and its contents to transport verbatim.
179
:param transport: The transport for the location to produce the clone
180
at. If the target directory does not exist, it will be created.
181
:param revision_id: The tip revision-id to use for any branch or
182
working tree. If not None, then the clone operation may tune
183
itself to download less data.
184
:param force_new_repo: Do not use a shared repository for the target,
185
even if one is available.
186
:param preserve_stacking: When cloning a stacked branch, stack the
187
new branch on top of the other branch's stacked-on branch.
189
transport.ensure_base()
190
require_stacking = (stacked_on is not None)
191
metadir = self.cloning_metadir(require_stacking)
192
result = metadir.initialize_on_transport(transport)
193
repository_policy = None
195
local_repo = self.find_repository()
196
except errors.NoRepositoryPresent:
199
local_branch = self.open_branch()
200
except errors.NotBranchError:
203
# enable fallbacks when branch is not a branch reference
204
if local_branch.repository.has_same_location(local_repo):
205
local_repo = local_branch.repository
206
if preserve_stacking:
208
stacked_on = local_branch.get_stacked_on_url()
209
except (errors.UnstackableBranchFormat,
210
errors.UnstackableRepositoryFormat,
215
# may need to copy content in
216
repository_policy = result.determine_repository_policy(
217
force_new_repo, stacked_on, self.root_transport.base,
218
require_stacking=require_stacking)
219
make_working_trees = local_repo.make_working_trees()
220
result_repo = repository_policy.acquire_repository(
221
make_working_trees, local_repo.is_shared())
222
result_repo.fetch(local_repo, revision_id=revision_id)
225
# 1 if there is a branch present
226
# make sure its content is available in the target repository
228
if local_branch is not None:
229
result_branch = local_branch.clone(result, revision_id=revision_id)
230
if repository_policy is not None:
231
repository_policy.configure_branch(result_branch)
232
if result_repo is None or result_repo.make_working_trees():
234
self.open_workingtree().clone(result)
235
except (errors.NoWorkingTree, errors.NotLocalUrl):
239
# TODO: This should be given a Transport, and should chdir up; otherwise
240
# this will open a new connection.
241
def _make_tail(self, url):
242
t = get_transport(url)
246
def create(cls, base, format=None, possible_transports=None):
247
"""Create a new BzrDir at the url 'base'.
249
:param format: If supplied, the format of branch to create. If not
250
supplied, the default is used.
251
:param possible_transports: If supplied, a list of transports that
252
can be reused to share a remote connection.
254
if cls is not BzrDir:
255
raise AssertionError("BzrDir.create always creates the default"
256
" format, not one of %r" % cls)
257
t = get_transport(base, possible_transports)
260
format = BzrDirFormat.get_default_format()
261
return format.initialize_on_transport(t)
264
def find_bzrdirs(transport, evaluate=None, list_current=None):
265
"""Find bzrdirs recursively from current location.
267
This is intended primarily as a building block for more sophisticated
268
functionality, like finding trees under a directory, or finding
269
branches that use a given repository.
270
:param evaluate: An optional callable that yields recurse, value,
271
where recurse controls whether this bzrdir is recursed into
272
and value is the value to yield. By default, all bzrdirs
273
are recursed into, and the return value is the bzrdir.
274
:param list_current: if supplied, use this function to list the current
275
directory, instead of Transport.list_dir
276
:return: a generator of found bzrdirs, or whatever evaluate returns.
278
if list_current is None:
279
def list_current(transport):
280
return transport.list_dir('')
282
def evaluate(bzrdir):
285
pending = [transport]
286
while len(pending) > 0:
287
current_transport = pending.pop()
290
bzrdir = BzrDir.open_from_transport(current_transport)
291
except errors.NotBranchError:
294
recurse, value = evaluate(bzrdir)
297
subdirs = list_current(current_transport)
298
except errors.NoSuchFile:
301
for subdir in sorted(subdirs, reverse=True):
302
pending.append(current_transport.clone(subdir))
305
def find_branches(transport):
306
"""Find all branches under a transport.
308
This will find all branches below the transport, including branches
309
inside other branches. Where possible, it will use
310
Repository.find_branches.
312
To list all the branches that use a particular Repository, see
313
Repository.find_branches
315
def evaluate(bzrdir):
317
repository = bzrdir.open_repository()
318
except errors.NoRepositoryPresent:
321
return False, (None, repository)
323
branch = bzrdir.open_branch()
324
except errors.NotBranchError:
325
return True, (None, None)
327
return True, (branch, None)
329
for branch, repo in BzrDir.find_bzrdirs(transport, evaluate=evaluate):
331
branches.extend(repo.find_branches())
332
if branch is not None:
333
branches.append(branch)
336
def destroy_repository(self):
337
"""Destroy the repository in this BzrDir"""
338
raise NotImplementedError(self.destroy_repository)
340
def create_branch(self):
341
"""Create a branch in this BzrDir.
343
The bzrdir's format will control what branch format is created.
344
For more control see BranchFormatXX.create(a_bzrdir).
346
raise NotImplementedError(self.create_branch)
348
def destroy_branch(self):
349
"""Destroy the branch in this BzrDir"""
350
raise NotImplementedError(self.destroy_branch)
353
def create_branch_and_repo(base, force_new_repo=False, format=None):
354
"""Create a new BzrDir, Branch and Repository at the url 'base'.
356
This will use the current default BzrDirFormat unless one is
357
specified, and use whatever
358
repository format that that uses via bzrdir.create_branch and
359
create_repository. If a shared repository is available that is used
362
The created Branch object is returned.
364
:param base: The URL to create the branch at.
365
:param force_new_repo: If True a new repository is always created.
366
:param format: If supplied, the format of branch to create. If not
367
supplied, the default is used.
369
bzrdir = BzrDir.create(base, format)
370
bzrdir._find_or_create_repository(force_new_repo)
371
return bzrdir.create_branch()
373
def determine_repository_policy(self, force_new_repo=False, stack_on=None,
374
stack_on_pwd=None, require_stacking=False):
375
"""Return an object representing a policy to use.
377
This controls whether a new repository is created, or a shared
378
repository used instead.
380
If stack_on is supplied, will not seek a containing shared repo.
382
:param force_new_repo: If True, require a new repository to be created.
383
:param stack_on: If supplied, the location to stack on. If not
384
supplied, a default_stack_on location may be used.
385
:param stack_on_pwd: If stack_on is relative, the location it is
388
def repository_policy(found_bzrdir):
391
config = found_bzrdir.get_config()
393
if config is not None:
394
stack_on = config.get_default_stack_on()
395
if stack_on is not None:
396
stack_on_pwd = found_bzrdir.root_transport.base
398
note('Using default stacking branch %s at %s', stack_on,
400
# does it have a repository ?
402
repository = found_bzrdir.open_repository()
403
except errors.NoRepositoryPresent:
406
if ((found_bzrdir.root_transport.base !=
407
self.root_transport.base) and not repository.is_shared()):
414
return UseExistingRepository(repository, stack_on,
415
stack_on_pwd, require_stacking=require_stacking), True
417
return CreateRepository(self, stack_on, stack_on_pwd,
418
require_stacking=require_stacking), True
420
if not force_new_repo:
422
policy = self._find_containing(repository_policy)
423
if policy is not None:
427
return UseExistingRepository(self.open_repository(),
428
stack_on, stack_on_pwd,
429
require_stacking=require_stacking)
430
except errors.NoRepositoryPresent:
432
return CreateRepository(self, stack_on, stack_on_pwd,
433
require_stacking=require_stacking)
435
def _find_or_create_repository(self, force_new_repo):
436
"""Create a new repository if needed, returning the repository."""
437
policy = self.determine_repository_policy(force_new_repo)
438
return policy.acquire_repository()
441
def create_branch_convenience(base, force_new_repo=False,
442
force_new_tree=None, format=None,
443
possible_transports=None):
444
"""Create a new BzrDir, Branch and Repository at the url 'base'.
446
This is a convenience function - it will use an existing repository
447
if possible, can be told explicitly whether to create a working tree or
450
This will use the current default BzrDirFormat unless one is
451
specified, and use whatever
452
repository format that that uses via bzrdir.create_branch and
453
create_repository. If a shared repository is available that is used
454
preferentially. Whatever repository is used, its tree creation policy
457
The created Branch object is returned.
458
If a working tree cannot be made due to base not being a file:// url,
459
no error is raised unless force_new_tree is True, in which case no
460
data is created on disk and NotLocalUrl is raised.
462
:param base: The URL to create the branch at.
463
:param force_new_repo: If True a new repository is always created.
464
:param force_new_tree: If True or False force creation of a tree or
465
prevent such creation respectively.
466
:param format: Override for the bzrdir format to create.
467
:param possible_transports: An optional reusable transports list.
470
# check for non local urls
471
t = get_transport(base, possible_transports)
472
if not isinstance(t, local.LocalTransport):
473
raise errors.NotLocalUrl(base)
474
bzrdir = BzrDir.create(base, format, possible_transports)
475
repo = bzrdir._find_or_create_repository(force_new_repo)
476
result = bzrdir.create_branch()
477
if force_new_tree or (repo.make_working_trees() and
478
force_new_tree is None):
480
bzrdir.create_workingtree()
481
except errors.NotLocalUrl:
486
def create_standalone_workingtree(base, format=None):
487
"""Create a new BzrDir, WorkingTree, Branch and Repository at 'base'.
489
'base' must be a local path or a file:// url.
491
This will use the current default BzrDirFormat unless one is
492
specified, and use whatever
493
repository format that that uses for bzrdirformat.create_workingtree,
494
create_branch and create_repository.
496
:param format: Override for the bzrdir format to create.
497
:return: The WorkingTree object.
499
t = get_transport(base)
500
if not isinstance(t, local.LocalTransport):
501
raise errors.NotLocalUrl(base)
502
bzrdir = BzrDir.create_branch_and_repo(base,
504
format=format).bzrdir
505
return bzrdir.create_workingtree()
507
def create_workingtree(self, revision_id=None, from_branch=None,
508
accelerator_tree=None, hardlink=False):
509
"""Create a working tree at this BzrDir.
511
:param revision_id: create it as of this revision id.
512
:param from_branch: override bzrdir branch (for lightweight checkouts)
513
:param accelerator_tree: A tree which can be used for retrieving file
514
contents more quickly than the revision tree, i.e. a workingtree.
515
The revision tree will be used for cases where accelerator_tree's
516
content is different.
518
raise NotImplementedError(self.create_workingtree)
520
def backup_bzrdir(self):
521
"""Backup this bzr control directory.
523
:return: Tuple with old path name and new path name
525
self.root_transport.copy_tree('.bzr', 'backup.bzr')
526
return (self.root_transport.abspath('.bzr'),
527
self.root_transport.abspath('backup.bzr'))
529
def retire_bzrdir(self, limit=10000):
530
"""Permanently disable the bzrdir.
532
This is done by renaming it to give the user some ability to recover
533
if there was a problem.
535
This will have horrible consequences if anyone has anything locked or
537
:param limit: number of times to retry
542
to_path = '.bzr.retired.%d' % i
543
self.root_transport.rename('.bzr', to_path)
544
note("renamed %s to %s"
545
% (self.root_transport.abspath('.bzr'), to_path))
547
except (errors.TransportError, IOError, errors.PathError):
554
def destroy_workingtree(self):
555
"""Destroy the working tree at this BzrDir.
557
Formats that do not support this may raise UnsupportedOperation.
559
raise NotImplementedError(self.destroy_workingtree)
561
def destroy_workingtree_metadata(self):
562
"""Destroy the control files for the working tree at this BzrDir.
564
The contents of working tree files are not affected.
565
Formats that do not support this may raise UnsupportedOperation.
567
raise NotImplementedError(self.destroy_workingtree_metadata)
569
def _find_containing(self, evaluate):
570
"""Find something in a containing control directory.
572
This method will scan containing control dirs, until it finds what
573
it is looking for, decides that it will never find it, or runs out
574
of containing control directories to check.
576
It is used to implement find_repository and
577
determine_repository_policy.
579
:param evaluate: A function returning (value, stop). If stop is True,
580
the value will be returned.
584
result, stop = evaluate(found_bzrdir)
587
next_transport = found_bzrdir.root_transport.clone('..')
588
if (found_bzrdir.root_transport.base == next_transport.base):
589
# top of the file system
591
# find the next containing bzrdir
593
found_bzrdir = BzrDir.open_containing_from_transport(
595
except errors.NotBranchError:
598
def find_repository(self):
599
"""Find the repository that should be used.
601
This does not require a branch as we use it to find the repo for
602
new branches as well as to hook existing branches up to their
605
def usable_repository(found_bzrdir):
606
# does it have a repository ?
608
repository = found_bzrdir.open_repository()
609
except errors.NoRepositoryPresent:
611
if found_bzrdir.root_transport.base == self.root_transport.base:
612
return repository, True
613
elif repository.is_shared():
614
return repository, True
618
found_repo = self._find_containing(usable_repository)
619
if found_repo is None:
620
raise errors.NoRepositoryPresent(self)
623
def get_branch_reference(self):
624
"""Return the referenced URL for the branch in this bzrdir.
626
:raises NotBranchError: If there is no Branch.
627
:return: The URL the branch in this bzrdir references if it is a
628
reference branch, or None for regular branches.
632
def get_branch_transport(self, branch_format):
633
"""Get the transport for use by branch format in this BzrDir.
635
Note that bzr dirs that do not support format strings will raise
636
IncompatibleFormat if the branch format they are given has
637
a format string, and vice versa.
639
If branch_format is None, the transport is returned with no
640
checking. If it is not None, then the returned transport is
641
guaranteed to point to an existing directory ready for use.
643
raise NotImplementedError(self.get_branch_transport)
645
def _find_creation_modes(self):
646
"""Determine the appropriate modes for files and directories.
648
They're always set to be consistent with the base directory,
649
assuming that this transport allows setting modes.
651
# TODO: Do we need or want an option (maybe a config setting) to turn
652
# this off or override it for particular locations? -- mbp 20080512
653
if self._mode_check_done:
655
self._mode_check_done = True
657
st = self.transport.stat('.')
658
except errors.TransportNotPossible:
659
self._dir_mode = None
660
self._file_mode = None
662
# Check the directory mode, but also make sure the created
663
# directories and files are read-write for this user. This is
664
# mostly a workaround for filesystems which lie about being able to
665
# write to a directory (cygwin & win32)
666
if (st.st_mode & 07777 == 00000):
667
# FTP allows stat but does not return dir/file modes
668
self._dir_mode = None
669
self._file_mode = None
671
self._dir_mode = (st.st_mode & 07777) | 00700
672
# Remove the sticky and execute bits for files
673
self._file_mode = self._dir_mode & ~07111
675
def _get_file_mode(self):
676
"""Return Unix mode for newly created files, or None.
678
if not self._mode_check_done:
679
self._find_creation_modes()
680
return self._file_mode
682
def _get_dir_mode(self):
683
"""Return Unix mode for newly created directories, or None.
685
if not self._mode_check_done:
686
self._find_creation_modes()
687
return self._dir_mode
689
def get_repository_transport(self, repository_format):
690
"""Get the transport for use by repository format in this BzrDir.
692
Note that bzr dirs that do not support format strings will raise
693
IncompatibleFormat if the repository format they are given has
694
a format string, and vice versa.
696
If repository_format is None, the transport is returned with no
697
checking. If it is not None, then the returned transport is
698
guaranteed to point to an existing directory ready for use.
700
raise NotImplementedError(self.get_repository_transport)
702
def get_workingtree_transport(self, tree_format):
703
"""Get the transport for use by workingtree format in this BzrDir.
705
Note that bzr dirs that do not support format strings will raise
706
IncompatibleFormat if the workingtree format they are given has a
707
format string, and vice versa.
709
If workingtree_format is None, the transport is returned with no
710
checking. If it is not None, then the returned transport is
711
guaranteed to point to an existing directory ready for use.
713
raise NotImplementedError(self.get_workingtree_transport)
715
def get_config(self):
716
if getattr(self, '_get_config', None) is None:
718
return self._get_config()
720
def __init__(self, _transport, _format):
721
"""Initialize a Bzr control dir object.
723
Only really common logic should reside here, concrete classes should be
724
made with varying behaviours.
726
:param _format: the format that is creating this BzrDir instance.
727
:param _transport: the transport this dir is based at.
729
self._format = _format
730
self.transport = _transport.clone('.bzr')
731
self.root_transport = _transport
732
self._mode_check_done = False
734
def is_control_filename(self, filename):
735
"""True if filename is the name of a path which is reserved for bzrdir's.
737
:param filename: A filename within the root transport of this bzrdir.
739
This is true IF and ONLY IF the filename is part of the namespace reserved
740
for bzr control dirs. Currently this is the '.bzr' directory in the root
741
of the root_transport. it is expected that plugins will need to extend
742
this in the future - for instance to make bzr talk with svn working
745
# this might be better on the BzrDirFormat class because it refers to
746
# all the possible bzrdir disk formats.
747
# This method is tested via the workingtree is_control_filename tests-
748
# it was extracted from WorkingTree.is_control_filename. If the method's
749
# contract is extended beyond the current trivial implementation, please
750
# add new tests for it to the appropriate place.
751
return filename == '.bzr' or filename.startswith('.bzr/')
753
def needs_format_conversion(self, format=None):
754
"""Return true if this bzrdir needs convert_format run on it.
756
For instance, if the repository format is out of date but the
757
branch and working tree are not, this should return True.
759
:param format: Optional parameter indicating a specific desired
760
format we plan to arrive at.
762
raise NotImplementedError(self.needs_format_conversion)
765
def open_unsupported(base):
766
"""Open a branch which is not supported."""
767
return BzrDir.open(base, _unsupported=True)
770
def open(base, _unsupported=False, possible_transports=None):
771
"""Open an existing bzrdir, rooted at 'base' (url).
773
:param _unsupported: a private parameter to the BzrDir class.
775
t = get_transport(base, possible_transports=possible_transports)
776
return BzrDir.open_from_transport(t, _unsupported=_unsupported)
779
def open_from_transport(transport, _unsupported=False,
780
_server_formats=True):
781
"""Open a bzrdir within a particular directory.
783
:param transport: Transport containing the bzrdir.
784
:param _unsupported: private.
786
# Keep initial base since 'transport' may be modified while following
788
base = transport.base
789
def find_format(transport):
790
return transport, BzrDirFormat.find_format(
791
transport, _server_formats=_server_formats)
793
def redirected(transport, e, redirection_notice):
794
redirected_transport = transport._redirected_to(e.source, e.target)
795
if redirected_transport is None:
796
raise errors.NotBranchError(base)
797
note('%s is%s redirected to %s',
798
transport.base, e.permanently, redirected_transport.base)
799
return redirected_transport
802
transport, format = do_catching_redirections(find_format,
805
except errors.TooManyRedirections:
806
raise errors.NotBranchError(base)
808
BzrDir._check_supported(format, _unsupported)
809
return format.open(transport, _found=True)
811
def open_branch(self, unsupported=False):
812
"""Open the branch object at this BzrDir if one is present.
814
If unsupported is True, then no longer supported branch formats can
817
TODO: static convenience version of this?
819
raise NotImplementedError(self.open_branch)
822
def open_containing(url, possible_transports=None):
823
"""Open an existing branch which contains url.
825
:param url: url to search from.
826
See open_containing_from_transport for more detail.
828
transport = get_transport(url, possible_transports)
829
return BzrDir.open_containing_from_transport(transport)
832
def open_containing_from_transport(a_transport):
833
"""Open an existing branch which contains a_transport.base.
835
This probes for a branch at a_transport, and searches upwards from there.
837
Basically we keep looking up until we find the control directory or
838
run into the root. If there isn't one, raises NotBranchError.
839
If there is one and it is either an unrecognised format or an unsupported
840
format, UnknownFormatError or UnsupportedFormatError are raised.
841
If there is one, it is returned, along with the unused portion of url.
843
:return: The BzrDir that contains the path, and a Unicode path
844
for the rest of the URL.
846
# this gets the normalised url back. I.e. '.' -> the full path.
847
url = a_transport.base
850
result = BzrDir.open_from_transport(a_transport)
851
return result, urlutils.unescape(a_transport.relpath(url))
852
except errors.NotBranchError, e:
855
new_t = a_transport.clone('..')
856
except errors.InvalidURLJoin:
857
# reached the root, whatever that may be
858
raise errors.NotBranchError(path=url)
859
if new_t.base == a_transport.base:
860
# reached the root, whatever that may be
861
raise errors.NotBranchError(path=url)
864
def _get_tree_branch(self):
865
"""Return the branch and tree, if any, for this bzrdir.
867
Return None for tree if not present or inaccessible.
868
Raise NotBranchError if no branch is present.
869
:return: (tree, branch)
872
tree = self.open_workingtree()
873
except (errors.NoWorkingTree, errors.NotLocalUrl):
875
branch = self.open_branch()
881
def open_tree_or_branch(klass, location):
882
"""Return the branch and working tree at a location.
884
If there is no tree at the location, tree will be None.
885
If there is no branch at the location, an exception will be
887
:return: (tree, branch)
889
bzrdir = klass.open(location)
890
return bzrdir._get_tree_branch()
893
def open_containing_tree_or_branch(klass, location):
894
"""Return the branch and working tree contained by a location.
896
Returns (tree, branch, relpath).
897
If there is no tree at containing the location, tree will be None.
898
If there is no branch containing the location, an exception will be
900
relpath is the portion of the path that is contained by the branch.
902
bzrdir, relpath = klass.open_containing(location)
903
tree, branch = bzrdir._get_tree_branch()
904
return tree, branch, relpath
907
def open_containing_tree_branch_or_repository(klass, location):
908
"""Return the working tree, branch and repo contained by a location.
910
Returns (tree, branch, repository, relpath).
911
If there is no tree containing the location, tree will be None.
912
If there is no branch containing the location, branch will be None.
913
If there is no repository containing the location, repository will be
915
relpath is the portion of the path that is contained by the innermost
918
If no tree, branch or repository is found, a NotBranchError is raised.
920
bzrdir, relpath = klass.open_containing(location)
922
tree, branch = bzrdir._get_tree_branch()
923
except errors.NotBranchError:
925
repo = bzrdir.find_repository()
926
return None, None, repo, relpath
927
except (errors.NoRepositoryPresent):
928
raise errors.NotBranchError(location)
929
return tree, branch, branch.repository, relpath
931
def open_repository(self, _unsupported=False):
932
"""Open the repository object at this BzrDir if one is present.
934
This will not follow the Branch object pointer - it's strictly a direct
935
open facility. Most client code should use open_branch().repository to
938
:param _unsupported: a private parameter, not part of the api.
939
TODO: static convenience version of this?
941
raise NotImplementedError(self.open_repository)
943
def open_workingtree(self, _unsupported=False,
944
recommend_upgrade=True, from_branch=None):
945
"""Open the workingtree object at this BzrDir if one is present.
947
:param recommend_upgrade: Optional keyword parameter, when True (the
948
default), emit through the ui module a recommendation that the user
949
upgrade the working tree when the workingtree being opened is old
950
(but still fully supported).
951
:param from_branch: override bzrdir branch (for lightweight checkouts)
953
raise NotImplementedError(self.open_workingtree)
955
def has_branch(self):
956
"""Tell if this bzrdir contains a branch.
958
Note: if you're going to open the branch, you should just go ahead
959
and try, and not ask permission first. (This method just opens the
960
branch and discards it, and that's somewhat expensive.)
965
except errors.NotBranchError:
968
def has_workingtree(self):
969
"""Tell if this bzrdir contains a working tree.
971
This will still raise an exception if the bzrdir has a workingtree that
972
is remote & inaccessible.
974
Note: if you're going to open the working tree, you should just go ahead
975
and try, and not ask permission first. (This method just opens the
976
workingtree and discards it, and that's somewhat expensive.)
979
self.open_workingtree(recommend_upgrade=False)
981
except errors.NoWorkingTree:
984
def _cloning_metadir(self):
985
"""Produce a metadir suitable for cloning with.
987
:returns: (destination_bzrdir_format, source_repository)
989
result_format = self._format.__class__()
992
branch = self.open_branch()
993
source_repository = branch.repository
994
result_format._branch_format = branch._format
995
except errors.NotBranchError:
997
source_repository = self.open_repository()
998
except errors.NoRepositoryPresent:
999
source_repository = None
1001
# XXX TODO: This isinstance is here because we have not implemented
1002
# the fix recommended in bug # 103195 - to delegate this choice the
1003
# repository itself.
1004
repo_format = source_repository._format
1005
if isinstance(repo_format, remote.RemoteRepositoryFormat):
1006
source_repository._ensure_real()
1007
repo_format = source_repository._real_repository._format
1008
result_format.repository_format = repo_format
1010
# TODO: Couldn't we just probe for the format in these cases,
1011
# rather than opening the whole tree? It would be a little
1012
# faster. mbp 20070401
1013
tree = self.open_workingtree(recommend_upgrade=False)
1014
except (errors.NoWorkingTree, errors.NotLocalUrl):
1015
result_format.workingtree_format = None
1017
result_format.workingtree_format = tree._format.__class__()
1018
return result_format, source_repository
1020
def cloning_metadir(self, require_stacking=False):
1021
"""Produce a metadir suitable for cloning or sprouting with.
1023
These operations may produce workingtrees (yes, even though they're
1024
"cloning" something that doesn't have a tree), so a viable workingtree
1025
format must be selected.
1027
:require_stacking: If True, non-stackable formats will be upgraded
1028
to similar stackable formats.
1029
:returns: a BzrDirFormat with all component formats either set
1030
appropriately or set to None if that component should not be
1033
format, repository = self._cloning_metadir()
1034
if format._workingtree_format is None:
1035
if repository is None:
1037
tree_format = repository._format._matchingbzrdir.workingtree_format
1038
format.workingtree_format = tree_format.__class__()
1039
if (require_stacking and not
1040
format.get_branch_format().supports_stacking()):
1041
# We need to make a stacked branch, but the default format for the
1042
# target doesn't support stacking. So force a branch that *can*
1044
from bzrlib.branch import BzrBranchFormat7
1045
format._branch_format = BzrBranchFormat7()
1046
mutter("using %r for stacking" % (format._branch_format,))
1047
from bzrlib.repofmt import pack_repo
1048
if format.repository_format.rich_root_data:
1049
bzrdir_format_name = '1.6.1-rich-root'
1050
repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
1052
bzrdir_format_name = '1.6'
1053
repo_format = pack_repo.RepositoryFormatKnitPack5()
1054
note('Source format does not support stacking, using format:'
1056
bzrdir_format_name, repo_format.get_format_description())
1057
format.repository_format = repo_format
1060
def checkout_metadir(self):
1061
return self.cloning_metadir()
1063
def sprout(self, url, revision_id=None, force_new_repo=False,
1064
recurse='down', possible_transports=None,
1065
accelerator_tree=None, hardlink=False, stacked=False,
1066
source_branch=None):
1067
"""Create a copy of this bzrdir prepared for use as a new line of
1070
If url's last component does not exist, it will be created.
1072
Attributes related to the identity of the source branch like
1073
branch nickname will be cleaned, a working tree is created
1074
whether one existed before or not; and a local branch is always
1077
if revision_id is not None, then the clone operation may tune
1078
itself to download less data.
1079
:param accelerator_tree: A tree which can be used for retrieving file
1080
contents more quickly than the revision tree, i.e. a workingtree.
1081
The revision tree will be used for cases where accelerator_tree's
1082
content is different.
1083
:param hardlink: If true, hard-link files from accelerator_tree,
1085
:param stacked: If true, create a stacked branch referring to the
1086
location of this control directory.
1088
target_transport = get_transport(url, possible_transports)
1089
target_transport.ensure_base()
1090
cloning_format = self.cloning_metadir(stacked)
1091
# Create/update the result branch
1092
result = cloning_format.initialize_on_transport(target_transport)
1093
# if a stacked branch wasn't requested, we don't create one
1094
# even if the origin was stacked
1095
stacked_branch_url = None
1096
if source_branch is not None:
1098
stacked_branch_url = self.root_transport.base
1099
source_repository = source_branch.repository
1102
source_branch = self.open_branch()
1103
source_repository = source_branch.repository
1105
stacked_branch_url = self.root_transport.base
1106
except errors.NotBranchError:
1107
source_branch = None
1109
source_repository = self.open_repository()
1110
except errors.NoRepositoryPresent:
1111
source_repository = None
1112
repository_policy = result.determine_repository_policy(
1113
force_new_repo, stacked_branch_url, require_stacking=stacked)
1114
result_repo = repository_policy.acquire_repository()
1115
if source_repository is not None:
1116
# Fetch while stacked to prevent unstacked fetch from
1118
result_repo.fetch(source_repository, revision_id=revision_id)
1120
if source_branch is None:
1121
# this is for sprouting a bzrdir without a branch; is that
1123
# Not especially, but it's part of the contract.
1124
result_branch = result.create_branch()
1126
# Force NULL revision to avoid using repository before stacking
1128
result_branch = source_branch.sprout(
1129
result, revision_id=_mod_revision.NULL_REVISION)
1130
parent_location = result_branch.get_parent()
1131
mutter("created new branch %r" % (result_branch,))
1132
repository_policy.configure_branch(result_branch)
1133
if source_branch is not None:
1134
source_branch.copy_content_into(result_branch, revision_id)
1135
# Override copy_content_into
1136
result_branch.set_parent(parent_location)
1138
# Create/update the result working tree
1139
if isinstance(target_transport, local.LocalTransport) and (
1140
result_repo is None or result_repo.make_working_trees()):
1141
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1145
if wt.path2id('') is None:
1147
wt.set_root_id(self.open_workingtree.get_root_id())
1148
except errors.NoWorkingTree:
1154
if recurse == 'down':
1156
basis = wt.basis_tree()
1158
subtrees = basis.iter_references()
1159
elif result_branch is not None:
1160
basis = result_branch.basis_tree()
1162
subtrees = basis.iter_references()
1163
elif source_branch is not None:
1164
basis = source_branch.basis_tree()
1166
subtrees = basis.iter_references()
1171
for path, file_id in subtrees:
1172
target = urlutils.join(url, urlutils.escape(path))
1173
sublocation = source_branch.reference_parent(file_id, path)
1174
sublocation.bzrdir.sprout(target,
1175
basis.get_reference_revision(file_id, path),
1176
force_new_repo=force_new_repo, recurse=recurse,
1179
if basis is not None:
1184
class BzrDirPreSplitOut(BzrDir):
1185
"""A common class for the all-in-one formats."""
1187
def __init__(self, _transport, _format):
1188
"""See BzrDir.__init__."""
1189
super(BzrDirPreSplitOut, self).__init__(_transport, _format)
1190
self._control_files = lockable_files.LockableFiles(
1191
self.get_branch_transport(None),
1192
self._format._lock_file_name,
1193
self._format._lock_class)
1195
def break_lock(self):
1196
"""Pre-splitout bzrdirs do not suffer from stale locks."""
1197
raise NotImplementedError(self.break_lock)
1199
def cloning_metadir(self, require_stacking=False):
1200
"""Produce a metadir suitable for cloning with."""
1201
if require_stacking:
1202
return format_registry.make_bzrdir('1.6')
1203
return self._format.__class__()
1205
def clone(self, url, revision_id=None, force_new_repo=False,
1206
preserve_stacking=False):
1207
"""See BzrDir.clone().
1209
force_new_repo has no effect, since this family of formats always
1210
require a new repository.
1211
preserve_stacking has no effect, since no source branch using this
1212
family of formats can be stacked, so there is no stacking to preserve.
1214
self._make_tail(url)
1215
result = self._format._initialize_for_clone(url)
1216
self.open_repository().clone(result, revision_id=revision_id)
1217
from_branch = self.open_branch()
1218
from_branch.clone(result, revision_id=revision_id)
1220
tree = self.open_workingtree()
1221
except errors.NotLocalUrl:
1222
# make a new one, this format always has to have one.
1223
result._init_workingtree()
1228
def create_branch(self):
1229
"""See BzrDir.create_branch."""
1230
return self._format.get_branch_format().initialize(self)
1232
def destroy_branch(self):
1233
"""See BzrDir.destroy_branch."""
1234
raise errors.UnsupportedOperation(self.destroy_branch, self)
1236
def create_repository(self, shared=False):
1237
"""See BzrDir.create_repository."""
1239
raise errors.IncompatibleFormat('shared repository', self._format)
1240
return self.open_repository()
1242
def destroy_repository(self):
1243
"""See BzrDir.destroy_repository."""
1244
raise errors.UnsupportedOperation(self.destroy_repository, self)
1246
def create_workingtree(self, revision_id=None, from_branch=None,
1247
accelerator_tree=None, hardlink=False):
1248
"""See BzrDir.create_workingtree."""
1249
# The workingtree is sometimes created when the bzrdir is created,
1250
# but not when cloning.
1252
# this looks buggy but is not -really-
1253
# because this format creates the workingtree when the bzrdir is
1255
# clone and sprout will have set the revision_id
1256
# and that will have set it for us, its only
1257
# specific uses of create_workingtree in isolation
1258
# that can do wonky stuff here, and that only
1259
# happens for creating checkouts, which cannot be
1260
# done on this format anyway. So - acceptable wart.
1262
result = self.open_workingtree(recommend_upgrade=False)
1263
except errors.NoSuchFile:
1264
result = self._init_workingtree()
1265
if revision_id is not None:
1266
if revision_id == _mod_revision.NULL_REVISION:
1267
result.set_parent_ids([])
1269
result.set_parent_ids([revision_id])
1272
def _init_workingtree(self):
1273
from bzrlib.workingtree import WorkingTreeFormat2
1275
return WorkingTreeFormat2().initialize(self)
1276
except errors.NotLocalUrl:
1277
# Even though we can't access the working tree, we need to
1278
# create its control files.
1279
return WorkingTreeFormat2()._stub_initialize_on_transport(
1280
self.transport, self._control_files._file_mode)
1282
def destroy_workingtree(self):
1283
"""See BzrDir.destroy_workingtree."""
1284
raise errors.UnsupportedOperation(self.destroy_workingtree, self)
1286
def destroy_workingtree_metadata(self):
1287
"""See BzrDir.destroy_workingtree_metadata."""
1288
raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
1291
def get_branch_transport(self, branch_format):
1292
"""See BzrDir.get_branch_transport()."""
1293
if branch_format is None:
1294
return self.transport
1296
branch_format.get_format_string()
1297
except NotImplementedError:
1298
return self.transport
1299
raise errors.IncompatibleFormat(branch_format, self._format)
1301
def get_repository_transport(self, repository_format):
1302
"""See BzrDir.get_repository_transport()."""
1303
if repository_format is None:
1304
return self.transport
1306
repository_format.get_format_string()
1307
except NotImplementedError:
1308
return self.transport
1309
raise errors.IncompatibleFormat(repository_format, self._format)
1311
def get_workingtree_transport(self, workingtree_format):
1312
"""See BzrDir.get_workingtree_transport()."""
1313
if workingtree_format is None:
1314
return self.transport
1316
workingtree_format.get_format_string()
1317
except NotImplementedError:
1318
return self.transport
1319
raise errors.IncompatibleFormat(workingtree_format, self._format)
1321
def needs_format_conversion(self, format=None):
1322
"""See BzrDir.needs_format_conversion()."""
1323
# if the format is not the same as the system default,
1324
# an upgrade is needed.
1326
format = BzrDirFormat.get_default_format()
1327
return not isinstance(self._format, format.__class__)
1329
def open_branch(self, unsupported=False):
1330
"""See BzrDir.open_branch."""
1331
from bzrlib.branch import BzrBranchFormat4
1332
format = BzrBranchFormat4()
1333
self._check_supported(format, unsupported)
1334
return format.open(self, _found=True)
1336
def sprout(self, url, revision_id=None, force_new_repo=False,
1337
possible_transports=None, accelerator_tree=None,
1338
hardlink=False, stacked=False):
1339
"""See BzrDir.sprout()."""
1341
raise errors.UnstackableBranchFormat(
1342
self._format, self.root_transport.base)
1343
from bzrlib.workingtree import WorkingTreeFormat2
1344
self._make_tail(url)
1345
result = self._format._initialize_for_clone(url)
1347
self.open_repository().clone(result, revision_id=revision_id)
1348
except errors.NoRepositoryPresent:
1351
self.open_branch().sprout(result, revision_id=revision_id)
1352
except errors.NotBranchError:
1354
# we always want a working tree
1355
WorkingTreeFormat2().initialize(result,
1356
accelerator_tree=accelerator_tree,
1361
class BzrDir4(BzrDirPreSplitOut):
1362
"""A .bzr version 4 control object.
1364
This is a deprecated format and may be removed after sept 2006.
1367
def create_repository(self, shared=False):
1368
"""See BzrDir.create_repository."""
1369
return self._format.repository_format.initialize(self, shared)
1371
def needs_format_conversion(self, format=None):
1372
"""Format 4 dirs are always in need of conversion."""
1375
def open_repository(self):
1376
"""See BzrDir.open_repository."""
1377
from bzrlib.repofmt.weaverepo import RepositoryFormat4
1378
return RepositoryFormat4().open(self, _found=True)
1381
class BzrDir5(BzrDirPreSplitOut):
1382
"""A .bzr version 5 control object.
1384
This is a deprecated format and may be removed after sept 2006.
1387
def open_repository(self):
1388
"""See BzrDir.open_repository."""
1389
from bzrlib.repofmt.weaverepo import RepositoryFormat5
1390
return RepositoryFormat5().open(self, _found=True)
1392
def open_workingtree(self, _unsupported=False,
1393
recommend_upgrade=True):
1394
"""See BzrDir.create_workingtree."""
1395
from bzrlib.workingtree import WorkingTreeFormat2
1396
wt_format = WorkingTreeFormat2()
1397
# we don't warn here about upgrades; that ought to be handled for the
1399
return wt_format.open(self, _found=True)
1402
class BzrDir6(BzrDirPreSplitOut):
1403
"""A .bzr version 6 control object.
1405
This is a deprecated format and may be removed after sept 2006.
1408
def open_repository(self):
1409
"""See BzrDir.open_repository."""
1410
from bzrlib.repofmt.weaverepo import RepositoryFormat6
1411
return RepositoryFormat6().open(self, _found=True)
1413
def open_workingtree(self, _unsupported=False,
1414
recommend_upgrade=True):
1415
"""See BzrDir.create_workingtree."""
1416
# we don't warn here about upgrades; that ought to be handled for the
1418
from bzrlib.workingtree import WorkingTreeFormat2
1419
return WorkingTreeFormat2().open(self, _found=True)
1422
class BzrDirMeta1(BzrDir):
1423
"""A .bzr meta version 1 control object.
1425
This is the first control object where the
1426
individual aspects are really split out: there are separate repository,
1427
workingtree and branch subdirectories and any subset of the three can be
1428
present within a BzrDir.
1431
def can_convert_format(self):
1432
"""See BzrDir.can_convert_format()."""
1435
def create_branch(self):
1436
"""See BzrDir.create_branch."""
1437
return self._format.get_branch_format().initialize(self)
1439
def destroy_branch(self):
1440
"""See BzrDir.create_branch."""
1441
self.transport.delete_tree('branch')
1443
def create_repository(self, shared=False):
1444
"""See BzrDir.create_repository."""
1445
return self._format.repository_format.initialize(self, shared)
1447
def destroy_repository(self):
1448
"""See BzrDir.destroy_repository."""
1449
self.transport.delete_tree('repository')
1451
def create_workingtree(self, revision_id=None, from_branch=None,
1452
accelerator_tree=None, hardlink=False):
1453
"""See BzrDir.create_workingtree."""
1454
return self._format.workingtree_format.initialize(
1455
self, revision_id, from_branch=from_branch,
1456
accelerator_tree=accelerator_tree, hardlink=hardlink)
1458
def destroy_workingtree(self):
1459
"""See BzrDir.destroy_workingtree."""
1460
wt = self.open_workingtree(recommend_upgrade=False)
1461
repository = wt.branch.repository
1462
empty = repository.revision_tree(_mod_revision.NULL_REVISION)
1463
wt.revert(old_tree=empty)
1464
self.destroy_workingtree_metadata()
1466
def destroy_workingtree_metadata(self):
1467
self.transport.delete_tree('checkout')
1469
def find_branch_format(self):
1470
"""Find the branch 'format' for this bzrdir.
1472
This might be a synthetic object for e.g. RemoteBranch and SVN.
1474
from bzrlib.branch import BranchFormat
1475
return BranchFormat.find_format(self)
1477
def _get_mkdir_mode(self):
1478
"""Figure out the mode to use when creating a bzrdir subdir."""
1479
temp_control = lockable_files.LockableFiles(self.transport, '',
1480
lockable_files.TransportLock)
1481
return temp_control._dir_mode
1483
def get_branch_reference(self):
1484
"""See BzrDir.get_branch_reference()."""
1485
from bzrlib.branch import BranchFormat
1486
format = BranchFormat.find_format(self)
1487
return format.get_reference(self)
1489
def get_branch_transport(self, branch_format):
1490
"""See BzrDir.get_branch_transport()."""
1491
if branch_format is None:
1492
return self.transport.clone('branch')
1494
branch_format.get_format_string()
1495
except NotImplementedError:
1496
raise errors.IncompatibleFormat(branch_format, self._format)
1498
self.transport.mkdir('branch', mode=self._get_mkdir_mode())
1499
except errors.FileExists:
1501
return self.transport.clone('branch')
1503
def get_repository_transport(self, repository_format):
1504
"""See BzrDir.get_repository_transport()."""
1505
if repository_format is None:
1506
return self.transport.clone('repository')
1508
repository_format.get_format_string()
1509
except NotImplementedError:
1510
raise errors.IncompatibleFormat(repository_format, self._format)
1512
self.transport.mkdir('repository', mode=self._get_mkdir_mode())
1513
except errors.FileExists:
1515
return self.transport.clone('repository')
1517
def get_workingtree_transport(self, workingtree_format):
1518
"""See BzrDir.get_workingtree_transport()."""
1519
if workingtree_format is None:
1520
return self.transport.clone('checkout')
1522
workingtree_format.get_format_string()
1523
except NotImplementedError:
1524
raise errors.IncompatibleFormat(workingtree_format, self._format)
1526
self.transport.mkdir('checkout', mode=self._get_mkdir_mode())
1527
except errors.FileExists:
1529
return self.transport.clone('checkout')
1531
def needs_format_conversion(self, format=None):
1532
"""See BzrDir.needs_format_conversion()."""
1534
format = BzrDirFormat.get_default_format()
1535
if not isinstance(self._format, format.__class__):
1536
# it is not a meta dir format, conversion is needed.
1538
# we might want to push this down to the repository?
1540
if not isinstance(self.open_repository()._format,
1541
format.repository_format.__class__):
1542
# the repository needs an upgrade.
1544
except errors.NoRepositoryPresent:
1547
if not isinstance(self.open_branch()._format,
1548
format.get_branch_format().__class__):
1549
# the branch needs an upgrade.
1551
except errors.NotBranchError:
1554
my_wt = self.open_workingtree(recommend_upgrade=False)
1555
if not isinstance(my_wt._format,
1556
format.workingtree_format.__class__):
1557
# the workingtree needs an upgrade.
1559
except (errors.NoWorkingTree, errors.NotLocalUrl):
1563
def open_branch(self, unsupported=False):
1564
"""See BzrDir.open_branch."""
1565
format = self.find_branch_format()
1566
self._check_supported(format, unsupported)
1567
return format.open(self, _found=True)
1569
def open_repository(self, unsupported=False):
1570
"""See BzrDir.open_repository."""
1571
from bzrlib.repository import RepositoryFormat
1572
format = RepositoryFormat.find_format(self)
1573
self._check_supported(format, unsupported)
1574
return format.open(self, _found=True)
1576
def open_workingtree(self, unsupported=False,
1577
recommend_upgrade=True):
1578
"""See BzrDir.open_workingtree."""
1579
from bzrlib.workingtree import WorkingTreeFormat
1580
format = WorkingTreeFormat.find_format(self)
1581
self._check_supported(format, unsupported,
1583
basedir=self.root_transport.base)
1584
return format.open(self, _found=True)
1586
def _get_config(self):
1587
return config.BzrDirConfig(self.transport)
1590
class BzrDirFormat(object):
1591
"""An encapsulation of the initialization and open routines for a format.
1593
Formats provide three things:
1594
* An initialization routine,
1598
Formats are placed in a dict by their format string for reference
1599
during bzrdir opening. These should be subclasses of BzrDirFormat
1602
Once a format is deprecated, just deprecate the initialize and open
1603
methods on the format class. Do not deprecate the object, as the
1604
object will be created every system load.
1607
_default_format = None
1608
"""The default format used for new .bzr dirs."""
1611
"""The known formats."""
1613
_control_formats = []
1614
"""The registered control formats - .bzr, ....
1616
This is a list of BzrDirFormat objects.
1619
_control_server_formats = []
1620
"""The registered control server formats, e.g. RemoteBzrDirs.
1622
This is a list of BzrDirFormat objects.
1625
_lock_file_name = 'branch-lock'
1627
# _lock_class must be set in subclasses to the lock type, typ.
1628
# TransportLock or LockDir
1631
def find_format(klass, transport, _server_formats=True):
1632
"""Return the format present at transport."""
1634
formats = klass._control_server_formats + klass._control_formats
1636
formats = klass._control_formats
1637
for format in formats:
1639
return format.probe_transport(transport)
1640
except errors.NotBranchError:
1641
# this format does not find a control dir here.
1643
raise errors.NotBranchError(path=transport.base)
1646
def probe_transport(klass, transport):
1647
"""Return the .bzrdir style format present in a directory."""
1649
format_string = transport.get(".bzr/branch-format").read()
1650
except errors.NoSuchFile:
1651
raise errors.NotBranchError(path=transport.base)
1654
return klass._formats[format_string]
1656
raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
1659
def get_default_format(klass):
1660
"""Return the current default format."""
1661
return klass._default_format
1663
def get_format_string(self):
1664
"""Return the ASCII format string that identifies this format."""
1665
raise NotImplementedError(self.get_format_string)
1667
def get_format_description(self):
1668
"""Return the short description for this format."""
1669
raise NotImplementedError(self.get_format_description)
1671
def get_converter(self, format=None):
1672
"""Return the converter to use to convert bzrdirs needing converts.
1674
This returns a bzrlib.bzrdir.Converter object.
1676
This should return the best upgrader to step this format towards the
1677
current default format. In the case of plugins we can/should provide
1678
some means for them to extend the range of returnable converters.
1680
:param format: Optional format to override the default format of the
1683
raise NotImplementedError(self.get_converter)
1685
def initialize(self, url, possible_transports=None):
1686
"""Create a bzr control dir at this url and return an opened copy.
1688
Subclasses should typically override initialize_on_transport
1689
instead of this method.
1691
return self.initialize_on_transport(get_transport(url,
1692
possible_transports))
1694
def initialize_on_transport(self, transport):
1695
"""Initialize a new bzrdir in the base directory of a Transport."""
1696
# Since we don't have a .bzr directory, inherit the
1697
# mode from the root directory
1698
temp_control = lockable_files.LockableFiles(transport,
1699
'', lockable_files.TransportLock)
1700
temp_control._transport.mkdir('.bzr',
1701
# FIXME: RBC 20060121 don't peek under
1703
mode=temp_control._dir_mode)
1704
if sys.platform == 'win32' and isinstance(transport, local.LocalTransport):
1705
win32utils.set_file_attr_hidden(transport._abspath('.bzr'))
1706
file_mode = temp_control._file_mode
1708
bzrdir_transport = transport.clone('.bzr')
1709
utf8_files = [('README',
1710
"This is a Bazaar control directory.\n"
1711
"Do not change any files in this directory.\n"
1712
"See http://bazaar-vcs.org/ for more information about Bazaar.\n"),
1713
('branch-format', self.get_format_string()),
1715
# NB: no need to escape relative paths that are url safe.
1716
control_files = lockable_files.LockableFiles(bzrdir_transport,
1717
self._lock_file_name, self._lock_class)
1718
control_files.create_lock()
1719
control_files.lock_write()
1721
for (filename, content) in utf8_files:
1722
bzrdir_transport.put_bytes(filename, content,
1725
control_files.unlock()
1726
return self.open(transport, _found=True)
1728
def is_supported(self):
1729
"""Is this format supported?
1731
Supported formats must be initializable and openable.
1732
Unsupported formats may not support initialization or committing or
1733
some other features depending on the reason for not being supported.
1737
def same_model(self, target_format):
1738
return (self.repository_format.rich_root_data ==
1739
target_format.rich_root_data)
1742
def known_formats(klass):
1743
"""Return all the known formats.
1745
Concrete formats should override _known_formats.
1747
# There is double indirection here to make sure that control
1748
# formats used by more than one dir format will only be probed
1749
# once. This can otherwise be quite expensive for remote connections.
1751
for format in klass._control_formats:
1752
result.update(format._known_formats())
1756
def _known_formats(klass):
1757
"""Return the known format instances for this control format."""
1758
return set(klass._formats.values())
1760
def open(self, transport, _found=False):
1761
"""Return an instance of this format for the dir transport points at.
1763
_found is a private parameter, do not use it.
1766
found_format = BzrDirFormat.find_format(transport)
1767
if not isinstance(found_format, self.__class__):
1768
raise AssertionError("%s was asked to open %s, but it seems to need "
1770
% (self, transport, found_format))
1771
return self._open(transport)
1773
def _open(self, transport):
1774
"""Template method helper for opening BzrDirectories.
1776
This performs the actual open and any additional logic or parameter
1779
raise NotImplementedError(self._open)
1782
def register_format(klass, format):
1783
klass._formats[format.get_format_string()] = format
1786
def register_control_format(klass, format):
1787
"""Register a format that does not use '.bzr' for its control dir.
1789
TODO: This should be pulled up into a 'ControlDirFormat' base class
1790
which BzrDirFormat can inherit from, and renamed to register_format
1791
there. It has been done without that for now for simplicity of
1794
klass._control_formats.append(format)
1797
def register_control_server_format(klass, format):
1798
"""Register a control format for client-server environments.
1800
These formats will be tried before ones registered with
1801
register_control_format. This gives implementations that decide to the
1802
chance to grab it before anything looks at the contents of the format
1805
klass._control_server_formats.append(format)
1808
def _set_default_format(klass, format):
1809
"""Set default format (for testing behavior of defaults only)"""
1810
klass._default_format = format
1814
return self.get_format_string().rstrip()
1817
def unregister_format(klass, format):
1818
del klass._formats[format.get_format_string()]
1821
def unregister_control_format(klass, format):
1822
klass._control_formats.remove(format)
1825
class BzrDirFormat4(BzrDirFormat):
1826
"""Bzr dir format 4.
1828
This format is a combined format for working tree, branch and repository.
1830
- Format 1 working trees [always]
1831
- Format 4 branches [always]
1832
- Format 4 repositories [always]
1834
This format is deprecated: it indexes texts using a text it which is
1835
removed in format 5; write support for this format has been removed.
1838
_lock_class = lockable_files.TransportLock
1840
def get_format_string(self):
1841
"""See BzrDirFormat.get_format_string()."""
1842
return "Bazaar-NG branch, format 0.0.4\n"
1844
def get_format_description(self):
1845
"""See BzrDirFormat.get_format_description()."""
1846
return "All-in-one format 4"
1848
def get_converter(self, format=None):
1849
"""See BzrDirFormat.get_converter()."""
1850
# there is one and only one upgrade path here.
1851
return ConvertBzrDir4To5()
1853
def initialize_on_transport(self, transport):
1854
"""Format 4 branches cannot be created."""
1855
raise errors.UninitializableFormat(self)
1857
def is_supported(self):
1858
"""Format 4 is not supported.
1860
It is not supported because the model changed from 4 to 5 and the
1861
conversion logic is expensive - so doing it on the fly was not
1866
def _open(self, transport):
1867
"""See BzrDirFormat._open."""
1868
return BzrDir4(transport, self)
1870
def __return_repository_format(self):
1871
"""Circular import protection."""
1872
from bzrlib.repofmt.weaverepo import RepositoryFormat4
1873
return RepositoryFormat4()
1874
repository_format = property(__return_repository_format)
1877
class BzrDirFormat5(BzrDirFormat):
1878
"""Bzr control format 5.
1880
This format is a combined format for working tree, branch and repository.
1882
- Format 2 working trees [always]
1883
- Format 4 branches [always]
1884
- Format 5 repositories [always]
1885
Unhashed stores in the repository.
1888
_lock_class = lockable_files.TransportLock
1890
def get_format_string(self):
1891
"""See BzrDirFormat.get_format_string()."""
1892
return "Bazaar-NG branch, format 5\n"
1894
def get_branch_format(self):
1895
from bzrlib import branch
1896
return branch.BzrBranchFormat4()
1898
def get_format_description(self):
1899
"""See BzrDirFormat.get_format_description()."""
1900
return "All-in-one format 5"
1902
def get_converter(self, format=None):
1903
"""See BzrDirFormat.get_converter()."""
1904
# there is one and only one upgrade path here.
1905
return ConvertBzrDir5To6()
1907
def _initialize_for_clone(self, url):
1908
return self.initialize_on_transport(get_transport(url), _cloning=True)
1910
def initialize_on_transport(self, transport, _cloning=False):
1911
"""Format 5 dirs always have working tree, branch and repository.
1913
Except when they are being cloned.
1915
from bzrlib.branch import BzrBranchFormat4
1916
from bzrlib.repofmt.weaverepo import RepositoryFormat5
1917
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1918
RepositoryFormat5().initialize(result, _internal=True)
1920
branch = BzrBranchFormat4().initialize(result)
1921
result._init_workingtree()
1924
def _open(self, transport):
1925
"""See BzrDirFormat._open."""
1926
return BzrDir5(transport, self)
1928
def __return_repository_format(self):
1929
"""Circular import protection."""
1930
from bzrlib.repofmt.weaverepo import RepositoryFormat5
1931
return RepositoryFormat5()
1932
repository_format = property(__return_repository_format)
1935
class BzrDirFormat6(BzrDirFormat):
1936
"""Bzr control format 6.
1938
This format is a combined format for working tree, branch and repository.
1940
- Format 2 working trees [always]
1941
- Format 4 branches [always]
1942
- Format 6 repositories [always]
1945
_lock_class = lockable_files.TransportLock
1947
def get_format_string(self):
1948
"""See BzrDirFormat.get_format_string()."""
1949
return "Bazaar-NG branch, format 6\n"
1951
def get_format_description(self):
1952
"""See BzrDirFormat.get_format_description()."""
1953
return "All-in-one format 6"
1955
def get_branch_format(self):
1956
from bzrlib import branch
1957
return branch.BzrBranchFormat4()
1959
def get_converter(self, format=None):
1960
"""See BzrDirFormat.get_converter()."""
1961
# there is one and only one upgrade path here.
1962
return ConvertBzrDir6ToMeta()
1964
def _initialize_for_clone(self, url):
1965
return self.initialize_on_transport(get_transport(url), _cloning=True)
1967
def initialize_on_transport(self, transport, _cloning=False):
1968
"""Format 6 dirs always have working tree, branch and repository.
1970
Except when they are being cloned.
1972
from bzrlib.branch import BzrBranchFormat4
1973
from bzrlib.repofmt.weaverepo import RepositoryFormat6
1974
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1975
RepositoryFormat6().initialize(result, _internal=True)
1977
branch = BzrBranchFormat4().initialize(result)
1978
result._init_workingtree()
1981
def _open(self, transport):
1982
"""See BzrDirFormat._open."""
1983
return BzrDir6(transport, self)
1985
def __return_repository_format(self):
1986
"""Circular import protection."""
1987
from bzrlib.repofmt.weaverepo import RepositoryFormat6
1988
return RepositoryFormat6()
1989
repository_format = property(__return_repository_format)
1992
class BzrDirMetaFormat1(BzrDirFormat):
1993
"""Bzr meta control format 1
1995
This is the first format with split out working tree, branch and repository
1998
- Format 3 working trees [optional]
1999
- Format 5 branches [optional]
2000
- Format 7 repositories [optional]
2003
_lock_class = lockdir.LockDir
2006
self._workingtree_format = None
2007
self._branch_format = None
2009
def __eq__(self, other):
2010
if other.__class__ is not self.__class__:
2012
if other.repository_format != self.repository_format:
2014
if other.workingtree_format != self.workingtree_format:
2018
def __ne__(self, other):
2019
return not self == other
2021
def get_branch_format(self):
2022
if self._branch_format is None:
2023
from bzrlib.branch import BranchFormat
2024
self._branch_format = BranchFormat.get_default_format()
2025
return self._branch_format
2027
def set_branch_format(self, format):
2028
self._branch_format = format
2030
def get_converter(self, format=None):
2031
"""See BzrDirFormat.get_converter()."""
2033
format = BzrDirFormat.get_default_format()
2034
if not isinstance(self, format.__class__):
2035
# converting away from metadir is not implemented
2036
raise NotImplementedError(self.get_converter)
2037
return ConvertMetaToMeta(format)
2039
def get_format_string(self):
2040
"""See BzrDirFormat.get_format_string()."""
2041
return "Bazaar-NG meta directory, format 1\n"
2043
def get_format_description(self):
2044
"""See BzrDirFormat.get_format_description()."""
2045
return "Meta directory format 1"
2047
def _open(self, transport):
2048
"""See BzrDirFormat._open."""
2049
return BzrDirMeta1(transport, self)
2051
def __return_repository_format(self):
2052
"""Circular import protection."""
2053
if getattr(self, '_repository_format', None):
2054
return self._repository_format
2055
from bzrlib.repository import RepositoryFormat
2056
return RepositoryFormat.get_default_format()
2058
def __set_repository_format(self, value):
2059
"""Allow changing the repository format for metadir formats."""
2060
self._repository_format = value
2062
repository_format = property(__return_repository_format, __set_repository_format)
2064
def __get_workingtree_format(self):
2065
if self._workingtree_format is None:
2066
from bzrlib.workingtree import WorkingTreeFormat
2067
self._workingtree_format = WorkingTreeFormat.get_default_format()
2068
return self._workingtree_format
2070
def __set_workingtree_format(self, wt_format):
2071
self._workingtree_format = wt_format
2073
workingtree_format = property(__get_workingtree_format,
2074
__set_workingtree_format)
2077
# Register bzr control format
2078
BzrDirFormat.register_control_format(BzrDirFormat)
2080
# Register bzr formats
2081
BzrDirFormat.register_format(BzrDirFormat4())
2082
BzrDirFormat.register_format(BzrDirFormat5())
2083
BzrDirFormat.register_format(BzrDirFormat6())
2084
__default_format = BzrDirMetaFormat1()
2085
BzrDirFormat.register_format(__default_format)
2086
BzrDirFormat._default_format = __default_format
2089
class Converter(object):
2090
"""Converts a disk format object from one format to another."""
2092
def convert(self, to_convert, pb):
2093
"""Perform the conversion of to_convert, giving feedback via pb.
2095
:param to_convert: The disk object to convert.
2096
:param pb: a progress bar to use for progress information.
2099
def step(self, message):
2100
"""Update the pb by a step."""
2102
self.pb.update(message, self.count, self.total)
2105
class ConvertBzrDir4To5(Converter):
2106
"""Converts format 4 bzr dirs to format 5."""
2109
super(ConvertBzrDir4To5, self).__init__()
2110
self.converted_revs = set()
2111
self.absent_revisions = set()
2115
def convert(self, to_convert, pb):
2116
"""See Converter.convert()."""
2117
self.bzrdir = to_convert
2119
self.pb.note('starting upgrade from format 4 to 5')
2120
if isinstance(self.bzrdir.transport, local.LocalTransport):
2121
self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
2122
self._convert_to_weaves()
2123
return BzrDir.open(self.bzrdir.root_transport.base)
2125
def _convert_to_weaves(self):
2126
self.pb.note('note: upgrade may be faster if all store files are ungzipped first')
2129
stat = self.bzrdir.transport.stat('weaves')
2130
if not S_ISDIR(stat.st_mode):
2131
self.bzrdir.transport.delete('weaves')
2132
self.bzrdir.transport.mkdir('weaves')
2133
except errors.NoSuchFile:
2134
self.bzrdir.transport.mkdir('weaves')
2135
# deliberately not a WeaveFile as we want to build it up slowly.
2136
self.inv_weave = Weave('inventory')
2137
# holds in-memory weaves for all files
2138
self.text_weaves = {}
2139
self.bzrdir.transport.delete('branch-format')
2140
self.branch = self.bzrdir.open_branch()
2141
self._convert_working_inv()
2142
rev_history = self.branch.revision_history()
2143
# to_read is a stack holding the revisions we still need to process;
2144
# appending to it adds new highest-priority revisions
2145
self.known_revisions = set(rev_history)
2146
self.to_read = rev_history[-1:]
2148
rev_id = self.to_read.pop()
2149
if (rev_id not in self.revisions
2150
and rev_id not in self.absent_revisions):
2151
self._load_one_rev(rev_id)
2153
to_import = self._make_order()
2154
for i, rev_id in enumerate(to_import):
2155
self.pb.update('converting revision', i, len(to_import))
2156
self._convert_one_rev(rev_id)
2158
self._write_all_weaves()
2159
self._write_all_revs()
2160
self.pb.note('upgraded to weaves:')
2161
self.pb.note(' %6d revisions and inventories', len(self.revisions))
2162
self.pb.note(' %6d revisions not present', len(self.absent_revisions))
2163
self.pb.note(' %6d texts', self.text_count)
2164
self._cleanup_spare_files_after_format4()
2165
self.branch._transport.put_bytes(
2167
BzrDirFormat5().get_format_string(),
2168
mode=self.bzrdir._get_file_mode())
2170
def _cleanup_spare_files_after_format4(self):
2171
# FIXME working tree upgrade foo.
2172
for n in 'merged-patches', 'pending-merged-patches':
2174
## assert os.path.getsize(p) == 0
2175
self.bzrdir.transport.delete(n)
2176
except errors.NoSuchFile:
2178
self.bzrdir.transport.delete_tree('inventory-store')
2179
self.bzrdir.transport.delete_tree('text-store')
2181
def _convert_working_inv(self):
2182
inv = xml4.serializer_v4.read_inventory(
2183
self.branch._transport.get('inventory'))
2184
new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv, working=True)
2185
self.branch._transport.put_bytes('inventory', new_inv_xml,
2186
mode=self.bzrdir._get_file_mode())
2188
def _write_all_weaves(self):
2189
controlweaves = WeaveStore(self.bzrdir.transport, prefixed=False)
2190
weave_transport = self.bzrdir.transport.clone('weaves')
2191
weaves = WeaveStore(weave_transport, prefixed=False)
2192
transaction = WriteTransaction()
2196
for file_id, file_weave in self.text_weaves.items():
2197
self.pb.update('writing weave', i, len(self.text_weaves))
2198
weaves._put_weave(file_id, file_weave, transaction)
2200
self.pb.update('inventory', 0, 1)
2201
controlweaves._put_weave('inventory', self.inv_weave, transaction)
2202
self.pb.update('inventory', 1, 1)
2206
def _write_all_revs(self):
2207
"""Write all revisions out in new form."""
2208
self.bzrdir.transport.delete_tree('revision-store')
2209
self.bzrdir.transport.mkdir('revision-store')
2210
revision_transport = self.bzrdir.transport.clone('revision-store')
2212
from bzrlib.xml5 import serializer_v5
2213
from bzrlib.repofmt.weaverepo import RevisionTextStore
2214
revision_store = RevisionTextStore(revision_transport,
2215
serializer_v5, False, versionedfile.PrefixMapper(),
2216
lambda:True, lambda:True)
2218
for i, rev_id in enumerate(self.converted_revs):
2219
self.pb.update('write revision', i, len(self.converted_revs))
2220
text = serializer_v5.write_revision_to_string(
2221
self.revisions[rev_id])
2223
revision_store.add_lines(key, None, osutils.split_lines(text))
2227
def _load_one_rev(self, rev_id):
2228
"""Load a revision object into memory.
2230
Any parents not either loaded or abandoned get queued to be
2232
self.pb.update('loading revision',
2233
len(self.revisions),
2234
len(self.known_revisions))
2235
if not self.branch.repository.has_revision(rev_id):
2237
self.pb.note('revision {%s} not present in branch; '
2238
'will be converted as a ghost',
2240
self.absent_revisions.add(rev_id)
2242
rev = self.branch.repository.get_revision(rev_id)
2243
for parent_id in rev.parent_ids:
2244
self.known_revisions.add(parent_id)
2245
self.to_read.append(parent_id)
2246
self.revisions[rev_id] = rev
2248
def _load_old_inventory(self, rev_id):
2249
old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
2250
inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
2251
inv.revision_id = rev_id
2252
rev = self.revisions[rev_id]
2255
def _load_updated_inventory(self, rev_id):
2256
inv_xml = self.inv_weave.get_text(rev_id)
2257
inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
2260
def _convert_one_rev(self, rev_id):
2261
"""Convert revision and all referenced objects to new format."""
2262
rev = self.revisions[rev_id]
2263
inv = self._load_old_inventory(rev_id)
2264
present_parents = [p for p in rev.parent_ids
2265
if p not in self.absent_revisions]
2266
self._convert_revision_contents(rev, inv, present_parents)
2267
self._store_new_inv(rev, inv, present_parents)
2268
self.converted_revs.add(rev_id)
2270
def _store_new_inv(self, rev, inv, present_parents):
2271
new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
2272
new_inv_sha1 = sha_string(new_inv_xml)
2273
self.inv_weave.add_lines(rev.revision_id,
2275
new_inv_xml.splitlines(True))
2276
rev.inventory_sha1 = new_inv_sha1
2278
def _convert_revision_contents(self, rev, inv, present_parents):
2279
"""Convert all the files within a revision.
2281
Also upgrade the inventory to refer to the text revision ids."""
2282
rev_id = rev.revision_id
2283
mutter('converting texts of revision {%s}',
2285
parent_invs = map(self._load_updated_inventory, present_parents)
2286
entries = inv.iter_entries()
2288
for path, ie in entries:
2289
self._convert_file_version(rev, ie, parent_invs)
2291
def _convert_file_version(self, rev, ie, parent_invs):
2292
"""Convert one version of one file.
2294
The file needs to be added into the weave if it is a merge
2295
of >=2 parents or if it's changed from its parent.
2297
file_id = ie.file_id
2298
rev_id = rev.revision_id
2299
w = self.text_weaves.get(file_id)
2302
self.text_weaves[file_id] = w
2303
text_changed = False
2304
parent_candiate_entries = ie.parent_candidates(parent_invs)
2305
heads = graph.Graph(self).heads(parent_candiate_entries.keys())
2306
# XXX: Note that this is unordered - and this is tolerable because
2307
# the previous code was also unordered.
2308
previous_entries = dict((head, parent_candiate_entries[head]) for head
2310
self.snapshot_ie(previous_entries, ie, w, rev_id)
2313
@symbol_versioning.deprecated_method(symbol_versioning.one_one)
2314
def get_parents(self, revision_ids):
2315
for revision_id in revision_ids:
2316
yield self.revisions[revision_id].parent_ids
2318
def get_parent_map(self, revision_ids):
2319
"""See graph._StackedParentsProvider.get_parent_map"""
2320
return dict((revision_id, self.revisions[revision_id])
2321
for revision_id in revision_ids
2322
if revision_id in self.revisions)
2324
def snapshot_ie(self, previous_revisions, ie, w, rev_id):
2325
# TODO: convert this logic, which is ~= snapshot to
2326
# a call to:. This needs the path figured out. rather than a work_tree
2327
# a v4 revision_tree can be given, or something that looks enough like
2328
# one to give the file content to the entry if it needs it.
2329
# and we need something that looks like a weave store for snapshot to
2331
#ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
2332
if len(previous_revisions) == 1:
2333
previous_ie = previous_revisions.values()[0]
2334
if ie._unchanged(previous_ie):
2335
ie.revision = previous_ie.revision
2338
text = self.branch.repository._text_store.get(ie.text_id)
2339
file_lines = text.readlines()
2340
w.add_lines(rev_id, previous_revisions, file_lines)
2341
self.text_count += 1
2343
w.add_lines(rev_id, previous_revisions, [])
2344
ie.revision = rev_id
2346
def _make_order(self):
2347
"""Return a suitable order for importing revisions.
2349
The order must be such that an revision is imported after all
2350
its (present) parents.
2352
todo = set(self.revisions.keys())
2353
done = self.absent_revisions.copy()
2356
# scan through looking for a revision whose parents
2358
for rev_id in sorted(list(todo)):
2359
rev = self.revisions[rev_id]
2360
parent_ids = set(rev.parent_ids)
2361
if parent_ids.issubset(done):
2362
# can take this one now
2363
order.append(rev_id)
2369
class ConvertBzrDir5To6(Converter):
2370
"""Converts format 5 bzr dirs to format 6."""
2372
def convert(self, to_convert, pb):
2373
"""See Converter.convert()."""
2374
self.bzrdir = to_convert
2376
self.pb.note('starting upgrade from format 5 to 6')
2377
self._convert_to_prefixed()
2378
return BzrDir.open(self.bzrdir.root_transport.base)
2380
def _convert_to_prefixed(self):
2381
from bzrlib.store import TransportStore
2382
self.bzrdir.transport.delete('branch-format')
2383
for store_name in ["weaves", "revision-store"]:
2384
self.pb.note("adding prefixes to %s" % store_name)
2385
store_transport = self.bzrdir.transport.clone(store_name)
2386
store = TransportStore(store_transport, prefixed=True)
2387
for urlfilename in store_transport.list_dir('.'):
2388
filename = urlutils.unescape(urlfilename)
2389
if (filename.endswith(".weave") or
2390
filename.endswith(".gz") or
2391
filename.endswith(".sig")):
2392
file_id, suffix = os.path.splitext(filename)
2396
new_name = store._mapper.map((file_id,)) + suffix
2397
# FIXME keep track of the dirs made RBC 20060121
2399
store_transport.move(filename, new_name)
2400
except errors.NoSuchFile: # catches missing dirs strangely enough
2401
store_transport.mkdir(osutils.dirname(new_name))
2402
store_transport.move(filename, new_name)
2403
self.bzrdir.transport.put_bytes(
2405
BzrDirFormat6().get_format_string(),
2406
mode=self.bzrdir._get_file_mode())
2409
class ConvertBzrDir6ToMeta(Converter):
2410
"""Converts format 6 bzr dirs to metadirs."""
2412
def convert(self, to_convert, pb):
2413
"""See Converter.convert()."""
2414
from bzrlib.repofmt.weaverepo import RepositoryFormat7
2415
from bzrlib.branch import BzrBranchFormat5
2416
self.bzrdir = to_convert
2419
self.total = 20 # the steps we know about
2420
self.garbage_inventories = []
2421
self.dir_mode = self.bzrdir._get_dir_mode()
2422
self.file_mode = self.bzrdir._get_file_mode()
2424
self.pb.note('starting upgrade from format 6 to metadir')
2425
self.bzrdir.transport.put_bytes(
2427
"Converting to format 6",
2428
mode=self.file_mode)
2429
# its faster to move specific files around than to open and use the apis...
2430
# first off, nuke ancestry.weave, it was never used.
2432
self.step('Removing ancestry.weave')
2433
self.bzrdir.transport.delete('ancestry.weave')
2434
except errors.NoSuchFile:
2436
# find out whats there
2437
self.step('Finding branch files')
2438
last_revision = self.bzrdir.open_branch().last_revision()
2439
bzrcontents = self.bzrdir.transport.list_dir('.')
2440
for name in bzrcontents:
2441
if name.startswith('basis-inventory.'):
2442
self.garbage_inventories.append(name)
2443
# create new directories for repository, working tree and branch
2444
repository_names = [('inventory.weave', True),
2445
('revision-store', True),
2447
self.step('Upgrading repository ')
2448
self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
2449
self.make_lock('repository')
2450
# we hard code the formats here because we are converting into
2451
# the meta format. The meta format upgrader can take this to a
2452
# future format within each component.
2453
self.put_format('repository', RepositoryFormat7())
2454
for entry in repository_names:
2455
self.move_entry('repository', entry)
2457
self.step('Upgrading branch ')
2458
self.bzrdir.transport.mkdir('branch', mode=self.dir_mode)
2459
self.make_lock('branch')
2460
self.put_format('branch', BzrBranchFormat5())
2461
branch_files = [('revision-history', True),
2462
('branch-name', True),
2464
for entry in branch_files:
2465
self.move_entry('branch', entry)
2467
checkout_files = [('pending-merges', True),
2468
('inventory', True),
2469
('stat-cache', False)]
2470
# If a mandatory checkout file is not present, the branch does not have
2471
# a functional checkout. Do not create a checkout in the converted
2473
for name, mandatory in checkout_files:
2474
if mandatory and name not in bzrcontents:
2475
has_checkout = False
2479
if not has_checkout:
2480
self.pb.note('No working tree.')
2481
# If some checkout files are there, we may as well get rid of them.
2482
for name, mandatory in checkout_files:
2483
if name in bzrcontents:
2484
self.bzrdir.transport.delete(name)
2486
from bzrlib.workingtree import WorkingTreeFormat3
2487
self.step('Upgrading working tree')
2488
self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
2489
self.make_lock('checkout')
2491
'checkout', WorkingTreeFormat3())
2492
self.bzrdir.transport.delete_multi(
2493
self.garbage_inventories, self.pb)
2494
for entry in checkout_files:
2495
self.move_entry('checkout', entry)
2496
if last_revision is not None:
2497
self.bzrdir.transport.put_bytes(
2498
'checkout/last-revision', last_revision)
2499
self.bzrdir.transport.put_bytes(
2501
BzrDirMetaFormat1().get_format_string(),
2502
mode=self.file_mode)
2503
return BzrDir.open(self.bzrdir.root_transport.base)
2505
def make_lock(self, name):
2506
"""Make a lock for the new control dir name."""
2507
self.step('Make %s lock' % name)
2508
ld = lockdir.LockDir(self.bzrdir.transport,
2510
file_modebits=self.file_mode,
2511
dir_modebits=self.dir_mode)
2514
def move_entry(self, new_dir, entry):
2515
"""Move then entry name into new_dir."""
2517
mandatory = entry[1]
2518
self.step('Moving %s' % name)
2520
self.bzrdir.transport.move(name, '%s/%s' % (new_dir, name))
2521
except errors.NoSuchFile:
2525
def put_format(self, dirname, format):
2526
self.bzrdir.transport.put_bytes('%s/format' % dirname,
2527
format.get_format_string(),
2531
class ConvertMetaToMeta(Converter):
2532
"""Converts the components of metadirs."""
2534
def __init__(self, target_format):
2535
"""Create a metadir to metadir converter.
2537
:param target_format: The final metadir format that is desired.
2539
self.target_format = target_format
2541
def convert(self, to_convert, pb):
2542
"""See Converter.convert()."""
2543
self.bzrdir = to_convert
2547
self.step('checking repository format')
2549
repo = self.bzrdir.open_repository()
2550
except errors.NoRepositoryPresent:
2553
if not isinstance(repo._format, self.target_format.repository_format.__class__):
2554
from bzrlib.repository import CopyConverter
2555
self.pb.note('starting repository conversion')
2556
converter = CopyConverter(self.target_format.repository_format)
2557
converter.convert(repo, pb)
2559
branch = self.bzrdir.open_branch()
2560
except errors.NotBranchError:
2563
# TODO: conversions of Branch and Tree should be done by
2564
# InterXFormat lookups/some sort of registry.
2565
# Avoid circular imports
2566
from bzrlib import branch as _mod_branch
2567
old = branch._format.__class__
2568
new = self.target_format.get_branch_format().__class__
2570
if (old == _mod_branch.BzrBranchFormat5 and
2571
new in (_mod_branch.BzrBranchFormat6,
2572
_mod_branch.BzrBranchFormat7)):
2573
branch_converter = _mod_branch.Converter5to6()
2574
elif (old == _mod_branch.BzrBranchFormat6 and
2575
new == _mod_branch.BzrBranchFormat7):
2576
branch_converter = _mod_branch.Converter6to7()
2578
raise errors.BadConversionTarget("No converter", new)
2579
branch_converter.convert(branch)
2580
branch = self.bzrdir.open_branch()
2581
old = branch._format.__class__
2583
tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2584
except (errors.NoWorkingTree, errors.NotLocalUrl):
2587
# TODO: conversions of Branch and Tree should be done by
2588
# InterXFormat lookups
2589
if (isinstance(tree, workingtree.WorkingTree3) and
2590
not isinstance(tree, workingtree_4.WorkingTree4) and
2591
isinstance(self.target_format.workingtree_format,
2592
workingtree_4.WorkingTreeFormat4)):
2593
workingtree_4.Converter3to4().convert(tree)
2594
if (isinstance(tree, workingtree_4.WorkingTree4) and
2595
not isinstance(tree, workingtree_5.WorkingTree5) and
2596
isinstance(self.target_format.workingtree_format,
2597
workingtree_5.WorkingTreeFormat5)):
2598
workingtree_5.Converter4to5().convert(tree)
2602
# This is not in remote.py because it's small, and needs to be registered.
2603
# Putting it in remote.py creates a circular import problem.
2604
# we can make it a lazy object if the control formats is turned into something
2606
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2607
"""Format representing bzrdirs accessed via a smart server"""
2609
def get_format_description(self):
2610
return 'bzr remote bzrdir'
2613
def probe_transport(klass, transport):
2614
"""Return a RemoteBzrDirFormat object if it looks possible."""
2616
medium = transport.get_smart_medium()
2617
except (NotImplementedError, AttributeError,
2618
errors.TransportNotPossible, errors.NoSmartMedium,
2619
errors.SmartProtocolError):
2620
# no smart server, so not a branch for this format type.
2621
raise errors.NotBranchError(path=transport.base)
2623
# Decline to open it if the server doesn't support our required
2624
# version (3) so that the VFS-based transport will do it.
2625
if medium.should_probe():
2627
server_version = medium.protocol_version()
2628
except errors.SmartProtocolError:
2629
# Apparently there's no usable smart server there, even though
2630
# the medium supports the smart protocol.
2631
raise errors.NotBranchError(path=transport.base)
2632
if server_version != '2':
2633
raise errors.NotBranchError(path=transport.base)
2636
def initialize_on_transport(self, transport):
2638
# hand off the request to the smart server
2639
client_medium = transport.get_smart_medium()
2640
except errors.NoSmartMedium:
2641
# TODO: lookup the local format from a server hint.
2642
local_dir_format = BzrDirMetaFormat1()
2643
return local_dir_format.initialize_on_transport(transport)
2644
client = _SmartClient(client_medium)
2645
path = client.remote_path_from_transport(transport)
2646
response = client.call('BzrDirFormat.initialize', path)
2647
if response[0] != 'ok':
2648
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2649
return remote.RemoteBzrDir(transport)
2651
def _open(self, transport):
2652
return remote.RemoteBzrDir(transport)
2654
def __eq__(self, other):
2655
if not isinstance(other, RemoteBzrDirFormat):
2657
return self.get_format_description() == other.get_format_description()
2660
def repository_format(self):
2661
# Using a property to avoid early loading of remote
2662
return remote.RemoteRepositoryFormat()
2665
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2668
class BzrDirFormatInfo(object):
2670
def __init__(self, native, deprecated, hidden, experimental):
2671
self.deprecated = deprecated
2672
self.native = native
2673
self.hidden = hidden
2674
self.experimental = experimental
2677
class BzrDirFormatRegistry(registry.Registry):
2678
"""Registry of user-selectable BzrDir subformats.
2680
Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2681
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
2685
"""Create a BzrDirFormatRegistry."""
2686
self._aliases = set()
2687
self._registration_order = list()
2688
super(BzrDirFormatRegistry, self).__init__()
2691
"""Return a set of the format names which are aliases."""
2692
return frozenset(self._aliases)
2694
def register_metadir(self, key,
2695
repository_format, help, native=True, deprecated=False,
2701
"""Register a metadir subformat.
2703
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2704
by the Repository format.
2706
:param repository_format: The fully-qualified repository format class
2708
:param branch_format: Fully-qualified branch format class name as
2710
:param tree_format: Fully-qualified tree format class name as
2713
# This should be expanded to support setting WorkingTree and Branch
2714
# formats, once BzrDirMetaFormat1 supports that.
2715
def _load(full_name):
2716
mod_name, factory_name = full_name.rsplit('.', 1)
2718
mod = __import__(mod_name, globals(), locals(),
2720
except ImportError, e:
2721
raise ImportError('failed to load %s: %s' % (full_name, e))
2723
factory = getattr(mod, factory_name)
2724
except AttributeError:
2725
raise AttributeError('no factory %s in module %r'
2730
bd = BzrDirMetaFormat1()
2731
if branch_format is not None:
2732
bd.set_branch_format(_load(branch_format))
2733
if tree_format is not None:
2734
bd.workingtree_format = _load(tree_format)
2735
if repository_format is not None:
2736
bd.repository_format = _load(repository_format)
2738
self.register(key, helper, help, native, deprecated, hidden,
2739
experimental, alias)
2741
def register(self, key, factory, help, native=True, deprecated=False,
2742
hidden=False, experimental=False, alias=False):
2743
"""Register a BzrDirFormat factory.
2745
The factory must be a callable that takes one parameter: the key.
2746
It must produce an instance of the BzrDirFormat when called.
2748
This function mainly exists to prevent the info object from being
2751
registry.Registry.register(self, key, factory, help,
2752
BzrDirFormatInfo(native, deprecated, hidden, experimental))
2754
self._aliases.add(key)
2755
self._registration_order.append(key)
2757
def register_lazy(self, key, module_name, member_name, help, native=True,
2758
deprecated=False, hidden=False, experimental=False, alias=False):
2759
registry.Registry.register_lazy(self, key, module_name, member_name,
2760
help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
2762
self._aliases.add(key)
2763
self._registration_order.append(key)
2765
def set_default(self, key):
2766
"""Set the 'default' key to be a clone of the supplied key.
2768
This method must be called once and only once.
2770
registry.Registry.register(self, 'default', self.get(key),
2771
self.get_help(key), info=self.get_info(key))
2772
self._aliases.add('default')
2774
def set_default_repository(self, key):
2775
"""Set the FormatRegistry default and Repository default.
2777
This is a transitional method while Repository.set_default_format
2780
if 'default' in self:
2781
self.remove('default')
2782
self.set_default(key)
2783
format = self.get('default')()
2785
def make_bzrdir(self, key):
2786
return self.get(key)()
2788
def help_topic(self, topic):
2790
default_realkey = None
2791
default_help = self.get_help('default')
2793
for key in self._registration_order:
2794
if key == 'default':
2796
help = self.get_help(key)
2797
if help == default_help:
2798
default_realkey = key
2800
help_pairs.append((key, help))
2802
def wrapped(key, help, info):
2804
help = '(native) ' + help
2805
return ':%s:\n%s\n\n' % (key,
2806
textwrap.fill(help, initial_indent=' ',
2807
subsequent_indent=' '))
2808
if default_realkey is not None:
2809
output += wrapped(default_realkey, '(default) %s' % default_help,
2810
self.get_info('default'))
2811
deprecated_pairs = []
2812
experimental_pairs = []
2813
for key, help in help_pairs:
2814
info = self.get_info(key)
2817
elif info.deprecated:
2818
deprecated_pairs.append((key, help))
2819
elif info.experimental:
2820
experimental_pairs.append((key, help))
2822
output += wrapped(key, help, info)
2823
output += "\nSee ``bzr help formats`` for more about storage formats."
2825
if len(experimental_pairs) > 0:
2826
other_output += "Experimental formats are shown below.\n\n"
2827
for key, help in experimental_pairs:
2828
info = self.get_info(key)
2829
other_output += wrapped(key, help, info)
2832
"No experimental formats are available.\n\n"
2833
if len(deprecated_pairs) > 0:
2834
other_output += "\nDeprecated formats are shown below.\n\n"
2835
for key, help in deprecated_pairs:
2836
info = self.get_info(key)
2837
other_output += wrapped(key, help, info)
2840
"\nNo deprecated formats are available.\n\n"
2842
"\nSee ``bzr help formats`` for more about storage formats."
2844
if topic == 'other-formats':
2850
class RepositoryAcquisitionPolicy(object):
2851
"""Abstract base class for repository acquisition policies.
2853
A repository acquisition policy decides how a BzrDir acquires a repository
2854
for a branch that is being created. The most basic policy decision is
2855
whether to create a new repository or use an existing one.
2857
def __init__(self, stack_on, stack_on_pwd, require_stacking):
2860
:param stack_on: A location to stack on
2861
:param stack_on_pwd: If stack_on is relative, the location it is
2863
:param require_stacking: If True, it is a failure to not stack.
2865
self._stack_on = stack_on
2866
self._stack_on_pwd = stack_on_pwd
2867
self._require_stacking = require_stacking
2869
def configure_branch(self, branch):
2870
"""Apply any configuration data from this policy to the branch.
2872
Default implementation sets repository stacking.
2874
if self._stack_on is None:
2876
if self._stack_on_pwd is None:
2877
stack_on = self._stack_on
2880
stack_on = urlutils.rebase_url(self._stack_on,
2882
branch.bzrdir.root_transport.base)
2883
except errors.InvalidRebaseURLs:
2884
stack_on = self._get_full_stack_on()
2886
branch.set_stacked_on_url(stack_on)
2887
except errors.UnstackableBranchFormat:
2888
if self._require_stacking:
2891
def _get_full_stack_on(self):
2892
"""Get a fully-qualified URL for the stack_on location."""
2893
if self._stack_on is None:
2895
if self._stack_on_pwd is None:
2896
return self._stack_on
2898
return urlutils.join(self._stack_on_pwd, self._stack_on)
2900
def _add_fallback(self, repository):
2901
"""Add a fallback to the supplied repository, if stacking is set."""
2902
stack_on = self._get_full_stack_on()
2903
if stack_on is None:
2905
stacked_dir = BzrDir.open(stack_on)
2907
stacked_repo = stacked_dir.open_branch().repository
2908
except errors.NotBranchError:
2909
stacked_repo = stacked_dir.open_repository()
2911
repository.add_fallback_repository(stacked_repo)
2912
except errors.UnstackableRepositoryFormat:
2913
if self._require_stacking:
2916
def acquire_repository(self, make_working_trees=None, shared=False):
2917
"""Acquire a repository for this bzrdir.
2919
Implementations may create a new repository or use a pre-exising
2921
:param make_working_trees: If creating a repository, set
2922
make_working_trees to this value (if non-None)
2923
:param shared: If creating a repository, make it shared if True
2924
:return: A repository
2926
raise NotImplemented(RepositoryAcquisitionPolicy.acquire_repository)
2929
class CreateRepository(RepositoryAcquisitionPolicy):
2930
"""A policy of creating a new repository"""
2932
def __init__(self, bzrdir, stack_on=None, stack_on_pwd=None,
2933
require_stacking=False):
2936
:param bzrdir: The bzrdir to create the repository on.
2937
:param stack_on: A location to stack on
2938
:param stack_on_pwd: If stack_on is relative, the location it is
2941
RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
2943
self._bzrdir = bzrdir
2945
def acquire_repository(self, make_working_trees=None, shared=False):
2946
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2948
Creates the desired repository in the bzrdir we already have.
2950
repository = self._bzrdir.create_repository(shared=shared)
2951
self._add_fallback(repository)
2952
if make_working_trees is not None:
2953
repository.set_make_working_trees(make_working_trees)
2957
class UseExistingRepository(RepositoryAcquisitionPolicy):
2958
"""A policy of reusing an existing repository"""
2960
def __init__(self, repository, stack_on=None, stack_on_pwd=None,
2961
require_stacking=False):
2964
:param repository: The repository to use.
2965
:param stack_on: A location to stack on
2966
:param stack_on_pwd: If stack_on is relative, the location it is
2969
RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
2971
self._repository = repository
2973
def acquire_repository(self, make_working_trees=None, shared=False):
2974
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2976
Returns an existing repository to use
2978
self._add_fallback(self._repository)
2979
return self._repository
2982
# Please register new formats after old formats so that formats
2983
# appear in chronological order and format descriptions can build
2985
format_registry = BzrDirFormatRegistry()
2986
format_registry.register('weave', BzrDirFormat6,
2987
'Pre-0.8 format. Slower than knit and does not'
2988
' support checkouts or shared repositories.',
2990
format_registry.register_metadir('metaweave',
2991
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2992
'Transitional format in 0.8. Slower than knit.',
2993
branch_format='bzrlib.branch.BzrBranchFormat5',
2994
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2996
format_registry.register_metadir('knit',
2997
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2998
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2999
branch_format='bzrlib.branch.BzrBranchFormat5',
3000
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3002
format_registry.register_metadir('dirstate',
3003
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3004
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
3005
'above when accessed over the network.',
3006
branch_format='bzrlib.branch.BzrBranchFormat5',
3007
# this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
3008
# directly from workingtree_4 triggers a circular import.
3009
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3011
format_registry.register_metadir('dirstate-tags',
3012
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3013
help='New in 0.15: Fast local operations and improved scaling for '
3014
'network operations. Additionally adds support for tags.'
3015
' Incompatible with bzr < 0.15.',
3016
branch_format='bzrlib.branch.BzrBranchFormat6',
3017
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3019
format_registry.register_metadir('rich-root',
3020
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
3021
help='New in 1.0. Better handling of tree roots. Incompatible with'
3023
branch_format='bzrlib.branch.BzrBranchFormat6',
3024
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3026
format_registry.register_metadir('dirstate-with-subtree',
3027
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
3028
help='New in 0.15: Fast local operations and improved scaling for '
3029
'network operations. Additionally adds support for versioning nested '
3030
'bzr branches. Incompatible with bzr < 0.15.',
3031
branch_format='bzrlib.branch.BzrBranchFormat6',
3032
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3036
format_registry.register_metadir('pack-0.92',
3037
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack1',
3038
help='New in 0.92: Pack-based format with data compatible with '
3039
'dirstate-tags format repositories. Interoperates with '
3040
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
3041
'Previously called knitpack-experimental. '
3042
'For more information, see '
3043
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
3044
branch_format='bzrlib.branch.BzrBranchFormat6',
3045
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3047
format_registry.register_metadir('pack-0.92-subtree',
3048
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack3',
3049
help='New in 0.92: Pack-based format with data compatible with '
3050
'dirstate-with-subtree format repositories. Interoperates with '
3051
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
3052
'Previously called knitpack-experimental. '
3053
'For more information, see '
3054
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
3055
branch_format='bzrlib.branch.BzrBranchFormat6',
3056
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3060
format_registry.register_metadir('rich-root-pack',
3061
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3062
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3063
'(needed for bzr-svn).',
3064
branch_format='bzrlib.branch.BzrBranchFormat6',
3065
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3067
format_registry.register_metadir('1.6',
3068
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3069
help='A format that allows a branch to indicate that there is another '
3070
'(stacked) repository that should be used to access data that is '
3071
'not present locally.',
3072
branch_format='bzrlib.branch.BzrBranchFormat7',
3073
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3075
format_registry.register_metadir('1.6.1-rich-root',
3076
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3077
help='A variant of 1.6 that supports rich-root data '
3078
'(needed for bzr-svn).',
3079
branch_format='bzrlib.branch.BzrBranchFormat7',
3080
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3082
format_registry.register_metadir('1.9',
3083
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3084
help='A repository format using B+tree indexes. These indexes '
3085
'are smaller in size, have smarter caching and provide faster '
3086
'performance for most operations.',
3087
branch_format='bzrlib.branch.BzrBranchFormat7',
3088
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3090
format_registry.register_metadir('1.9-rich-root',
3091
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3092
help='A variant of 1.9 that supports rich-root data '
3093
'(needed for bzr-svn).',
3094
branch_format='bzrlib.branch.BzrBranchFormat7',
3095
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3097
format_registry.register_metadir('1.7preview',
3098
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3099
help='A format that supports stacking, views and content filtering',
3100
branch_format='bzrlib.branch.BzrBranchFormat7',
3101
tree_format='bzrlib.workingtree_5.WorkingTreeFormat5',
3103
format_registry.register_metadir('1.7preview-rich-root',
3104
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3105
help='A format that supports stacking, views, content filtering '
3106
'and rich root data (needed for bzr-svn). ',
3107
branch_format='bzrlib.branch.BzrBranchFormat7',
3108
tree_format='bzrlib.workingtree_5.WorkingTreeFormat5',
3110
# The following two formats should always just be aliases.
3111
format_registry.register_metadir('development',
3112
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3113
help='Current development format. Can convert data to and from pack-0.92 '
3114
'(and anything compatible with pack-0.92) format repositories. '
3115
'Repositories and branches in this format can only be read by bzr.dev. '
3117
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3119
branch_format='bzrlib.branch.BzrBranchFormat7',
3120
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3124
format_registry.register_metadir('development-subtree',
3125
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3126
help='Current development format, subtree variant. Can convert data to and '
3127
'from pack-0.92-subtree (and anything compatible with '
3128
'pack-0.92-subtree) format repositories. Repositories and branches in '
3129
'this format can only be read by bzr.dev. Please read '
3130
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3132
branch_format='bzrlib.branch.BzrBranchFormat7',
3133
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3137
# And the development formats above will have aliased one of the following:
3138
format_registry.register_metadir('development2',
3139
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3140
help='1.6.1 with B+Tree based index. '
3142
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3144
branch_format='bzrlib.branch.BzrBranchFormat7',
3145
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3149
format_registry.register_metadir('development2-subtree',
3150
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3151
help='1.6.1-subtree with B+Tree based index. '
3153
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3155
branch_format='bzrlib.branch.BzrBranchFormat7',
3156
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3160
# The current format that is made on 'bzr init'.
3161
format_registry.set_default('pack-0.92')