~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2010-05-11 08:36:16 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100511083616-b8fjb19zomwupid0
Make all lock methods return Result objects, rather than lock_read returning self, as per John's review.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
50
50
from bzrlib.hooks import HookPoint, Hooks
51
51
from bzrlib.inter import InterObject
52
 
from bzrlib.lock import _RelockDebugMixin
 
52
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
53
53
from bzrlib import registry
54
54
from bzrlib.symbol_versioning import (
55
55
    deprecated_in,
295
295
    def lock_read(self):
296
296
        """Lock the branch for read operations.
297
297
 
298
 
        :return: An object with an unlock method which will release the lock
299
 
            obtained.
 
298
        :return: A bzrlib.lock.LogicalLockResult.
300
299
        """
301
300
        raise NotImplementedError(self.lock_read)
302
301
 
2276
2275
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2277
2276
 
2278
2277
 
2279
 
class BranchWriteLockResult(object):
 
2278
class BranchWriteLockResult(LogicalLockResult):
2280
2279
    """The result of write locking a branch.
2281
2280
 
2282
2281
    :ivar branch_token: The token obtained from the underlying branch lock, or
2285
2284
    """
2286
2285
 
2287
2286
    def __init__(self, unlock, branch_token):
 
2287
        LogicalLockResult.__init__(self, unlock)
2288
2288
        self.branch_token = branch_token
2289
 
        self.unlock = unlock
2290
2289
 
2291
 
    def __str__(self):
 
2290
    def __repr__(self):
2292
2291
        return "BranchWriteLockResult(%s, %s)" % (self.branch_token,
2293
2292
            self.unlock)
2294
2293
 
2379
2378
    def lock_read(self):
2380
2379
        """Lock the branch for read operations.
2381
2380
 
2382
 
        :return: An object with an unlock method which will release the lock
2383
 
            obtained.
 
2381
        :return: A bzrlib.lock.LogicalLockResult.
2384
2382
        """
2385
2383
        if not self.is_locked():
2386
2384
            self._note_lock('r')
2394
2392
            took_lock = False
2395
2393
        try:
2396
2394
            self.control_files.lock_read()
2397
 
            return self
 
2395
            return LogicalLockResult(self.unlock)
2398
2396
        except:
2399
2397
            if took_lock:
2400
2398
                self.repository.unlock()