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