14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from __future__ import absolute_import
17
19
import bzrlib.bzrdir
19
21
from cStringIO import StringIO
46
48
from bzrlib.i18n import gettext, ngettext
51
# Explicitly import bzrlib.bzrdir so that the BzrProber
52
# is guaranteed to be registered.
49
55
from bzrlib import (
52
59
from bzrlib.decorators import (
174
181
For instance, if the branch is at URL/.bzr/branch,
175
182
Branch.open(URL) -> a Branch instance.
177
control = controldir.ControlDir.open(base, _unsupported,
178
possible_transports=possible_transports)
184
control = controldir.ControlDir.open(base,
185
possible_transports=possible_transports, _unsupported=_unsupported)
179
186
return control.open_branch(unsupported=_unsupported,
180
187
possible_transports=possible_transports)
1163
1170
def _set_config_location(self, name, url, config=None,
1164
1171
make_relative=False):
1165
1172
if config is None:
1166
config = self.get_config()
1173
config = self.get_config_stack()
1167
1174
if url is None:
1169
1176
elif make_relative:
1170
1177
url = urlutils.relative_url(self.base, url)
1171
config.set_user_option(name, url, warn_masked=True)
1178
config.set(name, url)
1173
1180
def _get_config_location(self, name, config=None):
1174
1181
if config is None:
1175
config = self.get_config()
1176
location = config.get_user_option(name)
1182
config = self.get_config_stack()
1183
location = config.get(name)
1177
1184
if location == '':
1178
1185
location = None
1179
1186
return location
1559
1566
heads that must be fetched if present, but no error is necessary if
1560
1567
they are not present.
1562
# For bzr native formats must_fetch is just the tip, and if_present_fetch
1569
# For bzr native formats must_fetch is just the tip, and
1570
# if_present_fetch are the tags.
1564
1571
must_fetch = set([self.last_revision()])
1565
1572
if_present_fetch = set()
1566
c = self.get_config()
1567
include_tags = c.get_user_option_as_bool('branch.fetch_tags',
1573
if self.get_config_stack().get('branch.fetch_tags'):
1571
1575
if_present_fetch = set(self.tags.get_reverse_tag_dict())
1572
1576
except errors.TagsNotSupported:
1993
1997
self.revision_id)
1996
class BranchFormatMetadir(bzrdir.BzrDirMetaComponentFormat, BranchFormat):
2000
class BranchFormatMetadir(bzrdir.BzrFormat, BranchFormat):
1997
2001
"""Base class for branch formats that live in meta directories.
2000
2004
def __init__(self):
2001
2005
BranchFormat.__init__(self)
2002
bzrdir.BzrDirMetaComponentFormat.__init__(self)
2006
bzrdir.BzrFormat.__init__(self)
2005
2009
def find_format(klass, controldir, name=None):
2043
2047
control_files.create_lock()
2044
2048
control_files.lock_write()
2046
utf8_files += [('format', self.get_format_string())]
2050
utf8_files += [('format', self.as_string())]
2047
2051
for (filename, content) in utf8_files:
2048
2052
branch_transport.put_bytes(
2049
2053
filename, content,
2091
2095
def supports_leaving_lock(self):
2098
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
2100
BranchFormat.check_support_status(self,
2101
allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
2103
bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
2104
recommend_upgrade=recommend_upgrade, basedir=basedir)
2095
2107
class BzrBranchFormat5(BranchFormatMetadir):
2096
2108
"""Bzr branch format 5.
2298
2310
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
2299
2311
branch_transport.put_bytes('location',
2300
2312
target_branch.user_url)
2301
branch_transport.put_bytes('format', self.get_format_string())
2313
branch_transport.put_bytes('format', self.as_string())
2302
2314
branch = self.open(
2303
2315
a_bzrdir, name, _found=True,
2304
2316
possible_transports=[target_branch.bzrdir.root_transport])
2706
2718
self._transport.put_bytes('last-revision', out_string,
2707
2719
mode=self.bzrdir._get_file_mode())
2722
def update_feature_flags(self, updated_flags):
2723
"""Update the feature flags for this branch.
2725
:param updated_flags: Dictionary mapping feature names to necessities
2726
A necessity can be None to indicate the feature should be removed
2728
self._format._update_feature_flags(updated_flags)
2729
self.control_transport.put_bytes('format', self._format.as_string())
2710
2732
class FullHistoryBzrBranch(BzrBranch):
2711
2733
"""Bzr branch which contains the full revision history."""
2961
2983
"""See Branch.set_push_location."""
2962
2984
self._master_branch_cache = None
2964
config = self.get_config()
2986
conf = self.get_config_stack()
2965
2987
if location is None:
2966
if config.get_user_option('bound') != 'True':
2988
if not conf.get('bound'):
2969
config.set_user_option('bound', 'False', warn_masked=True)
2991
conf.set('bound', 'False')
2972
2994
self._set_config_location('bound_location', location,
2974
config.set_user_option('bound', 'True', warn_masked=True)
2996
conf.set('bound', 'True')
2977
2999
def _get_bound_location(self, bound):
2978
3000
"""Return the bound location in the config file.
2980
3002
Return None if the bound parameter does not match"""
2981
config = self.get_config()
2982
config_bound = (config.get_user_option('bound') == 'True')
2983
if config_bound != bound:
3003
conf = self.get_config_stack()
3004
if conf.get('bound') != bound:
2985
return self._get_config_location('bound_location', config=config)
3006
return self._get_config_location('bound_location', config=conf)
2987
3008
def get_bound_location(self):
2988
3009
"""See Branch.set_push_location."""
2998
3019
## self._check_stackable_repo()
2999
3020
# stacked_on_location is only ever defined in branch.conf, so don't
3000
3021
# waste effort reading the whole stack of config files.
3001
config = self.get_config()._get_branch_data_config()
3022
conf = _mod_config.BranchOnlyStack(self)
3002
3023
stacked_url = self._get_config_location('stacked_on_location',
3004
3025
if stacked_url is None:
3005
3026
raise errors.NotStacked(self)
3027
return stacked_url.encode('utf-8')
3008
3029
@needs_read_lock
3009
3030
def get_rev_id(self, revno, history=None):
3214
3235
# Copying done; now update target format
3215
3236
new_branch._transport.put_bytes('format',
3216
format.get_format_string(),
3217
3238
mode=new_branch.bzrdir._get_file_mode())
3219
3240
# Clean up old files
3232
3253
format = BzrBranchFormat7()
3233
3254
branch._set_config_location('stacked_on_location', '')
3234
3255
# update target format
3235
branch._transport.put_bytes('format', format.get_format_string())
3256
branch._transport.put_bytes('format', format.as_string())
3238
3259
class Converter7to8(object):
3242
3263
format = BzrBranchFormat8()
3243
3264
branch._transport.put_bytes('references', '')
3244
3265
# update target format
3245
branch._transport.put_bytes('format', format.get_format_string())
3266
branch._transport.put_bytes('format', format.as_string())
3248
3269
class InterBranch(InterObject):