~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: 2009-01-31 23:19:33 UTC
  • mfrom: (3975.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090131231933-8o4phfvmuuizyyn6
add stop-rule to iter_merge_sorted_revisions() (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
291
291
 
292
292
    @needs_read_lock
293
293
    def iter_merge_sorted_revisions(self, start_revision_id=None,
294
 
            stop_revision_id=None, direction='reverse'):
 
294
            stop_revision_id=None, stop_rule='exclude', direction='reverse'):
295
295
        """Walk the revisions for a branch in merge sorted order.
296
296
 
297
297
        Merge sorted order is the output from a merge-aware,
301
301
        :param start_revision_id: the revision_id to begin walking from.
302
302
            If None, the branch tip is used.
303
303
        :param stop_revision_id: the revision_id to terminate the walk
304
 
            after (i.e. the range is inclusive). If None, the rest of
305
 
            history is included.
 
304
            after. If None, the rest of history is included.
 
305
        :param stop_rule: if stop_revision_id is not None, the precise rule
 
306
            to use for termination:
 
307
            * 'exclude' - leave the stop revision out of the result (default)
 
308
            * 'include' - the stop revision is the last item in the result
 
309
            * 'with-merges' - include the stop revision and all of its
 
310
              merged revisions in the result
306
311
        :param direction: either 'reverse' or 'forward':
307
312
            * reverse means return the start_revision_id first, i.e.
308
313
              start at the most recent revision and go backwards in history
341
346
 
342
347
        filtered = self._filter_merge_sorted_revisions(
343
348
            self._merge_sorted_revisions_cache, start_revision_id,
344
 
            stop_revision_id)
 
349
            stop_revision_id, stop_rule)
345
350
        if direction == 'reverse':
346
351
            return filtered
347
352
        if direction == 'forward':
350
355
            raise ValueError('invalid direction %r' % direction)
351
356
 
352
357
    def _filter_merge_sorted_revisions(self, merge_sorted_revisions,
353
 
        start_revision_id, stop_revision_id):
 
358
        start_revision_id, stop_revision_id, stop_rule):
354
359
        """Iterate over an inclusive range of sorted revisions."""
355
360
        rev_iter = iter(merge_sorted_revisions)
356
361
        if start_revision_id is not None:
358
363
                if rev_id != start_revision_id:
359
364
                    continue
360
365
                else:
361
 
                    yield rev_id, depth, revno, end_of_merge
 
366
                    # The decision to include the start or not
 
367
                    # depends on the stop_rule if a stop is provided
 
368
                    rev_iter = chain(
 
369
                        iter([(rev_id, depth, revno, end_of_merge)]),
 
370
                        rev_iter)
362
371
                    break
363
 
        for rev_id, depth, revno, end_of_merge in rev_iter:
364
 
            yield rev_id, depth, revno, end_of_merge
365
 
            if stop_revision_id is not None and rev_id == stop_revision_id:
366
 
                return
 
372
        if stop_revision_id is None:
 
373
            for rev_id, depth, revno, end_of_merge in rev_iter:
 
374
                yield rev_id, depth, revno, end_of_merge
 
375
        elif stop_rule == 'exclude':
 
376
            for rev_id, depth, revno, end_of_merge in rev_iter:
 
377
                if rev_id == stop_revision_id:
 
378
                    return
 
379
                yield rev_id, depth, revno, end_of_merge
 
380
        elif stop_rule == 'include':
 
381
            for rev_id, depth, revno, end_of_merge in rev_iter:
 
382
                yield rev_id, depth, revno, end_of_merge
 
383
                if rev_id == stop_revision_id:
 
384
                    return
 
385
        elif stop_rule == 'with-merges':
 
386
            stop_rev = self.repository.get_revision(stop_revision_id)
 
387
            if stop_rev.parent_ids:
 
388
                left_parent = stop_rev.parent_ids[0]
 
389
            else:
 
390
                left_parent = _mod_revision.NULL_REVISION
 
391
            for rev_id, depth, revno, end_of_merge in rev_iter:
 
392
                if rev_id == left_parent:
 
393
                    return
 
394
                yield rev_id, depth, revno, end_of_merge
 
395
        else:
 
396
            raise ValueError('invalid stop_rule %r' % stop_rule)
367
397
 
368
398
    def leave_lock_in_place(self):
369
399
        """Tell this branch object not to release the physical lock when this