[PATCH] grep: hide cryptic revision number by default
Yuya Nishihara
yuya at tcha.org
Tue Jul 10 15:03:06 UTC 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1531230930 -32400
# Tue Jul 10 22:55:30 2018 +0900
# Node ID 24f62ea74586f554c3d7578f00df792e00b55094
# Parent 9ef10437bb88c27645796b95c6ab78e12c307117
grep: hide cryptic revision number by default
I believe nobody would want to see the "2147483647:" prefix while grepping
working directory files. It's still visible if "-r wdir()" is specified
since a revset may point to more than one revisions, and it seems confusing
to change the visibility based on the number of the matched revisions.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2545,7 +2545,8 @@ def grep(ui, repo, pattern, *pats, **opt
if opts.get('print0'):
sep = eol = '\0'
- if not opts.get('rev') and not diff:
+ plaingrep = not opts.get('rev') and not diff
+ if plaingrep:
opts['rev'] = ["wdir()"]
opts['allfiles'] = True
@@ -2644,7 +2645,7 @@ def grep(ui, repo, pattern, *pats, **opt
cols = [
('filename', fn, True),
- ('rev', rev, True),
+ ('rev', rev, not plaingrep),
('linenumber', l.linenum, opts.get('line_number')),
]
if diff:
diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -434,4 +434,17 @@ should not be grepp-ed on
$ hg commit -m "adds file1"
$ hg mv file1 file2
$ hg grep "some"
- file2:2147483647:some text
+ file2:some text
+ $ hg grep "some" -Tjson
+ [
+ {
+ "date": [0, 0],
+ "file": "file2",
+ "line_number": 1,
+ "node": "ffffffffffffffffffffffffffffffffffffffff",
+ "rev": 2147483647,
+ "texts": [{"matched": true, "text": "some"}, {"matched": false, "text": " text"}],
+ "user": "test"
+ }
+ ]
+ $ cd ..
More information about the Mercurial-devel
mailing list