1 # Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
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
16 """Stores per-repository settings."""
18 from bzrlib import osutils
19 from bzrlib.config import IniBasedConfig, config_dir, ensure_config_dir_exists, GlobalConfig
23 from scheme import BranchingScheme
25 # Settings are stored by UUID.
26 # Data stored includes default branching scheme and locations the repository
29 def subversion_config_filename():
30 """Return per-user configuration ini file filename."""
31 return osutils.pathjoin(config_dir(), 'subversion.conf')
34 class SvnRepositoryConfig(IniBasedConfig):
35 """Per-repository settings."""
37 def __init__(self, uuid):
38 name_generator = subversion_config_filename
39 super(SvnRepositoryConfig, self).__init__(name_generator)
41 if not self.uuid in self._get_parser():
42 self._get_parser()[self.uuid] = {}
44 def set_branching_scheme(self, scheme, mandatory=False):
45 """Change the branching scheme.
47 :param scheme: New branching scheme.
49 self.set_user_option('branching-scheme', str(scheme))
50 self.set_user_option('branching-scheme-mandatory', str(mandatory))
52 def _get_user_option(self, name, use_global=True):
54 return self._get_parser()[self.uuid][name]
58 return GlobalConfig()._get_user_option(name)
60 def get_branching_scheme(self):
61 """Get the branching scheme.
63 :return: BranchingScheme instance.
65 schemename = self._get_user_option("branching-scheme", use_global=False)
66 if schemename is not None:
67 return BranchingScheme.find_scheme(schemename.encode('ascii'))
70 def get_set_revprops(self):
71 """Check whether or not bzr-svn should attempt to store Bazaar
72 revision properties in Subversion revision properties during commit."""
74 return self._get_parser().get_bool(self.uuid, "set-revprops")
78 def get_supports_change_revprop(self):
79 """Check whether or not the repository supports changing existing
80 revision properties."""
82 return self._get_parser().get_bool(self.uuid, "supports-change-revprop")
86 def branching_scheme_is_mandatory(self):
87 """Check whether or not the branching scheme for this repository
91 return self._get_parser().get_bool(self.uuid, "branching-scheme-mandatory")
95 def get_override_svn_revprops(self):
96 """Check whether or not bzr-svn should attempt to override Subversion revision
97 properties after committing."""
99 return self._get_parser().get_bool(self.uuid, "override-svn-revprops")
102 global_config = GlobalConfig()
104 return global_config._get_parser().get_bool(global_config._get_section(), "override-svn-revprops")
108 def get_locations(self):
109 """Find the locations this repository has been seen at.
111 :return: Set with URLs.
113 val = self._get_user_option("locations", use_global=False)
116 return set(val.split(";"))
118 def add_location(self, location):
119 """Add a location for this repository.
121 :param location: URL of location to add.
123 locations = self.get_locations()
124 locations.add(location.rstrip("/"))
125 self.set_user_option('locations', ";".join(list(locations)))
127 def set_user_option(self, name, value):
128 """Change a user option.
130 :param name: Name of the option.
131 :param value: Value of the option.
133 conf_dir = os.path.dirname(self._get_filename())
134 ensure_config_dir_exists(conf_dir)
135 self._get_parser()[self.uuid][name] = value
136 f = open(self._get_filename(), 'wb')
137 self._get_parser().write(f)