grep: respect ui.relative-paths
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 30 Jan 2019 17:05:09 -0800
changeset 41513 718e9b444d97
parent 41512 16454d938299
child 41514 888e8b36b8d9
grep: respect ui.relative-paths Differential Revision: https://phab.mercurial-scm.org/D5777
mercurial/commands.py
tests/test-grep.t
--- a/mercurial/commands.py	Wed Jan 30 16:59:31 2019 -0800
+++ b/mercurial/commands.py	Wed Jan 30 17:05:09 2019 -0800
@@ -2848,6 +2848,7 @@
                 for i in pycompat.xrange(blo, bhi):
                     yield ('+', b[i])
 
+    uipathfn = scmutil.getuipathfn(repo)
     def display(fm, fn, ctx, pstates, states):
         rev = scmutil.intrev(ctx)
         if fm.isplain():
@@ -2875,8 +2876,8 @@
         for change, l in iter:
             fm.startitem()
             fm.context(ctx=ctx)
-            fm.data(node=fm.hexfunc(scmutil.binnode(ctx)))
-            fm.write('path', '%s', fn, label='grep.filename')
+            fm.data(node=fm.hexfunc(scmutil.binnode(ctx)), path=fn)
+            fm.plain(uipathfn(fn), label='grep.filename')
 
             cols = [
                 ('rev', '%d', rev, not plaingrep),
--- a/tests/test-grep.t	Wed Jan 30 16:59:31 2019 -0800
+++ b/tests/test-grep.t	Wed Jan 30 17:05:09 2019 -0800
@@ -32,6 +32,20 @@
   port:4:vaportight
   port:4:import/export
 
+simple from subdirectory
+
+  $ mkdir dir
+  $ cd dir
+  $ hg grep -r tip:0 port
+  port:4:export
+  port:4:vaportight
+  port:4:import/export
+  $ hg grep -r tip:0 port --config ui.relative-paths=yes
+  ../port:4:export
+  ../port:4:vaportight
+  ../port:4:import/export
+  $ cd ..
+
 simple with color
 
   $ hg --config extensions.color= grep --config color.mode=ansi \