##// END OF EJS Templates
grep: change default behaviour to search working directory files (BC)...
Sangeet Kumar Mishra -
r38650:9ef10437 default
parent child Browse files
Show More
@@ -2515,11 +2515,12 def grep(ui, repo, pattern, *pats, **opt
2515 2515 Search revision history for a regular expression in the specified
2516 2516 files or the entire project.
2517 2517
2518 By default, grep prints the most recent revision number for each
2519 file in which it finds a match. To get it to print every revision
2520 that contains a change in match status ("-" for a match that becomes
2521 a non-match, or "+" for a non-match that becomes a match), use the
2522 --diff flag.
2518 By default, grep searches the expression on the working directory.
2519 To search history and show the most recent revision number for each
2520 file in which it finds a match, use :hg:`grep -r tip:0`.
2521 To get it to print every revision that contains a change in match status
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 2525 PATTERN can be any Python (roughly Perl-compatible) regular
2525 2526 expression.
@@ -2544,6 +2545,10 def grep(ui, repo, pattern, *pats, **opt
2544 2545 if opts.get('print0'):
2545 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 2552 getfile = util.lrucachefunc(repo.file)
2548 2553
2549 2554 def matchlines(body):
@@ -23,11 +23,11 pattern error
23 23
24 24 simple
25 25
26 $ hg grep '.*'
26 $ hg grep -r tip:0 '.*'
27 27 port:4:export
28 28 port:4:vaportight
29 29 port:4:import/export
30 $ hg grep port port
30 $ hg grep -r tip:0 port port
31 31 port:4:export
32 32 port:4:vaportight
33 33 port:4:import/export
@@ -35,32 +35,32 simple
35 35 simple with color
36 36
37 37 $ hg --config extensions.color= grep --config color.mode=ansi \
38 > --color=always port port
38 > --color=always port port -r tip:0
39 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 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 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 43 simple templated
44 44
45 $ hg grep port \
45 $ hg grep port -r tip:0 \
46 46 > -T '{file}:{rev}:{node|short}:{texts % "{if(matched, text|upper, text)}"}\n'
47 47 port:4:914fa752cdea:exPORT
48 48 port:4:914fa752cdea:vaPORTight
49 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 52 port:4:export
53 53 port:4:vaportight
54 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 57 port:tip:export
58 58 port:tip:vaportight
59 59 port:tip:import/export
60 60
61 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 66 "date": [4, 0],
@@ -93,7 +93,7 simple JSON (no "change" field)
93 93
94 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 99 "date": [4, 0],
@@ -216,9 +216,9 all JSON
216 216
217 217 other
218 218
219 $ hg grep -l port port
219 $ hg grep -r tip:0 -l port port
220 220 port:4
221 $ hg grep import port
221 $ hg grep -r tip:0 import port
222 222 port:4:import/export
223 223
224 224 $ hg cp port port2
@@ -226,7 +226,7 other
226 226
227 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 230 port:0:import
231 231
232 232 $ echo deport >> port2
@@ -244,8 +244,8 follow
244 244 port:0:1:+:spam:import
245 245
246 246 $ hg up -q null
247 $ hg grep -f port
248 [1]
247 $ hg grep -r 'reverse(:.)' -f port
248 port:0:import
249 249
250 250 Test wdir
251 251 (at least, this shouldn't crash)
@@ -264,9 +264,9 Test wdir
264 264 $ cd ..
265 265 $ hg init t2
266 266 $ cd t2
267 $ hg grep foobar foo
267 $ hg grep -r tip:0 foobar foo
268 268 [1]
269 $ hg grep foobar
269 $ hg grep -r tip:0 foobar
270 270 [1]
271 271 $ echo blue >> color
272 272 $ echo black >> color
@@ -279,7 +279,7 Test wdir
279 279 $ echo orange >> color
280 280 $ echo blue >> color
281 281 $ hg ci -m 3
282 $ hg grep orange
282 $ hg grep -r tip:0 orange
283 283 color:3:orange
284 284 $ hg grep --all orange
285 285 color:3:+:orange
@@ -293,7 +293,7 Test wdir
293 293
294 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 297 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lack
298 298 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|o]range
299 299 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lue
@@ -303,7 +303,7 match in last "line" without newline
303 303 $ $PYTHON -c 'fp = open("noeol", "wb"); fp.write(b"no infinite loop"); fp.close();'
304 304 $ hg ci -Amnoeol
305 305 adding noeol
306 $ hg grep loop
306 $ hg grep -r tip:0 loop
307 307 noeol:4:no infinite loop
308 308
309 309 $ cd ..
@@ -320,7 +320,7 revision with renamed files.
320 320 adding color
321 321 $ hg rename color colour
322 322 $ hg ci -Am rename
323 $ hg grep octarine
323 $ hg grep -r tip:0 octarine
324 324 colour:1:octarine
325 325 color:0:octarine
326 326
@@ -424,3 +424,14 files modified in the working directory
424 424 a:2147483647:abracadara
425 425
426 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