~bzr-pqm/bzr/bzr.dev

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
6379.6.3 by Jelmer Vernooij
Use absolute_import.
19
from __future__ import absolute_import
20
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
21
from bzrlib import (
22
    errors,
23
    lockable_files,
24
    )
25
26
from bzrlib.trace import mutter
27
28
from bzrlib.branch import (
29
    BranchFormat,
5718.8.1 by Jelmer Vernooij
Add FullHistoryBzrBranch.
30
    FullHistoryBzrBranch,
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
31
    )
32
33
5718.8.1 by Jelmer Vernooij
Add FullHistoryBzrBranch.
34
class BzrBranch4(FullHistoryBzrBranch):
5718.8.2 by Jelmer Vernooij
Split out full history branch code.
35
    """Branch format 4."""
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
36
6127.1.9 by Jelmer Vernooij
Add lightweight option to _get_checkout_format().
37
    def _get_checkout_format(self, lightweight=False):
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
38
        """Return the most suitable metadir for a checkout of this branch.
39
        """
5582.10.83 by Jelmer Vernooij
merge weave-branch branch.
40
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
41
        from bzrlib.bzrdir import BzrDirMetaFormat1
42
        format = BzrDirMetaFormat1()
6127.1.11 by Jelmer Vernooij
Fix weave format test.
43
        if lightweight:
44
            format.set_branch_format(self._format)
45
            format.repository_format = self.bzrdir._format.repository_format
46
        else:
47
            format.repository_format = RepositoryFormat7()
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
48
        return format
49
5718.8.2 by Jelmer Vernooij
Split out full history branch code.
50
    def unbind(self):
51
        raise errors.UpgradeRequired(self.user_url)
52
53
    def bind(self, other):
54
        raise errors.UpgradeRequired(self.user_url)
55
56
    def set_bound_location(self, location):
57
        raise NotImplementedError(self.set_bound_location)
58
59
    def get_bound_location(self):
60
        return None
61
62
    def update(self):
63
        return None
64
65
    def get_master_branch(self, possible_transports=None):
66
        return None
67
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
68
69
class BzrBranchFormat4(BranchFormat):
70
    """Bzr branch format 4.
71
72
    This format has:
73
     - a revision-history file.
74
     - a branch-lock lock file [ to be shared with the bzrdir ]
5718.8.2 by Jelmer Vernooij
Split out full history branch code.
75
76
    It does not support binding.
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
77
    """
78
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
79
    def initialize(self, a_bzrdir, name=None, repository=None,
80
                   append_revisions_only=None):
5705.2.1 by Jelmer Vernooij
Inline _initialize_helper.
81
        """Create a branch of this format in a_bzrdir.
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
82
83
        :param a_bzrdir: The bzrdir to initialize the branch in
84
        :param name: Name of colocated branch to create, if any
5705.2.1 by Jelmer Vernooij
Inline _initialize_helper.
85
        :param repository: Repository for this branch (unused)
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
86
        """
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
87
        if append_revisions_only:
88
            raise errors.UpgradeRequired(a_bzrdir.user_url)
5705.2.1 by Jelmer Vernooij
Inline _initialize_helper.
89
        if repository is not None:
90
            raise NotImplementedError(
91
                "initialize(repository=<not None>) on %r" % (self,))
5705.2.2 by Jelmer Vernooij
Only support BzrBranchFormat4 in pre-metadir bzr dirs.
92
        if not [isinstance(a_bzrdir._format, format) for format in
93
                self._compatible_bzrdirs]:
94
            raise errors.IncompatibleFormat(self, a_bzrdir._format)
5705.2.1 by Jelmer Vernooij
Inline _initialize_helper.
95
        utf8_files = [('revision-history', ''),
96
                      ('branch-name', ''),
97
                      ]
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
98
        mutter('creating branch %r in %s', self, a_bzrdir.user_url)
99
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
100
        control_files = lockable_files.LockableFiles(branch_transport,
101
            'branch-lock', lockable_files.TransportLock)
102
        control_files.create_lock()
103
        try:
104
            control_files.lock_write()
105
        except errors.LockContention:
106
            lock_taken = False
107
        else:
108
            lock_taken = True
109
        try:
110
            for (filename, content) in utf8_files:
111
                branch_transport.put_bytes(
112
                    filename, content,
113
                    mode=a_bzrdir._get_file_mode())
114
        finally:
115
            if lock_taken:
116
                control_files.unlock()
117
        branch = self.open(a_bzrdir, name, _found=True,
118
                found_repository=None)
119
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
120
        return branch
121
122
    def __init__(self):
123
        super(BzrBranchFormat4, self).__init__()
5582.10.87 by Jelmer Vernooij
Merge bzr.dev.
124
        from bzrlib.plugins.weave_fmt.bzrdir import (
125
            BzrDirFormat4, BzrDirFormat5, BzrDirFormat6,
126
            )
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
127
        self._matchingbzrdir = BzrDirFormat6()
5705.2.2 by Jelmer Vernooij
Only support BzrBranchFormat4 in pre-metadir bzr dirs.
128
        self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5,
129
            BzrDirFormat6]
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
130
131
    def network_name(self):
132
        """The network name for this format is the control dirs disk label."""
133
        return self._matchingbzrdir.get_format_string()
134
5705.2.4 by Jelmer Vernooij
Add BzrBranchFormat4.get_format_description().
135
    def get_format_description(self):
5705.2.6 by Jelmer Vernooij
Fix case sensitivity.
136
        return "Branch format 4"
5705.2.4 by Jelmer Vernooij
Add BzrBranchFormat4.get_format_description().
137
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
138
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
6305.3.3 by Jelmer Vernooij
Fix use of possible_transports.
139
            found_repository=None, possible_transports=None):
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
140
        """See BranchFormat.open()."""
6436.1.2 by Jelmer Vernooij
Fix some tests.
141
        if name is None:
142
            name = a_bzrdir._get_selected_branch()
143
        if name != "":
5699.4.8 by Jelmer Vernooij
Properly raise NoColocatedBranchSupport.
144
            raise errors.NoColocatedBranchSupport(self)
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
145
        if not _found:
146
            # we are being called directly and must probe.
147
            raise NotImplementedError
148
        if found_repository is None:
149
            found_repository = a_bzrdir.open_repository()
5718.8.1 by Jelmer Vernooij
Add FullHistoryBzrBranch.
150
        return BzrBranch4(_format=self,
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
151
                         _control_files=a_bzrdir._control_files,
152
                         a_bzrdir=a_bzrdir,
153
                         name=name,
6305.3.3 by Jelmer Vernooij
Fix use of possible_transports.
154
                         _repository=found_repository,
155
                         possible_transports=possible_transports)
5697.2.1 by Jelmer Vernooij
Move weave branch to bzrlib.branch_weave.
156
157
    def __str__(self):
158
        return "Bazaar-NG branch format 4"
159
160
    def supports_leaving_lock(self):
161
        return False