~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Patch Queue Manager
  • Date: 2011-10-09 13:52:06 UTC
  • mfrom: (6202.1.3 revno-revision)
  • Revision ID: pqm@pqm.ubuntu.com-20111009135206-t3utsln6mtzv9eut
(jelmer) Add a --revision argument to 'bzr revno'. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
557
557
    takes_args = ['location?']
558
558
    takes_options = [
559
559
        Option('tree', help='Show revno of working tree'),
 
560
        'revision',
560
561
        ]
561
562
 
562
563
    @display_command
563
 
    def run(self, tree=False, location=u'.'):
 
564
    def run(self, tree=False, location=u'.', revision=None):
 
565
        if revision is not None and tree:
 
566
            raise errors.BzrCommandError(gettext("--tree and --revision can "
 
567
                "not be used together"))
 
568
 
564
569
        if tree:
565
570
            try:
566
571
                wt = WorkingTree.open_containing(location)[0]
567
572
                self.add_cleanup(wt.lock_read().unlock)
568
573
            except (errors.NoWorkingTree, errors.NotLocalUrl):
569
574
                raise errors.NoWorkingTree(location)
 
575
            b = wt.branch
570
576
            revid = wt.last_revision()
571
 
            try:
572
 
                revno_t = wt.branch.revision_id_to_dotted_revno(revid)
573
 
            except errors.NoSuchRevision:
574
 
                revno_t = ('???',)
575
 
            revno = ".".join(str(n) for n in revno_t)
576
577
        else:
577
578
            b = Branch.open_containing(location)[0]
578
579
            self.add_cleanup(b.lock_read().unlock)
579
 
            revno = b.revno()
 
580
            if revision:
 
581
                if len(revision) != 1:
 
582
                    raise errors.BzrCommandError(gettext(
 
583
                        "Tags can only be placed on a single revision, "
 
584
                        "not on a range"))
 
585
                revid = revision[0].as_revision_id(b)
 
586
            else:
 
587
                revid = b.last_revision()
 
588
        try:
 
589
            revno_t = b.revision_id_to_dotted_revno(revid)
 
590
        except errors.NoSuchRevision:
 
591
            revno_t = ('???',)
 
592
        revno = ".".join(str(n) for n in revno_t)
580
593
        self.cleanup_now()
581
 
        self.outf.write(str(revno) + '\n')
 
594
        self.outf.write(revno + '\n')
582
595
 
583
596
 
584
597
class cmd_revision_info(Command):