/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 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

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,
283
283
        new_history.reverse()
284
284
        return new_history
285
285
 
286
 
    def lock_write(self, token=None):
287
 
        """Lock the branch for write operations.
288
 
 
289
 
        :param token: A token to permit reacquiring a previously held and
290
 
            preserved lock.
291
 
        :return: A BranchWriteLockResult.
292
 
        """
 
286
    def lock_write(self):
293
287
        raise NotImplementedError(self.lock_write)
294
288
 
295
289
    def lock_read(self):
296
 
        """Lock the branch for read operations.
297
 
 
298
 
        :return: A bzrlib.lock.LogicalLockResult.
299
 
        """
300
290
        raise NotImplementedError(self.lock_read)
301
291
 
302
292
    def unlock(self):
2275
2265
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2276
2266
 
2277
2267
 
2278
 
class BranchWriteLockResult(LogicalLockResult):
2279
 
    """The result of write locking a branch.
2280
 
 
2281
 
    :ivar branch_token: The token obtained from the underlying branch lock, or
2282
 
        None.
2283
 
    :ivar unlock: A callable which will unlock the lock.
2284
 
    """
2285
 
 
2286
 
    def __init__(self, unlock, branch_token):
2287
 
        LogicalLockResult.__init__(self, unlock)
2288
 
        self.branch_token = branch_token
2289
 
 
2290
 
    def __repr__(self):
2291
 
        return "BranchWriteLockResult(%s, %s)" % (self.branch_token,
2292
 
            self.unlock)
2293
 
 
2294
 
 
2295
2268
class BzrBranch(Branch, _RelockDebugMixin):
2296
2269
    """A branch stored in the actual filesystem.
2297
2270
 
2351
2324
        return self.control_files.is_locked()
2352
2325
 
2353
2326
    def lock_write(self, token=None):
2354
 
        """Lock the branch for write operations.
2355
 
 
2356
 
        :param token: A token to permit reacquiring a previously held and
2357
 
            preserved lock.
2358
 
        :return: A BranchWriteLockResult.
2359
 
        """
2360
2327
        if not self.is_locked():
2361
2328
            self._note_lock('w')
2362
2329
        # All-in-one needs to always unlock/lock.
2368
2335
        else:
2369
2336
            took_lock = False
2370
2337
        try:
2371
 
            return BranchWriteLockResult(self.unlock,
2372
 
                self.control_files.lock_write(token=token))
 
2338
            return self.control_files.lock_write(token=token)
2373
2339
        except:
2374
2340
            if took_lock:
2375
2341
                self.repository.unlock()
2376
2342
            raise
2377
2343
 
2378
2344
    def lock_read(self):
2379
 
        """Lock the branch for read operations.
2380
 
 
2381
 
        :return: A bzrlib.lock.LogicalLockResult.
2382
 
        """
2383
2345
        if not self.is_locked():
2384
2346
            self._note_lock('r')
2385
2347
        # All-in-one needs to always unlock/lock.
2392
2354
            took_lock = False
2393
2355
        try:
2394
2356
            self.control_files.lock_read()
2395
 
            return LogicalLockResult(self.unlock)
2396
2357
        except:
2397
2358
            if took_lock:
2398
2359
                self.repository.unlock()