Status: | Merged |
---|---|
Approved by: | John A Meinel |
Approved revision: | no longer in the source branch. |
Merged at revision: | 143 |
Proposed branch: | lp:~jelmer/bzr-grep/lazy |
Merge into: | lp:bzr-grep |
Diff against target: |
500 lines (+242/-237) 2 files modified
__init__.py (+4/-237) cmds.py (+238/-0) |
To merge this branch: | bzr merge lp:~jelmer/bzr-grep/lazy |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
John A Meinel | Approve | ||
Review via email:
|
Commit message
Description of the change
This moves the actual command implementation to a separate file.
It shaves some (limited) time off the bzr startup time.
To post a comment you must log in.
lp:~jelmer/bzr-grep/lazy
updated
- 143. By Jelmer Vernooij
-
Merge lazy loading of command implementation.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '__init__.py' | |||
2 | --- __init__.py 2010-06-26 02:34:08 +0000 | |||
3 | +++ __init__.py 2011-02-20 00:38:52 +0000 | |||
4 | @@ -13,249 +13,16 @@ | |||
5 | 13 | # You should have received a copy of the GNU General Public License | 13 | # You should have received a copy of the GNU General Public License |
6 | 14 | # along with this program; if not, write to the Free Software | 14 | # along with this program; if not, write to the Free Software |
7 | 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
8 | 16 | |||
9 | 16 | """Print lines matching PATTERN for specified files and revisions.""" | 17 | """Print lines matching PATTERN for specified files and revisions.""" |
10 | 17 | 18 | ||
33 | 18 | import os | 19 | from bzrlib.commands import plugin_cmds |
34 | 19 | import sys | 20 | |
13 | 20 | |||
14 | 21 | from bzrlib import errors | ||
15 | 22 | from bzrlib.commands import Command, register_command, display_command | ||
16 | 23 | from bzrlib.option import Option, ListOption | ||
17 | 24 | |||
18 | 25 | from bzrlib.lazy_import import lazy_import | ||
19 | 26 | lazy_import(globals(), """ | ||
20 | 27 | import re | ||
21 | 28 | |||
22 | 29 | from termcolor import allow_color | ||
23 | 30 | import grep | ||
24 | 31 | |||
25 | 32 | import bzrlib | ||
26 | 33 | from bzrlib.revisionspec import RevisionSpec | ||
27 | 34 | from bzrlib import ( | ||
28 | 35 | osutils, | ||
29 | 36 | bzrdir, | ||
30 | 37 | trace, | ||
31 | 38 | ) | ||
32 | 39 | """) | ||
35 | 40 | import version | 21 | import version |
36 | 41 | 22 | ||
37 | 42 | version_info = version.version_info | 23 | version_info = version.version_info |
38 | 43 | 24 | ||
254 | 44 | # FIXME: _parse_levels should be shared with bzrlib.builtins. this is a copy | 25 | plugin_cmds.register_lazy("cmd_grep", [], "bzrlib.plugins.grep.cmds") |
40 | 45 | # to avoid the error | ||
41 | 46 | # "IllegalUseOfScopeReplacer: ScopeReplacer object '_parse_levels' was used | ||
42 | 47 | # incorrectly: Object already cleaned up, did you assign it to another | ||
43 | 48 | # variable?: _factory | ||
44 | 49 | # with lazy import | ||
45 | 50 | def _parse_levels(s): | ||
46 | 51 | try: | ||
47 | 52 | return int(s) | ||
48 | 53 | except ValueError: | ||
49 | 54 | msg = "The levels argument must be an integer." | ||
50 | 55 | raise errors.BzrCommandError(msg) | ||
51 | 56 | |||
52 | 57 | |||
53 | 58 | class GrepOptions(object): | ||
54 | 59 | """Container to pass around grep options. | ||
55 | 60 | |||
56 | 61 | This class is used as a container to pass around user option and | ||
57 | 62 | some other params (like outf) to processing functions. This makes | ||
58 | 63 | it easier to add more options as grep evolves. | ||
59 | 64 | """ | ||
60 | 65 | verbose = False | ||
61 | 66 | ignore_case = False | ||
62 | 67 | no_recursive = False | ||
63 | 68 | from_root = False | ||
64 | 69 | null = False | ||
65 | 70 | levels = None | ||
66 | 71 | line_number = False | ||
67 | 72 | path_list = None | ||
68 | 73 | revision = None | ||
69 | 74 | pattern = None | ||
70 | 75 | include = None | ||
71 | 76 | exclude = None | ||
72 | 77 | fixed_string = False | ||
73 | 78 | files_with_matches = False | ||
74 | 79 | files_without_match = False | ||
75 | 80 | color = None | ||
76 | 81 | diff = False | ||
77 | 82 | |||
78 | 83 | # derived options | ||
79 | 84 | recursive = None | ||
80 | 85 | eol_marker = None | ||
81 | 86 | patternc = None | ||
82 | 87 | sub_patternc = None | ||
83 | 88 | print_revno = None | ||
84 | 89 | fixed_string = None | ||
85 | 90 | outf = None | ||
86 | 91 | show_color = False | ||
87 | 92 | |||
88 | 93 | |||
89 | 94 | class cmd_grep(Command): | ||
90 | 95 | """Print lines matching PATTERN for specified files and revisions. | ||
91 | 96 | |||
92 | 97 | This command searches the specified files and revisions for a given | ||
93 | 98 | pattern. The pattern is specified as a Python regular expressions[1]. | ||
94 | 99 | |||
95 | 100 | If the file name is not specified, the revisions starting with the | ||
96 | 101 | current directory are searched recursively. If the revision number is | ||
97 | 102 | not specified, the working copy is searched. To search the last committed | ||
98 | 103 | revision, use the '-r -1' or '-r last:1' option. | ||
99 | 104 | |||
100 | 105 | Unversioned files are not searched unless explicitly specified on the | ||
101 | 106 | command line. Unversioned directores are not searched. | ||
102 | 107 | |||
103 | 108 | When searching a pattern, the output is shown in the 'filepath:string' | ||
104 | 109 | format. If a revision is explicitly searched, the output is shown as | ||
105 | 110 | 'filepath~N:string', where N is the revision number. | ||
106 | 111 | |||
107 | 112 | --include and --exclude options can be used to search only (or exclude | ||
108 | 113 | from search) files with base name matches the specified Unix style GLOB | ||
109 | 114 | pattern. The GLOB pattern an use *, ?, and [...] as wildcards, and \\ | ||
110 | 115 | to quote wildcard or backslash character literally. Note that the glob | ||
111 | 116 | pattern is not a regular expression. | ||
112 | 117 | |||
113 | 118 | [1] http://docs.python.org/library/re.html#regular-expression-syntax | ||
114 | 119 | """ | ||
115 | 120 | |||
116 | 121 | encoding_type = 'replace' | ||
117 | 122 | takes_args = ['pattern', 'path*'] | ||
118 | 123 | takes_options = [ | ||
119 | 124 | 'verbose', | ||
120 | 125 | 'revision', | ||
121 | 126 | Option('color', type=str, argname='when', | ||
122 | 127 | help='Show match in color. WHEN is never, always or auto.'), | ||
123 | 128 | Option('diff', short_name='p', | ||
124 | 129 | help='Grep for pattern in changeset for each revision.'), | ||
125 | 130 | ListOption('exclude', type=str, argname='glob', short_name='X', | ||
126 | 131 | help="Skip files whose base name matches GLOB."), | ||
127 | 132 | ListOption('include', type=str, argname='glob', short_name='I', | ||
128 | 133 | help="Search only files whose base name matches GLOB."), | ||
129 | 134 | Option('files-with-matches', short_name='l', | ||
130 | 135 | help='Print only the name of each input file in ' | ||
131 | 136 | 'which PATTERN is found.'), | ||
132 | 137 | Option('files-without-match', short_name='L', | ||
133 | 138 | help='Print only the name of each input file in ' | ||
134 | 139 | 'which PATTERN is not found.'), | ||
135 | 140 | Option('fixed-string', short_name='F', | ||
136 | 141 | help='Interpret PATTERN is a single fixed string (not regex).'), | ||
137 | 142 | Option('from-root', | ||
138 | 143 | help='Search for pattern starting from the root of the branch. ' | ||
139 | 144 | '(implies --recursive)'), | ||
140 | 145 | Option('ignore-case', short_name='i', | ||
141 | 146 | help='ignore case distinctions while matching.'), | ||
142 | 147 | Option('levels', | ||
143 | 148 | help='Number of levels to display - 0 for all, 1 for collapsed ' | ||
144 | 149 | '(1 is default).', | ||
145 | 150 | argname='N', | ||
146 | 151 | type=_parse_levels), | ||
147 | 152 | Option('line-number', short_name='n', | ||
148 | 153 | help='show 1-based line number.'), | ||
149 | 154 | Option('no-recursive', | ||
150 | 155 | help="Don't recurse into subdirectories. (default is --recursive)"), | ||
151 | 156 | Option('null', short_name='Z', | ||
152 | 157 | help='Write an ASCII NUL (\\0) separator ' | ||
153 | 158 | 'between output lines rather than a newline.'), | ||
154 | 159 | ] | ||
155 | 160 | |||
156 | 161 | |||
157 | 162 | @display_command | ||
158 | 163 | def run(self, verbose=False, ignore_case=False, no_recursive=False, | ||
159 | 164 | from_root=False, null=False, levels=None, line_number=False, | ||
160 | 165 | path_list=None, revision=None, pattern=None, include=None, | ||
161 | 166 | exclude=None, fixed_string=False, files_with_matches=False, | ||
162 | 167 | files_without_match=False, color='never', diff=False): | ||
163 | 168 | |||
164 | 169 | if path_list == None: | ||
165 | 170 | path_list = ['.'] | ||
166 | 171 | else: | ||
167 | 172 | if from_root: | ||
168 | 173 | raise errors.BzrCommandError('cannot specify both --from-root and PATH.') | ||
169 | 174 | |||
170 | 175 | if files_with_matches and files_without_match: | ||
171 | 176 | raise errors.BzrCommandError('cannot specify both ' | ||
172 | 177 | '-l/--files-with-matches and -L/--files-without-matches.') | ||
173 | 178 | |||
174 | 179 | if color not in ['always', 'never', 'auto']: | ||
175 | 180 | raise errors.BzrCommandError('Valid values for --color are ' | ||
176 | 181 | '"always", "never" or "auto".') | ||
177 | 182 | |||
178 | 183 | if levels==None: | ||
179 | 184 | levels=1 | ||
180 | 185 | |||
181 | 186 | print_revno = False | ||
182 | 187 | if revision != None or levels == 0: | ||
183 | 188 | # print revision numbers as we may be showing multiple revisions | ||
184 | 189 | print_revno = True | ||
185 | 190 | |||
186 | 191 | eol_marker = '\n' | ||
187 | 192 | if null: | ||
188 | 193 | eol_marker = '\0' | ||
189 | 194 | |||
190 | 195 | if not ignore_case and grep.is_fixed_string(pattern): | ||
191 | 196 | # if the pattern isalnum, implicitly use to -F for faster grep | ||
192 | 197 | fixed_string = True | ||
193 | 198 | elif ignore_case and fixed_string: | ||
194 | 199 | # GZ 2010-06-02: Fall back to regexp rather than lowercasing | ||
195 | 200 | # pattern and text which will cause pain later | ||
196 | 201 | fixed_string = False | ||
197 | 202 | pattern = re.escape(pattern) | ||
198 | 203 | |||
199 | 204 | patternc = None | ||
200 | 205 | re_flags = re.MULTILINE | ||
201 | 206 | if ignore_case: | ||
202 | 207 | re_flags |= re.IGNORECASE | ||
203 | 208 | |||
204 | 209 | if not fixed_string: | ||
205 | 210 | patternc = grep.compile_pattern(pattern, re_flags) | ||
206 | 211 | |||
207 | 212 | if color == 'always': | ||
208 | 213 | show_color = True | ||
209 | 214 | elif color == 'never': | ||
210 | 215 | show_color = False | ||
211 | 216 | elif color == 'auto': | ||
212 | 217 | show_color = allow_color() | ||
213 | 218 | |||
214 | 219 | GrepOptions.verbose = verbose | ||
215 | 220 | GrepOptions.ignore_case = ignore_case | ||
216 | 221 | GrepOptions.no_recursive = no_recursive | ||
217 | 222 | GrepOptions.from_root = from_root | ||
218 | 223 | GrepOptions.null = null | ||
219 | 224 | GrepOptions.levels = levels | ||
220 | 225 | GrepOptions.line_number = line_number | ||
221 | 226 | GrepOptions.path_list = path_list | ||
222 | 227 | GrepOptions.revision = revision | ||
223 | 228 | GrepOptions.pattern = pattern | ||
224 | 229 | GrepOptions.include = include | ||
225 | 230 | GrepOptions.exclude = exclude | ||
226 | 231 | GrepOptions.fixed_string = fixed_string | ||
227 | 232 | GrepOptions.files_with_matches = files_with_matches | ||
228 | 233 | GrepOptions.files_without_match = files_without_match | ||
229 | 234 | GrepOptions.color = color | ||
230 | 235 | GrepOptions.diff = False | ||
231 | 236 | |||
232 | 237 | GrepOptions.eol_marker = eol_marker | ||
233 | 238 | GrepOptions.print_revno = print_revno | ||
234 | 239 | GrepOptions.patternc = patternc | ||
235 | 240 | GrepOptions.recursive = not no_recursive | ||
236 | 241 | GrepOptions.fixed_string = fixed_string | ||
237 | 242 | GrepOptions.outf = self.outf | ||
238 | 243 | GrepOptions.show_color = show_color | ||
239 | 244 | |||
240 | 245 | if diff == True: | ||
241 | 246 | # options not used: | ||
242 | 247 | # files_with_matches, files_without_match | ||
243 | 248 | # levels(?), line_number, from_root | ||
244 | 249 | # include, exclude | ||
245 | 250 | # These are silently ignored. | ||
246 | 251 | grep.grep_diff(GrepOptions) | ||
247 | 252 | elif revision == None: | ||
248 | 253 | grep.workingtree_grep(GrepOptions) | ||
249 | 254 | else: | ||
250 | 255 | grep.versioned_grep(GrepOptions) | ||
251 | 256 | |||
252 | 257 | |||
253 | 258 | register_command(cmd_grep) | ||
255 | 259 | 26 | ||
256 | 260 | def test_suite(): | 27 | def test_suite(): |
257 | 261 | from bzrlib.tests import TestUtil | 28 | from bzrlib.tests import TestUtil |
258 | 262 | 29 | ||
259 | === added file 'cmds.py' | |||
260 | --- cmds.py 1970-01-01 00:00:00 +0000 | |||
261 | +++ cmds.py 2011-02-20 00:38:52 +0000 | |||
262 | @@ -0,0 +1,238 @@ | |||
263 | 1 | # Copyright (C) 2010 Canonical Ltd | ||
264 | 2 | # | ||
265 | 3 | # This program is free software; you can redistribute it and/or modify | ||
266 | 4 | # it under the terms of the GNU General Public License as published by | ||
267 | 5 | # the Free Software Foundation; either version 2 of the License, or | ||
268 | 6 | # (at your option) any later version. | ||
269 | 7 | # | ||
270 | 8 | # This program is distributed in the hope that it will be useful, | ||
271 | 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
272 | 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
273 | 11 | # GNU General Public License for more details. | ||
274 | 12 | # | ||
275 | 13 | # You should have received a copy of the GNU General Public License | ||
276 | 14 | # along with this program; if not, write to the Free Software | ||
277 | 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
278 | 16 | |||
279 | 17 | """Print lines matching PATTERN for specified files and revisions.""" | ||
280 | 18 | |||
281 | 19 | from bzrlib import errors | ||
282 | 20 | from bzrlib.commands import Command, display_command | ||
283 | 21 | from bzrlib.option import Option, ListOption | ||
284 | 22 | |||
285 | 23 | # FIXME: _parse_levels should be shared with bzrlib.builtins. this is a copy | ||
286 | 24 | # to avoid the error | ||
287 | 25 | # "IllegalUseOfScopeReplacer: ScopeReplacer object '_parse_levels' was used | ||
288 | 26 | # incorrectly: Object already cleaned up, did you assign it to another | ||
289 | 27 | # variable?: _factory | ||
290 | 28 | # with lazy import | ||
291 | 29 | def _parse_levels(s): | ||
292 | 30 | try: | ||
293 | 31 | return int(s) | ||
294 | 32 | except ValueError: | ||
295 | 33 | msg = "The levels argument must be an integer." | ||
296 | 34 | raise errors.BzrCommandError(msg) | ||
297 | 35 | |||
298 | 36 | |||
299 | 37 | class GrepOptions(object): | ||
300 | 38 | """Container to pass around grep options. | ||
301 | 39 | |||
302 | 40 | This class is used as a container to pass around user option and | ||
303 | 41 | some other params (like outf) to processing functions. This makes | ||
304 | 42 | it easier to add more options as grep evolves. | ||
305 | 43 | """ | ||
306 | 44 | verbose = False | ||
307 | 45 | ignore_case = False | ||
308 | 46 | no_recursive = False | ||
309 | 47 | from_root = False | ||
310 | 48 | null = False | ||
311 | 49 | levels = None | ||
312 | 50 | line_number = False | ||
313 | 51 | path_list = None | ||
314 | 52 | revision = None | ||
315 | 53 | pattern = None | ||
316 | 54 | include = None | ||
317 | 55 | exclude = None | ||
318 | 56 | fixed_string = False | ||
319 | 57 | files_with_matches = False | ||
320 | 58 | files_without_match = False | ||
321 | 59 | color = None | ||
322 | 60 | diff = False | ||
323 | 61 | |||
324 | 62 | # derived options | ||
325 | 63 | recursive = None | ||
326 | 64 | eol_marker = None | ||
327 | 65 | patternc = None | ||
328 | 66 | sub_patternc = None | ||
329 | 67 | print_revno = None | ||
330 | 68 | fixed_string = None | ||
331 | 69 | outf = None | ||
332 | 70 | show_color = False | ||
333 | 71 | |||
334 | 72 | |||
335 | 73 | class cmd_grep(Command): | ||
336 | 74 | """Print lines matching PATTERN for specified files and revisions. | ||
337 | 75 | |||
338 | 76 | This command searches the specified files and revisions for a given | ||
339 | 77 | pattern. The pattern is specified as a Python regular expressions[1]. | ||
340 | 78 | |||
341 | 79 | If the file name is not specified, the revisions starting with the | ||
342 | 80 | current directory are searched recursively. If the revision number is | ||
343 | 81 | not specified, the working copy is searched. To search the last committed | ||
344 | 82 | revision, use the '-r -1' or '-r last:1' option. | ||
345 | 83 | |||
346 | 84 | Unversioned files are not searched unless explicitly specified on the | ||
347 | 85 | command line. Unversioned directores are not searched. | ||
348 | 86 | |||
349 | 87 | When searching a pattern, the output is shown in the 'filepath:string' | ||
350 | 88 | format. If a revision is explicitly searched, the output is shown as | ||
351 | 89 | 'filepath~N:string', where N is the revision number. | ||
352 | 90 | |||
353 | 91 | --include and --exclude options can be used to search only (or exclude | ||
354 | 92 | from search) files with base name matches the specified Unix style GLOB | ||
355 | 93 | pattern. The GLOB pattern an use *, ?, and [...] as wildcards, and \\ | ||
356 | 94 | to quote wildcard or backslash character literally. Note that the glob | ||
357 | 95 | pattern is not a regular expression. | ||
358 | 96 | |||
359 | 97 | [1] http://docs.python.org/library/re.html#regular-expression-syntax | ||
360 | 98 | """ | ||
361 | 99 | |||
362 | 100 | encoding_type = 'replace' | ||
363 | 101 | takes_args = ['pattern', 'path*'] | ||
364 | 102 | takes_options = [ | ||
365 | 103 | 'verbose', | ||
366 | 104 | 'revision', | ||
367 | 105 | Option('color', type=str, argname='when', | ||
368 | 106 | help='Show match in color. WHEN is never, always or auto.'), | ||
369 | 107 | Option('diff', short_name='p', | ||
370 | 108 | help='Grep for pattern in changeset for each revision.'), | ||
371 | 109 | ListOption('exclude', type=str, argname='glob', short_name='X', | ||
372 | 110 | help="Skip files whose base name matches GLOB."), | ||
373 | 111 | ListOption('include', type=str, argname='glob', short_name='I', | ||
374 | 112 | help="Search only files whose base name matches GLOB."), | ||
375 | 113 | Option('files-with-matches', short_name='l', | ||
376 | 114 | help='Print only the name of each input file in ' | ||
377 | 115 | 'which PATTERN is found.'), | ||
378 | 116 | Option('files-without-match', short_name='L', | ||
379 | 117 | help='Print only the name of each input file in ' | ||
380 | 118 | 'which PATTERN is not found.'), | ||
381 | 119 | Option('fixed-string', short_name='F', | ||
382 | 120 | help='Interpret PATTERN is a single fixed string (not regex).'), | ||
383 | 121 | Option('from-root', | ||
384 | 122 | help='Search for pattern starting from the root of the branch. ' | ||
385 | 123 | '(implies --recursive)'), | ||
386 | 124 | Option('ignore-case', short_name='i', | ||
387 | 125 | help='ignore case distinctions while matching.'), | ||
388 | 126 | Option('levels', | ||
389 | 127 | help='Number of levels to display - 0 for all, 1 for collapsed ' | ||
390 | 128 | '(1 is default).', | ||
391 | 129 | argname='N', | ||
392 | 130 | type=_parse_levels), | ||
393 | 131 | Option('line-number', short_name='n', | ||
394 | 132 | help='show 1-based line number.'), | ||
395 | 133 | Option('no-recursive', | ||
396 | 134 | help="Don't recurse into subdirectories. (default is --recursive)"), | ||
397 | 135 | Option('null', short_name='Z', | ||
398 | 136 | help='Write an ASCII NUL (\\0) separator ' | ||
399 | 137 | 'between output lines rather than a newline.'), | ||
400 | 138 | ] | ||
401 | 139 | |||
402 | 140 | |||
403 | 141 | @display_command | ||
404 | 142 | def run(self, verbose=False, ignore_case=False, no_recursive=False, | ||
405 | 143 | from_root=False, null=False, levels=None, line_number=False, | ||
406 | 144 | path_list=None, revision=None, pattern=None, include=None, | ||
407 | 145 | exclude=None, fixed_string=False, files_with_matches=False, | ||
408 | 146 | files_without_match=False, color='never', diff=False): | ||
409 | 147 | from bzrlib.plugins.grep import ( | ||
410 | 148 | grep, | ||
411 | 149 | termcolor, | ||
412 | 150 | ) | ||
413 | 151 | import re | ||
414 | 152 | if path_list == None: | ||
415 | 153 | path_list = ['.'] | ||
416 | 154 | else: | ||
417 | 155 | if from_root: | ||
418 | 156 | raise errors.BzrCommandError('cannot specify both --from-root and PATH.') | ||
419 | 157 | |||
420 | 158 | if files_with_matches and files_without_match: | ||
421 | 159 | raise errors.BzrCommandError('cannot specify both ' | ||
422 | 160 | '-l/--files-with-matches and -L/--files-without-matches.') | ||
423 | 161 | |||
424 | 162 | if color not in ['always', 'never', 'auto']: | ||
425 | 163 | raise errors.BzrCommandError('Valid values for --color are ' | ||
426 | 164 | '"always", "never" or "auto".') | ||
427 | 165 | |||
428 | 166 | if levels==None: | ||
429 | 167 | levels=1 | ||
430 | 168 | |||
431 | 169 | print_revno = False | ||
432 | 170 | if revision != None or levels == 0: | ||
433 | 171 | # print revision numbers as we may be showing multiple revisions | ||
434 | 172 | print_revno = True | ||
435 | 173 | |||
436 | 174 | eol_marker = '\n' | ||
437 | 175 | if null: | ||
438 | 176 | eol_marker = '\0' | ||
439 | 177 | |||
440 | 178 | if not ignore_case and grep.is_fixed_string(pattern): | ||
441 | 179 | # if the pattern isalnum, implicitly use to -F for faster grep | ||
442 | 180 | fixed_string = True | ||
443 | 181 | elif ignore_case and fixed_string: | ||
444 | 182 | # GZ 2010-06-02: Fall back to regexp rather than lowercasing | ||
445 | 183 | # pattern and text which will cause pain later | ||
446 | 184 | fixed_string = False | ||
447 | 185 | pattern = re.escape(pattern) | ||
448 | 186 | |||
449 | 187 | patternc = None | ||
450 | 188 | re_flags = re.MULTILINE | ||
451 | 189 | if ignore_case: | ||
452 | 190 | re_flags |= re.IGNORECASE | ||
453 | 191 | |||
454 | 192 | if not fixed_string: | ||
455 | 193 | patternc = grep.compile_pattern(pattern, re_flags) | ||
456 | 194 | |||
457 | 195 | if color == 'always': | ||
458 | 196 | show_color = True | ||
459 | 197 | elif color == 'never': | ||
460 | 198 | show_color = False | ||
461 | 199 | elif color == 'auto': | ||
462 | 200 | show_color = termcolor.allow_color() | ||
463 | 201 | |||
464 | 202 | GrepOptions.verbose = verbose | ||
465 | 203 | GrepOptions.ignore_case = ignore_case | ||
466 | 204 | GrepOptions.no_recursive = no_recursive | ||
467 | 205 | GrepOptions.from_root = from_root | ||
468 | 206 | GrepOptions.null = null | ||
469 | 207 | GrepOptions.levels = levels | ||
470 | 208 | GrepOptions.line_number = line_number | ||
471 | 209 | GrepOptions.path_list = path_list | ||
472 | 210 | GrepOptions.revision = revision | ||
473 | 211 | GrepOptions.pattern = pattern | ||
474 | 212 | GrepOptions.include = include | ||
475 | 213 | GrepOptions.exclude = exclude | ||
476 | 214 | GrepOptions.fixed_string = fixed_string | ||
477 | 215 | GrepOptions.files_with_matches = files_with_matches | ||
478 | 216 | GrepOptions.files_without_match = files_without_match | ||
479 | 217 | GrepOptions.color = color | ||
480 | 218 | GrepOptions.diff = False | ||
481 | 219 | |||
482 | 220 | GrepOptions.eol_marker = eol_marker | ||
483 | 221 | GrepOptions.print_revno = print_revno | ||
484 | 222 | GrepOptions.patternc = patternc | ||
485 | 223 | GrepOptions.recursive = not no_recursive | ||
486 | 224 | GrepOptions.fixed_string = fixed_string | ||
487 | 225 | GrepOptions.outf = self.outf | ||
488 | 226 | GrepOptions.show_color = show_color | ||
489 | 227 | |||
490 | 228 | if diff == True: | ||
491 | 229 | # options not used: | ||
492 | 230 | # files_with_matches, files_without_match | ||
493 | 231 | # levels(?), line_number, from_root | ||
494 | 232 | # include, exclude | ||
495 | 233 | # These are silently ignored. | ||
496 | 234 | grep.grep_diff(GrepOptions) | ||
497 | 235 | elif revision == None: | ||
498 | 236 | grep.workingtree_grep(GrepOptions) | ||
499 | 237 | else: | ||
500 | 238 | grep.versioned_grep(GrepOptions) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 2/19/2011 6:39 PM, Jelmer Vernooij wrote: /code.launchpad .net/~jelmer/ bzr-grep/ lazy/+merge/ 50489
> Jelmer Vernooij has proposed merging lp:~jelmer/bzr-grep/lazy into lp:bzr-grep.
>
> Requested reviews:
> Bazaar Developers (bzr)
>
> For more details, see:
> https:/
>
> This moves the actual command implementation to a separate file.
>
> It shaves some (limited) time off the bzr startup time.
merge: approve
John enigmail. mozdev. org/
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAk1 mlmAACgkQJdeBCY SNAANz3wCeJ9WBF 1fIA4FO6F6XiS2M R8qm 97+dZE/ VOC0F3nj0AGSOiI n
QRcAn3zX/
=rohz
-----END PGP SIGNATURE-----