~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Packman
  • Date: 2012-01-05 10:44:12 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6427.
  • Revision ID: martin.packman@canonical.com-20120105104412-z03fi9m43h946fvs
Merge bzr.dev to resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
import bzrlib.bzrdir
18
20
 
19
21
from cStringIO import StringIO
46
48
from bzrlib.i18n import gettext, ngettext
47
49
""")
48
50
 
 
51
# Explicitly import bzrlib.bzrdir so that the BzrProber
 
52
# is guaranteed to be registered.
 
53
import bzrlib.bzrdir
 
54
 
49
55
from bzrlib import (
 
56
    bzrdir,
50
57
    controldir,
51
58
    )
52
59
from bzrlib.decorators import (
174
181
        For instance, if the branch is at URL/.bzr/branch,
175
182
        Branch.open(URL) -> a Branch instance.
176
183
        """
177
 
        control = controldir.ControlDir.open(base, _unsupported,
178
 
                                     possible_transports=possible_transports)
 
184
        control = controldir.ControlDir.open(base,
 
185
            possible_transports=possible_transports, _unsupported=_unsupported)
179
186
        return control.open_branch(unsupported=_unsupported,
180
187
            possible_transports=possible_transports)
181
188
 
1163
1170
    def _set_config_location(self, name, url, config=None,
1164
1171
                             make_relative=False):
1165
1172
        if config is None:
1166
 
            config = self.get_config()
 
1173
            config = self.get_config_stack()
1167
1174
        if url is None:
1168
1175
            url = ''
1169
1176
        elif make_relative:
1170
1177
            url = urlutils.relative_url(self.base, url)
1171
 
        config.set_user_option(name, url, warn_masked=True)
 
1178
        config.set(name, url)
1172
1179
 
1173
1180
    def _get_config_location(self, name, config=None):
1174
1181
        if config is None:
1175
 
            config = self.get_config()
1176
 
        location = config.get_user_option(name)
 
1182
            config = self.get_config_stack()
 
1183
        location = config.get(name)
1177
1184
        if location == '':
1178
1185
            location = None
1179
1186
        return location
1559
1566
            heads that must be fetched if present, but no error is necessary if
1560
1567
            they are not present.
1561
1568
        """
1562
 
        # For bzr native formats must_fetch is just the tip, and if_present_fetch
1563
 
        # are the tags.
 
1569
        # For bzr native formats must_fetch is just the tip, and
 
1570
        # if_present_fetch are the tags.
1564
1571
        must_fetch = set([self.last_revision()])
1565
1572
        if_present_fetch = set()
1566
 
        c = self.get_config()
1567
 
        include_tags = c.get_user_option_as_bool('branch.fetch_tags',
1568
 
                                                 default=False)
1569
 
        if include_tags:
 
1573
        if self.get_config_stack().get('branch.fetch_tags'):
1570
1574
            try:
1571
1575
                if_present_fetch = set(self.tags.get_reverse_tag_dict())
1572
1576
            except errors.TagsNotSupported:
1581
1585
 
1582
1586
    Formats provide three things:
1583
1587
     * An initialization routine,
1584
 
     * a format string,
 
1588
     * a format description
1585
1589
     * an open routine.
1586
1590
 
1587
1591
    Formats are placed in an dict by their format string for reference
1993
1997
            self.revision_id)
1994
1998
 
1995
1999
 
1996
 
class BranchFormatMetadir(bzrdir.BzrDirMetaComponentFormat, BranchFormat):
 
2000
class BranchFormatMetadir(bzrdir.BzrFormat, BranchFormat):
1997
2001
    """Base class for branch formats that live in meta directories.
1998
2002
    """
1999
2003
 
2000
2004
    def __init__(self):
2001
2005
        BranchFormat.__init__(self)
2002
 
        bzrdir.BzrDirMetaComponentFormat.__init__(self)
 
2006
        bzrdir.BzrFormat.__init__(self)
2003
2007
 
2004
2008
    @classmethod
2005
2009
    def find_format(klass, controldir, name=None):
2043
2047
        control_files.create_lock()
2044
2048
        control_files.lock_write()
2045
2049
        try:
2046
 
            utf8_files += [('format', self.get_format_string())]
 
2050
            utf8_files += [('format', self.as_string())]
2047
2051
            for (filename, content) in utf8_files:
2048
2052
                branch_transport.put_bytes(
2049
2053
                    filename, content,
2091
2095
    def supports_leaving_lock(self):
2092
2096
        return True
2093
2097
 
 
2098
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
 
2099
            basedir=None):
 
2100
        BranchFormat.check_support_status(self,
 
2101
            allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
 
2102
            basedir=basedir)
 
2103
        bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
 
2104
            recommend_upgrade=recommend_upgrade, basedir=basedir)
 
2105
 
2094
2106
 
2095
2107
class BzrBranchFormat5(BranchFormatMetadir):
2096
2108
    """Bzr branch format 5.
2298
2310
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
2299
2311
        branch_transport.put_bytes('location',
2300
2312
            target_branch.user_url)
2301
 
        branch_transport.put_bytes('format', self.get_format_string())
 
2313
        branch_transport.put_bytes('format', self.as_string())
2302
2314
        branch = self.open(
2303
2315
            a_bzrdir, name, _found=True,
2304
2316
            possible_transports=[target_branch.bzrdir.root_transport])
2706
2718
        self._transport.put_bytes('last-revision', out_string,
2707
2719
            mode=self.bzrdir._get_file_mode())
2708
2720
 
 
2721
    @needs_write_lock
 
2722
    def update_feature_flags(self, updated_flags):
 
2723
        """Update the feature flags for this branch.
 
2724
 
 
2725
        :param updated_flags: Dictionary mapping feature names to necessities
 
2726
            A necessity can be None to indicate the feature should be removed
 
2727
        """
 
2728
        self._format._update_feature_flags(updated_flags)
 
2729
        self.control_transport.put_bytes('format', self._format.as_string())
 
2730
 
2709
2731
 
2710
2732
class FullHistoryBzrBranch(BzrBranch):
2711
2733
    """Bzr branch which contains the full revision history."""
2961
2983
        """See Branch.set_push_location."""
2962
2984
        self._master_branch_cache = None
2963
2985
        result = None
2964
 
        config = self.get_config()
 
2986
        conf = self.get_config_stack()
2965
2987
        if location is None:
2966
 
            if config.get_user_option('bound') != 'True':
 
2988
            if not conf.get('bound'):
2967
2989
                return False
2968
2990
            else:
2969
 
                config.set_user_option('bound', 'False', warn_masked=True)
 
2991
                conf.set('bound', 'False')
2970
2992
                return True
2971
2993
        else:
2972
2994
            self._set_config_location('bound_location', location,
2973
 
                                      config=config)
2974
 
            config.set_user_option('bound', 'True', warn_masked=True)
 
2995
                                      config=conf)
 
2996
            conf.set('bound', 'True')
2975
2997
        return True
2976
2998
 
2977
2999
    def _get_bound_location(self, bound):
2978
3000
        """Return the bound location in the config file.
2979
3001
 
2980
3002
        Return None if the bound parameter does not match"""
2981
 
        config = self.get_config()
2982
 
        config_bound = (config.get_user_option('bound') == 'True')
2983
 
        if config_bound != bound:
 
3003
        conf = self.get_config_stack()
 
3004
        if conf.get('bound') != bound:
2984
3005
            return None
2985
 
        return self._get_config_location('bound_location', config=config)
 
3006
        return self._get_config_location('bound_location', config=conf)
2986
3007
 
2987
3008
    def get_bound_location(self):
2988
3009
        """See Branch.set_push_location."""
2998
3019
        ## self._check_stackable_repo()
2999
3020
        # stacked_on_location is only ever defined in branch.conf, so don't
3000
3021
        # waste effort reading the whole stack of config files.
3001
 
        config = self.get_config()._get_branch_data_config()
 
3022
        conf = _mod_config.BranchOnlyStack(self)
3002
3023
        stacked_url = self._get_config_location('stacked_on_location',
3003
 
            config=config)
 
3024
                                                config=conf)
3004
3025
        if stacked_url is None:
3005
3026
            raise errors.NotStacked(self)
3006
 
        return stacked_url
 
3027
        return stacked_url.encode('utf-8')
3007
3028
 
3008
3029
    @needs_read_lock
3009
3030
    def get_rev_id(self, revno, history=None):
3213
3234
 
3214
3235
        # Copying done; now update target format
3215
3236
        new_branch._transport.put_bytes('format',
3216
 
            format.get_format_string(),
 
3237
            format.as_string(),
3217
3238
            mode=new_branch.bzrdir._get_file_mode())
3218
3239
 
3219
3240
        # Clean up old files
3232
3253
        format = BzrBranchFormat7()
3233
3254
        branch._set_config_location('stacked_on_location', '')
3234
3255
        # update target format
3235
 
        branch._transport.put_bytes('format', format.get_format_string())
 
3256
        branch._transport.put_bytes('format', format.as_string())
3236
3257
 
3237
3258
 
3238
3259
class Converter7to8(object):
3242
3263
        format = BzrBranchFormat8()
3243
3264
        branch._transport.put_bytes('references', '')
3244
3265
        # update target format
3245
 
        branch._transport.put_bytes('format', format.get_format_string())
 
3266
        branch._transport.put_bytes('format', format.as_string())
3246
3267
 
3247
3268
 
3248
3269
class InterBranch(InterObject):