~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Ian Clatworthy
  • Date: 2008-07-23 08:12:59 UTC
  • mto: (4171.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 4173.
  • Revision ID: ian.clatworthy@canonical.com-20080723081259-4xoysrk6kqdx2z22
add --filters option to cat command

Show diffs side-by-side

added added

removed removed

Lines of Context:
2041
2041
    _see_also = ['ls']
2042
2042
    takes_options = [
2043
2043
        Option('name-from-revision', help='The path name in the old tree.'),
 
2044
        Option('filters', help='Apply content filters.'),
2044
2045
        'revision',
2045
2046
        ]
2046
2047
    takes_args = ['filename']
2047
2048
    encoding_type = 'exact'
2048
2049
 
2049
2050
    @display_command
2050
 
    def run(self, filename, revision=None, name_from_revision=False):
 
2051
    def run(self, filename, revision=None, name_from_revision=False,
 
2052
            filters=False):
2051
2053
        if revision is not None and len(revision) != 1:
2052
2054
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
2053
2055
                                         " one revision specifier")
2056
2058
        branch.lock_read()
2057
2059
        try:
2058
2060
            return self._run(tree, branch, relpath, filename, revision,
2059
 
                             name_from_revision)
 
2061
                             name_from_revision, filters)
2060
2062
        finally:
2061
2063
            branch.unlock()
2062
2064
 
2063
 
    def _run(self, tree, b, relpath, filename, revision, name_from_revision):
 
2065
    def _run(self, tree, b, relpath, filename, revision, name_from_revision,
 
2066
        filtered):
2064
2067
        if tree is None:
2065
2068
            tree = b.basis_tree()
2066
2069
        if revision is None:
2085
2088
        else:
2086
2089
            raise errors.BzrCommandError("%r is not present in revision %s" %
2087
2090
                                         (filename, revision_id))
2088
 
        self.outf.write(content)
 
2091
        if filtered:
 
2092
            from bzrlib.filters import (
 
2093
                ContentFilterContext,
 
2094
                filtered_output_bytes,
 
2095
                )
 
2096
            filters = tree._content_filter_stack(relpath)
 
2097
            content = filtered_output_bytes([content], filters,
 
2098
                ContentFilterContext(relpath))
 
2099
            self.outf.writelines(content)
 
2100
        else:
 
2101
            self.outf.write(content)
2089
2102
 
2090
2103
 
2091
2104
class cmd_local_time_offset(Command):