formatter: rename {abspath}/{file} to {path}, and drop relative {path} (BC)
Note that {path} in status is either relative-to-cwd or repository-absolute
depending on the command argument and config knob, which can't be reproduced
by using the {path|relpath} filter. The default template is updated to always
use a relative path.
.. bc::
``{abspath}`` and ``{file}`` in generic templates are renamed to ``{path}``.
Any ``{path}`` is a repository-absolute path. Use ``{path|relpath}`` to
convert it to a filesystem path.
--- a/hgext/keyword.py Sun Aug 05 16:27:09 2018 +0900
+++ b/hgext/keyword.py Sun Aug 05 16:44:16 2018 +0900
@@ -576,8 +576,8 @@
label = 'kwfiles.' + kwstate
for f in filenames:
fm.startitem()
- fm.write('kwstatus path', fmt, char,
- repo.pathto(f, cwd), label=label)
+ fm.data(kwstatus=char, path=f)
+ fm.plain(fmt % (char, repo.pathto(f, cwd)), label=label)
fm.end()
@command('kwshrink',
--- a/mercurial/cmdutil.py Sun Aug 05 16:27:09 2018 +0900
+++ b/mercurial/cmdutil.py Sun Aug 05 16:44:16 2018 +0900
@@ -2176,8 +2176,8 @@
if needsfctx:
fc = ctx[f]
fm.write('size flags', '% 10d % 1s ', fc.size(), fc.flags())
- fm.data(abspath=f)
- fm.write('path', fmt, m.rel(f))
+ fm.data(path=f)
+ fm.plain(fmt % m.rel(f))
ret = 0
for subpath in sorted(ctx.substate):
@@ -2323,7 +2323,7 @@
fm.startitem()
fm.context(ctx=ctx)
fm.write('data', '%s', data)
- fm.data(abspath=path, path=matcher.rel(path))
+ fm.data(path=path)
def cat(ui, repo, ctx, matcher, basefm, fntemplate, prefix, **opts):
err = 1
--- a/mercurial/commands.py Sun Aug 05 16:27:09 2018 +0900
+++ b/mercurial/commands.py Sun Aug 05 16:44:16 2018 +0900
@@ -337,10 +337,10 @@
('rev', ' ', lambda x: x.fctx.rev(), formatrev),
('node', ' ', lambda x: hexfn(x.fctx.node()), formathex),
('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)),
- ('file', ' ', lambda x: x.fctx.path(), pycompat.bytestr),
+ ('path', ' ', lambda x: x.fctx.path(), pycompat.bytestr),
('line_number', ':', lambda x: x.lineno, pycompat.bytestr),
]
- opnamemap = {'rev': 'number', 'node': 'changeset'}
+ opnamemap = {'rev': 'number', 'node': 'changeset', 'path': 'file'}
if (not opts.get('user') and not opts.get('changeset')
and not opts.get('date') and not opts.get('file')):
@@ -380,7 +380,7 @@
for abs in ctx.walk(m):
fctx = ctx[abs]
rootfm.startitem()
- rootfm.data(abspath=abs, path=m.rel(abs))
+ rootfm.data(path=abs)
if not opts.get('text') and fctx.isbinary():
rootfm.plain(_("%s: binary file\n")
% ((pats and m.rel(abs)) or abs))
@@ -2660,7 +2660,7 @@
except error.WdirUnsupported:
return ctx[fn].isbinary()
- fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'}
+ fieldnamemap = {'filename': 'path', 'linenumber': 'line_number'}
if diff:
iter = difflinestates(pstates, states)
else:
@@ -5187,10 +5187,12 @@
for f in files:
fm.startitem()
fm.context(ctx=ctx2)
+ fm.data(path=f)
fm.condwrite(showchar, 'status', '%s ', char, label=label)
- fm.write('path', fmt, repo.pathto(f, cwd), label=label)
+ fm.plain(fmt % repo.pathto(f, cwd), label=label)
if f in copy:
- fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd),
+ fm.data(copy=copy[f])
+ fm.plain((' %s' + end) % repo.pathto(copy[f], cwd),
label='status.copied')
if ((ui.verbose or ui.configbool('commands', 'status.verbose'))
--- a/mercurial/templates/map-cmdline.default Sun Aug 05 16:27:09 2018 +0900
+++ b/mercurial/templates/map-cmdline.default Sun Aug 05 16:44:16 2018 +0900
@@ -74,7 +74,7 @@
{label('ui.note log.description',
'{desc|strip}')}\n\n")}'
-status = '{status} {path}\n{if(copy, " {copy}\n")}'
+status = '{status} {path|relpath}\n{if(copy, " {copy|relpath}\n")}'
# Obsfate templates, it would be removed once we introduce the obsfate
# template fragment
--- a/tests/test-annotate.t Sun Aug 05 16:27:09 2018 +0900
+++ b/tests/test-annotate.t Sun Aug 05 16:44:16 2018 +0900
@@ -56,7 +56,6 @@
$ hg annotate -Tjson a
[
{
- "abspath": "a",
"lines": [{"line": "a\n", "rev": 0}],
"path": "a"
}
@@ -65,8 +64,7 @@
$ hg annotate -Tjson -cdfnul a
[
{
- "abspath": "a",
- "lines": [{"date": [1.0, 0], "file": "a", "line": "a\n", "line_number": 1, "node": "8435f90966e442695d2ded29fdade2bac5ad8065", "rev": 0, "user": "nobody"}],
+ "lines": [{"date": [1.0, 0], "line": "a\n", "line_number": 1, "node": "8435f90966e442695d2ded29fdade2bac5ad8065", "path": "a", "rev": 0, "user": "nobody"}],
"path": "a"
}
]
@@ -127,12 +125,10 @@
$ hg annotate -Tjson a b
[
{
- "abspath": "a",
"lines": [{"line": "a\n", "rev": 0}, {"line": "a\n", "rev": 1}, {"line": "a\n", "rev": 1}],
"path": "a"
},
{
- "abspath": "b",
"lines": [{"line": "a\n", "rev": 0}, {"line": "a\n", "rev": 1}, {"line": "a\n", "rev": 1}, {"line": "b4\n", "rev": 3}, {"line": "b5\n", "rev": 3}, {"line": "b6\n", "rev": 3}],
"path": "b"
}
@@ -140,7 +136,7 @@
annotate multiple files (template)
- $ hg annotate -T'== {abspath} ==\n{lines % "{rev}: {line}"}' a b
+ $ hg annotate -T'== {path} ==\n{lines % "{rev}: {line}"}' a b
== a ==
0: a
1: a
@@ -568,7 +564,6 @@
$ hg annotate -ncr "wdir()" -Tjson foo
[
{
- "abspath": "foo",
"lines": [{"line": "foo\n", "node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11}, {"line": "foofoo\n", "node": null, "rev": null}],
"path": "foo"
}
@@ -870,11 +865,9 @@
$ hg annotate -Tjson binary empty
[
{
- "abspath": "binary",
"path": "binary"
},
{
- "abspath": "empty",
"lines": [],
"path": "empty"
}
--- a/tests/test-cat.t Sun Aug 05 16:27:09 2018 +0900
+++ b/tests/test-cat.t Sun Aug 05 16:44:16 2018 +0900
@@ -65,7 +65,7 @@
Test template output
- $ hg --cwd tmp cat ../b ../c -T '== {path} ({abspath}) r{rev} ==\n{data}'
+ $ hg --cwd tmp cat ../b ../c -T '== {path|relpath} ({path}) r{rev} ==\n{data}'
== ../b (b) r2 ==
1
== ../c (c) r2 ==
@@ -74,12 +74,10 @@
$ hg cat b c -Tjson --output -
[
{
- "abspath": "b",
"data": "1\n",
"path": "b"
},
{
- "abspath": "c",
"data": "3\n",
"path": "c"
}
@@ -89,7 +87,6 @@
$ cat tmp/b.json
[
{
- "abspath": "b",
"data": "1\n",
"path": "b"
}
@@ -97,7 +94,6 @@
$ cat tmp/c.json
[
{
- "abspath": "c",
"data": "3\n",
"path": "c"
}
--- a/tests/test-fastannotate-hg.t Sun Aug 05 16:27:09 2018 +0900
+++ b/tests/test-fastannotate-hg.t Sun Aug 05 16:44:16 2018 +0900
@@ -69,7 +69,6 @@
$ hg annotate -Tjson a
[
{
- "abspath": "a",
"lines": [{"line": "a\n", "rev": 0}],
"path": "a"
}
@@ -78,8 +77,7 @@
$ hg annotate -Tjson -cdfnul a
[
{
- "abspath": "a",
- "lines": [{"date": [1.0, 0], "file": "a", "line": "a\n", "line_number": 1, "node": "8435f90966e442695d2ded29fdade2bac5ad8065", "rev": 0, "user": "nobody"}],
+ "lines": [{"date": [1.0, 0], "line": "a\n", "line_number": 1, "node": "8435f90966e442695d2ded29fdade2bac5ad8065", "path": "a", "rev": 0, "user": "nobody"}],
"path": "a"
}
]
@@ -571,7 +569,6 @@
$ hg annotate -ncr "wdir()" -Tjson foo
[
{
- "abspath": "foo",
"lines": [{"line": "foo\n", "node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11}, {"line": "foofoo\n", "node": null, "rev": null}],
"path": "foo"
}
--- a/tests/test-grep.t Sun Aug 05 16:27:09 2018 +0900
+++ b/tests/test-grep.t Sun Aug 05 16:44:16 2018 +0900
@@ -43,17 +43,17 @@
simple templated
$ hg grep port -r tip:0 \
- > -T '{file}:{rev}:{node|short}:{texts % "{if(matched, text|upper, text)}"}\n'
+ > -T '{path}:{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 -r tip:0 -T '{file}:{rev}:{texts}\n'
+ $ hg grep port -r tip:0 -T '{path}:{rev}:{texts}\n'
port:4:export
port:4:vaportight
port:4:import/export
- $ hg grep port -r tip:0 -T '{file}:{tags}:{texts}\n'
+ $ hg grep port -r tip:0 -T '{path}:{tags}:{texts}\n'
port:tip:export
port:tip:vaportight
port:tip:import/export
@@ -64,27 +64,27 @@
[
{
"date": [4, 0],
- "file": "port",
"line_number": 1,
"node": "914fa752cdea87777ac1a8d5c858b0c736218f6c",
+ "path": "port",
"rev": 4,
"texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}],
"user": "spam"
},
{
"date": [4, 0],
- "file": "port",
"line_number": 2,
"node": "914fa752cdea87777ac1a8d5c858b0c736218f6c",
+ "path": "port",
"rev": 4,
"texts": [{"matched": false, "text": "va"}, {"matched": true, "text": "port"}, {"matched": false, "text": "ight"}],
"user": "spam"
},
{
"date": [4, 0],
- "file": "port",
"line_number": 3,
"node": "914fa752cdea87777ac1a8d5c858b0c736218f6c",
+ "path": "port",
"rev": 4,
"texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}],
"user": "spam"
@@ -97,9 +97,9 @@
[
{
"date": [4, 0],
- "file": "port",
"line_number": 1,
"node": "914fa752cdea87777ac1a8d5c858b0c736218f6c",
+ "path": "port",
"rev": 4,
"user": "spam"
}
@@ -125,9 +125,9 @@
{
"change": "-",
"date": [4, 0],
- "file": "port",
"line_number": 4,
"node": "914fa752cdea87777ac1a8d5c858b0c736218f6c",
+ "path": "port",
"rev": 4,
"texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}],
"user": "spam"
@@ -135,9 +135,9 @@
{
"change": "+",
"date": [3, 0],
- "file": "port",
"line_number": 4,
"node": "95040cfd017d658c536071c6290230a613c4c2a6",
+ "path": "port",
"rev": 3,
"texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}],
"user": "eggs"
@@ -145,9 +145,9 @@
{
"change": "-",
"date": [2, 0],
- "file": "port",
"line_number": 1,
"node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
+ "path": "port",
"rev": 2,
"texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}],
"user": "spam"
@@ -155,9 +155,9 @@
{
"change": "-",
"date": [2, 0],
- "file": "port",
"line_number": 2,
"node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
+ "path": "port",
"rev": 2,
"texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}],
"user": "spam"
@@ -165,9 +165,9 @@
{
"change": "+",
"date": [2, 0],
- "file": "port",
"line_number": 1,
"node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
+ "path": "port",
"rev": 2,
"texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}],
"user": "spam"
@@ -175,9 +175,9 @@
{
"change": "+",
"date": [2, 0],
- "file": "port",
"line_number": 2,
"node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
+ "path": "port",
"rev": 2,
"texts": [{"matched": false, "text": "va"}, {"matched": true, "text": "port"}, {"matched": false, "text": "ight"}],
"user": "spam"
@@ -185,9 +185,9 @@
{
"change": "+",
"date": [2, 0],
- "file": "port",
"line_number": 3,
"node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
+ "path": "port",
"rev": 2,
"texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}],
"user": "spam"
@@ -195,9 +195,9 @@
{
"change": "+",
"date": [1, 0],
- "file": "port",
"line_number": 2,
"node": "8b20f75c158513ff5ac80bd0e5219bfb6f0eb587",
+ "path": "port",
"rev": 1,
"texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}],
"user": "eggs"
@@ -205,9 +205,9 @@
{
"change": "+",
"date": [0, 0],
- "file": "port",
"line_number": 1,
"node": "f31323c9217050ba245ee8b537c713ec2e8ab226",
+ "path": "port",
"rev": 0,
"texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}],
"user": "spam"
@@ -481,9 +481,9 @@
[
{
"date": [0, 0],
- "file": "file2",
"line_number": 1,
"node": "ffffffffffffffffffffffffffffffffffffffff",
+ "path": "file2",
"rev": 2147483647,
"texts": [{"matched": true, "text": "some"}, {"matched": false, "text": " text"}],
"user": "test"
--- a/tests/test-locate.t Sun Aug 05 16:27:09 2018 +0900
+++ b/tests/test-locate.t Sun Aug 05 16:44:16 2018 +0900
@@ -158,7 +158,7 @@
Convert native path separator to slash (issue5572)
- $ hg files -T '{path|slashpath}\n'
+ $ hg files -T '{path|relpath|slashpath}\n'
../b
../dir.h/foo
../t.h
--- a/tests/test-subrepo.t Sun Aug 05 16:27:09 2018 +0900
+++ b/tests/test-subrepo.t Sun Aug 05 16:44:16 2018 +0900
@@ -1066,19 +1066,18 @@
$ hg cat sub/repo/foo -Tjson | sed 's|\\\\|/|g'
[
{
- "abspath": "foo",
"data": "test\ntest\n",
- "path": "sub/repo/foo"
+ "path": "foo"
}
]
non-exact match:
- $ hg cat -T '{path}\n' 'glob:**'
+ $ hg cat -T '{path|relpath}\n' 'glob:**'
.hgsub
.hgsubstate
sub/repo/foo
- $ hg cat -T '{path}\n' 're:^sub'
+ $ hg cat -T '{path|relpath}\n' 're:^sub'
sub/repo/foo
missing subrepos in working directory: