/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 17:23: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-20100226172342-j9zil5y7bjyr9gdw
revno is now printed when rspec is given

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import grep
33
33
 
34
34
import bzrlib
35
 
from bzrlib.revisionspec import RevisionSpec
 
35
from bzrlib.revisionspec import RevisionSpec, RevisionInfo
36
36
from bzrlib.workingtree import WorkingTree
37
37
from bzrlib import (
38
38
    osutils,
75
75
            if from_root:
76
76
                raise errors.BzrCommandError('cannot specify both --from-root and PATH.')
77
77
 
 
78
        print_revno = False
78
79
        if revision == None:
79
80
            revision = [RevisionSpec.from_string("last:1")]
 
81
        else:
 
82
            print_revno = True # used to print revno in output.
 
83
 
80
84
        start_rev = revision[0]
81
85
        end_rev = None
82
86
        if len(revision) == 2:
92
96
        patternc = grep.compile_pattern(pattern, re_flags)
93
97
 
94
98
        wt, relpath = WorkingTree.open_containing('.')
 
99
        id_to_revno = wt.branch.get_revision_id_to_revno_map()
 
100
 
 
101
        rev = start_rev
95
102
 
96
103
        wt.lock_read()
97
104
        self.add_cleanup(wt.unlock)
98
105
        for path in path_list:
99
 
            tree = start_rev.as_tree(wt.branch)
 
106
            tree = rev.as_tree(wt.branch)
 
107
            revid = rev.as_revision_id(wt.branch)
 
108
            try:
 
109
                revno = ".".join([str(n) for n in id_to_revno[revid]])
 
110
            except KeyError, e:
 
111
                trace.warning("warning: file '%s' is not versioned." % path)
 
112
                continue
 
113
 
100
114
            if osutils.isdir(path):
101
115
                self._grep_dir(tree, relpath, recursive, line_number,
102
 
                    patternc, from_root, eol_marker)
 
116
                    patternc, from_root, eol_marker, revno, print_revno)
103
117
            else:
104
118
                id = tree.path2id(path)
105
119
                if not id:
108
122
                tree.lock_read()
109
123
                try:
110
124
                    grep.file_grep(tree, id, '.', path, patternc, eol_marker,
111
 
                        self.outf, line_number)
 
125
                        self.outf, line_number, revno, print_revno)
112
126
                finally:
113
127
                    tree.unlock()
114
128
 
115
129
    def _grep_dir(self, tree, relpath, recursive, line_number, compiled_pattern,
116
 
        from_root, eol_marker):
 
130
        from_root, eol_marker, revno, print_revno):
117
131
            # setup relpath to open files relative to cwd
118
132
            rpath = relpath
119
133
            if relpath:
130
144
                    from_dir=relpath, recursive=recursive):
131
145
                    if fc == 'V' and fkind == 'file':
132
146
                        grep.file_grep(tree, fid, rpath, fp, compiled_pattern,
133
 
                            eol_marker, self.outf, line_number)
 
147
                            eol_marker, self.outf, line_number, revno, print_revno)
134
148
            finally:
135
149
                tree.unlock()
136
150