~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

(jelmer) More fixes for the interface tests when run against foreign tests.
 (Jelmer Vernooij)

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)
1567
1575
    object will be created every time regardless.
1568
1576
    """
1569
1577
 
1570
 
    can_set_append_revisions_only = True
1571
 
 
1572
1578
    def __eq__(self, other):
1573
1579
        return self.__class__ is other.__class__
1574
1580
 
1646
1652
        for hook in hooks:
1647
1653
            hook(params)
1648
1654
 
1649
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
1655
    def initialize(self, a_bzrdir, name=None, repository=None,
 
1656
                   append_revisions_only=None):
1650
1657
        """Create a branch of this format in a_bzrdir.
1651
1658
        
1652
1659
        :param name: Name of the colocated branch to create.
1990
1997
        """What class to instantiate on open calls."""
1991
1998
        raise NotImplementedError(self._branch_class)
1992
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
 
1993
2008
    def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1994
2009
                           repository=None):
1995
2010
        """Initialize a branch in a bzrdir, with specified files
2085
2100
        """See BranchFormat.get_format_description()."""
2086
2101
        return "Branch format 5"
2087
2102
 
2088
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2103
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2104
                   append_revisions_only=None):
2089
2105
        """Create a branch of this format in a_bzrdir."""
 
2106
        if append_revisions_only:
 
2107
            raise errors.UpgradeRequired(a_bzrdir.user_url)
2090
2108
        utf8_files = [('revision-history', ''),
2091
2109
                      ('branch-name', ''),
2092
2110
                      ]
2118
2136
        """See BranchFormat.get_format_description()."""
2119
2137
        return "Branch format 6"
2120
2138
 
2121
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2139
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2140
                   append_revisions_only=None):
2122
2141
        """Create a branch of this format in a_bzrdir."""
2123
2142
        utf8_files = [('last-revision', '0 null:\n'),
2124
 
                      ('branch.conf', ''),
 
2143
                      ('branch.conf',
 
2144
                          self._get_initial_config(append_revisions_only)),
2125
2145
                      ('tags', ''),
2126
2146
                      ]
2127
2147
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2148
2168
        """See BranchFormat.get_format_description()."""
2149
2169
        return "Branch format 8"
2150
2170
 
2151
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2171
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2172
                   append_revisions_only=None):
2152
2173
        """Create a branch of this format in a_bzrdir."""
2153
2174
        utf8_files = [('last-revision', '0 null:\n'),
2154
 
                      ('branch.conf', ''),
 
2175
                      ('branch.conf',
 
2176
                          self._get_initial_config(append_revisions_only)),
2155
2177
                      ('tags', ''),
2156
2178
                      ('references', '')
2157
2179
                      ]
2179
2201
    This format was introduced in bzr 1.6.
2180
2202
    """
2181
2203
 
2182
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
2204
    def initialize(self, a_bzrdir, name=None, repository=None,
 
2205
                   append_revisions_only=None):
2183
2206
        """Create a branch of this format in a_bzrdir."""
2184
2207
        utf8_files = [('last-revision', '0 null:\n'),
2185
 
                      ('branch.conf', ''),
 
2208
                      ('branch.conf',
 
2209
                          self._get_initial_config(append_revisions_only)),
2186
2210
                      ('tags', ''),
2187
2211
                      ]
2188
2212
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2241
2265
        location = transport.put_bytes('location', to_branch.base)
2242
2266
 
2243
2267
    def initialize(self, a_bzrdir, name=None, target_branch=None,
2244
 
            repository=None):
 
2268
            repository=None, append_revisions_only=None):
2245
2269
        """Create a branch of this format in a_bzrdir."""
2246
2270
        if target_branch is None:
2247
2271
            # this format does not implement branch itself, thus the implicit
2511
2535
            raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2512
2536
        revision_id = _mod_revision.ensure_null(revision_id)
2513
2537
        old_revno, old_revid = self.last_revision_info()
2514
 
        if self._get_append_revisions_only():
 
2538
        if self.get_append_revisions_only():
2515
2539
            self._check_history_violation(revision_id)
2516
2540
        self._run_pre_change_branch_tip_hooks(revno, revision_id)
2517
2541
        self._write_last_revision_info(revno, revision_id)
2956
2980
            raise errors.NotStacked(self)
2957
2981
        return stacked_url
2958
2982
 
2959
 
    def _get_append_revisions_only(self):
2960
 
        return self.get_config(
2961
 
            ).get_user_option_as_bool('append_revisions_only')
2962
 
 
2963
2983
    @needs_read_lock
2964
2984
    def get_rev_id(self, revno, history=None):
2965
2985
        """Find the revision id of the specified revno."""