1
# Copyright (C) 2005-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from __future__ import absolute_import
28
revision as _mod_revision,
30
from ..repository import (
35
from ..sixish import (
40
class MetaDirRepository(Repository):
41
"""Repositories in the new meta-dir layout.
43
:ivar _transport: Transport for access to repository control files,
44
typically pointing to .bzr/repository.
47
def __init__(self, _format, a_bzrdir, control_files):
48
super(MetaDirRepository, self).__init__(
49
_format, a_bzrdir, control_files)
50
self._transport = control_files._transport
53
"""Return True if this repository is flagged as a shared repository."""
54
return self._transport.has('shared-storage')
56
def set_make_working_trees(self, new_value):
57
"""Set the policy flag for making working trees when creating branches.
59
This only applies to branches that use this repository.
61
The default is 'True'.
62
:param new_value: True to restore the default, False to disable making
65
with self.lock_write():
68
self._transport.delete('no-working-trees')
69
except errors.NoSuchFile:
72
self._transport.put_bytes(
73
'no-working-trees', b'',
74
mode=self.controldir._get_file_mode())
76
def make_working_trees(self):
77
"""Returns the policy for making working trees on new branches."""
78
return not self._transport.has('no-working-trees')
80
def update_feature_flags(self, updated_flags):
81
"""Update the feature flags for this branch.
83
:param updated_flags: Dictionary mapping feature names to necessities
84
A necessity can be None to indicate the feature should be removed
86
with self.lock_write():
87
self._format._update_feature_flags(updated_flags)
88
self.control_transport.put_bytes(
89
'format', self._format.as_string())
91
def _find_parent_ids_of_revisions(self, revision_ids):
92
"""Find all parent ids that are mentioned in the revision graph.
94
:return: set of revisions that are parents of revision_ids which are
95
not part of revision_ids themselves
97
parent_ids = set(itertools.chain.from_iterable(viewvalues(
98
self.get_parent_map(revision_ids))))
99
parent_ids.difference_update(revision_ids)
100
parent_ids.discard(_mod_revision.NULL_REVISION)
104
class RepositoryFormatMetaDir(bzrdir.BzrFormat, RepositoryFormat):
105
"""Common base class for the new repositories using the metadir layout."""
107
rich_root_data = False
108
supports_tree_reference = False
109
supports_external_lookups = False
110
supports_leaving_lock = True
111
supports_nesting_repositories = True
114
def _matchingcontroldir(self):
115
matching = bzrdir.BzrDirMetaFormat1()
116
matching.repository_format = self
120
RepositoryFormat.__init__(self)
121
bzrdir.BzrFormat.__init__(self)
123
def _create_control_files(self, a_bzrdir):
124
"""Create the required files and the initial control_files object."""
125
# FIXME: RBC 20060125 don't peek under the covers
126
# NB: no need to escape relative paths that are url safe.
127
repository_transport = a_bzrdir.get_repository_transport(self)
128
control_files = lockable_files.LockableFiles(repository_transport,
129
'lock', lockdir.LockDir)
130
control_files.create_lock()
133
def _upload_blank_content(self, a_bzrdir, dirs, files, utf8_files, shared):
134
"""Upload the initial blank content."""
135
control_files = self._create_control_files(a_bzrdir)
136
control_files.lock_write()
137
transport = control_files._transport
139
utf8_files += [('shared-storage', b'')]
142
transport.mkdir(dir, mode=a_bzrdir._get_dir_mode())
143
for (filename, content_stream) in files:
144
transport.put_file(filename, content_stream,
145
mode=a_bzrdir._get_file_mode())
146
for (filename, content_bytes) in utf8_files:
147
transport.put_bytes_non_atomic(filename, content_bytes,
148
mode=a_bzrdir._get_file_mode())
150
control_files.unlock()
153
def find_format(klass, a_bzrdir):
154
"""Return the format for the repository object in a_bzrdir.
156
This is used by brz native formats that have a "format" file in
157
the repository. Other methods may be used by different types of
161
transport = a_bzrdir.get_repository_transport(None)
162
format_string = transport.get_bytes("format")
163
except errors.NoSuchFile:
164
raise errors.NoRepositoryPresent(a_bzrdir)
165
return klass._find_format(format_registry, 'repository', format_string)
167
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
169
RepositoryFormat.check_support_status(self,
170
allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
172
bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
173
recommend_upgrade=recommend_upgrade, basedir=basedir)