~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: 2006-10-31 21:58:14 UTC
  • mfrom: (2104.2.1 wang_30190)
  • Revision ID: pqm@pqm.ubuntu.com-20061031215814-a9a1857c6e196637
(Cheuksan Edward Wang) Fix bug #30190: allow 'bzr cat' to look up paths in multiple trees

Show diffs side-by-side

added added

removed removed

Lines of Context:
1694
1694
class cmd_cat(Command):
1695
1695
    """Write a file's text from a previous revision."""
1696
1696
 
1697
 
    takes_options = ['revision']
 
1697
    takes_options = ['revision', 'name-from-revision']
1698
1698
    takes_args = ['filename']
1699
1699
 
1700
1700
    @display_command
1701
 
    def run(self, filename, revision=None):
 
1701
    def run(self, filename, revision=None, name_from_revision=False):
1702
1702
        if revision is not None and len(revision) != 1:
1703
 
            raise errors.BzrCommandError("bzr cat --revision takes exactly one number")
 
1703
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
 
1704
                                        " one number")
 
1705
 
1704
1706
        tree = None
1705
1707
        try:
1706
1708
            tree, relpath = WorkingTree.open_containing(filename)
1716
1718
            revision_id = b.last_revision()
1717
1719
        else:
1718
1720
            revision_id = revision[0].in_history(b).rev_id
1719
 
        b.print_file(relpath, revision_id)
 
1721
 
 
1722
        cur_file_id = tree.path2id(relpath)
 
1723
        rev_tree = b.repository.revision_tree(revision_id)
 
1724
        old_file_id = rev_tree.path2id(relpath)
 
1725
        
 
1726
        if name_from_revision:
 
1727
            if old_file_id is None:
 
1728
                raise errors.BzrCommandError("%r is not present in revision %s"
 
1729
                                                % (filename, revision_id))
 
1730
            else:
 
1731
                rev_tree.print_file(old_file_id)
 
1732
        elif cur_file_id is not None:
 
1733
            rev_tree.print_file(cur_file_id)
 
1734
        elif old_file_id is not None:
 
1735
            rev_tree.print_file(old_file_id)
 
1736
        else:
 
1737
            raise errors.BzrCommandError("%r is not present in revision %s" %
 
1738
                                         (filename, revision_id))
1720
1739
 
1721
1740
 
1722
1741
class cmd_local_time_offset(Command):