1
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
1
# Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
5
# the Free Software Foundation; either version 3 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
16
"""Stores per-repository settings."""
18
from bzrlib import osutils
19
from bzrlib.config import IniBasedConfig, config_dir, ensure_config_dir_exists, GlobalConfig
18
from bzrlib import osutils, urlutils, trace
19
from bzrlib.config import IniBasedConfig, config_dir, ensure_config_dir_exists, GlobalConfig, LocationConfig, Config, STORE_BRANCH, STORE_GLOBAL, STORE_LOCATION
23
from scheme import BranchingScheme
25
25
# Settings are stored by UUID.
26
26
# Data stored includes default branching scheme and locations the repository
58
58
return GlobalConfig()._get_user_option(name)
60
def get_reuse_revisions(self):
61
ret = self._get_user_option("reuse-revisions")
63
return "other-branches"
64
assert ret in ("none", "other-branches", "removed-branches")
60
67
def get_branching_scheme(self):
61
68
"""Get the branching scheme.
63
70
:return: BranchingScheme instance.
72
from mapping3.scheme import BranchingScheme
65
73
schemename = self._get_user_option("branching-scheme", use_global=False)
66
74
if schemename is not None:
67
75
return BranchingScheme.find_scheme(schemename.encode('ascii'))
95
117
def get_override_svn_revprops(self):
96
118
"""Check whether or not bzr-svn should attempt to override Subversion revision
97
119
properties after committing."""
99
return self._get_parser().get_bool(self.uuid, "override-svn-revprops")
120
def get_list(parser, section):
122
if parser.get_bool(section, "override-svn-revprops"):
123
return [svn.core.SVN_PROP_REVISION_DATE, svn.core.SVN_PROP_REVISION_AUTHOR]
126
return parser.get_value(section, "override-svn-revprops")
129
ret = get_list(self._get_parser(), self.uuid)
102
132
global_config = GlobalConfig()
133
return get_list(global_config._get_parser(), global_config._get_section())
135
def get_append_revisions_only(self):
136
"""Check whether it is possible to remove revisions from the mainline.
104
return global_config._get_parser().get_bool(global_config._get_section(), "override-svn-revprops")
139
return self._get_parser().get_bool(self.uuid, "append_revisions_only")
136
171
f = open(self._get_filename(), 'wb')
137
172
self._get_parser().write(f)
176
class BranchConfig(Config):
177
def __init__(self, branch):
178
super(BranchConfig, self).__init__()
179
self._location_config = None
180
self._repository_config = None
182
self.option_sources = (self._get_location_config,
183
self._get_repository_config)
185
def _get_location_config(self):
186
if self._location_config is None:
187
self._location_config = LocationConfig(self.branch.base)
188
return self._location_config
190
def _get_repository_config(self):
191
if self._repository_config is None:
192
self._repository_config = SvnRepositoryConfig(self.branch.repository.uuid)
193
return self._repository_config
195
def get_set_revprops(self):
196
return self._get_repository_config().get_set_revprops()
198
def get_log_strip_trailing_newline(self):
199
return self._get_repository_config().get_log_strip_trailing_newline()
201
def get_override_svn_revprops(self):
202
return self._get_repository_config().get_override_svn_revprops()
204
def _get_user_option(self, option_name):
205
"""See Config._get_user_option."""
206
for source in self.option_sources:
207
value = source()._get_user_option(option_name)
208
if value is not None:
212
def get_append_revisions_only(self):
213
return self.get_user_option("append_revision_only")
215
def _get_user_id(self):
216
"""Get the user id from the 'email' key in the current section."""
217
return self._get_user_option('email')
219
def get_option(self, key, section=None):
220
if section == "BUILDDEB" and key == "merge":
221
revnum = self.branch.get_revnum()
223
props = self.branch.repository.transport.get_dir(urlutils.join(self.branch.get_branch_path(revnum), "debian"), revnum)[2]
224
if props.has_key("mergeWithUpstream"):
228
except svn.core.SubversionException:
232
def set_user_option(self, name, value, store=STORE_LOCATION,
234
if store == STORE_GLOBAL:
235
self._get_global_config().set_user_option(name, value)
236
elif store == STORE_BRANCH:
237
raise NotImplementedError("Saving in branch config not supported for Subversion branches")
239
self._get_location_config().set_user_option(name, value, store)
242
if store in (STORE_GLOBAL, STORE_BRANCH):
243
mask_value = self._get_location_config().get_user_option(name)
244
if mask_value is not None:
245
trace.warning('Value "%s" is masked by "%s" from'
246
' locations.conf', value, mask_value)
248
if store == STORE_GLOBAL:
249
branch_config = self._get_branch_data_config()
250
mask_value = branch_config.get_user_option(name)
251
if mask_value is not None:
252
trace.warning('Value "%s" is masked by "%s" from'
253
' branch.conf', value, mask_value)