/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

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, LogicalLockResult
 
52
from bzrlib.lock import _RelockDebugMixin
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: A bzrlib.lock.LogicalLockResult.
 
298
        :return: An object with an unlock method which will release the lock
 
299
            obtained.
299
300
        """
300
301
        raise NotImplementedError(self.lock_read)
301
302
 
2275
2276
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2276
2277
 
2277
2278
 
2278
 
class BranchWriteLockResult(LogicalLockResult):
 
2279
class BranchWriteLockResult(object):
2279
2280
    """The result of write locking a branch.
2280
2281
 
2281
2282
    :ivar branch_token: The token obtained from the underlying branch lock, or
2284
2285
    """
2285
2286
 
2286
2287
    def __init__(self, unlock, branch_token):
2287
 
        LogicalLockResult.__init__(self, unlock)
2288
2288
        self.branch_token = branch_token
2289
 
 
2290
 
    def __repr__(self):
2291
 
        return "BranchWriteLockResult(%s, %s)" % (self.branch_token,
2292
 
            self.unlock)
 
2289
        self.unlock = unlock
2293
2290
 
2294
2291
 
2295
2292
class BzrBranch(Branch, _RelockDebugMixin):
2378
2375
    def lock_read(self):
2379
2376
        """Lock the branch for read operations.
2380
2377
 
2381
 
        :return: A bzrlib.lock.LogicalLockResult.
 
2378
        :return: An object with an unlock method which will release the lock
 
2379
            obtained.
2382
2380
        """
2383
2381
        if not self.is_locked():
2384
2382
            self._note_lock('r')
2392
2390
            took_lock = False
2393
2391
        try:
2394
2392
            self.control_files.lock_read()
2395
 
            return LogicalLockResult(self.unlock)
 
2393
            return self
2396
2394
        except:
2397
2395
            if took_lock:
2398
2396
                self.repository.unlock()