~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-04-28 09:40:23 UTC
  • mfrom: (5155.1.5 320119-exclude-ancestry)
  • Revision ID: pqm@pqm.ubuntu.com-20100428094023-7504mlou1qk28r9n
(vila) Add --exclude-common-ancestry log option (Vincent Ladeuil)

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
 
    def __str__(self):
2292
 
        return "BranchWriteLockResult(%s, %s)" % (self.branch_token,
2293
 
            self.unlock)
2294
 
 
2295
 
 
2296
2268
class BzrBranch(Branch, _RelockDebugMixin):
2297
2269
    """A branch stored in the actual filesystem.
2298
2270
 
2352
2324
        return self.control_files.is_locked()
2353
2325
 
2354
2326
    def lock_write(self, token=None):
2355
 
        """Lock the branch for write operations.
2356
 
 
2357
 
        :param token: A token to permit reacquiring a previously held and
2358
 
            preserved lock.
2359
 
        :return: A BranchWriteLockResult.
2360
 
        """
2361
2327
        if not self.is_locked():
2362
2328
            self._note_lock('w')
2363
2329
        # All-in-one needs to always unlock/lock.
2369
2335
        else:
2370
2336
            took_lock = False
2371
2337
        try:
2372
 
            return BranchWriteLockResult(self.unlock,
2373
 
                self.control_files.lock_write(token=token))
 
2338
            return self.control_files.lock_write(token=token)
2374
2339
        except:
2375
2340
            if took_lock:
2376
2341
                self.repository.unlock()
2377
2342
            raise
2378
2343
 
2379
2344
    def lock_read(self):
2380
 
        """Lock the branch for read operations.
2381
 
 
2382
 
        :return: An object with an unlock method which will release the lock
2383
 
            obtained.
2384
 
        """
2385
2345
        if not self.is_locked():
2386
2346
            self._note_lock('r')
2387
2347
        # All-in-one needs to always unlock/lock.
2394
2354
            took_lock = False
2395
2355
        try:
2396
2356
            self.control_files.lock_read()
2397
 
            return self
2398
2357
        except:
2399
2358
            if took_lock:
2400
2359
                self.repository.unlock()