Show More
@@ -2515,11 +2515,12 b' def grep(ui, repo, pattern, *pats, **opt' | |||||
2515 | Search revision history for a regular expression in the specified |
|
2515 | Search revision history for a regular expression in the specified | |
2516 | files or the entire project. |
|
2516 | files or the entire project. | |
2517 |
|
2517 | |||
2518 |
By default, grep |
|
2518 | By default, grep searches the expression on the working directory. | |
2519 | file in which it finds a match. To get it to print every revision |
|
2519 | To search history and show the most recent revision number for each | |
2520 | that contains a change in match status ("-" for a match that becomes |
|
2520 | file in which it finds a match, use :hg:`grep -r tip:0`. | |
2521 | a non-match, or "+" for a non-match that becomes a match), use the |
|
2521 | To get it to print every revision that contains a change in match status | |
2522 | --diff flag. |
|
2522 | ("-" for a match that becomes a non-match, or "+" for a non-match that | |
|
2523 | becomes a match), use the --diff flag. | |||
2523 |
|
2524 | |||
2524 | PATTERN can be any Python (roughly Perl-compatible) regular |
|
2525 | PATTERN can be any Python (roughly Perl-compatible) regular | |
2525 | expression. |
|
2526 | expression. | |
@@ -2544,6 +2545,10 b' def grep(ui, repo, pattern, *pats, **opt' | |||||
2544 | if opts.get('print0'): |
|
2545 | if opts.get('print0'): | |
2545 | sep = eol = '\0' |
|
2546 | sep = eol = '\0' | |
2546 |
|
2547 | |||
|
2548 | if not opts.get('rev') and not diff: | |||
|
2549 | opts['rev'] = ["wdir()"] | |||
|
2550 | opts['allfiles'] = True | |||
|
2551 | ||||
2547 | getfile = util.lrucachefunc(repo.file) |
|
2552 | getfile = util.lrucachefunc(repo.file) | |
2548 |
|
2553 | |||
2549 | def matchlines(body): |
|
2554 | def matchlines(body): |
@@ -23,11 +23,11 b' pattern error' | |||||
23 |
|
23 | |||
24 | simple |
|
24 | simple | |
25 |
|
25 | |||
26 | $ hg grep '.*' |
|
26 | $ hg grep -r tip:0 '.*' | |
27 | port:4:export |
|
27 | port:4:export | |
28 | port:4:vaportight |
|
28 | port:4:vaportight | |
29 | port:4:import/export |
|
29 | port:4:import/export | |
30 | $ hg grep port port |
|
30 | $ hg grep -r tip:0 port port | |
31 | port:4:export |
|
31 | port:4:export | |
32 | port:4:vaportight |
|
32 | port:4:vaportight | |
33 | port:4:import/export |
|
33 | port:4:import/export | |
@@ -35,32 +35,32 b' simple' | |||||
35 | simple with color |
|
35 | simple with color | |
36 |
|
36 | |||
37 | $ hg --config extensions.color= grep --config color.mode=ansi \ |
|
37 | $ hg --config extensions.color= grep --config color.mode=ansi \ | |
38 | > --color=always port port |
|
38 | > --color=always port port -r tip:0 | |
39 |
\x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0; |
|
39 | \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc) | |
40 |
\x1b[0; |
|
40 | \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc) | |
41 | \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc) |
|
41 | \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc) | |
42 |
|
42 | |||
43 | simple templated |
|
43 | simple templated | |
44 |
|
44 | |||
45 | $ hg grep port \ |
|
45 | $ hg grep port -r tip:0 \ | |
46 | > -T '{file}:{rev}:{node|short}:{texts % "{if(matched, text|upper, text)}"}\n' |
|
46 | > -T '{file}:{rev}:{node|short}:{texts % "{if(matched, text|upper, text)}"}\n' | |
47 | port:4:914fa752cdea:exPORT |
|
47 | port:4:914fa752cdea:exPORT | |
48 | port:4:914fa752cdea:vaPORTight |
|
48 | port:4:914fa752cdea:vaPORTight | |
49 | port:4:914fa752cdea:imPORT/exPORT |
|
49 | port:4:914fa752cdea:imPORT/exPORT | |
50 |
|
50 | |||
51 | $ hg grep port -T '{file}:{rev}:{texts}\n' |
|
51 | $ hg grep port -r tip:0 -T '{file}:{rev}:{texts}\n' | |
52 | port:4:export |
|
52 | port:4:export | |
53 | port:4:vaportight |
|
53 | port:4:vaportight | |
54 | port:4:import/export |
|
54 | port:4:import/export | |
55 |
|
55 | |||
56 | $ hg grep port -T '{file}:{tags}:{texts}\n' |
|
56 | $ hg grep port -r tip:0 -T '{file}:{tags}:{texts}\n' | |
57 | port:tip:export |
|
57 | port:tip:export | |
58 | port:tip:vaportight |
|
58 | port:tip:vaportight | |
59 | port:tip:import/export |
|
59 | port:tip:import/export | |
60 |
|
60 | |||
61 | simple JSON (no "change" field) |
|
61 | simple JSON (no "change" field) | |
62 |
|
62 | |||
63 | $ hg grep -Tjson port |
|
63 | $ hg grep -r tip:0 -Tjson port | |
64 | [ |
|
64 | [ | |
65 | { |
|
65 | { | |
66 | "date": [4, 0], |
|
66 | "date": [4, 0], | |
@@ -93,7 +93,7 b' simple JSON (no "change" field)' | |||||
93 |
|
93 | |||
94 | simple JSON without matching lines |
|
94 | simple JSON without matching lines | |
95 |
|
95 | |||
96 | $ hg grep -Tjson -l port |
|
96 | $ hg grep -r tip:0 -Tjson -l port | |
97 | [ |
|
97 | [ | |
98 | { |
|
98 | { | |
99 | "date": [4, 0], |
|
99 | "date": [4, 0], | |
@@ -216,9 +216,9 b' all JSON' | |||||
216 |
|
216 | |||
217 | other |
|
217 | other | |
218 |
|
218 | |||
219 | $ hg grep -l port port |
|
219 | $ hg grep -r tip:0 -l port port | |
220 | port:4 |
|
220 | port:4 | |
221 | $ hg grep import port |
|
221 | $ hg grep -r tip:0 import port | |
222 | port:4:import/export |
|
222 | port:4:import/export | |
223 |
|
223 | |||
224 | $ hg cp port port2 |
|
224 | $ hg cp port port2 | |
@@ -226,7 +226,7 b' other' | |||||
226 |
|
226 | |||
227 | follow |
|
227 | follow | |
228 |
|
228 | |||
229 | $ hg grep --traceback -f 'import\n\Z' port2 |
|
229 | $ hg grep -r tip:0 --traceback -f 'import\n\Z' port2 | |
230 | port:0:import |
|
230 | port:0:import | |
231 |
|
231 | |||
232 | $ echo deport >> port2 |
|
232 | $ echo deport >> port2 | |
@@ -244,8 +244,8 b' follow' | |||||
244 | port:0:1:+:spam:import |
|
244 | port:0:1:+:spam:import | |
245 |
|
245 | |||
246 | $ hg up -q null |
|
246 | $ hg up -q null | |
247 | $ hg grep -f port |
|
247 | $ hg grep -r 'reverse(:.)' -f port | |
248 | [1] |
|
248 | port:0:import | |
249 |
|
249 | |||
250 | Test wdir |
|
250 | Test wdir | |
251 | (at least, this shouldn't crash) |
|
251 | (at least, this shouldn't crash) | |
@@ -264,9 +264,9 b' Test wdir' | |||||
264 | $ cd .. |
|
264 | $ cd .. | |
265 | $ hg init t2 |
|
265 | $ hg init t2 | |
266 | $ cd t2 |
|
266 | $ cd t2 | |
267 | $ hg grep foobar foo |
|
267 | $ hg grep -r tip:0 foobar foo | |
268 | [1] |
|
268 | [1] | |
269 | $ hg grep foobar |
|
269 | $ hg grep -r tip:0 foobar | |
270 | [1] |
|
270 | [1] | |
271 | $ echo blue >> color |
|
271 | $ echo blue >> color | |
272 | $ echo black >> color |
|
272 | $ echo black >> color | |
@@ -279,7 +279,7 b' Test wdir' | |||||
279 | $ echo orange >> color |
|
279 | $ echo orange >> color | |
280 | $ echo blue >> color |
|
280 | $ echo blue >> color | |
281 | $ hg ci -m 3 |
|
281 | $ hg ci -m 3 | |
282 | $ hg grep orange |
|
282 | $ hg grep -r tip:0 orange | |
283 | color:3:orange |
|
283 | color:3:orange | |
284 | $ hg grep --all orange |
|
284 | $ hg grep --all orange | |
285 | color:3:+:orange |
|
285 | color:3:+:orange | |
@@ -293,7 +293,7 b' Test wdir' | |||||
293 |
|
293 | |||
294 | test substring match: '^' should only match at the beginning |
|
294 | test substring match: '^' should only match at the beginning | |
295 |
|
295 | |||
296 | $ hg grep '^.' --config extensions.color= --color debug |
|
296 | $ hg grep -r tip:0 '^.' --config extensions.color= --color debug | |
297 | [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lack |
|
297 | [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lack | |
298 | [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|o]range |
|
298 | [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|o]range | |
299 | [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lue |
|
299 | [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lue | |
@@ -303,7 +303,7 b' match in last "line" without newline' | |||||
303 | $ $PYTHON -c 'fp = open("noeol", "wb"); fp.write(b"no infinite loop"); fp.close();' |
|
303 | $ $PYTHON -c 'fp = open("noeol", "wb"); fp.write(b"no infinite loop"); fp.close();' | |
304 | $ hg ci -Amnoeol |
|
304 | $ hg ci -Amnoeol | |
305 | adding noeol |
|
305 | adding noeol | |
306 | $ hg grep loop |
|
306 | $ hg grep -r tip:0 loop | |
307 | noeol:4:no infinite loop |
|
307 | noeol:4:no infinite loop | |
308 |
|
308 | |||
309 | $ cd .. |
|
309 | $ cd .. | |
@@ -320,7 +320,7 b' revision with renamed files.' | |||||
320 | adding color |
|
320 | adding color | |
321 | $ hg rename color colour |
|
321 | $ hg rename color colour | |
322 | $ hg ci -Am rename |
|
322 | $ hg ci -Am rename | |
323 | $ hg grep octarine |
|
323 | $ hg grep -r tip:0 octarine | |
324 | colour:1:octarine |
|
324 | colour:1:octarine | |
325 | color:0:octarine |
|
325 | color:0:octarine | |
326 |
|
326 | |||
@@ -424,3 +424,14 b' files modified in the working directory' | |||||
424 | a:2147483647:abracadara |
|
424 | a:2147483647:abracadara | |
425 |
|
425 | |||
426 | $ cd .. |
|
426 | $ cd .. | |
|
427 | ||||
|
428 | Change Default of grep, that is, the files not in current working directory | |||
|
429 | should not be grepp-ed on | |||
|
430 | $ hg init ab | |||
|
431 | $ cd ab | |||
|
432 | $ echo "some text">>file1 | |||
|
433 | $ hg add file1 | |||
|
434 | $ hg commit -m "adds file1" | |||
|
435 | $ hg mv file1 file2 | |||
|
436 | $ hg grep "some" | |||
|
437 | file2:2147483647:some text |
General Comments 0
You need to be logged in to leave comments.
Login now