~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Jonathan Riddell
  • Date: 2011-09-16 11:13:47 UTC
  • mto: This revision was merged to the branch mainline in revision 6144.
  • Revision ID: jriddell@canonical.com-20110916111347-fyjk426bkl0jrbfu
gettext() show_warning usage

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
from cStringIO import StringIO
19
 
import sys
20
19
 
21
20
from bzrlib.lazy_import import lazy_import
22
21
lazy_import(globals(), """
23
 
from itertools import chain
 
22
import itertools
24
23
from bzrlib import (
25
24
        bzrdir,
26
25
        cache_utf8,
36
35
        repository,
37
36
        revision as _mod_revision,
38
37
        rio,
 
38
        tag as _mod_tag,
39
39
        transport,
40
40
        ui,
41
41
        urlutils,
42
42
        )
43
 
from bzrlib.config import BranchConfig, TransportConfig
44
 
from bzrlib.tag import (
45
 
    BasicTags,
46
 
    DisabledTags,
47
 
    )
 
43
from bzrlib.i18n import gettext
48
44
""")
49
45
 
50
46
from bzrlib import (
217
213
 
218
214
        :return: A bzrlib.config.BranchConfig.
219
215
        """
220
 
        return BranchConfig(self)
 
216
        return _mod_config.BranchConfig(self)
221
217
 
222
218
    def _get_config(self):
223
219
        """Get the concrete config for just the config in this branch.
515
511
                    # The decision to include the start or not
516
512
                    # depends on the stop_rule if a stop is provided
517
513
                    # so pop this node back into the iterator
518
 
                    rev_iter = chain(iter([node]), rev_iter)
 
514
                    rev_iter = itertools.chain(iter([node]), rev_iter)
519
515
                    break
520
516
        if stop_revision_id is None:
521
517
            # Yield everything
646
642
        """
647
643
        raise errors.UpgradeRequired(self.user_url)
648
644
 
 
645
    def get_append_revisions_only(self):
 
646
        """Whether it is only possible to append revisions to the history.
 
647
        """
 
648
        if not self._format.supports_set_append_revisions_only():
 
649
            return False
 
650
        return self.get_config(
 
651
            ).get_user_option_as_bool('append_revisions_only')
 
652
 
649
653
    def set_append_revisions_only(self, enabled):
650
654
        if not self._format.supports_set_append_revisions_only():
651
655
            raise errors.UpgradeRequired(self.user_url)
1377
1381
        # specific check.
1378
1382
        return result
1379
1383
 
1380
 
    def _get_checkout_format(self):
 
1384
    def _get_checkout_format(self, lightweight=False):
1381
1385
        """Return the most suitable metadir for a checkout of this branch.
1382
1386
        Weaves are used if this branch's repository uses weaves.
1383
1387
        """
1429
1433
        """
1430
1434
        t = transport.get_transport(to_location)
1431
1435
        t.ensure_base()
 
1436
        format = self._get_checkout_format(lightweight=lightweight)
1432
1437
        if lightweight:
1433
 
            format = self._get_checkout_format()
1434
1438
            checkout = format.initialize_on_transport(t)
1435
1439
            from_branch = BranchReferenceFormat().initialize(checkout, 
1436
1440
                target_branch=self)
1437
1441
        else:
1438
 
            format = self._get_checkout_format()
1439
1442
            checkout_branch = bzrdir.BzrDir.create_branch_convenience(
1440
1443
                to_location, force_new_tree=False, format=format)
1441
1444
            checkout = checkout_branch.bzrdir
1573
1576
    object will be created every time regardless.
1574
1577
    """
1575
1578
 
1576
 
    can_set_append_revisions_only = True
1577
 
 
1578
1579
    def __eq__(self, other):
1579
1580
        return self.__class__ is other.__class__
1580
1581
 
1652
1653
        for hook in hooks:
1653
1654
            hook(params)
1654
1655
 
1655
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
1656
    def initialize(self, a_bzrdir, name=None, repository=None,
 
1657
                   append_revisions_only=None):
1656
1658
        """Create a branch of this format in a_bzrdir.
1657
1659
        
1658
1660
        :param name: Name of the colocated branch to create.
1680
1682
        Note that it is normal for branch to be a RemoteBranch when using tags
1681
1683
        on a RemoteBranch.
1682
1684
        """
1683
 
        return DisabledTags(branch)
 
1685
        return _mod_tag.DisabledTags(branch)
1684
1686
 
1685
1687
    def network_name(self):
1686
1688
        """A simple byte string uniquely identifying this format for RPC calls.
1744
1746
        """True if this format supports tags stored in the branch"""
1745
1747
        return False  # by default
1746
1748
 
 
1749
    def tags_are_versioned(self):
 
1750
        """Whether the tag container for this branch versions tags."""
 
1751
        return False
 
1752
 
 
1753
    def supports_tags_referencing_ghosts(self):
 
1754
        """True if tags can reference ghost revisions."""
 
1755
        return True
 
1756
 
1747
1757
 
1748
1758
class MetaDirBranchFormatFactory(registry._LazyObjectGetter):
1749
1759
    """A factory for a BranchFormat object, permitting simple lazy registration.
1988
1998
        """What class to instantiate on open calls."""
1989
1999
        raise NotImplementedError(self._branch_class)
1990
2000
 
 
2001
    def _get_initial_config(self, append_revisions_only=None):
 
2002
        if append_revisions_only:
 
2003
            return "append_revisions_only = True\n"
 
2004
        else:
 
2005
            # Avoid writing anything if append_revisions_only is disabled,
 
2006
            # as that is the default.
 
2007
            return ""
 
2008
 
1991
2009
    def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1992
2010
                           repository=None):
1993
2011
        """Initialize a branch in a bzrdir, with specified files
2083
2101
        """See BranchFormat.get_format_description()."""
2084
2102
        return "Branch format 5"
2085
2103
 
2086
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2104
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2105
                   append_revisions_only=None):
2087
2106
        """Create a branch of this format in a_bzrdir."""
 
2107
        if append_revisions_only:
 
2108
            raise errors.UpgradeRequired(a_bzrdir.user_url)
2088
2109
        utf8_files = [('revision-history', ''),
2089
2110
                      ('branch-name', ''),
2090
2111
                      ]
2116
2137
        """See BranchFormat.get_format_description()."""
2117
2138
        return "Branch format 6"
2118
2139
 
2119
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2140
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2141
                   append_revisions_only=None):
2120
2142
        """Create a branch of this format in a_bzrdir."""
2121
2143
        utf8_files = [('last-revision', '0 null:\n'),
2122
 
                      ('branch.conf', ''),
 
2144
                      ('branch.conf',
 
2145
                          self._get_initial_config(append_revisions_only)),
2123
2146
                      ('tags', ''),
2124
2147
                      ]
2125
2148
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2126
2149
 
2127
2150
    def make_tags(self, branch):
2128
2151
        """See bzrlib.branch.BranchFormat.make_tags()."""
2129
 
        return BasicTags(branch)
 
2152
        return _mod_tag.BasicTags(branch)
2130
2153
 
2131
2154
    def supports_set_append_revisions_only(self):
2132
2155
        return True
2146
2169
        """See BranchFormat.get_format_description()."""
2147
2170
        return "Branch format 8"
2148
2171
 
2149
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2172
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2173
                   append_revisions_only=None):
2150
2174
        """Create a branch of this format in a_bzrdir."""
2151
2175
        utf8_files = [('last-revision', '0 null:\n'),
2152
 
                      ('branch.conf', ''),
 
2176
                      ('branch.conf',
 
2177
                          self._get_initial_config(append_revisions_only)),
2153
2178
                      ('tags', ''),
2154
2179
                      ('references', '')
2155
2180
                      ]
2157
2182
 
2158
2183
    def make_tags(self, branch):
2159
2184
        """See bzrlib.branch.BranchFormat.make_tags()."""
2160
 
        return BasicTags(branch)
 
2185
        return _mod_tag.BasicTags(branch)
2161
2186
 
2162
2187
    def supports_set_append_revisions_only(self):
2163
2188
        return True
2177
2202
    This format was introduced in bzr 1.6.
2178
2203
    """
2179
2204
 
2180
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2205
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2206
                   append_revisions_only=None):
2181
2207
        """Create a branch of this format in a_bzrdir."""
2182
2208
        utf8_files = [('last-revision', '0 null:\n'),
2183
 
                      ('branch.conf', ''),
 
2209
                      ('branch.conf',
 
2210
                          self._get_initial_config(append_revisions_only)),
2184
2211
                      ('tags', ''),
2185
2212
                      ]
2186
2213
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2204
2231
 
2205
2232
    def make_tags(self, branch):
2206
2233
        """See bzrlib.branch.BranchFormat.make_tags()."""
2207
 
        return BasicTags(branch)
 
2234
        return _mod_tag.BasicTags(branch)
2208
2235
 
2209
2236
    supports_reference_locations = False
2210
2237
 
2239
2266
        location = transport.put_bytes('location', to_branch.base)
2240
2267
 
2241
2268
    def initialize(self, a_bzrdir, name=None, target_branch=None,
2242
 
            repository=None):
 
2269
            repository=None, append_revisions_only=None):
2243
2270
        """Create a branch of this format in a_bzrdir."""
2244
2271
        if target_branch is None:
2245
2272
            # this format does not implement branch itself, thus the implicit
2246
2273
            # creation contract must see it as uninitializable
2247
2274
            raise errors.UninitializableFormat(self)
2248
2275
        mutter('creating branch reference in %s', a_bzrdir.user_url)
 
2276
        if a_bzrdir._format.fixed_components:
 
2277
            raise errors.IncompatibleFormat(self, a_bzrdir._format)
2249
2278
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
2250
2279
        branch_transport.put_bytes('location',
2251
2280
            target_branch.bzrdir.user_url)
2420
2449
    base = property(_get_base, doc="The URL for the root of this branch.")
2421
2450
 
2422
2451
    def _get_config(self):
2423
 
        return TransportConfig(self._transport, 'branch.conf')
 
2452
        return _mod_config.TransportConfig(self._transport, 'branch.conf')
2424
2453
 
2425
2454
    def is_locked(self):
2426
2455
        return self.control_files.is_locked()
2507
2536
            raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2508
2537
        revision_id = _mod_revision.ensure_null(revision_id)
2509
2538
        old_revno, old_revid = self.last_revision_info()
2510
 
        if self._get_append_revisions_only():
 
2539
        if self.get_append_revisions_only():
2511
2540
            self._check_history_violation(revision_id)
2512
2541
        self._run_pre_change_branch_tip_hooks(revno, revision_id)
2513
2542
        self._write_last_revision_info(revno, revision_id)
2952
2981
            raise errors.NotStacked(self)
2953
2982
        return stacked_url
2954
2983
 
2955
 
    def _get_append_revisions_only(self):
2956
 
        return self.get_config(
2957
 
            ).get_user_option_as_bool('append_revisions_only')
2958
 
 
2959
2984
    @needs_read_lock
2960
2985
    def get_rev_id(self, revno, history=None):
2961
2986
        """Find the revision id of the specified revno."""
3047
3072
    :ivar local_branch: target branch if there is a Master, else None
3048
3073
    :ivar target_branch: Target/destination branch object. (write locked)
3049
3074
    :ivar tag_conflicts: A list of tag conflicts, see BasicTags.merge_to
 
3075
    :ivar tag_updates: A dict with new tags, see BasicTags.merge_to
3050
3076
    """
3051
3077
 
3052
3078
    @deprecated_method(deprecated_in((2, 3, 0)))
3058
3084
        return self.new_revno - self.old_revno
3059
3085
 
3060
3086
    def report(self, to_file):
 
3087
        tag_conflicts = getattr(self, "tag_conflicts", None)
 
3088
        tag_updates = getattr(self, "tag_updates", None)
3061
3089
        if not is_quiet():
3062
 
            if self.old_revid == self.new_revid:
3063
 
                to_file.write('No revisions to pull.\n')
3064
 
            else:
 
3090
            if self.old_revid != self.new_revid:
3065
3091
                to_file.write('Now on revision %d.\n' % self.new_revno)
 
3092
            if tag_updates:
 
3093
                to_file.write('%d tag(s) updated.\n' % len(tag_updates))
 
3094
            if self.old_revid == self.new_revid and not tag_updates:
 
3095
                if not tag_conflicts:
 
3096
                    to_file.write('No revisions or tags to pull.\n')
 
3097
                else:
 
3098
                    to_file.write('No revisions to pull.\n')
3066
3099
        self._show_tag_conficts(to_file)
3067
3100
 
3068
3101
 
3094
3127
        return self.new_revno - self.old_revno
3095
3128
 
3096
3129
    def report(self, to_file):
3097
 
        """Write a human-readable description of the result."""
3098
 
        if self.old_revid == self.new_revid:
3099
 
            note('No new revisions to push.')
3100
 
        else:
3101
 
            note('Pushed up to revision %d.' % self.new_revno)
 
3130
        # TODO: This function gets passed a to_file, but then
 
3131
        # ignores it and calls note() instead. This is also
 
3132
        # inconsistent with PullResult(), which writes to stdout.
 
3133
        # -- JRV20110901, bug #838853
 
3134
        tag_conflicts = getattr(self, "tag_conflicts", None)
 
3135
        tag_updates = getattr(self, "tag_updates", None)
 
3136
        if not is_quiet():
 
3137
            if self.old_revid != self.new_revid:
 
3138
                note(gettext('Pushed up to revision %d.') % self.new_revno)
 
3139
            if tag_updates:
 
3140
                note(gettext('%d tag(s) updated.') % len(tag_updates))
 
3141
            if self.old_revid == self.new_revid and not tag_updates:
 
3142
                if not tag_conflicts:
 
3143
                    note(gettext('No new revisions or tags to push.'))
 
3144
                else:
 
3145
                    note(gettext('No new revisions to push.'))
3102
3146
        self._show_tag_conficts(to_file)
3103
3147
 
3104
3148
 
3118
3162
        :param verbose: Requests more detailed display of what was checked,
3119
3163
            if any.
3120
3164
        """
3121
 
        note('checked branch %s format %s', self.branch.user_url,
 
3165
        note(gettext('checked branch %s format %s'), self.branch.user_url,
3122
3166
            self.branch._format)
3123
3167
        for error in self.errors:
3124
 
            note('found error:%s', error)
 
3168
            note(gettext('found error:%s'), error)
3125
3169
 
3126
3170
 
3127
3171
class Converter5to6(object):
3412
3456
            self._update_revisions(stop_revision, overwrite=overwrite,
3413
3457
                    graph=graph)
3414
3458
        if self.source._push_should_merge_tags():
3415
 
            result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
3416
 
                overwrite)
 
3459
            result.tag_updates, result.tag_conflicts = (
 
3460
                self.source.tags.merge_to(self.target.tags, overwrite))
3417
3461
        result.new_revno, result.new_revid = self.target.last_revision_info()
3418
3462
        return result
3419
3463
 
3502
3546
            # TODO: The old revid should be specified when merging tags, 
3503
3547
            # so a tags implementation that versions tags can only 
3504
3548
            # pull in the most recent changes. -- JRV20090506
3505
 
            result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
3506
 
                overwrite, ignore_master=not merge_tags_to_master)
 
3549
            result.tag_updates, result.tag_conflicts = (
 
3550
                self.source.tags.merge_to(self.target.tags, overwrite,
 
3551
                    ignore_master=not merge_tags_to_master))
3507
3552
            result.new_revno, result.new_revid = self.target.last_revision_info()
3508
3553
            if _hook_master:
3509
3554
                result.master_branch = _hook_master