First pieces of generic templating support
Matt Mackall
mpm at selenic.com
Mon Feb 20 22:59:58 UTC 2012
So I've set a goal of adding "generic templating", which means:
- it should be possible to use templating for all commands
- there should be some built-in styles like JSON, XML, and pickle
- it should be relatively painless to convert existing code
- performance impact should be minimal when not in use
At this point I've introduced the basic interface, added a simple debug
mode, and converted the status command. So we can now get output like
this:
$ hg st --config ui.formatdebug=1
status = {
{'status': '?', 'char': 'branches.txt'},
{'status': '?', 'char': 'hgext/clonecache.py'},
{'status': '?', 'char': 'idcheck'},
{'status': '?', 'char': 'p'},
{'status': '?', 'char': 'status-daemon.txt'},
}
To get an idea of what's involved in adding templating support, see:
http://www.selenic.com/hg/rev/68007f0557de
The most important piece is:
- ui.write(format % repo.pathto(f, cwd),
- label='status.' + state)
+ fm.startitem()
+ fm.write("status char", format, char,
+ repo.pathto(f, cwd), label=label)
Basically, we've taken the old ui.write and replaced it with an fm.write
that gives each field a name. When no templating is happening, this
falls through to a normal ui.write. But when a templater is in use, we
ignore the format string and build data to pass to the templater.
Future steps:
- add support for hgweb-style templater
- add JSON/XML/etc templaters
- figure out a scheme for per-command --styles
- add global options --template and --style
- convert all the commands
Help wanted!
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list