mercurial/help/templates.txt
author Gregory Szorc <gregory.szorc@gmail.com>
Mon, 22 Aug 2016 21:48:50 -0700
changeset 29830 92ac2baaea86
parent 29717 a12d13eac513
child 30008 e83f89d3b1f7
permissions -rw-r--r--
revlog: use an LRU cache for delta chain bases Profiling using statprof revealed a hotspot during changegroup application calculating delta chain bases on generaldelta repos. Essentially, revlog._addrevision() was performing a lot of redundant work tracing the delta chain as part of determining when the chain distance was acceptable. This was most pronounced when adding revisions to manifests, which can have delta chains thousands of revisions long. There was a delta chain base cache on revlogs before, but it only captured a single revision. This was acceptable before generaldelta, when _addrevision would build deltas from the previous revision and thus we'd pretty much guarantee a cache hit when resolving the delta chain base on a subsequent _addrevision call. However, it isn't suitable for generaldelta because parent revisions aren't necessarily the last processed revision. This patch converts the delta chain base cache to an LRU dict cache. The cache can hold multiple entries, so generaldelta repos have a higher chance of getting a cache hit. The impact of this change when processing changegroup additions is significant. On a generaldelta conversion of the "mozilla-unified" repo (which contains heads of the main Firefox repositories in chronological order - this means there are lots of transitions between heads in revlog order), this change has the following impact when performing an `hg unbundle` of an uncompressed bundle of the repo: before: 5:42 CPU time after: 4:34 CPU time Most of this time is saved when applying the changelog and manifest revlogs: before: 2:30 CPU time after: 1:17 CPU time That nearly a 50% reduction in CPU time applying changesets and manifests! Applying a gzipped bundle of the same repo (effectively simulating a `hg clone` over HTTP) showed a similar speedup: before: 5:53 CPU time after: 4:46 CPU time Wall time improvements were basically the same as CPU time. I didn't measure explicitly, but it feels like most of the time is saved when processing manifests. This makes sense, as large manifests tend to have very long delta chains and thus benefit the most from this cache. So, this change effectively makes changegroup application (which is used by `hg unbundle`, `hg clone`, `hg pull`, `hg unshelve`, and various other commands) significantly faster when delta chains are long (which can happen on repos with large numbers of files and thus large manifests). In theory, this change can result in more memory utilization. However, we're caching a dict of ints. At most we have 200 ints + Python object overhead per revlog. And, the cache is really only populated when performing read-heavy operations, such as adding changegroups or scanning an individual revlog. For memory bloat to be an issue, we'd need to scan/read several revisions from several revlogs all while having active references to several revlogs. I don't think there are many operations that do this, so I don't think memory bloat from the cache will be an issue.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
     1
Mercurial allows you to customize output of commands through
21943
8534e670f4ee help: use --template to specify existing style
Yuya Nishihara <yuya@tcha.org>
parents: 21846
diff changeset
     2
templates. You can either pass in a template or select an existing
8534e670f4ee help: use --template to specify existing style
Yuya Nishihara <yuya@tcha.org>
parents: 21846
diff changeset
     3
template-style from the command line, via the --template option.
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
     4
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
     5
You can customize output for any "log-like" command: log,
21945
d603e7333281 help: drop reference to glog in templates topic
Matt Mackall <mpm@selenic.com>
parents: 21943
diff changeset
     6
outgoing, incoming, tip, parents, and heads.
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
     7
21946
868e2cea3ea0 help: mention '-T list' in templater topic
Matt Mackall <mpm@selenic.com>
parents: 21945
diff changeset
     8
Some built-in styles are packaged with Mercurial. These can be listed
868e2cea3ea0 help: mention '-T list' in templater topic
Matt Mackall <mpm@selenic.com>
parents: 21945
diff changeset
     9
with :hg:`log --template list`. Example usage::
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
    10
21946
868e2cea3ea0 help: mention '-T list' in templater topic
Matt Mackall <mpm@selenic.com>
parents: 21945
diff changeset
    11
    $ hg log -r1.0::1.1 --template changelog
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
    12
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    13
A template is a piece of text, with markup to invoke variable
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    14
expansion::
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
    15
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    16
    $ hg log -r1 --template "{node}\n"
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    17
    b56ce7b07c52de7d5fd79fb89701ea538af65746
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
    18
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    19
Strings in curly braces are called keywords. The availability of
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    20
keywords depends on the exact context of the templater. These
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    21
keywords are usually available for templating a log-like command:
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
    22
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13498
diff changeset
    23
.. keywordsmarker
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
    24
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    25
The "date" keyword does not produce human-readable output. If you
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    26
want to use a date in your output, you can use a filter to process
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    27
it. Filters are functions which return a string based on the input
10759
9f6e30a89f11 help: point out need for stringification
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10066
diff changeset
    28
variable. Be sure to use the stringify filter first when you're
9f6e30a89f11 help: point out need for stringification
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10066
diff changeset
    29
applying a string-input filter to a list-like input variable.
9f6e30a89f11 help: point out need for stringification
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 10066
diff changeset
    30
You can also use a chain of filters to get the desired output::
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
    31
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    32
   $ hg tip --template "{date|isodate}\n"
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    33
   2008-08-21 18:22 +0000
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
    34
9540
cad36e496640 help: un-indent help topics
Martin Geisler <mg@lazybytes.net>
parents: 9539
diff changeset
    35
List of filters:
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
    36
13591
264f292a0c6f templatefilters: move doc from templates.txt to docstrings
Patrick Mezard <pmezard@gmail.com>
parents: 13585
diff changeset
    37
.. filtersmarker
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    38
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    39
Note that a filter is nothing more than a function call, i.e.
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    40
``expr|filter`` is equivalent to ``filter(expr)``.
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    41
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    42
In addition to filters, there are some basic built-in functions:
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    43
24587
76c0b4cfa039 help: populate template functions via docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22434
diff changeset
    44
.. functionsmarker
21846
8f23f8096606 templater: introduce word function
Ryan McElroy <rmcelroy@fb.com>
parents: 21821
diff changeset
    45
28040
6db47740e681 help: update template examples to use reST literal syntax
Yuya Nishihara <yuya@tcha.org>
parents: 26485
diff changeset
    46
Also, for any expression that returns a list, there is a list operator::
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    47
28040
6db47740e681 help: update template examples to use reST literal syntax
Yuya Nishihara <yuya@tcha.org>
parents: 26485
diff changeset
    48
    expr % "{template}"
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    49
28040
6db47740e681 help: update template examples to use reST literal syntax
Yuya Nishihara <yuya@tcha.org>
parents: 26485
diff changeset
    50
As seen in the above example, ``{template}`` is interpreted as a template.
6db47740e681 help: update template examples to use reST literal syntax
Yuya Nishihara <yuya@tcha.org>
parents: 26485
diff changeset
    51
To prevent it from being interpreted, you can use an escape character ``\{``
6db47740e681 help: update template examples to use reST literal syntax
Yuya Nishihara <yuya@tcha.org>
parents: 26485
diff changeset
    52
or a raw string prefix, ``r'...'``.
25596
c1975809a6b5 templater: take any string literals as template, but not for rawstring (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 25348
diff changeset
    53
28957
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    54
New keywords and functions can be defined in the ``templatealias`` section of
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    55
a Mercurial configuration file::
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    56
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    57
  <alias> = <definition>
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    58
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    59
Arguments of the form `a1`, `a2`, etc. are substituted from the alias into
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    60
the definition.
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    61
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    62
For example,
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    63
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    64
::
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    65
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    66
  [templatealias]
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    67
  r = rev
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    68
  rn = "{r}:{node|short}"
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    69
  leftpad(s, w) = pad(s, w, ' ', True)
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    70
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    71
defines two symbol aliases, ``r`` and ``rn``, and a function alias
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    72
``leftpad()``.
d813132ea361 templater: load and expand aliases by template engine (API) (issue4842)
Yuya Nishihara <yuya@tcha.org>
parents: 28040
diff changeset
    73
29717
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    74
It's also possible to specify complete template strings, using the
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    75
``templates`` section. The syntax used is the general template string syntax.
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    76
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    77
For example,
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    78
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    79
::
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    80
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    81
  [templates]
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    82
  nodedate = "{node|short}: {date(date, "%Y-%m-%d")}\n"
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    83
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    84
defines a template, ``nodedate``, which can be called like::
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    85
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    86
  $ hg log -r . -Tnodedate
a12d13eac513 help: add example of '[templates]' usage
Mathias De Maré <mathias.demare@gmail.com>
parents: 29085
diff changeset
    87
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    88
Some sample command line templates:
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    89
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    90
- Format lists, e.g. files::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    91
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    92
   $ hg log -r 0 --template "files:\n{files % '  {file}\n'}"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    93
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    94
- Join the list of files with a ", "::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    95
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    96
   $ hg log -r 0 --template "files: {join(files, ', ')}\n"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
    97
29085
df838803c1d4 templater: add separate() template function
Martin von Zweigbergk <martinvonz@google.com>
parents: 28957
diff changeset
    98
- Separate non-empty arguments by a " "::
df838803c1d4 templater: add separate() template function
Martin von Zweigbergk <martinvonz@google.com>
parents: 28957
diff changeset
    99
df838803c1d4 templater: add separate() template function
Martin von Zweigbergk <martinvonz@google.com>
parents: 28957
diff changeset
   100
   $ hg log -r 0 --template "{separate(' ', node, bookmarks, tags}\n"
df838803c1d4 templater: add separate() template function
Martin von Zweigbergk <martinvonz@google.com>
parents: 28957
diff changeset
   101
21820
cce404b0c918 templatefilter: add splitlines function
Ryan McElroy <rmcelroy@fb.com>
parents: 20531
diff changeset
   102
- Modify each line of a commit description::
cce404b0c918 templatefilter: add splitlines function
Ryan McElroy <rmcelroy@fb.com>
parents: 20531
diff changeset
   103
cce404b0c918 templatefilter: add splitlines function
Ryan McElroy <rmcelroy@fb.com>
parents: 20531
diff changeset
   104
   $ hg log --template "{splitlines(desc) % '**** {line}\n'}"
cce404b0c918 templatefilter: add splitlines function
Ryan McElroy <rmcelroy@fb.com>
parents: 20531
diff changeset
   105
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   106
- Format date::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   107
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   108
   $ hg log -r 0 --template "{date(date, '%Y')}\n"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   109
26128
51f6940d3b4f templater: add optional timezone argument to localdate()
Yuya Nishihara <yuya@tcha.org>
parents: 25786
diff changeset
   110
- Display date in UTC::
51f6940d3b4f templater: add optional timezone argument to localdate()
Yuya Nishihara <yuya@tcha.org>
parents: 25786
diff changeset
   111
51f6940d3b4f templater: add optional timezone argument to localdate()
Yuya Nishihara <yuya@tcha.org>
parents: 25786
diff changeset
   112
   $ hg log -r 0 --template "{localdate(date, 'UTC')|date}\n"
51f6940d3b4f templater: add optional timezone argument to localdate()
Yuya Nishihara <yuya@tcha.org>
parents: 25786
diff changeset
   113
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   114
- Output the description set to a fill-width of 30::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   115
25004
e264d4c9629b help: rewrite template examples to use integer literals where appropriate
Yuya Nishihara <yuya@tcha.org>
parents: 24587
diff changeset
   116
   $ hg log -r 0 --template "{fill(desc, 30)}"
18465
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   117
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   118
- Use a conditional to test for the default branch::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   119
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   120
   $ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch',
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   121
   'on branch {branch}')}\n"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   122
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   123
- Append a newline if not empty::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   124
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   125
   $ hg tip --template "{if(author, '{author}\n')}"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   126
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   127
- Label the output for use with the color extension::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   128
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   129
   $ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n"
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   130
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   131
- Invert the firstline filter, i.e. everything but the first line::
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   132
3aa8b4b36b64 help: add documentation for new template functions
Sean Farley <sean.michael.farley@gmail.com>
parents: 13591
diff changeset
   133
   $ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n"
20016
f4b3bdc3019e help: adding example 'extras' printing to 'hg help templates'
Matthew Turk <matthewturk@gmail.com>
parents: 19390
diff changeset
   134
f4b3bdc3019e help: adding example 'extras' printing to 'hg help templates'
Matthew Turk <matthewturk@gmail.com>
parents: 19390
diff changeset
   135
- Display the contents of the 'extra' field, one per line::
f4b3bdc3019e help: adding example 'extras' printing to 'hg help templates'
Matthew Turk <matthewturk@gmail.com>
parents: 19390
diff changeset
   136
20170
574f3b6e0e8b help: fix formatting of template example
Steve Hoelzer <shoelzer@gmail.com>
parents: 20016
diff changeset
   137
   $ hg log -r 0 --template "{join(extras, '\n')}\n"
20531
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
   138
25348
f26efa4f0eff templatekw: introduce active subkeyword from bookmarks keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25004
diff changeset
   139
- Mark the active bookmark with '*'::
20531
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
   140
25786
35fa7c77c754 help: rewrite template examples to not use shell escaping
Yuya Nishihara <yuya@tcha.org>
parents: 25596
diff changeset
   141
   $ hg log --template "{bookmarks % '{bookmark}{ifeq(bookmark, active, '*')} '}\n"
20531
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
   142
26485
43bf9471fae9 templater: introduce {latesttag()} function to match a pattern (issue4184)
Matt Harbison <matt_harbison@yahoo.com>
parents: 26234
diff changeset
   143
- Find the previous release candidate tag, the distance and changes since the tag::
43bf9471fae9 templater: introduce {latesttag()} function to match a pattern (issue4184)
Matt Harbison <matt_harbison@yahoo.com>
parents: 26234
diff changeset
   144
43bf9471fae9 templater: introduce {latesttag()} function to match a pattern (issue4184)
Matt Harbison <matt_harbison@yahoo.com>
parents: 26234
diff changeset
   145
   $ hg log -r . --template "{latesttag('re:^.*-rc$') % '{tag}, {changes}, {distance}'}\n"
43bf9471fae9 templater: introduce {latesttag()} function to match a pattern (issue4184)
Matt Harbison <matt_harbison@yahoo.com>
parents: 26234
diff changeset
   146
20531
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
   147
- Mark the working copy parent with '@'::
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
   148
01a75c9d5b5e help: add ifcontains, revset, and shortest to template help
Durham Goode <durham@fb.com>
parents: 20170
diff changeset
   149
   $ hg log --template "{ifcontains(rev, revset('.'), '@')}\n"
21821
4a445dc5abff templater: introduce startswith function
Ryan McElroy <rmcelroy@fb.com>
parents: 21820
diff changeset
   150
26234
e4609ec959f8 templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 26128
diff changeset
   151
- Show details of parent revisions::
e4609ec959f8 templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 26128
diff changeset
   152
e4609ec959f8 templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 26128
diff changeset
   153
   $ hg log --template "{revset('parents(%d)', rev) % '{desc|firstline}\n'}"
e4609ec959f8 templater: switch ctx of list expression to rev of revset() (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 26128
diff changeset
   154
21821
4a445dc5abff templater: introduce startswith function
Ryan McElroy <rmcelroy@fb.com>
parents: 21820
diff changeset
   155
- Show only commit descriptions that start with "template"::
4a445dc5abff templater: introduce startswith function
Ryan McElroy <rmcelroy@fb.com>
parents: 21820
diff changeset
   156
25786
35fa7c77c754 help: rewrite template examples to not use shell escaping
Yuya Nishihara <yuya@tcha.org>
parents: 25596
diff changeset
   157
   $ hg log --template "{startswith('template', firstline(desc))}\n"
21846
8f23f8096606 templater: introduce word function
Ryan McElroy <rmcelroy@fb.com>
parents: 21821
diff changeset
   158
8f23f8096606 templater: introduce word function
Ryan McElroy <rmcelroy@fb.com>
parents: 21821
diff changeset
   159
- Print the first word of each line of a commit message::
8f23f8096606 templater: introduce word function
Ryan McElroy <rmcelroy@fb.com>
parents: 21821
diff changeset
   160
25004
e264d4c9629b help: rewrite template examples to use integer literals where appropriate
Yuya Nishihara <yuya@tcha.org>
parents: 24587
diff changeset
   161
   $ hg log --template "{word(0, desc)}\n"