~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-11 11:47:36 UTC
  • mfrom: (5200.3.8 lock_return)
  • Revision ID: pqm@pqm.ubuntu.com-20100511114736-mc1sq9zyo3vufec7
(lifeless) Provide a consistent interface to Tree, Branch,
 Repository where lock methods return an object with an unlock method to
 unlock the lock. This breaks the API for Branch,
 Repository on their lock_write methods. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    GraphIndex,
65
65
    InMemoryGraphIndex,
66
66
    )
 
67
from bzrlib.lock import LogicalLockResult
67
68
from bzrlib.repofmt.knitrepo import KnitRepository
68
69
from bzrlib.repository import (
69
70
    CommitBuilder,
70
71
    MetaDirRepositoryFormat,
71
72
    RepositoryFormat,
 
73
    RepositoryWriteLockResult,
72
74
    RootCommitBuilder,
73
75
    StreamSource,
74
76
    )
2340
2342
        return self._write_lock_count
2341
2343
 
2342
2344
    def lock_write(self, token=None):
 
2345
        """Lock the repository for writes.
 
2346
 
 
2347
        :return: A bzrlib.repository.RepositoryWriteLockResult.
 
2348
        """
2343
2349
        locked = self.is_locked()
2344
2350
        if not self._write_lock_count and locked:
2345
2351
            raise errors.ReadOnlyError(self)
2354
2360
                # Writes don't affect fallback repos
2355
2361
                repo.lock_read()
2356
2362
            self._refresh_data()
 
2363
        return RepositoryWriteLockResult(self.unlock, None)
2357
2364
 
2358
2365
    def lock_read(self):
 
2366
        """Lock the repository for reads.
 
2367
 
 
2368
        :return: A bzrlib.lock.LogicalLockResult.
 
2369
        """
2359
2370
        locked = self.is_locked()
2360
2371
        if self._write_lock_count:
2361
2372
            self._write_lock_count += 1
2368
2379
            for repo in self._fallback_repositories:
2369
2380
                repo.lock_read()
2370
2381
            self._refresh_data()
 
2382
        return LogicalLockResult(self.unlock)
2371
2383
 
2372
2384
    def leave_lock_in_place(self):
2373
2385
        # not supported - raise an error