/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
1
# Copyright (C) 2010 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
17
"""Weave-era branch implementations."""
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from ... import (
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
20
    errors,
21
    lockable_files,
22
    )
23
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
24
from ...decorators import (
6531.2.1 by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code).
25
    only_raises,
26
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
27
from ...lock import LogicalLockResult
28
from ...trace import mutter
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
29
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
30
from ...branch import (
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
31
    BranchFormat,
6531.2.1 by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code).
32
    BranchWriteLockResult,
6517.1.2 by Jelmer Vernooij
Move BzrBranchFormat5 into a separate file.
33
    )
6670.4.1 by Jelmer Vernooij
Update imports.
34
from ...bzr.fullhistory import (
5718.8.1 by Jelmer Vernooij
Add FullHistoryBzrBranch.
35
    FullHistoryBzrBranch,
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
36
    )
37
38
5718.8.1 by Jelmer Vernooij
Add FullHistoryBzrBranch.
39
class BzrBranch4(FullHistoryBzrBranch):
5718.8.2 by Jelmer Vernooij
Split out full history branch code.
40
    """Branch format 4."""
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
41
6531.2.1 by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code).
42
    def lock_write(self, token=None):
43
        """Lock the branch for write operations.
44
45
        :param token: A token to permit reacquiring a previously held and
46
            preserved lock.
47
        :return: A BranchWriteLockResult.
48
        """
49
        if not self.is_locked():
50
            self._note_lock('w')
6531.2.4 by Vincent Ladeuil
Always means always. Full test suite revealed a possible further simplication.
51
        # All-in-one needs to always unlock/lock.
52
        self.repository._warn_if_deprecated(self)
53
        self.repository.lock_write()
6531.2.1 by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code).
54
        try:
55
            return BranchWriteLockResult(self.unlock,
7143.15.2 by Jelmer Vernooij
Run autopep8.
56
                                         self.control_files.lock_write(token=token))
6531.2.1 by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code).
57
        except:
6531.2.4 by Vincent Ladeuil
Always means always. Full test suite revealed a possible further simplication.
58
            self.repository.unlock()
6531.2.1 by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code).
59
            raise
60
61
    def lock_read(self):
62
        """Lock the branch for read operations.
63
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
64
        :return: A breezy.lock.LogicalLockResult.
6531.2.1 by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code).
65
        """
66
        if not self.is_locked():
67
            self._note_lock('r')
6531.2.4 by Vincent Ladeuil
Always means always. Full test suite revealed a possible further simplication.
68
        # All-in-one needs to always unlock/lock.
69
        self.repository._warn_if_deprecated(self)
70
        self.repository.lock_read()
6531.2.1 by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code).
71
        try:
72
            self.control_files.lock_read()
73
            return LogicalLockResult(self.unlock)
74
        except:
6531.2.4 by Vincent Ladeuil
Always means always. Full test suite revealed a possible further simplication.
75
            self.repository.unlock()
6531.2.1 by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code).
76
            raise
77
78
    @only_raises(errors.LockNotHeld, errors.LockBroken)
79
    def unlock(self):
80
        if self.control_files._lock_count == 2 and self.conf_store is not None:
81
            self.conf_store.save_changes()
82
        try:
83
            self.control_files.unlock()
84
        finally:
85
            # All-in-one needs to always unlock/lock.
6531.2.2 by Vincent Ladeuil
Better version separating the lock methods between branch and branch format 4 and removing the duplication.
86
            self.repository.unlock()
6531.2.1 by Vincent Ladeuil
Add a failing test and a brain-dead fix (duplicating the existing code).
87
            if not self.control_files.is_locked():
88
                # we just released the lock
89
                self._clear_cached_state()
90
6127.1.9 by Jelmer Vernooij
Add lightweight option to _get_checkout_format().
91
    def _get_checkout_format(self, lightweight=False):
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
92
        """Return the most suitable metadir for a checkout of this branch.
93
        """
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
94
        from .repository import RepositoryFormat7
6670.4.3 by Jelmer Vernooij
Fix more imports.
95
        from ...bzr.bzrdir import BzrDirMetaFormat1
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
96
        format = BzrDirMetaFormat1()
6127.1.11 by Jelmer Vernooij
Fix weave format test.
97
        if lightweight:
98
            format.set_branch_format(self._format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
99
            format.repository_format = self.controldir._format.repository_format
6127.1.11 by Jelmer Vernooij
Fix weave format test.
100
        else:
101
            format.repository_format = RepositoryFormat7()
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
102
        return format
103
5718.8.2 by Jelmer Vernooij
Split out full history branch code.
104
    def unbind(self):
105
        raise errors.UpgradeRequired(self.user_url)
106
107
    def bind(self, other):
108
        raise errors.UpgradeRequired(self.user_url)
109
110
    def set_bound_location(self, location):
111
        raise NotImplementedError(self.set_bound_location)
112
113
    def get_bound_location(self):
114
        return None
115
116
    def update(self):
117
        return None
118
119
    def get_master_branch(self, possible_transports=None):
120
        return None
121
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
122
123
class BzrBranchFormat4(BranchFormat):
124
    """Bzr branch format 4.
125
126
    This format has:
127
     - a revision-history file.
128
     - a branch-lock lock file [ to be shared with the bzrdir ]
5718.8.2 by Jelmer Vernooij
Split out full history branch code.
129
130
    It does not support binding.
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
131
    """
132
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
133
    def initialize(self, a_controldir, name=None, repository=None,
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
134
                   append_revisions_only=None):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
135
        """Create a branch of this format in a_controldir.
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
136
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
137
        :param a_controldir: The bzrdir to initialize the branch in
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
138
        :param name: Name of colocated branch to create, if any
5705.2.1 by Jelmer Vernooij
Inline _initialize_helper.
139
        :param repository: Repository for this branch (unused)
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
140
        """
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
141
        if append_revisions_only:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
142
            raise errors.UpgradeRequired(a_controldir.user_url)
5705.2.1 by Jelmer Vernooij
Inline _initialize_helper.
143
        if repository is not None:
144
            raise NotImplementedError(
145
                "initialize(repository=<not None>) on %r" % (self,))
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
146
        if not [isinstance(a_controldir._format, format) for format in
5705.2.2 by Jelmer Vernooij
Only support BzrBranchFormat4 in pre-metadir bzr dirs.
147
                self._compatible_bzrdirs]:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
148
            raise errors.IncompatibleFormat(self, a_controldir._format)
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
149
        utf8_files = [('revision-history', b''),
150
                      ('branch-name', b''),
5705.2.1 by Jelmer Vernooij
Inline _initialize_helper.
151
                      ]
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
152
        mutter('creating branch %r in %s', self, a_controldir.user_url)
153
        branch_transport = a_controldir.get_branch_transport(self, name=name)
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
154
        control_files = lockable_files.LockableFiles(branch_transport,
7143.15.2 by Jelmer Vernooij
Run autopep8.
155
                                                     'branch-lock', lockable_files.TransportLock)
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
156
        control_files.create_lock()
157
        try:
158
            control_files.lock_write()
159
        except errors.LockContention:
160
            lock_taken = False
161
        else:
162
            lock_taken = True
163
        try:
164
            for (filename, content) in utf8_files:
165
                branch_transport.put_bytes(
166
                    filename, content,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
167
                    mode=a_controldir._get_file_mode())
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
168
        finally:
169
            if lock_taken:
170
                control_files.unlock()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
171
        branch = self.open(a_controldir, name, _found=True,
7143.15.2 by Jelmer Vernooij
Run autopep8.
172
                           found_repository=None)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
173
        self._run_post_branch_init_hooks(a_controldir, name, branch)
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
174
        return branch
175
176
    def __init__(self):
177
        super(BzrBranchFormat4, self).__init__()
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
178
        from .bzrdir import (
5582.10.87 by Jelmer Vernooij
Merge bzr.dev.
179
            BzrDirFormat4, BzrDirFormat5, BzrDirFormat6,
180
            )
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
181
        self._matchingcontroldir = BzrDirFormat6()
5705.2.2 by Jelmer Vernooij
Only support BzrBranchFormat4 in pre-metadir bzr dirs.
182
        self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5,
7143.15.2 by Jelmer Vernooij
Run autopep8.
183
                                    BzrDirFormat6]
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
184
185
    def network_name(self):
186
        """The network name for this format is the control dirs disk label."""
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
187
        return self._matchingcontroldir.get_format_string()
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
188
5705.2.4 by Jelmer Vernooij
Add BzrBranchFormat4.get_format_description().
189
    def get_format_description(self):
5705.2.6 by Jelmer Vernooij
Fix case sensitivity.
190
        return "Branch format 4"
5705.2.4 by Jelmer Vernooij
Add BzrBranchFormat4.get_format_description().
191
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
192
    def open(self, a_controldir, name=None, _found=False, ignore_fallbacks=False,
7143.15.2 by Jelmer Vernooij
Run autopep8.
193
             found_repository=None, possible_transports=None):
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
194
        """See BranchFormat.open()."""
6436.1.2 by Jelmer Vernooij
Fix some tests.
195
        if name is None:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
196
            name = a_controldir._get_selected_branch()
6436.1.2 by Jelmer Vernooij
Fix some tests.
197
        if name != "":
5699.4.8 by Jelmer Vernooij
Properly raise NoColocatedBranchSupport.
198
            raise errors.NoColocatedBranchSupport(self)
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
199
        if not _found:
200
            # we are being called directly and must probe.
201
            raise NotImplementedError
202
        if found_repository is None:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
203
            found_repository = a_controldir.open_repository()
5718.8.1 by Jelmer Vernooij
Add FullHistoryBzrBranch.
204
        return BzrBranch4(_format=self,
7143.15.2 by Jelmer Vernooij
Run autopep8.
205
                          _control_files=a_controldir._control_files,
206
                          a_controldir=a_controldir,
207
                          name=name,
208
                          _repository=found_repository,
209
                          possible_transports=possible_transports)
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
210
211
    def __str__(self):
212
        return "Bazaar-NG branch format 4"
213
214
    def supports_leaving_lock(self):
215
        return False
7449.2.4 by Jelmer Vernooij
Set BranchFormat.supports_reference_locations everywhere.
216
217
    supports_reference_locations = False