/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:
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: An object with an unlock method which will release the lock
299
 
            obtained.
300
 
        """
301
290
        raise NotImplementedError(self.lock_read)
302
291
 
303
292
    def unlock(self):
2276
2265
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2277
2266
 
2278
2267
 
2279
 
class BranchWriteLockResult(object):
2280
 
    """The result of write locking a branch.
2281
 
 
2282
 
    :ivar branch_token: The token obtained from the underlying branch lock, or
2283
 
        None.
2284
 
    :ivar unlock: A callable which will unlock the lock.
2285
 
    """
2286
 
 
2287
 
    def __init__(self, unlock, branch_token):
2288
 
        self.branch_token = branch_token
2289
 
        self.unlock = unlock
2290
 
 
2291
 
 
2292
2268
class BzrBranch(Branch, _RelockDebugMixin):
2293
2269
    """A branch stored in the actual filesystem.
2294
2270
 
2348
2324
        return self.control_files.is_locked()
2349
2325
 
2350
2326
    def lock_write(self, token=None):
2351
 
        """Lock the branch for write operations.
2352
 
 
2353
 
        :param token: A token to permit reacquiring a previously held and
2354
 
            preserved lock.
2355
 
        :return: A BranchWriteLockResult.
2356
 
        """
2357
2327
        if not self.is_locked():
2358
2328
            self._note_lock('w')
2359
2329
        # All-in-one needs to always unlock/lock.
2365
2335
        else:
2366
2336
            took_lock = False
2367
2337
        try:
2368
 
            return BranchWriteLockResult(self.unlock,
2369
 
                self.control_files.lock_write(token=token))
 
2338
            return self.control_files.lock_write(token=token)
2370
2339
        except:
2371
2340
            if took_lock:
2372
2341
                self.repository.unlock()
2373
2342
            raise
2374
2343
 
2375
2344
    def lock_read(self):
2376
 
        """Lock the branch for read operations.
2377
 
 
2378
 
        :return: An object with an unlock method which will release the lock
2379
 
            obtained.
2380
 
        """
2381
2345
        if not self.is_locked():
2382
2346
            self._note_lock('r')
2383
2347
        # All-in-one needs to always unlock/lock.
2390
2354
            took_lock = False
2391
2355
        try:
2392
2356
            self.control_files.lock_read()
2393
 
            return self
2394
2357
        except:
2395
2358
            if took_lock:
2396
2359
                self.repository.unlock()