~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-24 10:10:59 UTC
  • mfrom: (6405 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6407.
  • Revision ID: jelmer@samba.org-20111224101059-epghsc5y61hsgbl2
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
import bzrlib.bzrdir
54
54
 
55
55
from bzrlib import (
 
56
    bzrdir,
56
57
    controldir,
57
58
    )
58
59
from bzrlib.decorators import (
1169
1170
    def _set_config_location(self, name, url, config=None,
1170
1171
                             make_relative=False):
1171
1172
        if config is None:
1172
 
            config = self.get_config()
 
1173
            config = self.get_config_stack()
1173
1174
        if url is None:
1174
1175
            url = ''
1175
1176
        elif make_relative:
1176
1177
            url = urlutils.relative_url(self.base, url)
1177
 
        config.set_user_option(name, url, warn_masked=True)
 
1178
        config.set(name, url)
1178
1179
 
1179
1180
    def _get_config_location(self, name, config=None):
1180
1181
        if config is None:
1181
 
            config = self.get_config()
1182
 
        location = config.get_user_option(name)
 
1182
            config = self.get_config_stack()
 
1183
        location = config.get(name)
1183
1184
        if location == '':
1184
1185
            location = None
1185
1186
        return location
1587
1588
 
1588
1589
    Formats provide three things:
1589
1590
     * An initialization routine,
1590
 
     * a format string,
 
1591
     * a format description
1591
1592
     * an open routine.
1592
1593
 
1593
1594
    Formats are placed in an dict by their format string for reference
1999
2000
            self.revision_id)
2000
2001
 
2001
2002
 
2002
 
class BranchFormatMetadir(bzrdir.BzrDirMetaComponentFormat, BranchFormat):
 
2003
class BranchFormatMetadir(bzrdir.BzrFormat, BranchFormat):
2003
2004
    """Base class for branch formats that live in meta directories.
2004
2005
    """
2005
2006
 
2006
2007
    def __init__(self):
2007
2008
        BranchFormat.__init__(self)
2008
 
        bzrdir.BzrDirMetaComponentFormat.__init__(self)
 
2009
        bzrdir.BzrFormat.__init__(self)
2009
2010
 
2010
2011
    @classmethod
2011
2012
    def find_format(klass, controldir, name=None):
2049
2050
        control_files.create_lock()
2050
2051
        control_files.lock_write()
2051
2052
        try:
2052
 
            utf8_files += [('format', self.get_format_string())]
 
2053
            utf8_files += [('format', self.as_string())]
2053
2054
            for (filename, content) in utf8_files:
2054
2055
                branch_transport.put_bytes(
2055
2056
                    filename, content,
2097
2098
    def supports_leaving_lock(self):
2098
2099
        return True
2099
2100
 
 
2101
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
 
2102
            basedir=None):
 
2103
        BranchFormat.check_support_status(self,
 
2104
            allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
 
2105
            basedir=basedir)
 
2106
        bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
 
2107
            recommend_upgrade=recommend_upgrade, basedir=basedir)
 
2108
 
2100
2109
 
2101
2110
class BzrBranchFormat5(BranchFormatMetadir):
2102
2111
    """Bzr branch format 5.
2304
2313
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
2305
2314
        branch_transport.put_bytes('location',
2306
2315
            target_branch.user_url)
2307
 
        branch_transport.put_bytes('format', self.get_format_string())
 
2316
        branch_transport.put_bytes('format', self.as_string())
2308
2317
        branch = self.open(
2309
2318
            a_bzrdir, name, _found=True,
2310
2319
            possible_transports=[target_branch.bzrdir.root_transport])
2967
2976
        """See Branch.set_push_location."""
2968
2977
        self._master_branch_cache = None
2969
2978
        result = None
2970
 
        config = self.get_config()
 
2979
        conf = self.get_config_stack()
2971
2980
        if location is None:
2972
 
            if config.get_user_option('bound') != 'True':
 
2981
            if not conf.get('bound'):
2973
2982
                return False
2974
2983
            else:
2975
 
                config.set_user_option('bound', 'False', warn_masked=True)
 
2984
                conf.set('bound', 'False')
2976
2985
                return True
2977
2986
        else:
2978
2987
            self._set_config_location('bound_location', location,
2979
 
                                      config=config)
2980
 
            config.set_user_option('bound', 'True', warn_masked=True)
 
2988
                                      config=conf)
 
2989
            conf.set('bound', 'True')
2981
2990
        return True
2982
2991
 
2983
2992
    def _get_bound_location(self, bound):
2984
2993
        """Return the bound location in the config file.
2985
2994
 
2986
2995
        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:
 
2996
        conf = self.get_config_stack()
 
2997
        if conf.get('bound') != bound:
2990
2998
            return None
2991
 
        return self._get_config_location('bound_location', config=config)
 
2999
        return self._get_config_location('bound_location', config=conf)
2992
3000
 
2993
3001
    def get_bound_location(self):
2994
3002
        """See Branch.set_push_location."""
3004
3012
        ## self._check_stackable_repo()
3005
3013
        # stacked_on_location is only ever defined in branch.conf, so don't
3006
3014
        # waste effort reading the whole stack of config files.
3007
 
        config = self.get_config()._get_branch_data_config()
 
3015
        conf = _mod_config.BranchOnlyStack(self)
3008
3016
        stacked_url = self._get_config_location('stacked_on_location',
3009
 
            config=config)
 
3017
                                                config=conf)
3010
3018
        if stacked_url is None:
3011
3019
            raise errors.NotStacked(self)
3012
3020
        return stacked_url
3219
3227
 
3220
3228
        # Copying done; now update target format
3221
3229
        new_branch._transport.put_bytes('format',
3222
 
            format.get_format_string(),
 
3230
            format.as_string(),
3223
3231
            mode=new_branch.bzrdir._get_file_mode())
3224
3232
 
3225
3233
        # Clean up old files
3238
3246
        format = BzrBranchFormat7()
3239
3247
        branch._set_config_location('stacked_on_location', '')
3240
3248
        # update target format
3241
 
        branch._transport.put_bytes('format', format.get_format_string())
 
3249
        branch._transport.put_bytes('format', format.as_string())
3242
3250
 
3243
3251
 
3244
3252
class Converter7to8(object):
3248
3256
        format = BzrBranchFormat8()
3249
3257
        branch._transport.put_bytes('references', '')
3250
3258
        # update target format
3251
 
        branch._transport.put_bytes('format', format.get_format_string())
 
3259
        branch._transport.put_bytes('format', format.as_string())
3252
3260
 
3253
3261
 
3254
3262
class InterBranch(InterObject):