~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-12-16 17:36:12 UTC
  • mfrom: (3904.2.4 bzr.tags_revision)
  • Revision ID: pqm@pqm.ubuntu.com-20081216173612-rj1jkrqcezr6sb3b
(Marius) Support showing revisions in a specific range in 'bzr tags'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1848
1848
 
1849
1849
        b.lock_read()
1850
1850
        try:
1851
 
            if revision is None:
1852
 
                rev1 = None
1853
 
                rev2 = None
1854
 
            elif len(revision) == 1:
1855
 
                rev1 = rev2 = revision[0].in_history(b)
1856
 
            elif len(revision) == 2:
1857
 
                if revision[1].get_branch() != revision[0].get_branch():
1858
 
                    # b is taken from revision[0].get_branch(), and
1859
 
                    # show_log will use its revision_history. Having
1860
 
                    # different branches will lead to weird behaviors.
1861
 
                    raise errors.BzrCommandError(
1862
 
                        "Log doesn't accept two revisions in different"
1863
 
                        " branches.")
1864
 
                rev1 = revision[0].in_history(b)
1865
 
                rev2 = revision[1].in_history(b)
1866
 
            else:
1867
 
                raise errors.BzrCommandError(
1868
 
                    'bzr log --revision takes one or two values.')
1869
 
 
 
1851
            rev1, rev2 = _get_revision_range(revision, b, self.name())
1870
1852
            if log_format is None:
1871
1853
                log_format = log.log_formatter_registry.get_default(b)
1872
1854
 
1886
1868
        finally:
1887
1869
            b.unlock()
1888
1870
 
 
1871
def _get_revision_range(revisionspec_list, branch, command_name):
 
1872
    """Take the input of a revision option and turn it into a revision range.
 
1873
 
 
1874
    It returns RevisionInfo objects which can be used to obtain the rev_id's
 
1875
    of the desired revisons. It does some user input validations.
 
1876
    """
 
1877
    if revisionspec_list is None:
 
1878
        rev1 = None
 
1879
        rev2 = None
 
1880
    elif len(revisionspec_list) == 1:
 
1881
        rev1 = rev2 = revisionspec_list[0].in_history(branch)
 
1882
    elif len(revisionspec_list) == 2:
 
1883
        if revisionspec_list[1].get_branch() != revisionspec_list[0
 
1884
                ].get_branch():
 
1885
            # b is taken from revision[0].get_branch(), and
 
1886
            # show_log will use its revision_history. Having
 
1887
            # different branches will lead to weird behaviors.
 
1888
            raise errors.BzrCommandError(
 
1889
                "bzr %s doesn't accept two revisions in different"
 
1890
                " branches." % command_name)
 
1891
        rev1 = revisionspec_list[0].in_history(branch)
 
1892
        rev2 = revisionspec_list[1].in_history(branch)
 
1893
    else:
 
1894
        raise errors.BzrCommandError(
 
1895
            'bzr %s --revision takes one or two values.' % command_name)
 
1896
    return rev1, rev2
1889
1897
 
1890
1898
def get_log_format(long=False, short=False, line=False, default='long'):
1891
1899
    log_format = default
4576
4584
            time='Sort tags chronologically.',
4577
4585
            ),
4578
4586
        'show-ids',
 
4587
        'revision',
4579
4588
    ]
4580
4589
 
4581
4590
    @display_command
4583
4592
            directory='.',
4584
4593
            sort='alpha',
4585
4594
            show_ids=False,
 
4595
            revision=None,
4586
4596
            ):
4587
4597
        branch, relpath = Branch.open_containing(directory)
 
4598
 
4588
4599
        tags = branch.tags.get_tag_dict().items()
4589
4600
        if not tags:
4590
4601
            return
 
4602
 
 
4603
        if revision:
 
4604
            branch.lock_read()
 
4605
            try:
 
4606
                graph = branch.repository.get_graph()
 
4607
                rev1, rev2 = _get_revision_range(revision, branch, self.name())
 
4608
                revid1, revid2 = rev1.rev_id, rev2.rev_id
 
4609
                # only show revisions between revid1 and revid2 (inclusive)
 
4610
                tags = [(tag, revid) for tag, revid in tags if
 
4611
                     (revid2 is None or
 
4612
                         graph.is_ancestor(revid, revid2)) and
 
4613
                     (revid1 is None or
 
4614
                         graph.is_ancestor(revid1, revid))]
 
4615
            finally:
 
4616
                branch.unlock()
4591
4617
        if sort == 'alpha':
4592
4618
            tags.sort()
4593
4619
        elif sort == 'time':