~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

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):
 
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
        format.repository_format = RepositoryFormat7()
 
42
        return format
 
43
 
 
44
    def unbind(self):
 
45
        raise errors.UpgradeRequired(self.user_url)
 
46
 
 
47
    def bind(self, other):
 
48
        raise errors.UpgradeRequired(self.user_url)
 
49
 
 
50
    def set_bound_location(self, location):
 
51
        raise NotImplementedError(self.set_bound_location)
 
52
 
 
53
    def get_bound_location(self):
 
54
        return None
 
55
 
 
56
    def update(self):
 
57
        return None
 
58
 
 
59
    def get_master_branch(self, possible_transports=None):
 
60
        return None
 
61
 
 
62
 
 
63
class BzrBranchFormat4(BranchFormat):
 
64
    """Bzr branch format 4.
 
65
 
 
66
    This format has:
 
67
     - a revision-history file.
 
68
     - a branch-lock lock file [ to be shared with the bzrdir ]
 
69
 
 
70
    It does not support binding.
 
71
    """
 
72
 
 
73
    def initialize(self, a_bzrdir, name=None, repository=None):
 
74
        """Create a branch of this format in a_bzrdir.
 
75
 
 
76
        :param a_bzrdir: The bzrdir to initialize the branch in
 
77
        :param name: Name of colocated branch to create, if any
 
78
        :param repository: Repository for this branch (unused)
 
79
        """
 
80
        if repository is not None:
 
81
            raise NotImplementedError(
 
82
                "initialize(repository=<not None>) on %r" % (self,))
 
83
        if not [isinstance(a_bzrdir._format, format) for format in
 
84
                self._compatible_bzrdirs]:
 
85
            raise errors.IncompatibleFormat(self, a_bzrdir._format)
 
86
        utf8_files = [('revision-history', ''),
 
87
                      ('branch-name', ''),
 
88
                      ]
 
89
        mutter('creating branch %r in %s', self, a_bzrdir.user_url)
 
90
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
 
91
        control_files = lockable_files.LockableFiles(branch_transport,
 
92
            'branch-lock', lockable_files.TransportLock)
 
93
        control_files.create_lock()
 
94
        try:
 
95
            control_files.lock_write()
 
96
        except errors.LockContention:
 
97
            lock_taken = False
 
98
        else:
 
99
            lock_taken = True
 
100
        try:
 
101
            for (filename, content) in utf8_files:
 
102
                branch_transport.put_bytes(
 
103
                    filename, content,
 
104
                    mode=a_bzrdir._get_file_mode())
 
105
        finally:
 
106
            if lock_taken:
 
107
                control_files.unlock()
 
108
        branch = self.open(a_bzrdir, name, _found=True,
 
109
                found_repository=None)
 
110
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
 
111
        return branch
 
112
 
 
113
    def __init__(self):
 
114
        super(BzrBranchFormat4, self).__init__()
 
115
        from bzrlib.plugins.weave_fmt.bzrdir import (
 
116
            BzrDirFormat4, BzrDirFormat5, BzrDirFormat6,
 
117
            )
 
118
        self._matchingbzrdir = BzrDirFormat6()
 
119
        self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5,
 
120
            BzrDirFormat6]
 
121
 
 
122
    def network_name(self):
 
123
        """The network name for this format is the control dirs disk label."""
 
124
        return self._matchingbzrdir.get_format_string()
 
125
 
 
126
    def get_format_description(self):
 
127
        return "Branch format 4"
 
128
 
 
129
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
 
130
            found_repository=None):
 
131
        """See BranchFormat.open()."""
 
132
        if name is not None:
 
133
            raise errors.NoColocatedBranchSupport(self)
 
134
        if not _found:
 
135
            # we are being called directly and must probe.
 
136
            raise NotImplementedError
 
137
        if found_repository is None:
 
138
            found_repository = a_bzrdir.open_repository()
 
139
        return BzrBranch4(_format=self,
 
140
                         _control_files=a_bzrdir._control_files,
 
141
                         a_bzrdir=a_bzrdir,
 
142
                         name=name,
 
143
                         _repository=found_repository)
 
144
 
 
145
    def __str__(self):
 
146
        return "Bazaar-NG branch format 4"
 
147
 
 
148
    def supports_leaving_lock(self):
 
149
        return False