| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 6 |
<meta name="generator" content="Docutils 0.21.2: https://docutils.sourceforge.io/" /> |
| 7 |
<title>Template Usage</title> |
| 8 |
<link rel="stylesheet" href="../style.css" type="text/css" /> |
| 9 |
</head> |
| 10 |
<body> |
| 11 |
<div class="document" id="template-usage"> |
| 12 |
<span id="topic-templating"></span> |
| 13 |
<h1 class="title">Template Usage</h1> |
| 14 |
|
| 15 |
<div class="contents htmlonly topic" id="contents"> |
| 16 |
<p class="topic-title"><a class="reference internal" href="#top">Contents</a></p> |
| 17 |
<ul class="simple"> |
| 18 |
<li><a class="reference internal" href="#keywords" id="toc-entry-1">Keywords</a></li> |
| 19 |
<li><a class="reference internal" href="#filters" id="toc-entry-2">Filters</a></li> |
| 20 |
<li><a class="reference internal" href="#functions" id="toc-entry-3">Functions</a></li> |
| 21 |
<li><a class="reference internal" href="#operators" id="toc-entry-4">Operators</a></li> |
| 22 |
<li><a class="reference internal" href="#aliases" id="toc-entry-5">Aliases</a></li> |
| 23 |
<li><a class="reference internal" href="#examples" id="toc-entry-6">Examples</a></li> |
| 24 |
</ul> |
| 25 |
</div> |
| 26 |
<p id="style"><span id="template"></span><span id="templates"></span><span id="templating"></span>Mercurial allows you to customize output of commands through |
| 27 |
templates. You can either pass in a template or select an existing |
| 28 |
template-style from the command line, via the --template option.</p> |
| 29 |
<p>You can customize output for any "log-like" command: log, |
| 30 |
outgoing, incoming, tip, parents, and heads.</p> |
| 31 |
<p>Some built-in styles are packaged with Mercurial. These can be listed |
| 32 |
with <a class="reference external" href="hg-log.html"><tt class="docutils literal">hg log <span class="pre">--template</span> list</tt></a>. Example usage:</p> |
| 33 |
<pre class="literal-block"> |
| 34 |
$ hg log -r1.0::1.1 --template changelog |
| 35 |
</pre> |
| 36 |
<p>A template is a piece of text, with markup to invoke variable |
| 37 |
expansion:</p> |
| 38 |
<pre class="literal-block"> |
| 39 |
$ hg log -r1 --template "{node}\n" |
| 40 |
b56ce7b07c52de7d5fd79fb89701ea538af65746 |
| 41 |
</pre> |
| 42 |
<div class="section" id="keywords"> |
| 43 |
<h1><a class="toc-backref" href="#contents">Keywords</a></h1> |
| 44 |
<p>Strings in curly braces are called keywords. The availability of |
| 45 |
keywords depends on the exact context of the templater. These |
| 46 |
keywords are usually available for templating a log-like command:</p> |
| 47 |
<table class="docutils field-list" frame="void" rules="none"> |
| 48 |
<col class="field-name" /> |
| 49 |
<col class="field-body" /> |
| 50 |
<tbody valign="top"> |
| 51 |
<tr class="field"><th class="field-name">_fast_rank:</th><td class="field-body"><p class="first">the rank of a changeset if cached</p> |
| 52 |
<p>The rank of a revision is the size of the sub-graph it defines as a head. |
| 53 |
Equivalently, the rank of a revision <cite>r</cite> is the size of the set |
| 54 |
<cite>ancestors(r)</cite>, <cite>r</cite> included.</p> |
| 55 |
</td> |
| 56 |
</tr> |
| 57 |
<tr class="field"><th class="field-name">activebookmark:</th><td class="field-body"><p class="first">String. The active bookmark, if it is associated with the changeset.</p> |
| 58 |
</td> |
| 59 |
</tr> |
| 60 |
<tr class="field"><th class="field-name">author:</th><td class="field-body"><p class="first">Alias for <tt class="docutils literal">{user}</tt></p> |
| 61 |
</td> |
| 62 |
</tr> |
| 63 |
<tr class="field"><th class="field-name">bisect:</th><td class="field-body"><p class="first">String. The changeset bisection status.</p> |
| 64 |
</td> |
| 65 |
</tr> |
| 66 |
<tr class="field"><th class="field-name">bookmarks:</th><td class="field-body"><p class="first">List of strings. Any bookmarks associated with the |
| 67 |
changeset. Also sets 'active', the name of the active bookmark.</p> |
| 68 |
</td> |
| 69 |
</tr> |
| 70 |
<tr class="field"><th class="field-name">branch:</th><td class="field-body"><p class="first">String. The name of the branch on which the changeset was |
| 71 |
committed.</p> |
| 72 |
</td> |
| 73 |
</tr> |
| 74 |
<tr class="field"><th class="field-name" colspan="2">changessincelatesttag:</th></tr> |
| 75 |
<tr class="field"><td> </td><td class="field-body"><p class="first">Integer. All ancestors not in the latest tag.</p> |
| 76 |
</td> |
| 77 |
</tr> |
| 78 |
<tr class="field"><th class="field-name">children:</th><td class="field-body"><p class="first">List of strings. The children of the changeset.</p> |
| 79 |
</td> |
| 80 |
</tr> |
| 81 |
<tr class="field"><th class="field-name">closesbranch:</th><td class="field-body"><p class="first">"yes" if this changeset is branch-closing, "no" otherwise</p> |
| 82 |
</td> |
| 83 |
</tr> |
| 84 |
<tr class="field"><th class="field-name">date:</th><td class="field-body"><p class="first">Date information. The date when the changeset was committed.</p> |
| 85 |
</td> |
| 86 |
</tr> |
| 87 |
<tr class="field"><th class="field-name">desc:</th><td class="field-body"><p class="first">String. The text of the changeset description.</p> |
| 88 |
</td> |
| 89 |
</tr> |
| 90 |
<tr class="field"><th class="field-name">diffstat:</th><td class="field-body"><p class="first">String. Statistics of changes with the following format: |
| 91 |
"modified files: +added/-removed lines"</p> |
| 92 |
</td> |
| 93 |
</tr> |
| 94 |
<tr class="field"><th class="field-name">extras:</th><td class="field-body"><p class="first">List of dicts with key, value entries of the 'extras' |
| 95 |
field of this changeset.</p> |
| 96 |
</td> |
| 97 |
</tr> |
| 98 |
<tr class="field"><th class="field-name">file_adds:</th><td class="field-body"><p class="first">List of strings. Files added by this changeset.</p> |
| 99 |
</td> |
| 100 |
</tr> |
| 101 |
<tr class="field"><th class="field-name">file_copies:</th><td class="field-body"><p class="first">List of strings. Files copied in this changeset with |
| 102 |
their sources.</p> |
| 103 |
</td> |
| 104 |
</tr> |
| 105 |
<tr class="field"><th class="field-name" colspan="2">file_copies_switch:</th></tr> |
| 106 |
<tr class="field"><td> </td><td class="field-body"><p class="first">List of strings. Like "file_copies" but displayed |
| 107 |
only if the --copied switch is set.</p> |
| 108 |
</td> |
| 109 |
</tr> |
| 110 |
<tr class="field"><th class="field-name">file_dels:</th><td class="field-body"><p class="first">List of strings. Files removed by this changeset.</p> |
| 111 |
</td> |
| 112 |
</tr> |
| 113 |
<tr class="field"><th class="field-name">file_mods:</th><td class="field-body"><p class="first">List of strings. Files modified by this changeset.</p> |
| 114 |
</td> |
| 115 |
</tr> |
| 116 |
<tr class="field"><th class="field-name">files:</th><td class="field-body"><p class="first">List of strings. All files modified, added, or removed by this |
| 117 |
changeset.</p> |
| 118 |
</td> |
| 119 |
</tr> |
| 120 |
<tr class="field"><th class="field-name">graphnode:</th><td class="field-body"><p class="first">String. The character representing the changeset node in an ASCII |
| 121 |
revision graph.</p> |
| 122 |
</td> |
| 123 |
</tr> |
| 124 |
<tr class="field"><th class="field-name">graphwidth:</th><td class="field-body"><p class="first">Integer. The width of the graph drawn by 'log --graph' or zero.</p> |
| 125 |
</td> |
| 126 |
</tr> |
| 127 |
<tr class="field"><th class="field-name">index:</th><td class="field-body"><p class="first">Integer. The current iteration of the loop. (0 indexed)</p> |
| 128 |
</td> |
| 129 |
</tr> |
| 130 |
<tr class="field"><th class="field-name">latesttag:</th><td class="field-body"><p class="first">List of strings. The global tags on the most recent globally |
| 131 |
tagged ancestor of this changeset. If no such tags exist, the list |
| 132 |
consists of the single string "null".</p> |
| 133 |
</td> |
| 134 |
</tr> |
| 135 |
<tr class="field"><th class="field-name" colspan="2">latesttagdistance:</th></tr> |
| 136 |
<tr class="field"><td> </td><td class="field-body"><p class="first">Integer. Longest path to the latest tag.</p> |
| 137 |
</td> |
| 138 |
</tr> |
| 139 |
<tr class="field"><th class="field-name">namespaces:</th><td class="field-body"><p class="first">Dict of lists. Names attached to this changeset per |
| 140 |
namespace.</p> |
| 141 |
</td> |
| 142 |
</tr> |
| 143 |
<tr class="field"><th class="field-name">negrev:</th><td class="field-body"><p class="first">Integer. The repository-local changeset negative revision number, |
| 144 |
which counts in the opposite direction.</p> |
| 145 |
</td> |
| 146 |
</tr> |
| 147 |
<tr class="field"><th class="field-name">node:</th><td class="field-body"><p class="first">String. The changeset identification hash, as a 40 hexadecimal |
| 148 |
digit string.</p> |
| 149 |
</td> |
| 150 |
</tr> |
| 151 |
<tr class="field"><th class="field-name">onelinesummary:</th><td class="field-body"><p class="first">String. A one-line summary for the ctx (not including trailing newline). |
| 152 |
The default template be overridden in command-templates.oneline-summary.</p> |
| 153 |
</td> |
| 154 |
</tr> |
| 155 |
<tr class="field"><th class="field-name">p1:</th><td class="field-body"><p class="first">Changeset. The changeset's first parent. <tt class="docutils literal">{p1.rev}</tt> for the revision |
| 156 |
number, and <tt class="docutils literal">{p1.node}</tt> for the identification hash.</p> |
| 157 |
</td> |
| 158 |
</tr> |
| 159 |
<tr class="field"><th class="field-name">p2:</th><td class="field-body"><p class="first">Changeset. The changeset's second parent. <tt class="docutils literal">{p2.rev}</tt> for the revision |
| 160 |
number, and <tt class="docutils literal">{p2.node}</tt> for the identification hash.</p> |
| 161 |
</td> |
| 162 |
</tr> |
| 163 |
<tr class="field"><th class="field-name">parents:</th><td class="field-body"><p class="first">List of strings. The parents of the changeset in "rev:node" |
| 164 |
format. If the changeset has only one "natural" parent (the predecessor |
| 165 |
revision) nothing is shown.</p> |
| 166 |
</td> |
| 167 |
</tr> |
| 168 |
<tr class="field"><th class="field-name">peerurls:</th><td class="field-body"><p class="first">A dictionary of repository locations defined in the [paths] section |
| 169 |
of your configuration file.</p> |
| 170 |
</td> |
| 171 |
</tr> |
| 172 |
<tr class="field"><th class="field-name">phase:</th><td class="field-body"><p class="first">String. The changeset phase name.</p> |
| 173 |
</td> |
| 174 |
</tr> |
| 175 |
<tr class="field"><th class="field-name">reporoot:</th><td class="field-body"><p class="first">String. The root directory of the current repository.</p> |
| 176 |
</td> |
| 177 |
</tr> |
| 178 |
<tr class="field"><th class="field-name">rev:</th><td class="field-body"><p class="first">Integer. The repository-local changeset revision number.</p> |
| 179 |
</td> |
| 180 |
</tr> |
| 181 |
<tr class="field"><th class="field-name">subrepos:</th><td class="field-body"><p class="first">List of strings. Updated subrepositories in the changeset.</p> |
| 182 |
</td> |
| 183 |
</tr> |
| 184 |
<tr class="field"><th class="field-name">tags:</th><td class="field-body"><p class="first">List of strings. Any tags associated with the changeset.</p> |
| 185 |
</td> |
| 186 |
</tr> |
| 187 |
<tr class="field"><th class="field-name">termwidth:</th><td class="field-body"><p class="first">Integer. The width of the current terminal.</p> |
| 188 |
</td> |
| 189 |
</tr> |
| 190 |
<tr class="field"><th class="field-name">user:</th><td class="field-body"><p class="first">String. The unmodified author of the changeset.</p> |
| 191 |
</td> |
| 192 |
</tr> |
| 193 |
<tr class="field"><th class="field-name">verbosity:</th><td class="field-body"><p class="first last">String. The current output verbosity in 'debug', 'quiet', 'verbose', |
| 194 |
or ''.</p> |
| 195 |
</td> |
| 196 |
</tr> |
| 197 |
</tbody> |
| 198 |
</table> |
| 199 |
<p>The "date" keyword does not produce human-readable output. If you |
| 200 |
want to use a date in your output, you can use a filter to process |
| 201 |
it. Filters are functions which return a string based on the input |
| 202 |
variable. Be sure to use the stringify filter first when you're |
| 203 |
applying a string-input filter to a list-like input variable. |
| 204 |
You can also use a chain of filters to get the desired output:</p> |
| 205 |
<pre class="literal-block"> |
| 206 |
$ hg tip --template "{date|isodate}\n" |
| 207 |
2008-08-21 18:22 +0000 |
| 208 |
</pre> |
| 209 |
</div> |
| 210 |
<div class="section" id="filters"> |
| 211 |
<h1><a class="toc-backref" href="#contents">Filters</a></h1> |
| 212 |
<p>List of filters:</p> |
| 213 |
<table class="docutils field-list" frame="void" rules="none"> |
| 214 |
<col class="field-name" /> |
| 215 |
<col class="field-body" /> |
| 216 |
<tbody valign="top"> |
| 217 |
<tr class="field"><th class="field-name">addbreaks:</th><td class="field-body"><p class="first">Any text. Add an XHTML "<br />" tag before the end of |
| 218 |
every line except the last.</p> |
| 219 |
</td> |
| 220 |
</tr> |
| 221 |
<tr class="field"><th class="field-name">age:</th><td class="field-body"><p class="first">Date. Returns a human-readable date/time difference between the |
| 222 |
given date/time and the current date/time.</p> |
| 223 |
</td> |
| 224 |
</tr> |
| 225 |
<tr class="field"><th class="field-name">basename:</th><td class="field-body"><p class="first">Any text. Treats the text as a path, and returns the last |
| 226 |
component of the path after splitting by the path separator. |
| 227 |
For example, "foo/bar/baz" becomes "baz" and "foo/bar//" becomes "".</p> |
| 228 |
</td> |
| 229 |
</tr> |
| 230 |
<tr class="field"><th class="field-name">cbor:</th><td class="field-body"><p class="first">Any object. Serializes the object to CBOR bytes.</p> |
| 231 |
</td> |
| 232 |
</tr> |
| 233 |
<tr class="field"><th class="field-name">commondir:</th><td class="field-body"><p class="first">List of text. Treats each list item as file name with / |
| 234 |
as path separator and returns the longest common directory |
| 235 |
prefix shared by all list items. |
| 236 |
Returns the empty string if no common prefix exists.</p> |
| 237 |
<p>The list items are not normalized, i.e. "foo/../bar" is handled as |
| 238 |
file "bar" in the directory "foo/..". Leading slashes are ignored.</p> |
| 239 |
<p>For example, ["foo/bar/baz", "foo/baz/bar"] becomes "foo" and |
| 240 |
["foo/bar", "baz"] becomes "".</p> |
| 241 |
</td> |
| 242 |
</tr> |
| 243 |
<tr class="field"><th class="field-name">count:</th><td class="field-body"><p class="first">List or text. Returns the length as an integer.</p> |
| 244 |
</td> |
| 245 |
</tr> |
| 246 |
<tr class="field"><th class="field-name">dirname:</th><td class="field-body"><p class="first">Any text. Treats the text as a path, and strips the last |
| 247 |
component of the path after splitting by the path separator.</p> |
| 248 |
</td> |
| 249 |
</tr> |
| 250 |
<tr class="field"><th class="field-name">domain:</th><td class="field-body"><p class="first">Any text. Finds the first string that looks like an email |
| 251 |
address, and extracts just the domain component. Example: <tt class="docutils literal">User |
| 252 |
<user@example.com></tt> becomes <tt class="docutils literal">example.com</tt>.</p> |
| 253 |
</td> |
| 254 |
</tr> |
| 255 |
<tr class="field"><th class="field-name">email:</th><td class="field-body"><p class="first">Any text. Extracts the first string that looks like an email |
| 256 |
address. Example: <tt class="docutils literal">User <user@example.com></tt> becomes |
| 257 |
<tt class="docutils literal">user@example.com</tt>.</p> |
| 258 |
</td> |
| 259 |
</tr> |
| 260 |
<tr class="field"><th class="field-name">emailuser:</th><td class="field-body"><p class="first">Any text. Returns the user portion of an email address.</p> |
| 261 |
</td> |
| 262 |
</tr> |
| 263 |
<tr class="field"><th class="field-name">escape:</th><td class="field-body"><p class="first">Any text. Replaces the special XML/XHTML characters "&", "<" |
| 264 |
and ">" with XML entities, and filters out NUL characters.</p> |
| 265 |
</td> |
| 266 |
</tr> |
| 267 |
<tr class="field"><th class="field-name">fill68:</th><td class="field-body"><p class="first">Any text. Wraps the text to fit in 68 columns.</p> |
| 268 |
</td> |
| 269 |
</tr> |
| 270 |
<tr class="field"><th class="field-name">fill76:</th><td class="field-body"><p class="first">Any text. Wraps the text to fit in 76 columns.</p> |
| 271 |
</td> |
| 272 |
</tr> |
| 273 |
<tr class="field"><th class="field-name">firstline:</th><td class="field-body"><p class="first">Any text. Returns the first line of text.</p> |
| 274 |
</td> |
| 275 |
</tr> |
| 276 |
<tr class="field"><th class="field-name">hex:</th><td class="field-body"><p class="first">Any text. Convert a binary Mercurial node identifier into |
| 277 |
its long hexadecimal representation.</p> |
| 278 |
</td> |
| 279 |
</tr> |
| 280 |
<tr class="field"><th class="field-name">hgdate:</th><td class="field-body"><p class="first">Date. Returns the date as a pair of numbers: "1157407993 |
| 281 |
25200" (Unix timestamp, timezone offset).</p> |
| 282 |
</td> |
| 283 |
</tr> |
| 284 |
<tr class="field"><th class="field-name">isodate:</th><td class="field-body"><p class="first">Date. Returns the date in ISO 8601 format: "2009-08-18 13:00 |
| 285 |
+0200".</p> |
| 286 |
</td> |
| 287 |
</tr> |
| 288 |
<tr class="field"><th class="field-name">isodatesec:</th><td class="field-body"><p class="first">Date. Returns the date in ISO 8601 format, including |
| 289 |
seconds: "2009-08-18 13:00:13 +0200". See also the rfc3339date |
| 290 |
filter.</p> |
| 291 |
</td> |
| 292 |
</tr> |
| 293 |
<tr class="field"><th class="field-name">json:</th><td class="field-body"><p class="first">Any object. Serializes the object to a JSON formatted text.</p> |
| 294 |
</td> |
| 295 |
</tr> |
| 296 |
<tr class="field"><th class="field-name">lower:</th><td class="field-body"><p class="first">Any text. Converts the text to lowercase.</p> |
| 297 |
</td> |
| 298 |
</tr> |
| 299 |
<tr class="field"><th class="field-name">nonempty:</th><td class="field-body"><p class="first">Any text. Returns '(none)' if the string is empty.</p> |
| 300 |
</td> |
| 301 |
</tr> |
| 302 |
<tr class="field"><th class="field-name">obfuscate:</th><td class="field-body"><p class="first">Any text. Returns the input text rendered as a sequence of |
| 303 |
XML entities.</p> |
| 304 |
</td> |
| 305 |
</tr> |
| 306 |
<tr class="field"><th class="field-name">person:</th><td class="field-body"><p class="first">Any text. Returns the name before an email address, |
| 307 |
interpreting it as per RFC 5322.</p> |
| 308 |
</td> |
| 309 |
</tr> |
| 310 |
<tr class="field"><th class="field-name">reverse:</th><td class="field-body"><p class="first">List. Reverses the order of list items.</p> |
| 311 |
</td> |
| 312 |
</tr> |
| 313 |
<tr class="field"><th class="field-name">revescape:</th><td class="field-body"><p class="first">Any text. Escapes all "special" characters, except @. |
| 314 |
Forward slashes are escaped twice to prevent web servers from prematurely |
| 315 |
unescaping them. For example, "@foo bar/baz" becomes "@foo%20bar%252Fbaz".</p> |
| 316 |
</td> |
| 317 |
</tr> |
| 318 |
<tr class="field"><th class="field-name">rfc3339date:</th><td class="field-body"><p class="first">Date. Returns a date using the Internet date format |
| 319 |
specified in RFC 3339: "2009-08-18T13:00:13+02:00".</p> |
| 320 |
</td> |
| 321 |
</tr> |
| 322 |
<tr class="field"><th class="field-name">rfc822date:</th><td class="field-body"><p class="first">Date. Returns a date using the same format used in email |
| 323 |
headers: "Tue, 18 Aug 2009 13:00:13 +0200".</p> |
| 324 |
</td> |
| 325 |
</tr> |
| 326 |
<tr class="field"><th class="field-name">short:</th><td class="field-body"><p class="first">Changeset hash. Returns the short form of a changeset hash, |
| 327 |
i.e. a 12 hexadecimal digit string.</p> |
| 328 |
</td> |
| 329 |
</tr> |
| 330 |
<tr class="field"><th class="field-name">shortbisect:</th><td class="field-body"><p class="first">Any text. Treats <cite>label</cite> as a bisection status, and |
| 331 |
returns a single-character representing the status (G: good, B: bad, |
| 332 |
S: skipped, U: untested, I: ignored). Returns single space if <cite>text</cite> |
| 333 |
is not a valid bisection status.</p> |
| 334 |
</td> |
| 335 |
</tr> |
| 336 |
<tr class="field"><th class="field-name">shortdate:</th><td class="field-body"><p class="first">Date. Returns a date like "2006-09-18".</p> |
| 337 |
</td> |
| 338 |
</tr> |
| 339 |
<tr class="field"><th class="field-name">slashpath:</th><td class="field-body"><p class="first">Any text. Replaces the native path separator with slash.</p> |
| 340 |
</td> |
| 341 |
</tr> |
| 342 |
<tr class="field"><th class="field-name">splitlines:</th><td class="field-body"><p class="first">Any text. Split text into a list of lines.</p> |
| 343 |
</td> |
| 344 |
</tr> |
| 345 |
<tr class="field"><th class="field-name">stringify:</th><td class="field-body"><p class="first">Any type. Turns the value into text by converting values into |
| 346 |
text and concatenating them.</p> |
| 347 |
</td> |
| 348 |
</tr> |
| 349 |
<tr class="field"><th class="field-name">stripdir:</th><td class="field-body"><p class="first">Treat the text as path and strip a directory level, if |
| 350 |
possible. For example, "foo" and "foo/bar" becomes "foo".</p> |
| 351 |
</td> |
| 352 |
</tr> |
| 353 |
<tr class="field"><th class="field-name">tabindent:</th><td class="field-body"><p class="first">Any text. Returns the text, with every non-empty line |
| 354 |
except the first starting with a tab character.</p> |
| 355 |
</td> |
| 356 |
</tr> |
| 357 |
<tr class="field"><th class="field-name">upper:</th><td class="field-body"><p class="first">Any text. Converts the text to uppercase.</p> |
| 358 |
</td> |
| 359 |
</tr> |
| 360 |
<tr class="field"><th class="field-name">urlescape:</th><td class="field-body"><p class="first">Any text. Escapes all "special" characters. For example, |
| 361 |
"foo bar" becomes "foo%20bar".</p> |
| 362 |
</td> |
| 363 |
</tr> |
| 364 |
<tr class="field"><th class="field-name">user:</th><td class="field-body"><p class="first">Any text. Returns a short representation of a user name or email |
| 365 |
address.</p> |
| 366 |
</td> |
| 367 |
</tr> |
| 368 |
<tr class="field"><th class="field-name">utf8:</th><td class="field-body"><p class="first last">Any text. Converts from the local character encoding to UTF-8.</p> |
| 369 |
</td> |
| 370 |
</tr> |
| 371 |
</tbody> |
| 372 |
</table> |
| 373 |
<p>Note that a filter is nothing more than a function call, i.e. |
| 374 |
<tt class="docutils literal">expr|filter</tt> is equivalent to <tt class="docutils literal">filter(expr)</tt>.</p> |
| 375 |
</div> |
| 376 |
<div class="section" id="functions"> |
| 377 |
<h1><a class="toc-backref" href="#contents">Functions</a></h1> |
| 378 |
<p>In addition to filters, there are some basic built-in functions:</p> |
| 379 |
<table class="docutils field-list" frame="void" rules="none"> |
| 380 |
<col class="field-name" /> |
| 381 |
<col class="field-body" /> |
| 382 |
<tbody valign="top"> |
| 383 |
<tr class="field"><th class="field-name" colspan="2">config(section, name[, default]):</th></tr> |
| 384 |
<tr class="field"><td> </td><td class="field-body">Returns the requested hgrc config option as a string.</td> |
| 385 |
</tr> |
| 386 |
<tr class="field"><th class="field-name" colspan="2">configbool(section, name[, default]):</th></tr> |
| 387 |
<tr class="field"><td> </td><td class="field-body">Returns the requested hgrc config option as a boolean.</td> |
| 388 |
</tr> |
| 389 |
<tr class="field"><th class="field-name" colspan="2">configint(section, name[, default]):</th></tr> |
| 390 |
<tr class="field"><td> </td><td class="field-body">Returns the requested hgrc config option as an integer.</td> |
| 391 |
</tr> |
| 392 |
<tr class="field"><th class="field-name" colspan="2">date(date[, fmt]):</th></tr> |
| 393 |
<tr class="field"><td> </td><td class="field-body">Format a date. The format string uses the Python strftime format. |
| 394 |
The default is a Unix date format, including the timezone: |
| 395 |
"Mon Sep 04 15:13:13 2006 0700".</td> |
| 396 |
</tr> |
| 397 |
<tr class="field"><th class="field-name" colspan="2">dict([[key=]value...]):</th></tr> |
| 398 |
<tr class="field"><td> </td><td class="field-body">Construct a dict from key-value pairs. A key may be omitted if |
| 399 |
a value expression can provide an unambiguous name.</td> |
| 400 |
</tr> |
| 401 |
<tr class="field"><th class="field-name" colspan="2">diff([includepattern [, excludepattern]]):</th></tr> |
| 402 |
<tr class="field"><td> </td><td class="field-body">Show a diff, optionally |
| 403 |
specifying files to include or exclude.</td> |
| 404 |
</tr> |
| 405 |
<tr class="field"><th class="field-name">files(pattern):</th><td class="field-body">All files of the current changeset matching the pattern. See |
| 406 |
<a class="reference external" href="topic-patterns.html"><tt class="docutils literal">hg help patterns</tt></a>.</td> |
| 407 |
</tr> |
| 408 |
<tr class="field"><th class="field-name" colspan="2">fill(text[, width[, initialident[, hangindent]]]):</th></tr> |
| 409 |
<tr class="field"><td> </td><td class="field-body">Fill many |
| 410 |
paragraphs with optional indentation. See the "fill" filter.</td> |
| 411 |
</tr> |
| 412 |
<tr class="field"><th class="field-name" colspan="2">filter(iterable[, expr]):</th></tr> |
| 413 |
<tr class="field"><td> </td><td class="field-body">Remove empty elements from a list or a dict. If expr specified, it's |
| 414 |
applied to each element to test emptiness.</td> |
| 415 |
</tr> |
| 416 |
<tr class="field"><th class="field-name">get(dict, key):</th><td class="field-body">Get an attribute/key from an object. Some keywords |
| 417 |
are complex types. This function allows you to obtain the value of an |
| 418 |
attribute on these types.</td> |
| 419 |
</tr> |
| 420 |
<tr class="field"><th class="field-name" colspan="2">if(expr, then[, else]):</th></tr> |
| 421 |
<tr class="field"><td> </td><td class="field-body">Conditionally execute based on the result of |
| 422 |
an expression.</td> |
| 423 |
</tr> |
| 424 |
<tr class="field"><th class="field-name" colspan="2">ifcontains(needle, haystack, then[, else]):</th></tr> |
| 425 |
<tr class="field"><td> </td><td class="field-body">Conditionally execute based |
| 426 |
on whether the item "needle" is in "haystack".</td> |
| 427 |
</tr> |
| 428 |
<tr class="field"><th class="field-name" colspan="2">ifeq(expr1, expr2, then[, else]):</th></tr> |
| 429 |
<tr class="field"><td> </td><td class="field-body">Conditionally execute based on |
| 430 |
whether 2 items are equivalent.</td> |
| 431 |
</tr> |
| 432 |
<tr class="field"><th class="field-name" colspan="2">indent(text, indentchars[, firstline]):</th></tr> |
| 433 |
<tr class="field"><td> </td><td class="field-body">Indents all non-empty lines |
| 434 |
with the characters given in the indentchars string. An optional |
| 435 |
third parameter will override the indent for the first line only |
| 436 |
if present.</td> |
| 437 |
</tr> |
| 438 |
<tr class="field"><th class="field-name" colspan="2">join(list, sep):</th></tr> |
| 439 |
<tr class="field"><td> </td><td class="field-body">Join items in a list with a delimiter.</td> |
| 440 |
</tr> |
| 441 |
<tr class="field"><th class="field-name" colspan="2">label(label, expr):</th></tr> |
| 442 |
<tr class="field"><td> </td><td class="field-body">Apply a label to generated content. Content with a label |
| 443 |
applied can result in additional post-processing, such as |
| 444 |
automatic colorization. In order to receive effects, labels must |
| 445 |
have a dot, such as <cite>log.secret</cite> or <cite>branch.active</cite>.</td> |
| 446 |
</tr> |
| 447 |
<tr class="field"><th class="field-name" colspan="2">latesttag([pattern]):</th></tr> |
| 448 |
<tr class="field"><td> </td><td class="field-body">The global tags matching the given pattern on the |
| 449 |
most recent globally tagged ancestor of this changeset. |
| 450 |
If no such tags exist, the "{tag}" template resolves to |
| 451 |
the string "null". See <a class="reference external" href="hg.1.html#revisions.patterns"><tt class="docutils literal">hg help revisions.patterns</tt></a> for the pattern |
| 452 |
syntax.</td> |
| 453 |
</tr> |
| 454 |
<tr class="field"><th class="field-name" colspan="2">localdate(date[, tz]):</th></tr> |
| 455 |
<tr class="field"><td> </td><td class="field-body">Converts a date to the specified timezone. |
| 456 |
The default is local date.</td> |
| 457 |
</tr> |
| 458 |
<tr class="field"><th class="field-name" colspan="2">mailmap(author):</th></tr> |
| 459 |
<tr class="field"><td> </td><td class="field-body">Return the author, updated according to the value |
| 460 |
set in the .mailmap file</td> |
| 461 |
</tr> |
| 462 |
<tr class="field"><th class="field-name">max(iterable):</th><td class="field-body">Return the max of an iterable</td> |
| 463 |
</tr> |
| 464 |
<tr class="field"><th class="field-name">min(iterable):</th><td class="field-body">Return the min of an iterable</td> |
| 465 |
</tr> |
| 466 |
<tr class="field"><th class="field-name">mod(a, b):</th><td class="field-body">Calculate a mod b such that a / b + a mod b == a</td> |
| 467 |
</tr> |
| 468 |
<tr class="field"><th class="field-name" colspan="2">pad(text, width[, fillchar=' '[, left=False[, truncate=False]]]):</th></tr> |
| 469 |
<tr class="field"><td> </td><td class="field-body">Pad text with a |
| 470 |
fill character.</td> |
| 471 |
</tr> |
| 472 |
<tr class="field"><th class="field-name">relpath(path):</th><td class="field-body">Convert a repository-absolute path into a filesystem path relative to |
| 473 |
the current working directory.</td> |
| 474 |
</tr> |
| 475 |
<tr class="field"><th class="field-name" colspan="2">revset(query[, formatargs...]):</th></tr> |
| 476 |
<tr class="field"><td> </td><td class="field-body">Execute a revision set query. See |
| 477 |
<a class="reference external" href="hg.1.html#revset"><tt class="docutils literal">hg help revset</tt></a>.</td> |
| 478 |
</tr> |
| 479 |
<tr class="field"><th class="field-name" colspan="2">rstdoc(text, style):</th></tr> |
| 480 |
<tr class="field"><td> </td><td class="field-body">Format reStructuredText.</td> |
| 481 |
</tr> |
| 482 |
<tr class="field"><th class="field-name" colspan="2">search(pattern, text):</th></tr> |
| 483 |
<tr class="field"><td> </td><td class="field-body">Look for the first text matching the regular expression pattern. |
| 484 |
Groups are accessible as <tt class="docutils literal">{1}</tt>, <tt class="docutils literal">{2}</tt>, ... in %-mapped template.</td> |
| 485 |
</tr> |
| 486 |
<tr class="field"><th class="field-name" colspan="2">separate(sep, args...):</th></tr> |
| 487 |
<tr class="field"><td> </td><td class="field-body">Add a separator between non-empty arguments.</td> |
| 488 |
</tr> |
| 489 |
<tr class="field"><th class="field-name" colspan="2">shortest(node, minlength=4):</th></tr> |
| 490 |
<tr class="field"><td> </td><td class="field-body">Obtain the shortest representation of |
| 491 |
a node.</td> |
| 492 |
</tr> |
| 493 |
<tr class="field"><th class="field-name" colspan="2">startswith(pattern, text):</th></tr> |
| 494 |
<tr class="field"><td> </td><td class="field-body">Returns the value from the "text" argument |
| 495 |
if it begins with the content from the "pattern" argument.</td> |
| 496 |
</tr> |
| 497 |
<tr class="field"><th class="field-name" colspan="2">strip(text[, chars]):</th></tr> |
| 498 |
<tr class="field"><td> </td><td class="field-body">Strip characters from a string. By default, |
| 499 |
strips all leading and trailing whitespace.</td> |
| 500 |
</tr> |
| 501 |
<tr class="field"><th class="field-name" colspan="2">sub(pattern, replacement, expression):</th></tr> |
| 502 |
<tr class="field"><td> </td><td class="field-body">Perform text substitution |
| 503 |
using regular expressions.</td> |
| 504 |
</tr> |
| 505 |
<tr class="field"><th class="field-name" colspan="2">subsetparents(rev, revset):</th></tr> |
| 506 |
<tr class="field"><td> </td><td class="field-body">Look up parents of the rev in the sub graph given by the revset.</td> |
| 507 |
</tr> |
| 508 |
<tr class="field"><th class="field-name" colspan="2">word(number, text[, separator]):</th></tr> |
| 509 |
<tr class="field"><td> </td><td class="field-body">Return the nth word from a string.</td> |
| 510 |
</tr> |
| 511 |
</tbody> |
| 512 |
</table> |
| 513 |
</div> |
| 514 |
<div class="section" id="operators"> |
| 515 |
<h1><a class="toc-backref" href="#contents">Operators</a></h1> |
| 516 |
<p>We provide a limited set of infix arithmetic operations on integers:</p> |
| 517 |
<pre class="literal-block"> |
| 518 |
+ for addition |
| 519 |
- for subtraction |
| 520 |
* for multiplication |
| 521 |
/ for floor division (division rounded to integer nearest -infinity) |
| 522 |
</pre> |
| 523 |
<p>Division fulfills the law x = x / y + mod(x, y).</p> |
| 524 |
<p>Also, for any expression that returns a list, there is a list operator:</p> |
| 525 |
<pre class="literal-block"> |
| 526 |
expr % "{template}" |
| 527 |
</pre> |
| 528 |
<p>As seen in the above example, <tt class="docutils literal">{template}</tt> is interpreted as a template. |
| 529 |
To prevent it from being interpreted, you can use an escape character <tt class="docutils literal">\{</tt> |
| 530 |
or a raw string prefix, <tt class="docutils literal"><span class="pre">r'...'</span></tt>.</p> |
| 531 |
<p>The dot operator can be used as a shorthand for accessing a sub item:</p> |
| 532 |
<ul class="simple"> |
| 533 |
<li><tt class="docutils literal">expr.member</tt> is roughly equivalent to <tt class="docutils literal">expr % '{member}'</tt> if <tt class="docutils literal">expr</tt> |
| 534 |
returns a non-list/dict. The returned value is not stringified.</li> |
| 535 |
<li><tt class="docutils literal">dict.key</tt> is identical to <tt class="docutils literal">get(dict, 'key')</tt>.</li> |
| 536 |
</ul> |
| 537 |
</div> |
| 538 |
<div class="section" id="aliases"> |
| 539 |
<h1><a class="toc-backref" href="#contents">Aliases</a></h1> |
| 540 |
<p>New keywords and functions can be defined in the <tt class="docutils literal">templatealias</tt> section of |
| 541 |
a Mercurial configuration file:</p> |
| 542 |
<pre class="literal-block"> |
| 543 |
<alias> = <definition> |
| 544 |
</pre> |
| 545 |
<p>Arguments of the form <cite>a1</cite>, <cite>a2</cite>, etc. are substituted from the alias into |
| 546 |
the definition.</p> |
| 547 |
<p>For example,</p> |
| 548 |
<pre class="literal-block"> |
| 549 |
[templatealias] |
| 550 |
r = rev |
| 551 |
rn = "{r}:{node|short}" |
| 552 |
leftpad(s, w) = pad(s, w, ' ', True) |
| 553 |
</pre> |
| 554 |
<p>defines two symbol aliases, <tt class="docutils literal">r</tt> and <tt class="docutils literal">rn</tt>, and a function alias |
| 555 |
<tt class="docutils literal">leftpad()</tt>.</p> |
| 556 |
<p>It's also possible to specify complete template strings, using the |
| 557 |
<tt class="docutils literal">templates</tt> section. The syntax used is the general template string syntax.</p> |
| 558 |
<p>For example,</p> |
| 559 |
<pre class="literal-block"> |
| 560 |
[templates] |
| 561 |
nodedate = "{node|short}: {date(date, "%Y-%m-%d")}\n" |
| 562 |
</pre> |
| 563 |
<p>defines a template, <tt class="docutils literal">nodedate</tt>, which can be called like:</p> |
| 564 |
<pre class="literal-block"> |
| 565 |
$ hg log -r . -Tnodedate |
| 566 |
</pre> |
| 567 |
<p>A template defined in <tt class="docutils literal">templates</tt> section can also be referenced from |
| 568 |
another template:</p> |
| 569 |
<pre class="literal-block"> |
| 570 |
$ hg log -r . -T "{rev} {nodedate}" |
| 571 |
</pre> |
| 572 |
<p>but be aware that the keywords cannot be overridden by templates. For example, |
| 573 |
a template defined as <tt class="docutils literal">templates.rev</tt> cannot be referenced as <tt class="docutils literal">{rev}</tt>.</p> |
| 574 |
<p>A template defined in <tt class="docutils literal">templates</tt> section may have sub templates which |
| 575 |
are inserted before/after/between items:</p> |
| 576 |
<pre class="literal-block"> |
| 577 |
[templates] |
| 578 |
myjson = ' {dict(rev, node|short)|json}' |
| 579 |
myjson:docheader = '\{\n' |
| 580 |
myjson:docfooter = '\n}\n' |
| 581 |
myjson:separator = ',\n' |
| 582 |
</pre> |
| 583 |
</div> |
| 584 |
<div class="section" id="examples"> |
| 585 |
<h1><a class="toc-backref" href="#contents">Examples</a></h1> |
| 586 |
<p>Some sample command line templates:</p> |
| 587 |
<ul> |
| 588 |
<li><p class="first">Format lists, e.g. files:</p> |
| 589 |
<pre class="literal-block"> |
| 590 |
$ hg log -r 0 --template "files:\n{files % ' {file}\n'}" |
| 591 |
</pre> |
| 592 |
</li> |
| 593 |
<li><p class="first">Join the list of files with a ", ":</p> |
| 594 |
<pre class="literal-block"> |
| 595 |
$ hg log -r 0 --template "files: {join(files, ', ')}\n" |
| 596 |
</pre> |
| 597 |
</li> |
| 598 |
<li><p class="first">Join the list of files ending with ".py" with a ", ":</p> |
| 599 |
<pre class="literal-block"> |
| 600 |
$ hg log -r 0 --template "pythonfiles: {join(files('**.py'), ', ')}\n" |
| 601 |
</pre> |
| 602 |
</li> |
| 603 |
<li><p class="first">Separate non-empty arguments by a " ":</p> |
| 604 |
<pre class="literal-block"> |
| 605 |
$ hg log -r 0 --template "{separate(' ', node, bookmarks, tags}\n" |
| 606 |
</pre> |
| 607 |
</li> |
| 608 |
<li><p class="first">Modify each line of a commit description:</p> |
| 609 |
<pre class="literal-block"> |
| 610 |
$ hg log --template "{splitlines(desc) % '**** {line}\n'}" |
| 611 |
</pre> |
| 612 |
</li> |
| 613 |
<li><p class="first">Format date:</p> |
| 614 |
<pre class="literal-block"> |
| 615 |
$ hg log -r 0 --template "{date(date, '%Y')}\n" |
| 616 |
</pre> |
| 617 |
</li> |
| 618 |
<li><p class="first">Display date in UTC:</p> |
| 619 |
<pre class="literal-block"> |
| 620 |
$ hg log -r 0 --template "{localdate(date, 'UTC')|date}\n" |
| 621 |
</pre> |
| 622 |
</li> |
| 623 |
<li><p class="first">Output the description set to a fill-width of 30:</p> |
| 624 |
<pre class="literal-block"> |
| 625 |
$ hg log -r 0 --template "{fill(desc, 30)}" |
| 626 |
</pre> |
| 627 |
</li> |
| 628 |
<li><p class="first">Use a conditional to test for the default branch:</p> |
| 629 |
<pre class="literal-block"> |
| 630 |
$ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch', |
| 631 |
'on branch {branch}')}\n" |
| 632 |
</pre> |
| 633 |
</li> |
| 634 |
<li><p class="first">Append a newline if not empty:</p> |
| 635 |
<pre class="literal-block"> |
| 636 |
$ hg tip --template "{if(author, '{author}\n')}" |
| 637 |
</pre> |
| 638 |
</li> |
| 639 |
<li><p class="first">Label the output for use with the color extension:</p> |
| 640 |
<pre class="literal-block"> |
| 641 |
$ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n" |
| 642 |
</pre> |
| 643 |
</li> |
| 644 |
<li><p class="first">Invert the firstline filter, i.e. everything but the first line:</p> |
| 645 |
<pre class="literal-block"> |
| 646 |
$ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n" |
| 647 |
</pre> |
| 648 |
</li> |
| 649 |
<li><p class="first">Display the contents of the 'extra' field, one per line:</p> |
| 650 |
<pre class="literal-block"> |
| 651 |
$ hg log -r 0 --template "{join(extras, '\n')}\n" |
| 652 |
</pre> |
| 653 |
</li> |
| 654 |
<li><p class="first">Mark the active bookmark with '*':</p> |
| 655 |
<pre class="literal-block"> |
| 656 |
$ hg log --template "{bookmarks % '{bookmark}{ifeq(bookmark, active, '*')} '}\n" |
| 657 |
</pre> |
| 658 |
</li> |
| 659 |
<li><p class="first">Find the previous release candidate tag, the distance and changes since the tag:</p> |
| 660 |
<pre class="literal-block"> |
| 661 |
$ hg log -r . --template "{latesttag('re:^.*-rc$') % '{tag}, {changes}, {distance}'}\n" |
| 662 |
</pre> |
| 663 |
</li> |
| 664 |
<li><p class="first">Mark the working copy parent with '@':</p> |
| 665 |
<pre class="literal-block"> |
| 666 |
$ hg log --template "{ifcontains(rev, revset('.'), '@')}\n" |
| 667 |
</pre> |
| 668 |
</li> |
| 669 |
<li><p class="first">Show details of parent revisions:</p> |
| 670 |
<pre class="literal-block"> |
| 671 |
$ hg log --template "{revset('parents(%d)', rev) % '{desc|firstline}\n'}" |
| 672 |
</pre> |
| 673 |
</li> |
| 674 |
<li><p class="first">Show only commit descriptions that start with "template":</p> |
| 675 |
<pre class="literal-block"> |
| 676 |
$ hg log --template "{startswith('template', firstline(desc))}\n" |
| 677 |
</pre> |
| 678 |
</li> |
| 679 |
<li><p class="first">Print the first word of each line of a commit message:</p> |
| 680 |
<pre class="literal-block"> |
| 681 |
$ hg log --template "{word(0, desc)}\n" |
| 682 |
</pre> |
| 683 |
</li> |
| 684 |
</ul> |
| 685 |
</div> |
| 686 |
</div> |
| 687 |
</body> |
| 688 |
</html> |