Mercurial > hg
comparison mercurial/templates/map-cmdline.default @ 22766:0ded0f0b1c04
log: rewrite default template to use labels (issue2866)
This is a complete rewrite of the default template to use labels. This
seems ultimately useless to me in most cases. The biggest benefit of
this patch to me seems to be a fairly complicated example of the
templating engine. It was a lot of hard work to figure out the precise
acceptable syntax, since it's almost undocumented. Hat tip to Steve
Losh's smartlog template, which helped me figure out a lot of the
syntax. Hopefully later I can use the present default log template
as an example for documenting the templating engine.
A test is attached. My goal was to match the --color=debug output,
which may differ slightly in newlines from the actual ANSI escape
codes output. I consider this an acceptable invisible deviation.
There seems to be a considerable slowdown with this rewrite.
Before:
$ time hg log -T default -r .~100::. > /dev/null
real 0m0.882s
user 0m0.812s
sys 0m0.064s
$ time hg log -T default -r .~100::. > /dev/null
real 0m0.872s
user 0m0.796s
sys 0m0.068s
$ time hg log -T default -r .~100::. > /dev/null
real 0m0.917s
user 0m0.836s
sys 0m0.076s
After:
$ time hg log -T default -r .~100::. > /dev/null
real 0m1.480s
user 0m1.392s
sys 0m0.072s
$ time hg log -T default -r .~100::. > /dev/null
real 0m1.500s
user 0m1.400s
sys 0m0.088s
$ time hg log -T default -r .~100::. > /dev/null
real 0m1.462s
user 0m1.364s
sys 0m0.092s
Following the maxim, "make it work, profile, make it faster, in that
order", I deem this slowdown acceptable for now.
I suspect but have not confirmed that a big slowdown comes from
calling keywords twice in the file templates, once to test the
existence of output and again to actually list the output. If so, a
simple speedup might be to improve the templating engine to cache
keywords when called more than once on the same revision.
TODO: I found a bug while working on this. The following stack traces:
hg log -r . -T '{ifcontains(phase, "secret public", "lol", "omg")}\n'
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Fri, 03 Oct 2014 19:48:56 -0400 |
parents | 51fc43253a52 |
children | 6136704b975d |
comparison
equal
deleted
inserted
replaced
22765:55dcc7fb731c | 22766:0ded0f0b1c04 |
---|---|
1 changeset = 'changeset: {rev}:{node|short}\n{branches}{bookmarks}{tags}{parents}user: {author}\ndate: {date|date}\nsummary: {desc|firstline}\n\n' | 1 # Base templates. Due to name clashes with existing keywords, we have |
2 changeset_quiet = '{rev}:{node|short}\n' | 2 # to replace some keywords with 'lkeyword', for 'labelled keyword' |
3 changeset_verbose = 'changeset: {rev}:{node|short}\n{branches}{bookmarks}{tags}{parents}user: {author}\ndate: {date|date}\n{files}{file_copies_switch}description:\n{desc|strip}\n\n\n' | 3 changeset = '{cset}{branches}{bookmarks}{tags}{parents}{user}{ldate}{summary}\n' |
4 changeset_debug = 'changeset: {rev}:{node}\n{branches}{bookmarks}{tags}phase: {phase}\n{parents}{manifest}user: {author}\ndate: {date|date}\n{file_mods}{file_adds}{file_dels}{file_copies_switch}{extras}description:\n{desc|strip}\n\n\n' | 4 changeset_quiet = '{node}' |
5 start_files = 'files: ' | 5 changeset_verbose = '{cset}{branches}{bookmarks}{tags}{parents}{user}{ldate}{lfiles}{lfile_copies_switch}{description}\n' |
6 file = ' {file}' | 6 changeset_debug = '{fullcset}{branches}{bookmarks}{tags}{lphase}{parents}{manifest}{user}{ldate}{lfile_mods}{lfile_adds}{lfile_dels}{lfile_copies_switch}{extras}{description}\n' |
7 end_files = '\n' | 7 |
8 start_file_mods = 'files: ' | 8 # File templates |
9 file_mod = ' {file_mod}' | 9 lfiles = '{if(files, |
10 end_file_mods = '\n' | 10 label("ui.note log.files", |
11 start_file_adds = 'files+: ' | 11 "files: {files}\n"))}' |
12 file_add = ' {file_add}' | 12 |
13 end_file_adds = '\n' | 13 lfile_mods = '{if(file_mods, |
14 start_file_dels = 'files-: ' | 14 label("ui.debug log.files", |
15 file_del = ' {file_del}' | 15 "files: {file_mods}\n"))}' |
16 end_file_dels = '\n' | 16 |
17 start_file_copies = 'copies: ' | 17 lfile_adds = '{if(file_adds, |
18 file_copy = ' {name} ({source})' | 18 label("ui.debug log.files", |
19 end_file_copies = '\n' | 19 "files+: {file_adds}\n"))}' |
20 parent = 'parent: {rev}:{node|formatnode}\n' | 20 |
21 manifest = 'manifest: {rev}:{node}\n' | 21 lfile_dels = '{if(file_dels, |
22 branch = 'branch: {branch}\n' | 22 label("ui.debug log.files", |
23 tag = 'tag: {tag}\n' | 23 "files-: {file_dels}\n"))}' |
24 bookmark = 'bookmark: {bookmark}\n' | 24 |
25 extra = 'extra: {key}={value|stringescape}\n' | 25 lfile_copies_switch = '{if(file_copies_switch, |
26 label("ui.note log.copies", | |
27 "copies: {file_copies_switch | |
28 % ' {name} ({source})'}\n"))}' | |
29 | |
30 # General templates | |
31 cset = '{label("log.changeset changeset.{phase}", | |
32 "changeset: {rev}:{node|short}")}\n' | |
33 | |
34 lphase = '{label("log.phase", | |
35 "phase: {phase}")}\n' | |
36 | |
37 fullcset = '{label("log.changeset changeset.{phase}", | |
38 "changeset: {rev}:{node}")}\n' | |
39 | |
40 parent = '{label("log.parent changeset.{phase}", | |
41 "parent: {rev}:{node|formatnode}")}\n' | |
42 | |
43 node = '{label("log.node", | |
44 "{rev}:{node|short}")}\n' | |
45 | |
46 manifest = '{label("ui.debug log.manifest", | |
47 "manifest: {rev}:{node}")}\n' | |
48 | |
49 branch = '{label("log.branch", | |
50 "branch: {branch}")}\n' | |
51 | |
52 tag = '{label("log.tag", | |
53 "tag: {tag}")}\n' | |
54 | |
55 bookmark = '{label("log.bookmark", | |
56 "bookmark: {bookmark}")}\n' | |
57 | |
58 user = '{label("log.user", | |
59 "user: {author}")}\n' | |
60 | |
61 summary = '{label("log.summary", | |
62 "summary: {desc|firstline}")}\n' | |
63 | |
64 ldate = '{label("log.date", | |
65 "date: {date|date}")}\n' | |
66 | |
67 extra = '{label("ui.debug log.extra", | |
68 "extra: {key}={value|stringescape}")}\n' | |
69 | |
70 description = '{label("ui.note log.description", | |
71 "description:")} | |
72 {label("ui.note log.description", | |
73 "{desc|strip}")}\n\n' |