-# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
+# Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Stores per-repository settings."""
-from bzrlib import osutils
-from bzrlib.config import IniBasedConfig, config_dir, ensure_config_dir_exists, GlobalConfig
+from bzrlib import osutils, urlutils, trace
+from bzrlib.config import IniBasedConfig, config_dir, ensure_config_dir_exists, GlobalConfig, LocationConfig, Config, STORE_BRANCH, STORE_GLOBAL, STORE_LOCATION
+
+from bzrlib.plugins.svn.core import SubversionException
import os
-from scheme import BranchingScheme
+from bzrlib.plugins.svn import properties
# Settings are stored by UUID.
# Data stored includes default branching scheme and locations the repository
return None
return GlobalConfig()._get_user_option(name)
+ def get_reuse_revisions(self):
+ ret = self._get_user_option("reuse-revisions")
+ if ret is None:
+ return "other-branches"
+ assert ret in ("none", "other-branches", "removed-branches")
+ return ret
+
def get_branching_scheme(self):
"""Get the branching scheme.
:return: BranchingScheme instance.
"""
+ from mapping3.scheme import BranchingScheme
schemename = self._get_user_option("branching-scheme", use_global=False)
if schemename is not None:
return BranchingScheme.find_scheme(schemename.encode('ascii'))
except KeyError:
return None
+ def get_use_cache(self):
+ try:
+ return self._get_parser().get_bool(self.uuid, "use-cache")
+ except KeyError:
+ return True
+
+ def get_log_strip_trailing_newline(self):
+ """Check whether or not trailing newlines should be stripped in the
+ Subversion log message (where support by the bzr<->svn mapping used)."""
+ try:
+ return self._get_parser().get_bool(self.uuid, "log-strip-trailing-newline")
+ except KeyError:
+ return False
+
def branching_scheme_is_mandatory(self):
"""Check whether or not the branching scheme for this repository
is mandatory.
"""
- mandatory = self._get_user_option("branching-scheme-mandatory",
- use_global=False)
- if mandatory is not None:
- return bool(mandatory)
- return False
+ try:
+ return self._get_parser().get_bool(self.uuid, "branching-scheme-mandatory")
+ except KeyError:
+ return False
def get_override_svn_revprops(self):
"""Check whether or not bzr-svn should attempt to override Subversion revision
properties after committing."""
- try:
- return self._get_parser().get_bool(self.uuid, "override-svn-revprops")
- except KeyError:
- pass
+ def get_list(parser, section):
+ try:
+ if parser.get_bool(section, "override-svn-revprops"):
+ return [properties.PROP_REVISION_DATE, properties.PROP_REVISION_AUTHOR]
+ return []
+ except ValueError:
+ val = parser.get_value(section, "override-svn-revprops")
+ if not isinstance(val, list):
+ return [val]
+ return val
+ except KeyError:
+ return None
+ ret = get_list(self._get_parser(), self.uuid)
+ if ret is not None:
+ return ret
global_config = GlobalConfig()
+ return get_list(global_config._get_parser(), global_config._get_section())
+
+ def get_append_revisions_only(self):
+ """Check whether it is possible to remove revisions from the mainline.
+ """
try:
- return global_config._get_parser().get_bool(global_config._get_section(), "override-svn-revprops")
+ return self._get_parser().get_bool(self.uuid, "append_revisions_only")
except KeyError:
return None
f = open(self._get_filename(), 'wb')
self._get_parser().write(f)
f.close()
+
+
+class BranchConfig(Config):
+ def __init__(self, branch):
+ super(BranchConfig, self).__init__()
+ self._location_config = None
+ self._repository_config = None
+ self.branch = branch
+ self.option_sources = (self._get_location_config,
+ self._get_repository_config)
+
+ def _get_location_config(self):
+ if self._location_config is None:
+ self._location_config = LocationConfig(self.branch.base)
+ return self._location_config
+
+ def _get_repository_config(self):
+ if self._repository_config is None:
+ self._repository_config = SvnRepositoryConfig(self.branch.repository.uuid)
+ return self._repository_config
+
+ def get_set_revprops(self):
+ return self._get_repository_config().get_set_revprops()
+
+ def get_log_strip_trailing_newline(self):
+ return self._get_repository_config().get_log_strip_trailing_newline()
+
+ def get_override_svn_revprops(self):
+ return self._get_repository_config().get_override_svn_revprops()
+
+ def _get_user_option(self, option_name):
+ """See Config._get_user_option."""
+ for source in self.option_sources:
+ value = source()._get_user_option(option_name)
+ if value is not None:
+ return value
+ return None
+
+ def get_append_revisions_only(self):
+ return self.get_user_option("append_revision_only")
+
+ def _get_user_id(self):
+ """Get the user id from the 'email' key in the current section."""
+ return self._get_user_option('email')
+
+ def get_option(self, key, section=None):
+ if section == "BUILDDEB" and key == "merge":
+ revnum = self.branch.get_revnum()
+ try:
+ props = self.branch.repository.transport.get_dir(urlutils.join(self.branch.get_branch_path(revnum), "debian"), revnum)[2]
+ if props.has_key("mergeWithUpstream"):
+ return "True"
+ else:
+ return "False"
+ except SubversionException:
+ return None
+ return None
+
+ def set_user_option(self, name, value, store=STORE_LOCATION,
+ warn_masked=False):
+ if store == STORE_GLOBAL:
+ self._get_global_config().set_user_option(name, value)
+ elif store == STORE_BRANCH:
+ raise NotImplementedError("Saving in branch config not supported for Subversion branches")
+ else:
+ self._get_location_config().set_user_option(name, value, store)
+ if not warn_masked:
+ return
+ if store in (STORE_GLOBAL, STORE_BRANCH):
+ mask_value = self._get_location_config().get_user_option(name)
+ if mask_value is not None:
+ trace.warning('Value "%s" is masked by "%s" from'
+ ' locations.conf', value, mask_value)
+ else:
+ if store == STORE_GLOBAL:
+ branch_config = self._get_branch_data_config()
+ mask_value = branch_config.get_user_option(name)
+ if mask_value is not None:
+ trace.warning('Value "%s" is masked by "%s" from'
+ ' branch.conf', value, mask_value)