~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/weave_fmt/branch.py

  • Committer: Andrew Bennetts
  • Date: 2010-11-22 03:35:24 UTC
  • mto: This revision was merged to the branch mainline in revision 5547.
  • Revision ID: andrew.bennetts@canonical.com-20101122033524-ouxj0onm3gtkimx3
Remove RepositoryFormatCHK1 and RepositoryFormatCHK2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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,
28
 
    FullHistoryBzrBranch,
29
 
    )
30
 
 
31
 
 
32
 
class BzrBranch4(FullHistoryBzrBranch):
33
 
    """Branch format 4."""
34
 
 
35
 
    def _get_checkout_format(self, lightweight=False):
36
 
        """Return the most suitable metadir for a checkout of this branch.
37
 
        """
38
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
39
 
        from bzrlib.bzrdir import BzrDirMetaFormat1
40
 
        format = BzrDirMetaFormat1()
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()
46
 
        return format
47
 
 
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
 
 
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 ]
73
 
 
74
 
    It does not support binding.
75
 
    """
76
 
 
77
 
    def initialize(self, a_bzrdir, name=None, repository=None,
78
 
                   append_revisions_only=None):
79
 
        """Create a branch of this format in a_bzrdir.
80
 
 
81
 
        :param a_bzrdir: The bzrdir to initialize the branch in
82
 
        :param name: Name of colocated branch to create, if any
83
 
        :param repository: Repository for this branch (unused)
84
 
        """
85
 
        if append_revisions_only:
86
 
            raise errors.UpgradeRequired(a_bzrdir.user_url)
87
 
        if repository is not None:
88
 
            raise NotImplementedError(
89
 
                "initialize(repository=<not None>) on %r" % (self,))
90
 
        if not [isinstance(a_bzrdir._format, format) for format in
91
 
                self._compatible_bzrdirs]:
92
 
            raise errors.IncompatibleFormat(self, a_bzrdir._format)
93
 
        utf8_files = [('revision-history', ''),
94
 
                      ('branch-name', ''),
95
 
                      ]
96
 
        mutter('creating branch %r in %s', self, a_bzrdir.user_url)
97
 
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
98
 
        control_files = lockable_files.LockableFiles(branch_transport,
99
 
            'branch-lock', lockable_files.TransportLock)
100
 
        control_files.create_lock()
101
 
        try:
102
 
            control_files.lock_write()
103
 
        except errors.LockContention:
104
 
            lock_taken = False
105
 
        else:
106
 
            lock_taken = True
107
 
        try:
108
 
            for (filename, content) in utf8_files:
109
 
                branch_transport.put_bytes(
110
 
                    filename, content,
111
 
                    mode=a_bzrdir._get_file_mode())
112
 
        finally:
113
 
            if lock_taken:
114
 
                control_files.unlock()
115
 
        branch = self.open(a_bzrdir, name, _found=True,
116
 
                found_repository=None)
117
 
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
118
 
        return branch
119
 
 
120
 
    def __init__(self):
121
 
        super(BzrBranchFormat4, self).__init__()
122
 
        from bzrlib.plugins.weave_fmt.bzrdir import (
123
 
            BzrDirFormat4, BzrDirFormat5, BzrDirFormat6,
124
 
            )
125
 
        self._matchingbzrdir = BzrDirFormat6()
126
 
        self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5,
127
 
            BzrDirFormat6]
128
 
 
129
 
    def network_name(self):
130
 
        """The network name for this format is the control dirs disk label."""
131
 
        return self._matchingbzrdir.get_format_string()
132
 
 
133
 
    def get_format_description(self):
134
 
        return "Branch format 4"
135
 
 
136
 
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
137
 
            found_repository=None):
138
 
        """See BranchFormat.open()."""
139
 
        if name is not None:
140
 
            raise errors.NoColocatedBranchSupport(self)
141
 
        if not _found:
142
 
            # we are being called directly and must probe.
143
 
            raise NotImplementedError
144
 
        if found_repository is None:
145
 
            found_repository = a_bzrdir.open_repository()
146
 
        return BzrBranch4(_format=self,
147
 
                         _control_files=a_bzrdir._control_files,
148
 
                         a_bzrdir=a_bzrdir,
149
 
                         name=name,
150
 
                         _repository=found_repository)
151
 
 
152
 
    def __str__(self):
153
 
        return "Bazaar-NG branch format 4"
154
 
 
155
 
    def supports_leaving_lock(self):
156
 
        return False