~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.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:
33
33
    static_tuple,
34
34
    symbol_versioning,
35
35
)
36
 
from bzrlib.branch import BranchReferenceFormat
 
36
from bzrlib.branch import BranchReferenceFormat, BranchWriteLockResult
37
37
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
38
38
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
39
39
from bzrlib.errors import (
43
43
from bzrlib.lockable_files import LockableFiles
44
44
from bzrlib.smart import client, vfs, repository as smart_repo
45
45
from bzrlib.revision import ensure_null, NULL_REVISION
 
46
from bzrlib.repository import RepositoryWriteLockResult
46
47
from bzrlib.trace import mutter, note, warning
47
48
 
48
49
 
997
998
        pass
998
999
 
999
1000
    def lock_read(self):
 
1001
        """Lock the repository for read operations.
 
1002
 
 
1003
        :return: An object with an unlock method which will release the lock
 
1004
            obtained.
 
1005
        """
1000
1006
        # wrong eventually - want a local lock cache context
1001
1007
        if not self._lock_mode:
1002
1008
            self._note_lock('r')
1009
1015
                repo.lock_read()
1010
1016
        else:
1011
1017
            self._lock_count += 1
 
1018
        return self
1012
1019
 
1013
1020
    def _remote_lock_write(self, token):
1014
1021
        path = self.bzrdir._path_for_remote_call(self._client)
1054
1061
            raise errors.ReadOnlyError(self)
1055
1062
        else:
1056
1063
            self._lock_count += 1
1057
 
        return self._lock_token or None
 
1064
        return RepositoryWriteLockResult(self.unlock, self._lock_token or None)
1058
1065
 
1059
1066
    def leave_lock_in_place(self):
1060
1067
        if not self._lock_token:
2387
2394
            self._vfs_set_tags_bytes(bytes)
2388
2395
 
2389
2396
    def lock_read(self):
 
2397
        """Lock the branch for read operations.
 
2398
 
 
2399
        :return: An object with an unlock method which will release the lock
 
2400
            obtained.
 
2401
        """
2390
2402
        self.repository.lock_read()
2391
2403
        if not self._lock_mode:
2392
2404
            self._note_lock('r')
2396
2408
                self._real_branch.lock_read()
2397
2409
        else:
2398
2410
            self._lock_count += 1
 
2411
        return self
2399
2412
 
2400
2413
    def _remote_lock_write(self, token):
2401
2414
        if token is None:
2402
2415
            branch_token = repo_token = ''
2403
2416
        else:
2404
2417
            branch_token = token
2405
 
            repo_token = self.repository.lock_write()
 
2418
            repo_token = self.repository.lock_write().repository_token
2406
2419
            self.repository.unlock()
2407
2420
        err_context = {'token': token}
2408
2421
        response = self._call(
2445
2458
            self._lock_count += 1
2446
2459
            # Re-lock the repository too.
2447
2460
            self.repository.lock_write(self._repo_lock_token)
2448
 
        return self._lock_token or None
 
2461
        return BranchWriteLockResult(self.unlock, self._lock_token or None)
2449
2462
 
2450
2463
    def _unlock(self, branch_token, repo_token):
2451
2464
        err_context = {'token': str((branch_token, repo_token))}