~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2012-03-29 08:34:13 UTC
  • mto: (6015.44.14 2.4)
  • mto: This revision was merged to the branch mainline in revision 6513.
  • Revision ID: bialix@ukr.net-20120329083413-d4bqqdtfn2yrxp4f
change st_dev, st_ino, st_uid, st_gid from int members to properties.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Weave-era branch implementations."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
from bzrlib import (
22
20
    errors,
23
21
    lockable_files,
24
22
    )
25
23
 
26
 
from bzrlib.decorators import (
27
 
    needs_read_lock,
28
 
    needs_write_lock,
29
 
    only_raises,
30
 
    )
31
 
from bzrlib.lock import LogicalLockResult
32
24
from bzrlib.trace import mutter
33
25
 
34
26
from bzrlib.branch import (
35
27
    BranchFormat,
36
 
    BranchWriteLockResult,
37
 
    )
38
 
from bzrlib.branchfmt.fullhistory import (
39
28
    FullHistoryBzrBranch,
40
29
    )
41
30
 
43
32
class BzrBranch4(FullHistoryBzrBranch):
44
33
    """Branch format 4."""
45
34
 
46
 
    def lock_write(self, token=None):
47
 
        """Lock the branch for write operations.
48
 
 
49
 
        :param token: A token to permit reacquiring a previously held and
50
 
            preserved lock.
51
 
        :return: A BranchWriteLockResult.
52
 
        """
53
 
        if not self.is_locked():
54
 
            self._note_lock('w')
55
 
        # All-in-one needs to always unlock/lock.
56
 
        self.repository._warn_if_deprecated(self)
57
 
        self.repository.lock_write()
58
 
        try:
59
 
            return BranchWriteLockResult(self.unlock,
60
 
                self.control_files.lock_write(token=token))
61
 
        except:
62
 
            self.repository.unlock()
63
 
            raise
64
 
 
65
 
    def lock_read(self):
66
 
        """Lock the branch for read operations.
67
 
 
68
 
        :return: A bzrlib.lock.LogicalLockResult.
69
 
        """
70
 
        if not self.is_locked():
71
 
            self._note_lock('r')
72
 
        # All-in-one needs to always unlock/lock.
73
 
        self.repository._warn_if_deprecated(self)
74
 
        self.repository.lock_read()
75
 
        try:
76
 
            self.control_files.lock_read()
77
 
            return LogicalLockResult(self.unlock)
78
 
        except:
79
 
            self.repository.unlock()
80
 
            raise
81
 
 
82
 
    @only_raises(errors.LockNotHeld, errors.LockBroken)
83
 
    def unlock(self):
84
 
        if self.control_files._lock_count == 2 and self.conf_store is not None:
85
 
            self.conf_store.save_changes()
86
 
        try:
87
 
            self.control_files.unlock()
88
 
        finally:
89
 
            # All-in-one needs to always unlock/lock.
90
 
            self.repository.unlock()
91
 
            if not self.control_files.is_locked():
92
 
                # we just released the lock
93
 
                self._clear_cached_state()
94
 
 
95
 
    def _get_checkout_format(self, lightweight=False):
 
35
    def _get_checkout_format(self):
96
36
        """Return the most suitable metadir for a checkout of this branch.
97
37
        """
98
38
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
99
39
        from bzrlib.bzrdir import BzrDirMetaFormat1
100
40
        format = BzrDirMetaFormat1()
101
 
        if lightweight:
102
 
            format.set_branch_format(self._format)
103
 
            format.repository_format = self.bzrdir._format.repository_format
104
 
        else:
105
 
            format.repository_format = RepositoryFormat7()
 
41
        format.repository_format = RepositoryFormat7()
106
42
        return format
107
43
 
108
44
    def unbind(self):
134
70
    It does not support binding.
135
71
    """
136
72
 
137
 
    def initialize(self, a_bzrdir, name=None, repository=None,
138
 
                   append_revisions_only=None):
 
73
    def initialize(self, a_bzrdir, name=None, repository=None):
139
74
        """Create a branch of this format in a_bzrdir.
140
75
 
141
76
        :param a_bzrdir: The bzrdir to initialize the branch in
142
77
        :param name: Name of colocated branch to create, if any
143
78
        :param repository: Repository for this branch (unused)
144
79
        """
145
 
        if append_revisions_only:
146
 
            raise errors.UpgradeRequired(a_bzrdir.user_url)
147
80
        if repository is not None:
148
81
            raise NotImplementedError(
149
82
                "initialize(repository=<not None>) on %r" % (self,))
194
127
        return "Branch format 4"
195
128
 
196
129
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
197
 
            found_repository=None, possible_transports=None):
 
130
            found_repository=None):
198
131
        """See BranchFormat.open()."""
199
 
        if name is None:
200
 
            name = a_bzrdir._get_selected_branch()
201
 
        if name != "":
 
132
        if name is not None:
202
133
            raise errors.NoColocatedBranchSupport(self)
203
134
        if not _found:
204
135
            # we are being called directly and must probe.
209
140
                         _control_files=a_bzrdir._control_files,
210
141
                         a_bzrdir=a_bzrdir,
211
142
                         name=name,
212
 
                         _repository=found_repository,
213
 
                         possible_transports=possible_transports)
 
143
                         _repository=found_repository)
214
144
 
215
145
    def __str__(self):
216
146
        return "Bazaar-NG branch format 4"