##// END OF EJS Templates
grep: add --diff flag...
Sangeet Kumar Mishra -
r38440:7fbb5d76 default
parent child Browse files
Show More
@@ -2391,6 +2391,8 b' def _stopgraft(ui, repo, graftstate):'
2391 2391 @command('grep',
2392 2392 [('0', 'print0', None, _('end fields with NUL')),
2393 2393 ('', 'all', None, _('print all revisions that match')),
2394 ('', 'diff', None, _('print all revisions when the term was introduced '
2395 'or removed')),
2394 2396 ('a', 'text', None, _('treat all files as text')),
2395 2397 ('f', 'follow', None,
2396 2398 _('follow changeset history,'
@@ -2419,7 +2421,7 b' def grep(ui, repo, pattern, *pats, **opt'
2419 2421 file in which it finds a match. To get it to print every revision
2420 2422 that contains a change in match status ("-" for a match that becomes
2421 2423 a non-match, or "+" for a non-match that becomes a match), use the
2422 --all flag.
2424 --diff/--all flag.
2423 2425
2424 2426 PATTERN can be any Python (roughly Perl-compatible) regular
2425 2427 expression.
@@ -2431,6 +2433,7 b' def grep(ui, repo, pattern, *pats, **opt'
2431 2433 Returns 0 if a match is found, 1 otherwise.
2432 2434 """
2433 2435 opts = pycompat.byteskwargs(opts)
2436 diff = opts.get('all') or opts.get('diff')
2434 2437 reflags = re.M
2435 2438 if opts.get('ignore_case'):
2436 2439 reflags |= re.I
@@ -2527,7 +2530,7 b' def grep(ui, repo, pattern, *pats, **opt'
2527 2530 return ctx[fn].isbinary()
2528 2531
2529 2532 fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'}
2530 if opts.get('all'):
2533 if diff:
2531 2534 iter = difflinestates(pstates, states)
2532 2535 else:
2533 2536 iter = [('', l) for l in states]
@@ -2540,7 +2543,7 b' def grep(ui, repo, pattern, *pats, **opt'
2540 2543 ('rev', rev, True),
2541 2544 ('linenumber', l.linenum, opts.get('line_number')),
2542 2545 ]
2543 if opts.get('all'):
2546 if diff:
2544 2547 cols.append(('change', change, True))
2545 2548 cols.extend([
2546 2549 ('user', formatuser(ctx.user()), opts.get('user')),
@@ -2644,7 +2647,7 b' def grep(ui, repo, pattern, *pats, **opt'
2644 2647 if pstates or states:
2645 2648 r = display(fm, fn, ctx, pstates, states)
2646 2649 found = found or r
2647 if r and not opts.get('all'):
2650 if r and not diff:
2648 2651 skip[fn] = True
2649 2652 if copy:
2650 2653 skip[copy] = True
@@ -313,7 +313,7 b' Show all commands + options'
313 313 debugwireproto: localssh, peer, noreadstderr, nologhandshake, ssh, remotecmd, insecure
314 314 files: rev, print0, include, exclude, template, subrepos
315 315 graft: rev, continue, stop, edit, log, force, currentdate, currentuser, date, user, tool, dry-run
316 grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, allfiles, user, date, template, include, exclude
316 grep: print0, all, diff, text, follow, ignore-case, files-with-matches, line-number, rev, allfiles, user, date, template, include, exclude
317 317 heads: rev, topo, active, closed, style, template
318 318 help: extension, command, keyword, system
319 319 identify: rev, num, id, branch, tags, bookmarks, ssh, remotecmd, insecure, template
@@ -281,6 +281,11 b' Test wdir'
281 281 color:2:-:orange
282 282 color:1:+:orange
283 283
284 $ hg grep --diff orange
285 color:3:+:orange
286 color:2:-:orange
287 color:1:+:orange
288
284 289 test substring match: '^' should only match at the beginning
285 290
286 291 $ hg grep '^.' --config extensions.color= --color debug
@@ -349,6 +354,10 b' of just using revision numbers.'
349 354 color:3:-:red
350 355 color:1:+:red
351 356
357 $ hg grep --diff red
358 color:3:-:red
359 color:1:+:red
360
352 361 Issue3885: test that changing revision order does not alter the
353 362 revisions printed, just their order.
354 363
@@ -360,6 +369,14 b' revisions printed, just their order.'
360 369 color:3:-:red
361 370 color:1:+:red
362 371
372 $ hg grep --diff red -r "all()"
373 color:1:+:red
374 color:3:-:red
375
376 $ hg grep --diff red -r "reverse(all())"
377 color:3:-:red
378 color:1:+:red
379
363 380 $ cd ..
364 381
365 382 $ hg init a
@@ -370,6 +387,9 b' revisions printed, just their order.'
370 387 $ hg grep "MaCam" --all
371 388 binfile.bin:0:+: Binary file matches
372 389
390 $ hg grep "MaCam" --diff
391 binfile.bin:0:+: Binary file matches
392
373 393 $ cd ..
374 394
375 395 Test for showing working of allfiles flag
General Comments 0
You need to be logged in to leave comments. Login now