~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/branch.py

  • Committer: Andrew Bennetts
  • Date: 2007-02-28 07:08:25 UTC
  • mfrom: (2018.13.1 hpss)
  • mto: (2018.5.80 hpss)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: andrew.bennetts@canonical.com-20070228070825-q2dvkjb0a11ouhtx
Update to current hpss branch?  Fix lots of test failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        return self.do_with_branch(branch, *args)
40
40
 
41
41
 
 
42
class SmartServerLockedBranchRequest(SmartServerBranchRequest):
 
43
    """Base class for handling common branch request logic for requests that
 
44
    need a write lock.
 
45
    """
 
46
 
 
47
    def do_with_branch(self, branch, branch_token, repo_token, *args):
 
48
        """Execute a request for a branch.
 
49
 
 
50
        A write lock will be acquired with the given tokens for the branch and
 
51
        repository locks.  The lock will be released once the request is
 
52
        processed.  The physical lock state won't be changed.
 
53
        """
 
54
        # XXX: write a test for LockContention
 
55
        branch.lock_write(tokens=(branch_token, repo_token))
 
56
        try:
 
57
            return self.do_with_locked_branch(branch, *args)
 
58
        finally:
 
59
            branch.unlock()
 
60
 
 
61
 
42
62
class SmartServerBranchGetConfigFile(SmartServerBranchRequest):
43
63
    
44
64
    def do_with_branch(self, branch):
79
99
            ('ok', str(revno), last_revision.encode('utf8')))
80
100
 
81
101
 
82
 
class SmartServerBranchRequestSetLastRevision(SmartServerBranchRequest):
 
102
class SmartServerBranchRequestSetLastRevision(SmartServerLockedBranchRequest):
83
103
    
84
 
    def do_with_branch(self, branch, new_last_revision_id):
 
104
    def do_with_locked_branch(self, branch, new_last_revision_id):
85
105
        unicode_new_last_revision_id = new_last_revision_id.decode('utf-8')  # XXX test
86
106
        if new_last_revision_id == '':
87
107
            branch.set_revision_history([])