##// END OF EJS Templates
grep: enable all-files by default (BC)...
Sushil khanchi -
r43598:8cb5f96d default
parent child Browse files
Show More
@@ -3310,7 +3310,7 b' statemod.addunfinished('
3310 3310 b'all-files',
3311 3311 None,
3312 3312 _(
3313 b'include all files in the changeset while grepping (EXPERIMENTAL)'
3313 b'include all files in the changeset while grepping (DEPRECATED)'
3314 3314 ),
3315 3315 ),
3316 3316 (b'u', b'user', None, _(b'list the author (long with -v)')),
@@ -3366,14 +3366,12 b' def grep(ui, repo, pattern, *pats, **opt'
3366 3366 """
3367 3367 opts = pycompat.byteskwargs(opts)
3368 3368 diff = opts.get(b'all') or opts.get(b'diff')
3369 all_files = opts.get(b'all_files')
3370 3369 if diff and opts.get(b'all_files'):
3371 3370 raise error.Abort(_(b'--diff and --all-files are mutually exclusive'))
3372 # TODO: remove "not opts.get('rev')" if --all-files -rMULTIREV gets working
3373 if opts.get(b'all_files') is None and not opts.get(b'rev') and not diff:
3374 # experimental config: commands.grep.all-files
3375 opts[b'all_files'] = ui.configbool(b'commands', b'grep.all-files')
3371 if opts.get(b'all_files') is None and not diff:
3372 opts[b'all_files'] = True
3376 3373 plaingrep = opts.get(b'all_files') and not opts.get(b'rev')
3374 all_files = opts.get(b'all_files')
3377 3375 if plaingrep:
3378 3376 opts[b'rev'] = [b'wdir()']
3379 3377
@@ -27,10 +27,30 b' simple'
27 27 port:4:export
28 28 port:4:vaportight
29 29 port:4:import/export
30 port:3:export
31 port:3:vaportight
32 port:3:import/export
33 port:3:import/export
34 port:2:export
35 port:2:vaportight
36 port:2:import/export
37 port:1:import
38 port:1:export
39 port:0:import
30 40 $ hg grep -r tip:0 port port
31 41 port:4:export
32 42 port:4:vaportight
33 43 port:4:import/export
44 port:3:export
45 port:3:vaportight
46 port:3:import/export
47 port:3:import/export
48 port:2:export
49 port:2:vaportight
50 port:2:import/export
51 port:1:import
52 port:1:export
53 port:0:import
34 54
35 55 simple from subdirectory
36 56
@@ -40,10 +60,30 b' simple from subdirectory'
40 60 port:4:export
41 61 port:4:vaportight
42 62 port:4:import/export
63 port:3:export
64 port:3:vaportight
65 port:3:import/export
66 port:3:import/export
67 port:2:export
68 port:2:vaportight
69 port:2:import/export
70 port:1:import
71 port:1:export
72 port:0:import
43 73 $ hg grep -r tip:0 port --config ui.relative-paths=yes
44 74 ../port:4:export
45 75 ../port:4:vaportight
46 76 ../port:4:import/export
77 ../port:3:export
78 ../port:3:vaportight
79 ../port:3:import/export
80 ../port:3:import/export
81 ../port:2:export
82 ../port:2:vaportight
83 ../port:2:import/export
84 ../port:1:import
85 ../port:1:export
86 ../port:0:import
47 87 $ cd ..
48 88
49 89 simple with color
@@ -53,6 +93,16 b' simple with color'
53 93 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m4\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc)
54 94 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m4\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc)
55 95 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc)
96 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m3\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc)
97 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m3\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc)
98 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m3\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc)
99 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m3\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc)
100 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m2\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc)
101 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m2\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc)
102 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m2\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc)
103 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m1\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m (esc)
104 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m1\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc)
105 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m0\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m (esc)
56 106
57 107 simple templated
58 108
@@ -61,16 +111,46 b' simple templated'
61 111 port:4:914fa752cdea:exPORT
62 112 port:4:914fa752cdea:vaPORTight
63 113 port:4:914fa752cdea:imPORT/exPORT
114 port:3:95040cfd017d:exPORT
115 port:3:95040cfd017d:vaPORTight
116 port:3:95040cfd017d:imPORT/exPORT
117 port:3:95040cfd017d:imPORT/exPORT
118 port:2:3b325e3481a1:exPORT
119 port:2:3b325e3481a1:vaPORTight
120 port:2:3b325e3481a1:imPORT/exPORT
121 port:1:8b20f75c1585:imPORT
122 port:1:8b20f75c1585:exPORT
123 port:0:f31323c92170:imPORT
64 124
65 125 $ hg grep port -r tip:0 -T '{path}:{rev}:{texts}\n'
66 126 port:4:export
67 127 port:4:vaportight
68 128 port:4:import/export
129 port:3:export
130 port:3:vaportight
131 port:3:import/export
132 port:3:import/export
133 port:2:export
134 port:2:vaportight
135 port:2:import/export
136 port:1:import
137 port:1:export
138 port:0:import
69 139
70 140 $ hg grep port -r tip:0 -T '{path}:{tags}:{texts}\n'
71 141 port:tip:export
72 142 port:tip:vaportight
73 143 port:tip:import/export
144 port::export
145 port::vaportight
146 port::import/export
147 port::import/export
148 port::export
149 port::vaportight
150 port::import/export
151 port::import
152 port::export
153 port::import
74 154
75 155 simple JSON (no "change" field)
76 156
@@ -102,6 +182,96 b' simple JSON (no "change" field)'
102 182 "rev": 4,
103 183 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}],
104 184 "user": "spam"
185 },
186 {
187 "date": [3, 0],
188 "lineno": 1,
189 "node": "95040cfd017d658c536071c6290230a613c4c2a6",
190 "path": "port",
191 "rev": 3,
192 "texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}],
193 "user": "eggs"
194 },
195 {
196 "date": [3, 0],
197 "lineno": 2,
198 "node": "95040cfd017d658c536071c6290230a613c4c2a6",
199 "path": "port",
200 "rev": 3,
201 "texts": [{"matched": false, "text": "va"}, {"matched": true, "text": "port"}, {"matched": false, "text": "ight"}],
202 "user": "eggs"
203 },
204 {
205 "date": [3, 0],
206 "lineno": 3,
207 "node": "95040cfd017d658c536071c6290230a613c4c2a6",
208 "path": "port",
209 "rev": 3,
210 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}],
211 "user": "eggs"
212 },
213 {
214 "date": [3, 0],
215 "lineno": 4,
216 "node": "95040cfd017d658c536071c6290230a613c4c2a6",
217 "path": "port",
218 "rev": 3,
219 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}],
220 "user": "eggs"
221 },
222 {
223 "date": [2, 0],
224 "lineno": 1,
225 "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
226 "path": "port",
227 "rev": 2,
228 "texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}],
229 "user": "spam"
230 },
231 {
232 "date": [2, 0],
233 "lineno": 2,
234 "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
235 "path": "port",
236 "rev": 2,
237 "texts": [{"matched": false, "text": "va"}, {"matched": true, "text": "port"}, {"matched": false, "text": "ight"}],
238 "user": "spam"
239 },
240 {
241 "date": [2, 0],
242 "lineno": 3,
243 "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
244 "path": "port",
245 "rev": 2,
246 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}],
247 "user": "spam"
248 },
249 {
250 "date": [1, 0],
251 "lineno": 1,
252 "node": "8b20f75c158513ff5ac80bd0e5219bfb6f0eb587",
253 "path": "port",
254 "rev": 1,
255 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}],
256 "user": "eggs"
257 },
258 {
259 "date": [1, 0],
260 "lineno": 2,
261 "node": "8b20f75c158513ff5ac80bd0e5219bfb6f0eb587",
262 "path": "port",
263 "rev": 1,
264 "texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}],
265 "user": "eggs"
266 },
267 {
268 "date": [0, 0],
269 "lineno": 1,
270 "node": "f31323c9217050ba245ee8b537c713ec2e8ab226",
271 "path": "port",
272 "rev": 0,
273 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}],
274 "user": "spam"
105 275 }
106 276 ]
107 277
@@ -116,6 +286,38 b' simple JSON without matching lines'
116 286 "path": "port",
117 287 "rev": 4,
118 288 "user": "spam"
289 },
290 {
291 "date": [3, 0],
292 "lineno": 1,
293 "node": "95040cfd017d658c536071c6290230a613c4c2a6",
294 "path": "port",
295 "rev": 3,
296 "user": "eggs"
297 },
298 {
299 "date": [2, 0],
300 "lineno": 1,
301 "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
302 "path": "port",
303 "rev": 2,
304 "user": "spam"
305 },
306 {
307 "date": [1, 0],
308 "lineno": 1,
309 "node": "8b20f75c158513ff5ac80bd0e5219bfb6f0eb587",
310 "path": "port",
311 "rev": 1,
312 "user": "eggs"
313 },
314 {
315 "date": [0, 0],
316 "lineno": 1,
317 "node": "f31323c9217050ba245ee8b537c713ec2e8ab226",
318 "path": "port",
319 "rev": 0,
320 "user": "spam"
119 321 }
120 322 ]
121 323
@@ -232,8 +434,17 b' other'
232 434
233 435 $ hg grep -r tip:0 -l port port
234 436 port:4
437 port:3
438 port:2
439 port:1
440 port:0
235 441 $ hg grep -r tip:0 import port
236 442 port:4:import/export
443 port:3:import/export
444 port:3:import/export
445 port:2:import/export
446 port:1:import
447 port:0:import
237 448
238 449 $ hg cp port port2
239 450 $ hg commit -m 4 -u spam -d '5 0'
@@ -241,8 +452,7 b' other'
241 452 follow
242 453
243 454 $ hg grep -r tip:0 --traceback -f 'import\n\Z' port2
244 port:0:import
245
455 [1]
246 456 $ echo deport >> port2
247 457 $ hg commit -m 5 -u eggs -d '6 0'
248 458 $ hg grep -f --all -nu port port2
@@ -269,6 +479,9 b' Test wdir'
269 479 $ hg stat
270 480 M port2
271 481 $ hg grep -r 'wdir()' port
482 port:2147483647:export
483 port:2147483647:vaportight
484 port:2147483647:import/export
272 485 port2:2147483647:export
273 486 port2:2147483647:vaportight
274 487 port2:2147483647:import/export
@@ -295,6 +508,7 b' Test wdir'
295 508 $ hg ci -m 3
296 509 $ hg grep -r tip:0 orange
297 510 color:3:orange
511 color:1:orange
298 512 $ hg grep --all orange
299 513 color:3:+:orange
300 514 color:2:-:orange
@@ -320,6 +534,12 b" test substring match: '^' should only ma"
320 534 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lack
321 535 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|o]range
322 536 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lue
537 [grep.filename|color][grep.sep|:][grep.rev|2][grep.sep|:][grep.match|b]lack
538 [grep.filename|color][grep.sep|:][grep.rev|1][grep.sep|:][grep.match|b]lue
539 [grep.filename|color][grep.sep|:][grep.rev|1][grep.sep|:][grep.match|b]lack
540 [grep.filename|color][grep.sep|:][grep.rev|1][grep.sep|:][grep.match|o]range
541 [grep.filename|color][grep.sep|:][grep.rev|0][grep.sep|:][grep.match|b]lue
542 [grep.filename|color][grep.sep|:][grep.rev|0][grep.sep|:][grep.match|b]lack
323 543
324 544 match in last "line" without newline
325 545
@@ -431,39 +651,21 b' Test for showing working of allfiles fla'
431 651 $ hg ci -A -m "second commit"
432 652 adding new
433 653 $ hg grep -r "." "unmod"
434 [1]
435 $ hg grep -r "." "unmod" --all-files
436 654 um:1:unmod
437 655
438 With --all-files, the working directory is searched by default
656 Working directory is searched by default
439 657
440 658 $ echo modified >> new
441 $ hg grep --all-files mod
659 $ hg grep mod
442 660 new:modified
443 661 um:unmod
444 662
445 663 which can be overridden by -rREV
446 664
447 $ hg grep --all-files -r. mod
665 $ hg grep -r. mod
448 666 um:1:unmod
449 667
450 commands.all-files can be negated by --no-all-files
451
452 $ hg grep --config commands.grep.all-files=True mod
453 new:modified
454 um:unmod
455 $ hg grep --config commands.grep.all-files=True --no-all-files mod
456 um:0:unmod
457
458 --diff --all-files makes no sense since --diff is the option to grep history
459
460 $ hg grep --diff --all-files um
461 abort: --diff and --all-files are mutually exclusive
462 [255]
463
464 but --diff should precede the commands.grep.all-files option
465
466 $ hg grep --config commands.grep.all-files=True --diff mod
668 $ hg grep --diff mod
467 669 um:0:+:unmod
468 670
469 671 $ cd ..
@@ -515,18 +717,18 b' but it should be available in template d'
515 717
516 718 $ cd ..
517 719
518 test -rMULTIREV with --all-files
720 test -rMULTIREV
519 721
520 722 $ cd sng
521 723 $ hg rm um
522 724 $ hg commit -m "deletes um"
523 $ hg grep -r "0:2" "unmod" --all-files
725 $ hg grep -r "0:2" "unmod"
524 726 um:0:unmod
525 727 um:1:unmod
526 $ hg grep -r "0:2" "unmod" --all-files um
728 $ hg grep -r "0:2" "unmod" um
527 729 um:0:unmod
528 730 um:1:unmod
529 $ hg grep -r "0:2" "unmod" --all-files "glob:**/um" # Check that patterns also work
731 $ hg grep -r "0:2" "unmod" "glob:**/um" # Check that patterns also work
530 732 um:0:unmod
531 733 um:1:unmod
532 734 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now