~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2006-01-12 08:37:10 UTC
  • mto: (1185.65.25 storage)
  • mto: This revision was merged to the branch mainline in revision 1550.
  • Revision ID: mbp@sourcefrog.net-20060112083710-642730d8ae44f906
Various updates to make storage branch mergeable:

 * remove duplication of needs_read_lock, needs_write_lock decorators, 
   and move them into bzrlib.decorators

 * add Branch.peek_lock_mode

 * some docs

 * fix up merge flux in tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
from bzrlib.tree import EmptyTree, RevisionTree
49
49
import bzrlib.ui
50
50
import bzrlib.xml5
 
51
from bzrlib.decorators import needs_read_lock, needs_write_lock
51
52
 
52
53
 
53
54
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n"
54
55
BZR_BRANCH_FORMAT_5 = "Bazaar-NG branch, format 5\n"
55
56
BZR_BRANCH_FORMAT_6 = "Bazaar-NG branch, format 6\n"
56
 
## TODO: Maybe include checks for common corruption of newlines, etc?
57
 
 
 
57
 
 
58
 
 
59
# TODO: Maybe include checks for common corruption of newlines, etc?
58
60
 
59
61
# TODO: Some operations like log might retrieve the same revisions
60
62
# repeatedly to calculate deltas.  We could perhaps have a weakref
61
63
# cache in memory to make this faster.  In general anything can be
62
64
# cached in memory between lock and unlock operations.
63
65
 
 
66
# FIXME: At the moment locking the Branch locks both the repository and the
 
67
# control files, representing the two aspects currently controlled by one
 
68
# object.  However, they currently both map to the same lockfile. 
 
69
 
64
70
def find_branch(*ignored, **ignored_too):
65
71
    # XXX: leave this here for about one release, then remove it
66
72
    raise NotImplementedError('find_branch() is not supported anymore, '
67
73
                              'please use one of the new branch constructors')
68
74
 
69
75
 
70
 
def needs_read_lock(unbound):
71
 
    """Decorate unbound to take out and release a read lock."""
72
 
    def decorated(self, *args, **kwargs):
73
 
        self.lock_read()
74
 
        try:
75
 
            return unbound(self, *args, **kwargs)
76
 
        finally:
77
 
            self.unlock()
78
 
    return decorated
79
 
 
80
 
 
81
 
def needs_write_lock(unbound):
82
 
    """Decorate unbound to take out and release a write lock."""
83
 
    def decorated(self, *args, **kwargs):
84
 
        self.lock_write()
85
 
        try:
86
 
            return unbound(self, *args, **kwargs)
87
 
        finally:
88
 
            self.unlock()
89
 
    return decorated
90
 
 
91
76
######################################################################
92
77
# branch objects
93
78
 
174
159
    def unlock(self):
175
160
        raise NotImplementedError('unlock is abstract')
176
161
 
 
162
    def peek_lock_mode(self):
 
163
        """Return lock mode for the Branch: 'r', 'w' or None"""
 
164
        raise NotImplementedError(self.is_locked)
 
165
 
177
166
    def abspath(self, name):
178
167
        """Return absolute filename for something in the branch
179
168
        
619
608
        self.repository.unlock()
620
609
        self.control_files.unlock()
621
610
 
 
611
    def peek_lock_mode(self):
 
612
        if self.control_files._lock_count == 0:
 
613
            return None
 
614
        else:
 
615
            return self.control_files._lock_mode
 
616
 
622
617
    @needs_read_lock
623
618
    def print_file(self, file, revision_id):
624
619
        """See Branch.print_file."""