##// 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 b'all-files',
3310 b'all-files',
3311 None,
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 (b'u', b'user', None, _(b'list the author (long with -v)')),
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 opts = pycompat.byteskwargs(opts)
3367 opts = pycompat.byteskwargs(opts)
3368 diff = opts.get(b'all') or opts.get(b'diff')
3368 diff = opts.get(b'all') or opts.get(b'diff')
3369 all_files = opts.get(b'all_files')
3370 if diff and opts.get(b'all_files'):
3369 if diff and opts.get(b'all_files'):
3371 raise error.Abort(_(b'--diff and --all-files are mutually exclusive'))
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
3371 if opts.get(b'all_files') is None and not diff:
3373 if opts.get(b'all_files') is None and not opts.get(b'rev') and not diff:
3372 opts[b'all_files'] = True
3374 # experimental config: commands.grep.all-files
3375 opts[b'all_files'] = ui.configbool(b'commands', b'grep.all-files')
3376 plaingrep = opts.get(b'all_files') and not opts.get(b'rev')
3373 plaingrep = opts.get(b'all_files') and not opts.get(b'rev')
3374 all_files = opts.get(b'all_files')
3377 if plaingrep:
3375 if plaingrep:
3378 opts[b'rev'] = [b'wdir()']
3376 opts[b'rev'] = [b'wdir()']
3379
3377
@@ -27,10 +27,30 b' simple'
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 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 $ hg grep -r tip:0 port port
40 $ hg grep -r tip:0 port port
31 port:4:export
41 port:4:export
32 port:4:vaportight
42 port:4:vaportight
33 port:4:import/export
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 simple from subdirectory
55 simple from subdirectory
36
56
@@ -40,10 +60,30 b' simple from subdirectory'
40 port:4:export
60 port:4:export
41 port:4:vaportight
61 port:4:vaportight
42 port:4:import/export
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 $ hg grep -r tip:0 port --config ui.relative-paths=yes
73 $ hg grep -r tip:0 port --config ui.relative-paths=yes
44 ../port:4:export
74 ../port:4:export
45 ../port:4:vaportight
75 ../port:4:vaportight
46 ../port:4:import/export
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 $ cd ..
87 $ cd ..
48
88
49 simple with color
89 simple with color
@@ -53,6 +93,16 b' simple with color'
53 \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)
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 \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)
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 \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)
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 simple templated
107 simple templated
58
108
@@ -61,16 +111,46 b' simple templated'
61 port:4:914fa752cdea:exPORT
111 port:4:914fa752cdea:exPORT
62 port:4:914fa752cdea:vaPORTight
112 port:4:914fa752cdea:vaPORTight
63 port:4:914fa752cdea:imPORT/exPORT
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 $ hg grep port -r tip:0 -T '{path}:{rev}:{texts}\n'
125 $ hg grep port -r tip:0 -T '{path}:{rev}:{texts}\n'
66 port:4:export
126 port:4:export
67 port:4:vaportight
127 port:4:vaportight
68 port:4:import/export
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 $ hg grep port -r tip:0 -T '{path}:{tags}:{texts}\n'
140 $ hg grep port -r tip:0 -T '{path}:{tags}:{texts}\n'
71 port:tip:export
141 port:tip:export
72 port:tip:vaportight
142 port:tip:vaportight
73 port:tip:import/export
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 simple JSON (no "change" field)
155 simple JSON (no "change" field)
76
156
@@ -102,6 +182,96 b' simple JSON (no "change" field)'
102 "rev": 4,
182 "rev": 4,
103 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}],
183 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}],
104 "user": "spam"
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 "path": "port",
286 "path": "port",
117 "rev": 4,
287 "rev": 4,
118 "user": "spam"
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 $ hg grep -r tip:0 -l port port
435 $ hg grep -r tip:0 -l port port
234 port:4
436 port:4
437 port:3
438 port:2
439 port:1
440 port:0
235 $ hg grep -r tip:0 import port
441 $ hg grep -r tip:0 import port
236 port:4:import/export
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 $ hg cp port port2
449 $ hg cp port port2
239 $ hg commit -m 4 -u spam -d '5 0'
450 $ hg commit -m 4 -u spam -d '5 0'
@@ -241,8 +452,7 b' other'
241 follow
452 follow
242
453
243 $ hg grep -r tip:0 --traceback -f 'import\n\Z' port2
454 $ hg grep -r tip:0 --traceback -f 'import\n\Z' port2
244 port:0:import
455 [1]
245
246 $ echo deport >> port2
456 $ echo deport >> port2
247 $ hg commit -m 5 -u eggs -d '6 0'
457 $ hg commit -m 5 -u eggs -d '6 0'
248 $ hg grep -f --all -nu port port2
458 $ hg grep -f --all -nu port port2
@@ -269,6 +479,9 b' Test wdir'
269 $ hg stat
479 $ hg stat
270 M port2
480 M port2
271 $ hg grep -r 'wdir()' port
481 $ hg grep -r 'wdir()' port
482 port:2147483647:export
483 port:2147483647:vaportight
484 port:2147483647:import/export
272 port2:2147483647:export
485 port2:2147483647:export
273 port2:2147483647:vaportight
486 port2:2147483647:vaportight
274 port2:2147483647:import/export
487 port2:2147483647:import/export
@@ -295,6 +508,7 b' Test wdir'
295 $ hg ci -m 3
508 $ hg ci -m 3
296 $ hg grep -r tip:0 orange
509 $ hg grep -r tip:0 orange
297 color:3:orange
510 color:3:orange
511 color:1:orange
298 $ hg grep --all orange
512 $ hg grep --all orange
299 color:3:+:orange
513 color:3:+:orange
300 color:2:-:orange
514 color:2:-:orange
@@ -320,6 +534,12 b" test substring match: '^' should only ma"
320 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lack
534 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lack
321 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|o]range
535 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|o]range
322 [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lue
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 match in last "line" without newline
544 match in last "line" without newline
325
545
@@ -431,39 +651,21 b' Test for showing working of allfiles fla'
431 $ hg ci -A -m "second commit"
651 $ hg ci -A -m "second commit"
432 adding new
652 adding new
433 $ hg grep -r "." "unmod"
653 $ hg grep -r "." "unmod"
434 [1]
435 $ hg grep -r "." "unmod" --all-files
436 um:1:unmod
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 $ echo modified >> new
658 $ echo modified >> new
441 $ hg grep --all-files mod
659 $ hg grep mod
442 new:modified
660 new:modified
443 um:unmod
661 um:unmod
444
662
445 which can be overridden by -rREV
663 which can be overridden by -rREV
446
664
447 $ hg grep --all-files -r. mod
665 $ hg grep -r. mod
448 um:1:unmod
666 um:1:unmod
449
667
450 commands.all-files can be negated by --no-all-files
668 $ hg grep --diff mod
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
467 um:0:+:unmod
669 um:0:+:unmod
468
670
469 $ cd ..
671 $ cd ..
@@ -515,18 +717,18 b' but it should be available in template d'
515
717
516 $ cd ..
718 $ cd ..
517
719
518 test -rMULTIREV with --all-files
720 test -rMULTIREV
519
721
520 $ cd sng
722 $ cd sng
521 $ hg rm um
723 $ hg rm um
522 $ hg commit -m "deletes um"
724 $ hg commit -m "deletes um"
523 $ hg grep -r "0:2" "unmod" --all-files
725 $ hg grep -r "0:2" "unmod"
524 um:0:unmod
726 um:0:unmod
525 um:1:unmod
727 um:1:unmod
526 $ hg grep -r "0:2" "unmod" --all-files um
728 $ hg grep -r "0:2" "unmod" um
527 um:0:unmod
729 um:0:unmod
528 um:1:unmod
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 um:0:unmod
732 um:0:unmod
531 um:1:unmod
733 um:1:unmod
532 $ cd ..
734 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now