New templater features: if/ifeq, join, sub, date, fill
Matt Mackall
mpm at selenic.com
Mon Sep 24 16:25:19 CDT 2012
I rewrote the templater a while back to allow the addition of a bunch of
new features, but got stalled on working around a quirk in the
command-line implementation of lists. Now I've worked around that issue
and added a bunch of new features.
First is the ability to specify templates for lists on the commandline
without creating a style file. For instance:
$ hg log -r 0 --template "files:\n{files % ' {file}\n'}"
files:
PKG-INFO
README
hg
mercurial/__init__.py
mercurial/byterange.py
mercurial/fancyopts.py
mercurial/hg.py
mercurial/mdiff.py
mercurial/revlog.py
mercurial/transaction.py
notes.txt
setup.py
tkmerge
We also have a join function, which is nice for lists:
$ hg log -r 0 --template "files: {join(files, ', ')}\n"
files: PKG-INFO, README, hg, mercurial/__init__.py,
mercurial/byterange.py, mercurial/fancyopts.py, mercurial/hg.py,
mercurial/mdiff.py, mercurial/revlog.py, mercurial/transaction.py,
notes.txt, setup.py, tkmerge
There's also a sub function, which supports regular expressions:
$ hg log -r 0 --template 'files: {sub("/", r"\\", files)}\n'
files: PKG-INFO README hg mercurial\__init__.py mercurial\byterange.py
mercurial\fancyopts.py mercurial\hg.py mercurial\mdiff.py mercurial
\revlog.py mercurial\transaction.py notes.txt setup.py tkmerge
We can now do some basic conditionals using if(test, then, else) or
ifeq(test, match, then, else):
$ hg log -r 0 --template '{ifeq(branch, "default", "on the main branch",
"on branch {branch}")}\n'
on the main branch
Lastly, I've parameterized a couple of the existing filters:
$ hg log -r 0 --template '{date(date, "%Y")}\n'
2005
$ hg log -r 0 --template '{fill(desc, "30")}'
Add back links from file
revisions to changeset
revisions Add simple
transaction support Add hg
verify Improve caching in
revlog Fix a bunch of bugs
Self-hosting now that the
metadata is close to finalized
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list