/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: Martin Pool
  • Date: 2010-04-28 07:03:38 UTC
  • mfrom: (5188 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5189.
  • Revision ID: mbp@sourcefrog.net-20100428070338-2af8y3takgfkrkyp
merge news

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):
428
417
            * 'include' - the stop revision is the last item in the result
429
418
            * 'with-merges' - include the stop revision and all of its
430
419
              merged revisions in the result
431
 
            * 'with-merges-without-common-ancestry' - filter out revisions 
432
 
              that are in both ancestries
433
420
        :param direction: either 'reverse' or 'forward':
434
421
            * reverse means return the start_revision_id first, i.e.
435
422
              start at the most recent revision and go backwards in history
466
453
            stop_revision_id, stop_rule)
467
454
        # Make sure we don't return revisions that are not part of the
468
455
        # start_revision_id ancestry.
469
 
        filtered = self._filter_start_non_ancestors(filtered)
 
456
        filtered = self._filter_non_ancestors(filtered)
470
457
        if direction == 'reverse':
471
458
            return filtered
472
459
        if direction == 'forward':
509
496
                       node.end_of_merge)
510
497
                if rev_id == stop_revision_id:
511
498
                    return
512
 
        elif stop_rule == 'with-merges-without-common-ancestry':
513
 
            # We want to exclude all revisions that are already part of the
514
 
            # stop_revision_id ancestry.
515
 
            graph = self.repository.get_graph()
516
 
            ancestors = graph.find_unique_ancestors(start_revision_id,
517
 
                                                    [stop_revision_id])
518
 
            for node in rev_iter:
519
 
                rev_id = node.key[-1]
520
 
                if rev_id not in ancestors:
521
 
                    continue
522
 
                yield (rev_id, node.merge_depth, node.revno,
523
 
                       node.end_of_merge)
524
499
        elif stop_rule == 'with-merges':
525
500
            stop_rev = self.repository.get_revision(stop_revision_id)
526
501
            if stop_rev.parent_ids:
549
524
        else:
550
525
            raise ValueError('invalid stop_rule %r' % stop_rule)
551
526
 
552
 
    def _filter_start_non_ancestors(self, rev_iter):
 
527
    def _filter_non_ancestors(self, rev_iter):
553
528
        # If we started from a dotted revno, we want to consider it as a tip
554
529
        # and don't want to yield revisions that are not part of its
555
530
        # ancestry. Given the order guaranteed by the merge sort, we will see
2276
2251
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2277
2252
 
2278
2253
 
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
2254
class BzrBranch(Branch, _RelockDebugMixin):
2293
2255
    """A branch stored in the actual filesystem.
2294
2256
 
2348
2310
        return self.control_files.is_locked()
2349
2311
 
2350
2312
    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
2313
        if not self.is_locked():
2358
2314
            self._note_lock('w')
2359
2315
        # All-in-one needs to always unlock/lock.
2365
2321
        else:
2366
2322
            took_lock = False
2367
2323
        try:
2368
 
            return BranchWriteLockResult(self.unlock,
2369
 
                self.control_files.lock_write(token=token))
 
2324
            return self.control_files.lock_write(token=token)
2370
2325
        except:
2371
2326
            if took_lock:
2372
2327
                self.repository.unlock()
2373
2328
            raise
2374
2329
 
2375
2330
    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
2331
        if not self.is_locked():
2382
2332
            self._note_lock('r')
2383
2333
        # All-in-one needs to always unlock/lock.
2390
2340
            took_lock = False
2391
2341
        try:
2392
2342
            self.control_files.lock_read()
2393
 
            return self
2394
2343
        except:
2395
2344
            if took_lock:
2396
2345
                self.repository.unlock()