~bzr/ubuntu/maverick/bzr-svn/bzr-ppa

« back to all changes in this revision

Viewing changes to config.py

  • Committer: Jelmer Vernooij
  • Date: 2008-05-11 19:29:26 UTC
  • mfrom: (220.36.144 0.4)
  • Revision ID: jelmer@samba.org-20080511192926-7mh02j45r25qmzkz
Merge 0.4 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
 
1
# Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
2
2
 
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.
7
7
 
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."""
17
17
 
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
20
20
 
21
21
import os
22
22
 
23
 
from scheme import BranchingScheme
 
23
import svn.core
24
24
 
25
25
# Settings are stored by UUID. 
26
26
# Data stored includes default branching scheme and locations the repository 
57
57
                return None
58
58
            return GlobalConfig()._get_user_option(name)
59
59
 
 
60
    def get_reuse_revisions(self):
 
61
        ret = self._get_user_option("reuse-revisions")
 
62
        if ret is None:
 
63
            return "other-branches"
 
64
        assert ret in ("none", "other-branches", "removed-branches")
 
65
        return ret
 
66
 
60
67
    def get_branching_scheme(self):
61
68
        """Get the branching scheme.
62
69
 
63
70
        :return: BranchingScheme instance.
64
71
        """
 
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'))
83
91
        except KeyError:
84
92
            return None
85
93
 
 
94
    def get_use_cache(self):
 
95
        try:
 
96
            return self._get_parser().get_bool(self.uuid, "use-cache")
 
97
        except KeyError:
 
98
            return True
 
99
 
 
100
    def get_log_strip_trailing_newline(self):
 
101
        """Check whether or not trailing newlines should be stripped in the 
 
102
        Subversion log message (where support by the bzr<->svn mapping used)."""
 
103
        try:
 
104
            return self._get_parser().get_bool(self.uuid, "log-strip-trailing-newline")
 
105
        except KeyError:
 
106
            return False
 
107
 
86
108
    def branching_scheme_is_mandatory(self):
87
109
        """Check whether or not the branching scheme for this repository 
88
110
        is mandatory.
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."""
98
 
        try:
99
 
            return self._get_parser().get_bool(self.uuid, "override-svn-revprops")
100
 
        except KeyError:
101
 
            pass
 
120
        def get_list(parser, section):
 
121
            try:
 
122
                if parser.get_bool(section, "override-svn-revprops"):
 
123
                    return [svn.core.SVN_PROP_REVISION_DATE, svn.core.SVN_PROP_REVISION_AUTHOR]
 
124
                return []
 
125
            except ValueError:
 
126
                return parser.get_value(section, "override-svn-revprops")
 
127
            except KeyError:
 
128
                return None
 
129
        ret = get_list(self._get_parser(), self.uuid)
 
130
        if ret is not None:
 
131
            return ret
102
132
        global_config = GlobalConfig()
 
133
        return get_list(global_config._get_parser(), global_config._get_section())
 
134
 
 
135
    def get_append_revisions_only(self):
 
136
        """Check whether it is possible to remove revisions from the mainline.
 
137
        """
103
138
        try:
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")
105
140
        except KeyError:
106
141
            return None
107
142
 
136
171
        f = open(self._get_filename(), 'wb')
137
172
        self._get_parser().write(f)
138
173
        f.close()
 
174
 
 
175
 
 
176
class BranchConfig(Config):
 
177
    def __init__(self, branch):
 
178
        super(BranchConfig, self).__init__()
 
179
        self._location_config = None
 
180
        self._repository_config = None
 
181
        self.branch = branch
 
182
        self.option_sources = (self._get_location_config, 
 
183
                               self._get_repository_config)
 
184
 
 
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
 
189
 
 
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
 
194
 
 
195
    def get_set_revprops(self):
 
196
        return self._get_repository_config().get_set_revprops()
 
197
 
 
198
    def get_log_strip_trailing_newline(self):
 
199
        return self._get_repository_config().get_log_strip_trailing_newline()
 
200
 
 
201
    def get_override_svn_revprops(self):
 
202
        return self._get_repository_config().get_override_svn_revprops()
 
203
 
 
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:
 
209
                return value
 
210
        return None
 
211
 
 
212
    def get_append_revisions_only(self):
 
213
        return self.get_user_option("append_revision_only")
 
214
 
 
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')
 
218
 
 
219
    def get_option(self, key, section=None):
 
220
        if section == "BUILDDEB" and key == "merge":
 
221
            revnum = self.branch.get_revnum()
 
222
            try:
 
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"):
 
225
                    return "True"
 
226
                else:
 
227
                    return "False"
 
228
            except svn.core.SubversionException:
 
229
                return None
 
230
        return None
 
231
 
 
232
    def set_user_option(self, name, value, store=STORE_LOCATION,
 
233
        warn_masked=False):
 
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")
 
238
        else:
 
239
            self._get_location_config().set_user_option(name, value, store)
 
240
        if not warn_masked:
 
241
            return
 
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)
 
247
            else:
 
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)