Patchwork grep: hide cryptic revision number by default

login
register
mail settings
Submitter Yuya Nishihara
Date July 10, 2018, 3:03 p.m.
Message ID <24f62ea74586f554c3d7.1531234986@mimosa>
Download mbox | patch
Permalink /patch/32757/
State New
Headers show

Comments

Yuya Nishihara - July 10, 2018, 3:03 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.
Yuya Nishihara - July 11, 2018, 11:55 a.m.
On Wed, 11 Jul 2018 00:03:06 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@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

Please disregard this patch. I'll rework on it to fix python-hglib breakage.

Patch

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 ..