~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2011-07-04 20:29:44 UTC
  • mto: (6034.1.1 filter-tree)
  • mto: This revision was merged to the branch mainline in revision 6035.
  • Revision ID: mbp@canonical.com-20110704202944-l1v8eamq6dmy1iav
Change cmd_cat to use ContentFilterTree, and clean it up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3033
3033
                    "%r is not present in revision %s" % (
3034
3034
                        filename, rev_tree.get_revision_id()))
3035
3035
            else:
3036
 
                content = rev_tree.get_file_text(old_file_id)
 
3036
                actual_file_id = old_file_id
3037
3037
        else:
3038
3038
            cur_file_id = tree.path2id(relpath)
3039
 
            found = False
3040
 
            if cur_file_id is not None:
3041
 
                # Then try with the actual file id
3042
 
                try:
3043
 
                    content = rev_tree.get_file_text(cur_file_id)
3044
 
                    found = True
3045
 
                except errors.NoSuchId:
3046
 
                    # The actual file id didn't exist at that time
3047
 
                    pass
3048
 
            if not found and old_file_id is not None:
3049
 
                # Finally try with the old file id
3050
 
                content = rev_tree.get_file_text(old_file_id)
3051
 
                found = True
3052
 
            if not found:
3053
 
                # Can't be found anywhere
 
3039
            if cur_file_id is not None and rev_tree.has_id(cur_file_id):
 
3040
                actual_file_id = cur_file_id
 
3041
            elif old_file_id is not None:
 
3042
                actual_file_id = old_file_id
 
3043
            else:
3054
3044
                raise errors.BzrCommandError(
3055
3045
                    "%r is not present in revision %s" % (
3056
3046
                        filename, rev_tree.get_revision_id()))
3057
3047
        if filtered:
3058
 
            from bzrlib.filters import (
3059
 
                ContentFilterContext,
3060
 
                filtered_output_bytes,
3061
 
                )
3062
 
            filters = rev_tree._content_filter_stack(relpath)
3063
 
            chunks = content.splitlines(True)
3064
 
            content = filtered_output_bytes(chunks, filters,
3065
 
                ContentFilterContext(relpath, rev_tree))
3066
 
            self.cleanup_now()
3067
 
            self.outf.writelines(content)
 
3048
            from bzrlib.filter_tree import ContentFilterTree
 
3049
            filter_tree = ContentFilterTree(rev_tree,
 
3050
                rev_tree._content_filter_stack)
 
3051
            content = filter_tree.get_file_text(actual_file_id)
3068
3052
        else:
3069
 
            self.cleanup_now()
3070
 
            self.outf.write(content)
 
3053
            content = rev_tree.get_file_text(actual_file_id)
 
3054
        self.cleanup_now()
 
3055
        self.outf.write(content)
3071
3056
 
3072
3057
 
3073
3058
class cmd_local_time_offset(Command):