~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2011-09-12 18:40:02 UTC
  • mfrom: (6132 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6133.
  • Revision ID: john@arbash-meinel.com-20110912184002-o23eu21fdgp35h2q
Merge bzr.dev, resolve release-notes (aka NEWS) conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
641
641
        """
642
642
        raise errors.UpgradeRequired(self.user_url)
643
643
 
 
644
    def get_append_revisions_only(self):
 
645
        """Whether it is only possible to append revisions to the history.
 
646
        """
 
647
        if not self._format.supports_set_append_revisions_only():
 
648
            return False
 
649
        return self.get_config(
 
650
            ).get_user_option_as_bool('append_revisions_only')
 
651
 
644
652
    def set_append_revisions_only(self, enabled):
645
653
        if not self._format.supports_set_append_revisions_only():
646
654
            raise errors.UpgradeRequired(self.user_url)
1372
1380
        # specific check.
1373
1381
        return result
1374
1382
 
1375
 
    def _get_checkout_format(self):
 
1383
    def _get_checkout_format(self, lightweight=False):
1376
1384
        """Return the most suitable metadir for a checkout of this branch.
1377
1385
        Weaves are used if this branch's repository uses weaves.
1378
1386
        """
1424
1432
        """
1425
1433
        t = transport.get_transport(to_location)
1426
1434
        t.ensure_base()
 
1435
        format = self._get_checkout_format(lightweight=lightweight)
1427
1436
        if lightweight:
1428
 
            format = self._get_checkout_format()
1429
1437
            checkout = format.initialize_on_transport(t)
1430
1438
            from_branch = BranchReferenceFormat().initialize(checkout, 
1431
1439
                target_branch=self)
1432
1440
        else:
1433
 
            format = self._get_checkout_format()
1434
1441
            checkout_branch = bzrdir.BzrDir.create_branch_convenience(
1435
1442
                to_location, force_new_tree=False, format=format)
1436
1443
            checkout = checkout_branch.bzrdir
1568
1575
    object will be created every time regardless.
1569
1576
    """
1570
1577
 
1571
 
    can_set_append_revisions_only = True
1572
 
 
1573
1578
    def __eq__(self, other):
1574
1579
        return self.__class__ is other.__class__
1575
1580
 
1647
1652
        for hook in hooks:
1648
1653
            hook(params)
1649
1654
 
1650
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
1655
    def initialize(self, a_bzrdir, name=None, repository=None,
 
1656
                   append_revisions_only=None):
1651
1657
        """Create a branch of this format in a_bzrdir.
1652
1658
        
1653
1659
        :param name: Name of the colocated branch to create.
1739
1745
        """True if this format supports tags stored in the branch"""
1740
1746
        return False  # by default
1741
1747
 
 
1748
    def tags_are_versioned(self):
 
1749
        """Whether the tag container for this branch versions tags."""
 
1750
        return False
 
1751
 
 
1752
    def supports_tags_referencing_ghosts(self):
 
1753
        """True if tags can reference ghost revisions."""
 
1754
        return True
 
1755
 
1742
1756
 
1743
1757
class MetaDirBranchFormatFactory(registry._LazyObjectGetter):
1744
1758
    """A factory for a BranchFormat object, permitting simple lazy registration.
1983
1997
        """What class to instantiate on open calls."""
1984
1998
        raise NotImplementedError(self._branch_class)
1985
1999
 
 
2000
    def _get_initial_config(self, append_revisions_only=None):
 
2001
        if append_revisions_only:
 
2002
            return "append_revisions_only = True\n"
 
2003
        else:
 
2004
            # Avoid writing anything if append_revisions_only is disabled,
 
2005
            # as that is the default.
 
2006
            return ""
 
2007
 
1986
2008
    def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1987
2009
                           repository=None):
1988
2010
        """Initialize a branch in a bzrdir, with specified files
2078
2100
        """See BranchFormat.get_format_description()."""
2079
2101
        return "Branch format 5"
2080
2102
 
2081
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2103
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2104
                   append_revisions_only=None):
2082
2105
        """Create a branch of this format in a_bzrdir."""
 
2106
        if append_revisions_only:
 
2107
            raise errors.UpgradeRequired(a_bzrdir.user_url)
2083
2108
        utf8_files = [('revision-history', ''),
2084
2109
                      ('branch-name', ''),
2085
2110
                      ]
2111
2136
        """See BranchFormat.get_format_description()."""
2112
2137
        return "Branch format 6"
2113
2138
 
2114
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2139
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2140
                   append_revisions_only=None):
2115
2141
        """Create a branch of this format in a_bzrdir."""
2116
2142
        utf8_files = [('last-revision', '0 null:\n'),
2117
 
                      ('branch.conf', ''),
 
2143
                      ('branch.conf',
 
2144
                          self._get_initial_config(append_revisions_only)),
2118
2145
                      ('tags', ''),
2119
2146
                      ]
2120
2147
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2141
2168
        """See BranchFormat.get_format_description()."""
2142
2169
        return "Branch format 8"
2143
2170
 
2144
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2171
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2172
                   append_revisions_only=None):
2145
2173
        """Create a branch of this format in a_bzrdir."""
2146
2174
        utf8_files = [('last-revision', '0 null:\n'),
2147
 
                      ('branch.conf', ''),
 
2175
                      ('branch.conf',
 
2176
                          self._get_initial_config(append_revisions_only)),
2148
2177
                      ('tags', ''),
2149
2178
                      ('references', '')
2150
2179
                      ]
2172
2201
    This format was introduced in bzr 1.6.
2173
2202
    """
2174
2203
 
2175
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2204
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2205
                   append_revisions_only=None):
2176
2206
        """Create a branch of this format in a_bzrdir."""
2177
2207
        utf8_files = [('last-revision', '0 null:\n'),
2178
 
                      ('branch.conf', ''),
 
2208
                      ('branch.conf',
 
2209
                          self._get_initial_config(append_revisions_only)),
2179
2210
                      ('tags', ''),
2180
2211
                      ]
2181
2212
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2234
2265
        location = transport.put_bytes('location', to_branch.base)
2235
2266
 
2236
2267
    def initialize(self, a_bzrdir, name=None, target_branch=None,
2237
 
            repository=None):
 
2268
            repository=None, append_revisions_only=None):
2238
2269
        """Create a branch of this format in a_bzrdir."""
2239
2270
        if target_branch is None:
2240
2271
            # this format does not implement branch itself, thus the implicit
2504
2535
            raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2505
2536
        revision_id = _mod_revision.ensure_null(revision_id)
2506
2537
        old_revno, old_revid = self.last_revision_info()
2507
 
        if self._get_append_revisions_only():
 
2538
        if self.get_append_revisions_only():
2508
2539
            self._check_history_violation(revision_id)
2509
2540
        self._run_pre_change_branch_tip_hooks(revno, revision_id)
2510
2541
        self._write_last_revision_info(revno, revision_id)
2949
2980
            raise errors.NotStacked(self)
2950
2981
        return stacked_url
2951
2982
 
2952
 
    def _get_append_revisions_only(self):
2953
 
        return self.get_config(
2954
 
            ).get_user_option_as_bool('append_revisions_only')
2955
 
 
2956
2983
    @needs_read_lock
2957
2984
    def get_rev_id(self, revno, history=None):
2958
2985
        """Find the revision id of the specified revno."""
3044
3071
    :ivar local_branch: target branch if there is a Master, else None
3045
3072
    :ivar target_branch: Target/destination branch object. (write locked)
3046
3073
    :ivar tag_conflicts: A list of tag conflicts, see BasicTags.merge_to
 
3074
    :ivar tag_updates: A dict with new tags, see BasicTags.merge_to
3047
3075
    """
3048
3076
 
3049
3077
    @deprecated_method(deprecated_in((2, 3, 0)))
3055
3083
        return self.new_revno - self.old_revno
3056
3084
 
3057
3085
    def report(self, to_file):
 
3086
        tag_conflicts = getattr(self, "tag_conflicts", None)
 
3087
        tag_updates = getattr(self, "tag_updates", None)
3058
3088
        if not is_quiet():
3059
 
            if self.old_revid == self.new_revid:
3060
 
                to_file.write('No revisions to pull.\n')
3061
 
            else:
 
3089
            if self.old_revid != self.new_revid:
3062
3090
                to_file.write('Now on revision %d.\n' % self.new_revno)
 
3091
            if tag_updates:
 
3092
                to_file.write('%d tag(s) updated.\n' % len(tag_updates))
 
3093
            if self.old_revid == self.new_revid and not tag_updates:
 
3094
                if not tag_conflicts:
 
3095
                    to_file.write('No revisions or tags to pull.\n')
 
3096
                else:
 
3097
                    to_file.write('No revisions to pull.\n')
3063
3098
        self._show_tag_conficts(to_file)
3064
3099
 
3065
3100
 
3091
3126
        return self.new_revno - self.old_revno
3092
3127
 
3093
3128
    def report(self, to_file):
3094
 
        """Write a human-readable description of the result."""
3095
 
        if self.old_revid == self.new_revid:
3096
 
            note('No new revisions to push.')
3097
 
        else:
3098
 
            note('Pushed up to revision %d.' % self.new_revno)
 
3129
        # TODO: This function gets passed a to_file, but then
 
3130
        # ignores it and calls note() instead. This is also
 
3131
        # inconsistent with PullResult(), which writes to stdout.
 
3132
        # -- JRV20110901, bug #838853
 
3133
        tag_conflicts = getattr(self, "tag_conflicts", None)
 
3134
        tag_updates = getattr(self, "tag_updates", None)
 
3135
        if not is_quiet():
 
3136
            if self.old_revid != self.new_revid:
 
3137
                note('Pushed up to revision %d.' % self.new_revno)
 
3138
            if tag_updates:
 
3139
                note('%d tag(s) updated.' % len(tag_updates))
 
3140
            if self.old_revid == self.new_revid and not tag_updates:
 
3141
                if not tag_conflicts:
 
3142
                    note('No new revisions or tags to push.')
 
3143
                else:
 
3144
                    note('No new revisions to push.')
3099
3145
        self._show_tag_conficts(to_file)
3100
3146
 
3101
3147
 
3409
3455
            self._update_revisions(stop_revision, overwrite=overwrite,
3410
3456
                    graph=graph)
3411
3457
        if self.source._push_should_merge_tags():
3412
 
            result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
3413
 
                overwrite)
 
3458
            result.tag_updates, result.tag_conflicts = (
 
3459
                self.source.tags.merge_to(self.target.tags, overwrite))
3414
3460
        result.new_revno, result.new_revid = self.target.last_revision_info()
3415
3461
        return result
3416
3462
 
3499
3545
            # TODO: The old revid should be specified when merging tags, 
3500
3546
            # so a tags implementation that versions tags can only 
3501
3547
            # pull in the most recent changes. -- JRV20090506
3502
 
            result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
3503
 
                overwrite, ignore_master=not merge_tags_to_master)
 
3548
            result.tag_updates, result.tag_conflicts = (
 
3549
                self.source.tags.merge_to(self.target.tags, overwrite,
 
3550
                    ignore_master=not merge_tags_to_master))
3504
3551
            result.new_revno, result.new_revid = self.target.last_revision_info()
3505
3552
            if _hook_master:
3506
3553
                result.master_branch = _hook_master