~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Andrew Bennetts
  • Date: 2009-10-07 08:17:25 UTC
  • mto: This revision was merged to the branch mainline in revision 4734.
  • Revision ID: andrew.bennetts@canonical.com-20091007081725-4t3vkhher69a4k0j
Refactor to reduce duplication.

Show diffs side-by-side

added added

removed removed

Lines of Context:
619
619
        return self._custom_format._serializer
620
620
 
621
621
 
622
 
class RemoteRepository(_RpcHelper):
 
622
class RemoteRepository(_RpcHelper, lock._RelockDebugMixin):
623
623
    """Repository accessed over rpc.
624
624
 
625
625
    For the moment most operations are performed using local transport-backed
651
651
        self._lock_token = None
652
652
        self._lock_count = 0
653
653
        self._leave_lock = False
654
 
        self._prev_lock = None
655
654
        # Cache of revision parents; misses are cached during read locks, and
656
655
        # write locks when no _real_repository has been set.
657
656
        self._unstacked_provider = graph.CachingParentsProvider(
950
949
    def lock_read(self):
951
950
        # wrong eventually - want a local lock cache context
952
951
        if not self._lock_mode:
953
 
            if 'relock' in debug.debug_flags and self._prev_lock == 'r':
954
 
                note('%r was read locked again', self)
955
 
            self._prev_lock = 'r'
 
952
            self._note_lock('r')
956
953
            self._lock_mode = 'r'
957
954
            self._lock_count = 1
958
955
            self._unstacked_provider.enable_cache(cache_misses=True)
978
975
 
979
976
    def lock_write(self, token=None, _skip_rpc=False):
980
977
        if not self._lock_mode:
981
 
            if 'relock' in debug.debug_flags and self._prev_lock == 'w':
982
 
                note('%r was write locked again', self)
983
 
            self._prev_lock = 'w'
 
978
            self._note_lock('w')
984
979
            if _skip_rpc:
985
980
                if self._lock_token is not None:
986
981
                    if token != self._lock_token:
2088
2083
        return self._custom_format.supports_set_append_revisions_only()
2089
2084
 
2090
2085
 
2091
 
class RemoteBranch(branch.Branch, _RpcHelper):
 
2086
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2092
2087
    """Branch stored on a server accessed by HPSS RPC.
2093
2088
 
2094
2089
    At the moment most operations are mapped down to simple file operations.
2138
2133
        self._repo_lock_token = None
2139
2134
        self._lock_count = 0
2140
2135
        self._leave_lock = False
2141
 
        self._prev_lock = None
2142
2136
        # Setup a format: note that we cannot call _ensure_real until all the
2143
2137
        # attributes above are set: This code cannot be moved higher up in this
2144
2138
        # function.
2326
2320
    def lock_read(self):
2327
2321
        self.repository.lock_read()
2328
2322
        if not self._lock_mode:
2329
 
            if 'relock' in debug.debug_flags and self._prev_lock == 'r':
2330
 
                note('%r was read locked again', self)
2331
 
            self._prev_lock = 'r'
 
2323
            self._note_lock('r')
2332
2324
            self._lock_mode = 'r'
2333
2325
            self._lock_count = 1
2334
2326
            if self._real_branch is not None:
2354
2346
 
2355
2347
    def lock_write(self, token=None):
2356
2348
        if not self._lock_mode:
2357
 
            if 'relock' in debug.debug_flags and self._prev_lock == 'w':
2358
 
                note('%r was write locked again', self)
2359
 
            self._prev_lock = 'w'
 
2349
            self._note_lock('w')
2360
2350
            # Lock the branch and repo in one remote call.
2361
2351
            remote_tokens = self._remote_lock_write(token)
2362
2352
            self._lock_token, self._repo_lock_token = remote_tokens