~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: 2009-03-20 05:08:48 UTC
  • mfrom: (4171.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090320050848-c1wdgzf5kkfdt1ys
Content filters (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2527
2527
               help="Type of file to export to.",
2528
2528
               type=unicode),
2529
2529
        'revision',
 
2530
        Option('filters', help='Apply content filters to export the '
 
2531
                'convenient form.'),
2530
2532
        Option('root',
2531
2533
               type=str,
2532
2534
               help="Name of the root directory inside the exported file."),
2533
2535
        ]
2534
2536
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2535
 
        root=None):
 
2537
        root=None, filters=False):
2536
2538
        from bzrlib.export import export
2537
2539
 
2538
2540
        if branch_or_subdir is None:
2545
2547
 
2546
2548
        rev_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
2547
2549
        try:
2548
 
            export(rev_tree, dest, format, root, subdir)
 
2550
            export(rev_tree, dest, format, root, subdir, filtered=filters)
2549
2551
        except errors.NoSuchExportFormat, e:
2550
2552
            raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
2551
2553
 
2562
2564
    _see_also = ['ls']
2563
2565
    takes_options = [
2564
2566
        Option('name-from-revision', help='The path name in the old tree.'),
 
2567
        Option('filters', help='Apply content filters to display the '
 
2568
                'convenience form.'),
2565
2569
        'revision',
2566
2570
        ]
2567
2571
    takes_args = ['filename']
2568
2572
    encoding_type = 'exact'
2569
2573
 
2570
2574
    @display_command
2571
 
    def run(self, filename, revision=None, name_from_revision=False):
 
2575
    def run(self, filename, revision=None, name_from_revision=False,
 
2576
            filters=False):
2572
2577
        if revision is not None and len(revision) != 1:
2573
2578
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
2574
2579
                                         " one revision specifier")
2577
2582
        branch.lock_read()
2578
2583
        try:
2579
2584
            return self._run(tree, branch, relpath, filename, revision,
2580
 
                             name_from_revision)
 
2585
                             name_from_revision, filters)
2581
2586
        finally:
2582
2587
            branch.unlock()
2583
2588
 
2584
 
    def _run(self, tree, b, relpath, filename, revision, name_from_revision):
 
2589
    def _run(self, tree, b, relpath, filename, revision, name_from_revision,
 
2590
        filtered):
2585
2591
        if tree is None:
2586
2592
            tree = b.basis_tree()
2587
2593
        rev_tree = _get_one_revision_tree('cat', revision, branch=b)
2616
2622
                raise errors.BzrCommandError(
2617
2623
                    "%r is not present in revision %s" % (
2618
2624
                        filename, rev_tree.get_revision_id()))
2619
 
        self.outf.write(content)
 
2625
        if filtered:
 
2626
            from bzrlib.filters import (
 
2627
                ContentFilterContext,
 
2628
                filtered_output_bytes,
 
2629
                )
 
2630
            filters = rev_tree._content_filter_stack(relpath)
 
2631
            chunks = content.splitlines(True)
 
2632
            content = filtered_output_bytes(chunks, filters,
 
2633
                ContentFilterContext(relpath, rev_tree))
 
2634
            self.outf.writelines(content)
 
2635
        else:
 
2636
            self.outf.write(content)
2620
2637
 
2621
2638
 
2622
2639
class cmd_local_time_offset(Command):