~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

(vila) Migrate branch location options to config stacks. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1169
1169
    def _set_config_location(self, name, url, config=None,
1170
1170
                             make_relative=False):
1171
1171
        if config is None:
1172
 
            config = self.get_config()
 
1172
            config = self.get_config_stack()
1173
1173
        if url is None:
1174
1174
            url = ''
1175
1175
        elif make_relative:
1176
1176
            url = urlutils.relative_url(self.base, url)
1177
 
        config.set_user_option(name, url, warn_masked=True)
 
1177
        config.set(name, url)
1178
1178
 
1179
1179
    def _get_config_location(self, name, config=None):
1180
1180
        if config is None:
1181
 
            config = self.get_config()
1182
 
        location = config.get_user_option(name)
1183
 
        if location == '':
 
1181
            config = self.get_config_stack()
 
1182
        location = config.get(name)
 
1183
        # FIXME: There is a glitch around quoting/unquoting in config stores:
 
1184
        # an empty string can be seen as '""' instead of '' -- vila 2011-12-20
 
1185
        if location in ('', '""') :
1184
1186
            location = None
1185
1187
        return location
1186
1188
 
2967
2969
        """See Branch.set_push_location."""
2968
2970
        self._master_branch_cache = None
2969
2971
        result = None
2970
 
        config = self.get_config()
 
2972
        conf = self.get_config_stack()
2971
2973
        if location is None:
2972
 
            if config.get_user_option('bound') != 'True':
 
2974
            if not conf.get('bound'):
2973
2975
                return False
2974
2976
            else:
2975
 
                config.set_user_option('bound', 'False', warn_masked=True)
 
2977
                conf.set('bound', 'False')
2976
2978
                return True
2977
2979
        else:
2978
2980
            self._set_config_location('bound_location', location,
2979
 
                                      config=config)
2980
 
            config.set_user_option('bound', 'True', warn_masked=True)
 
2981
                                      config=conf)
 
2982
            conf.set('bound', 'True')
2981
2983
        return True
2982
2984
 
2983
2985
    def _get_bound_location(self, bound):
2984
2986
        """Return the bound location in the config file.
2985
2987
 
2986
2988
        Return None if the bound parameter does not match"""
2987
 
        config = self.get_config()
2988
 
        config_bound = (config.get_user_option('bound') == 'True')
2989
 
        if config_bound != bound:
 
2989
        conf = self.get_config_stack()
 
2990
        if conf.get('bound') != bound:
2990
2991
            return None
2991
 
        return self._get_config_location('bound_location', config=config)
 
2992
        return self._get_config_location('bound_location', config=conf)
2992
2993
 
2993
2994
    def get_bound_location(self):
2994
2995
        """See Branch.set_push_location."""
3004
3005
        ## self._check_stackable_repo()
3005
3006
        # stacked_on_location is only ever defined in branch.conf, so don't
3006
3007
        # waste effort reading the whole stack of config files.
3007
 
        config = self.get_config()._get_branch_data_config()
 
3008
        conf = _mod_config.BranchOnlyStack(self)
3008
3009
        stacked_url = self._get_config_location('stacked_on_location',
3009
 
            config=config)
 
3010
                                                config=conf)
3010
3011
        if stacked_url is None:
3011
3012
            raise errors.NotStacked(self)
3012
3013
        return stacked_url