/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Parth Malwankar
  • Date: 2010-02-26 13:39:42 UTC
  • mto: (0.44.2 grep) (6531.3.1 merge-grep)
  • mto: This revision was merged to the branch mainline in revision 6555.
  • Revision ID: parth.malwankar@gmail.com-20100226133942-bmkibf90ibthzdah
basic revision spec is used for grepping

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
import re
31
31
 
32
32
import grep
 
33
 
33
34
import bzrlib
 
35
from bzrlib.revisionspec import RevisionSpec
 
36
from bzrlib.workingtree import WorkingTree
34
37
from bzrlib import (
35
38
    osutils,
36
39
    bzrdir,
47
50
    takes_args = ['pattern', 'path*']
48
51
    takes_options = [
49
52
        'verbose',
 
53
        'revision',
50
54
        Option('line-number', short_name='n',
51
55
               help='show 1-based line number.'),
52
56
        Option('ignore-case', short_name='i',
64
68
 
65
69
    @display_command
66
70
    def run(self, verbose=False, ignore_case=False, recursive=False, from_root=False,
67
 
            null=False, line_number=False, path_list=None, pattern=None):
 
71
            null=False, line_number=False, path_list=None, revision=None, pattern=None):
68
72
        if path_list == None:
69
73
            path_list = ['.']
70
74
        else:
71
75
            if from_root:
72
76
                raise errors.BzrCommandError('cannot specify both --from-root and PATH.')
73
77
 
 
78
        if revision == None:
 
79
            revision = [RevisionSpec.from_string("last:1")]
 
80
        start_rev = revision[0]
 
81
        end_rev = None
 
82
        if len(revision) == 2:
 
83
            end_rev = revision[1]
 
84
 
74
85
        eol_marker = '\n'
75
86
        if null:
76
87
            eol_marker = '\0'
80
91
            re_flags = re.IGNORECASE
81
92
        patternc = grep.compile_pattern(pattern, re_flags)
82
93
 
 
94
        wt, relpath = WorkingTree.open_containing('.')
 
95
 
 
96
        wt.lock_read()
 
97
        self.add_cleanup(wt.unlock)
83
98
        for path in path_list:
84
 
            tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(path)
 
99
            tree = start_rev.as_tree(wt.branch)
85
100
 
86
101
            if osutils.isdir(path):
87
102
                # setup rpath to open files relative to cwd