~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

Add Repository.{dont_,}leave_lock_in_place.

Show diffs side-by-side

added added

removed removed

Lines of Context:
189
189
        else:
190
190
            self._client = _client
191
191
        self._format = RemoteRepositoryFormat()
 
192
        self._lock_mode = None
 
193
        self._lock_token = None
 
194
        self._lock_count = 0
192
195
 
193
196
    def _ensure_real(self):
194
197
        """Ensure that there is a _real_repository set.
273
276
 
274
277
    def lock_read(self):
275
278
        # wrong eventually - want a local lock cache context
 
279
        if not self._lock_mode:
 
280
            self._lock_mode = 'r'
 
281
            self._lock_count = 1
 
282
        else:
 
283
            self._lock_count += 1
276
284
        self._ensure_real()
277
285
        return self._real_repository.lock_read()
278
286
 
279
 
    def lock_write(self):
 
287
    def lock_write(self, token=None):
280
288
        # definately wrong: want to check if there is a real repo
281
289
        # and not thunk through if not
282
 
        self._ensure_real()
283
 
        return self._real_repository.lock_write()
 
290
        if not self._lock_mode:
 
291
            self._ensure_real()
 
292
            self._lock_token = self._real_repository.lock_write(token=token)
 
293
            self._lock_mode = 'w'
 
294
            self._lock_count = 1
 
295
        elif self._lock_mode == 'r':
 
296
            raise errors.ReadOnlyTransaction
 
297
        else:
 
298
            self._lock_count += 1
 
299
        return self._lock_token
 
300
 
 
301
    def leave_lock_in_place(self):
 
302
        self._real_repository.leave_lock_in_place()
 
303
 
 
304
    def dont_leave_lock_in_place(self):
 
305
        self._real_repository.dont_leave_lock_in_place()
 
306
 
 
307
    def _set_real_repository(self, repository):
 
308
        """Set the _real_repository for this repository.
 
309
 
 
310
        :param repository: The repository to fallback to for non-hpss
 
311
            implemented operations.
 
312
        """
 
313
        self._real_repository = repository
 
314
        if self._lock_mode == 'w':
 
315
            # if we are already locked, the real repository must be able to
 
316
            # acquire the lock with our token.
 
317
            self._real_repository.lock_write(self._lock_token)
284
318
 
285
319
    def unlock(self):
286
320
        # should free cache context.
287
 
        return self._real_repository.unlock()
 
321
        self._lock_count -= 1
 
322
        if not self._lock_count:
 
323
            self._lock_mode = None
 
324
            self._lock_token = None
 
325
            return self._real_repository.unlock()
288
326
 
289
327
    def break_lock(self):
290
328
        # should hand off to the network - or better yet, we should not
370
408
            assert vfs.vfs_enabled()
371
409
            self.bzrdir._ensure_real()
372
410
            self._real_branch = self.bzrdir._real_bzrdir.open_branch()
373
 
            # give the repository the matching file level repo.
374
 
            self.repository._real_repository = self._real_branch.repository
375
 
            # give the branch the remote repository to let fast-pathing happen
 
411
            # Give the remote repository the matching real repo.
 
412
            self.repository._set_real_repository(self._real_branch.repository)
 
413
            # Give the branch the remote repository to let fast-pathing happen.
376
414
            self._real_branch.repository = self.repository
377
415
 
378
416
    def get_physical_lock_status(self):
385
423
        self._ensure_real()
386
424
        return self._real_branch.lock_read()
387
425
 
388
 
    def lock_write(self):
 
426
    def lock_write(self, token=None):
389
427
        self._ensure_real()
390
 
        return self._real_branch.lock_write()
 
428
        return self._real_branch.lock_write(token=token)
391
429
 
392
430
    def unlock(self):
393
431
        self._ensure_real()