Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 38631:9ef10437bb88
grep: change default behaviour to search working directory files (BC)
With this patch, grep searches on the working directory by default
and looks for all files tracked by the working directory and greps on them.
### OLD BEHAVIOUR
$ hg init a
$ cd a
$ echo "some text">>file1
$ hg add file1
$ hg commit -m "adds file1"
$ hg mv file1 file2
$ hg grep "some"
`file2:1:some text`
`file1:0:some text`
This behaviour is undesirable since file1 is not in the current history and was
renamed as file2, so the second result was redundant and confusing.
### NEW BEHAVIOUR
$ hg init a
$ cd a
$ echo "some text">>file1
$ hg add file1
$ hg commit -m "adds file1"
$ hg mv file1 file2
$ hg grep "some"
`file2:2147483647:some text`
Differential Revision: https://phab.mercurial-scm.org/D3826
author | Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com> |
---|---|
date | Fri, 06 Jul 2018 00:39:21 +0530 |
parents | afef1e362d65 |
children | ffd08ec22955 |
comparison
equal
deleted
inserted
replaced
38630:e1987261dd05 | 38631:9ef10437bb88 |
---|---|
2513 """search revision history for a pattern in specified files | 2513 """search revision history for a pattern in specified files |
2514 | 2514 |
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 prints the most recent revision number for each | 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. |
2526 | 2527 |
2527 If no FILEs are specified (and -f/--follow isn't set), all files in | 2528 If no FILEs are specified (and -f/--follow isn't set), all files in |
2541 ui.warn(_("grep: invalid match pattern: %s\n") % pycompat.bytestr(inst)) | 2542 ui.warn(_("grep: invalid match pattern: %s\n") % pycompat.bytestr(inst)) |
2542 return 1 | 2543 return 1 |
2543 sep, eol = ':', '\n' | 2544 sep, eol = ':', '\n' |
2544 if opts.get('print0'): | 2545 if opts.get('print0'): |
2545 sep = eol = '\0' | 2546 sep = eol = '\0' |
2547 | |
2548 if not opts.get('rev') and not diff: | |
2549 opts['rev'] = ["wdir()"] | |
2550 opts['allfiles'] = True | |
2546 | 2551 |
2547 getfile = util.lrucachefunc(repo.file) | 2552 getfile = util.lrucachefunc(repo.file) |
2548 | 2553 |
2549 def matchlines(body): | 2554 def matchlines(body): |
2550 begin = 0 | 2555 begin = 0 |