D3826: grep: change default behaviour of grep
sangeet259 (Sangeet Kumar Mishra)
phabricator at mercurial-scm.org
Mon Jul 9 16:52:27 UTC 2018
sangeet259 updated this revision to Diff 9482.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D3826?vs=9481&id=9482
REVISION DETAIL
https://phab.mercurial-scm.org/D3826
AFFECTED FILES
mercurial/commands.py
tests/test-grep.t
CHANGE DETAILS
diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -23,39 +23,39 @@
simple
- $ hg grep '.*'
+ $ hg grep -r tip:0 '.*'
port:4:export
port:4:vaportight
port:4:import/export
- $ hg grep port port
+ $ hg grep -r tip:0 port port
port:4:export
port:4:vaportight
port:4:import/export
simple with color
$ hg --config extensions.color= grep --config color.mode=ansi \
- > --color=always port port
+ > --color=always port port -r tip:0
\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)
\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)
\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)
simple templated
- $ hg grep port \
+ $ hg grep port -r tip:0 \
> -T '{file}:{rev}:{node|short}:{texts % "{if(matched, text|upper, text)}"}\n'
port:4:914fa752cdea:exPORT
port:4:914fa752cdea:vaPORTight
port:4:914fa752cdea:imPORT/exPORT
- $ hg grep port -T '{file}:{rev}:{texts}\n'
+ $ hg grep port -r tip:0 -T '{file}:{rev}:{texts}\n'
port:4:export
port:4:vaportight
port:4:import/export
simple JSON (no "change" field)
- $ hg grep -Tjson port
+ $ hg grep -r tip:0 -Tjson port
[
{
"date": [4, 0],
@@ -88,7 +88,7 @@
simple JSON without matching lines
- $ hg grep -Tjson -l port
+ $ hg grep -r tip:0 -Tjson -l port
[
{
"date": [4, 0],
@@ -211,17 +211,17 @@
other
- $ hg grep -l port port
+ $ hg grep -r tip:0 -l port port
port:4
- $ hg grep import port
+ $ hg grep -r tip:0 import port
port:4:import/export
$ hg cp port port2
$ hg commit -m 4 -u spam -d '5 0'
follow
- $ hg grep --traceback -f 'import\n\Z' port2
+ $ hg grep -r tip:0 --traceback -f 'import\n\Z' port2
port:0:import
$ echo deport >> port2
@@ -239,8 +239,11 @@
port:0:1:+:spam:import
$ hg up -q null
- $ hg grep -f port
- [1]
+ $ hg grep -r tip:0 -f port
+ port2:6:export
+ port2:6:vaportight
+ port2:6:import/export
+ port2:6:deport
Test wdir
(at least, this shouldn't crash)
@@ -259,9 +262,9 @@
$ cd ..
$ hg init t2
$ cd t2
- $ hg grep foobar foo
+ $ hg grep -r tip:0 foobar foo
[1]
- $ hg grep foobar
+ $ hg grep -r tip:0 foobar
[1]
$ echo blue >> color
$ echo black >> color
@@ -274,7 +277,7 @@
$ echo orange >> color
$ echo blue >> color
$ hg ci -m 3
- $ hg grep orange
+ $ hg grep -r tip:0 orange
color:3:orange
$ hg grep --all orange
color:3:+:orange
@@ -288,7 +291,7 @@
test substring match: '^' should only match at the beginning
- $ hg grep '^.' --config extensions.color= --color debug
+ $ hg grep -r tip:0 '^.' --config extensions.color= --color debug
[grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lack
[grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|o]range
[grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.match|b]lue
@@ -298,7 +301,7 @@
$ $PYTHON -c 'fp = open("noeol", "wb"); fp.write(b"no infinite loop"); fp.close();'
$ hg ci -Amnoeol
adding noeol
- $ hg grep loop
+ $ hg grep -r tip:0 loop
noeol:4:no infinite loop
$ cd ..
@@ -315,7 +318,7 @@
adding color
$ hg rename color colour
$ hg ci -Am rename
- $ hg grep octarine
+ $ hg grep -r tip:0 octarine
colour:1:octarine
color:0:octarine
@@ -419,3 +422,14 @@
a:2147483647:abracadara
$ cd ..
+
+Change Default of grep, that is, the files not in current working directory
+should not be grepp-ed on
+ $ hg init ab
+ $ cd ab
+ $ echo "some text">>file1
+ $ hg add file1
+ $ hg commit -m "adds file1"
+ $ hg mv file1 file2
+ $ hg grep "some"
+ file2:2147483647:some text
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2544,6 +2544,10 @@
if opts.get('print0'):
sep = eol = '\0'
+ if not opts.get('rev') and not diff:
+ opts['rev'] = ["wdir()"]
+ opts['allfiles'] = True
+
getfile = util.lrucachefunc(repo.file)
def matchlines(body):
To: sangeet259, #hg-reviewers
Cc: yuja, mercurial-devel
More information about the Mercurial-devel
mailing list