hgbook

view en/ch10-template.xml @ 679:06458701453c

Fix up some links to example URLs that aren't actually real.
author Bryan O'Sullivan <bos@serpentine.com>
date Tue Apr 21 21:07:20 2009 -0700 (2009-04-21)
parents 7e7c47481e4f 4ce9d0754af3
children ef53d025f410
line source
1 <!-- vim: set filetype=docbkxml shiftwidth=2 autoindent expandtab tw=77 : -->
3 <chapter id="chap:template">
4 <?dbhtml filename="customizing-the-output-of-mercurial.html"?>
5 <title>Customising the output of Mercurial</title>
7 <para id="x_578">Mercurial provides a powerful mechanism to let you control how
8 it displays information. The mechanism is based on templates.
9 You can use templates to generate specific output for a single
10 command, or to customise the entire appearance of the built-in web
11 interface.</para>
13 <sect1 id="sec:style">
14 <title>Using precanned output styles</title>
16 <para id="x_579">Packaged with Mercurial are some output styles that you can
17 use immediately. A style is simply a precanned template that
18 someone wrote and installed somewhere that Mercurial can
19 find.</para>
21 <para id="x_57a">Before we take a look at Mercurial's bundled styles, let's
22 review its normal output.</para>
24 &interaction.template.simple.normal;
26 <para id="x_57b">This is somewhat informative, but it takes up a lot of
27 space&emdash;five lines of output per changeset. The
28 <literal>compact</literal> style reduces this to three lines,
29 presented in a sparse manner.</para>
31 &interaction.template.simple.compact;
33 <para id="x_57c">The <literal>changelog</literal> style hints at the
34 expressive power of Mercurial's templating engine. This style
35 attempts to follow the GNU Project's changelog
36 guidelines<citation>web:changelog</citation>.</para>
38 &interaction.template.simple.changelog;
40 <para id="x_57d">You will not be shocked to learn that Mercurial's default
41 output style is named <literal>default</literal>.</para>
43 <sect2>
44 <title>Setting a default style</title>
46 <para id="x_57e">You can modify the output style that Mercurial will use
47 for every command by editing your <filename
48 role="special">~/.hgrc</filename> file, naming the style
49 you would prefer to use.</para>
51 <programlisting>[ui]
52 style = compact</programlisting>
54 <para id="x_57f">If you write a style of your own, you can use it by either
55 providing the path to your style file, or copying your style
56 file into a location where Mercurial can find it (typically
57 the <literal>templates</literal> subdirectory of your
58 Mercurial install directory).</para>
60 </sect2>
61 </sect1>
62 <sect1>
63 <title>Commands that support styles and templates</title>
65 <para id="x_580">All of Mercurial's
66 <quote><literal>log</literal>-like</quote> commands let you use
67 styles and templates: <command role="hg-cmd">hg
68 incoming</command>, <command role="hg-cmd">hg log</command>,
69 <command role="hg-cmd">hg outgoing</command>, and <command
70 role="hg-cmd">hg tip</command>.</para>
72 <para id="x_581">As I write this manual, these are so far the only commands
73 that support styles and templates. Since these are the most
74 important commands that need customisable output, there has been
75 little pressure from the Mercurial user community to add style
76 and template support to other commands.</para>
78 </sect1>
79 <sect1>
80 <title>The basics of templating</title>
82 <para id="x_582">At its simplest, a Mercurial template is a piece of text.
83 Some of the text never changes, while other parts are
84 <emphasis>expanded</emphasis>, or replaced with new text, when
85 necessary.</para>
87 <para id="x_583">Before we continue, let's look again at a simple example of
88 Mercurial's normal output.</para>
90 &interaction.template.simple.normal;
92 <para id="x_584">Now, let's run the same command, but using a template to
93 change its output.</para>
95 &interaction.template.simple.simplest;
97 <para id="x_585">The example above illustrates the simplest possible
98 template; it's just a piece of static text, printed once for
99 each changeset. The <option
100 role="hg-opt-log">--template</option> option to the <command
101 role="hg-cmd">hg log</command> command tells Mercurial to use
102 the given text as the template when printing each
103 changeset.</para>
105 <para id="x_586">Notice that the template string above ends with the text
106 <quote><literal>\n</literal></quote>. This is an
107 <emphasis>escape sequence</emphasis>, telling Mercurial to print
108 a newline at the end of each template item. If you omit this
109 newline, Mercurial will run each piece of output together. See
110 <xref linkend="sec:template:escape"/> for more details
111 of escape sequences.</para>
113 <para id="x_587">A template that prints a fixed string of text all the time
114 isn't very useful; let's try something a bit more
115 complex.</para>
117 &interaction.template.simple.simplesub;
119 <para id="x_588">As you can see, the string
120 <quote><literal>{desc}</literal></quote> in the template has
121 been replaced in the output with the description of each
122 changeset. Every time Mercurial finds text enclosed in curly
123 braces (<quote><literal>{</literal></quote> and
124 <quote><literal>}</literal></quote>), it will try to replace the
125 braces and text with the expansion of whatever is inside. To
126 print a literal curly brace, you must escape it, as described in
127 <xref linkend="sec:template:escape"/>.</para>
129 </sect1>
130 <sect1 id="sec:template:keyword">
131 <title>Common template keywords</title>
133 <para id="x_589">You can start writing simple templates immediately using the
134 keywords below.</para>
136 <itemizedlist>
137 <listitem><para id="x_58a"><literal
138 role="template-keyword">author</literal>: String. The
139 unmodified author of the changeset.</para>
140 </listitem>
141 <listitem><para id="x_58b"><literal
142 role="template-keyword">branches</literal>: String. The
143 name of the branch on which the changeset was committed.
144 Will be empty if the branch name was
145 <literal>default</literal>.</para>
146 </listitem>
147 <listitem><para id="x_58c"><literal role="template-keyword">date</literal>:
148 Date information. The date when the changeset was
149 committed. This is <emphasis>not</emphasis> human-readable;
150 you must pass it through a filter that will render it
151 appropriately. See <xref
152 linkend="sec:template:filter"/> for more information
153 on filters. The date is expressed as a pair of numbers. The
154 first number is a Unix UTC timestamp (seconds since January
155 1, 1970); the second is the offset of the committer's
156 timezone from UTC, in seconds.</para>
157 </listitem>
158 <listitem><para id="x_58d"><literal role="template-keyword">desc</literal>:
159 String. The text of the changeset description.</para>
160 </listitem>
161 <listitem><para id="x_58e"><literal
162 role="template-keyword">files</literal>: List of strings.
163 All files modified, added, or removed by this
164 changeset.</para>
165 </listitem>
166 <listitem><para id="x_58f"><literal
167 role="template-keyword">file_adds</literal>: List of
168 strings. Files added by this changeset.</para>
169 </listitem>
170 <listitem><para id="x_590"><literal
171 role="template-keyword">file_dels</literal>: List of
172 strings. Files removed by this changeset.</para>
173 </listitem>
174 <listitem><para id="x_591"><literal role="template-keyword">node</literal>:
175 String. The changeset identification hash, as a
176 40-character hexadecimal string.</para>
177 </listitem>
178 <listitem><para id="x_592"><literal
179 role="template-keyword">parents</literal>: List of
180 strings. The parents of the changeset.</para>
181 </listitem>
182 <listitem><para id="x_593"><literal role="template-keyword">rev</literal>:
183 Integer. The repository-local changeset revision
184 number.</para>
185 </listitem>
186 <listitem><para id="x_594"><literal role="template-keyword">tags</literal>:
187 List of strings. Any tags associated with the
188 changeset.</para>
189 </listitem></itemizedlist>
191 <para id="x_595">A few simple experiments will show us what to expect when we
192 use these keywords; you can see the results below.</para>
194 &interaction.template.simple.keywords;
196 <para id="x_596">As we noted above, the date keyword does not produce
197 human-readable output, so we must treat it specially. This
198 involves using a <emphasis>filter</emphasis>, about which more
199 in <xref linkend="sec:template:filter"/>.</para>
201 &interaction.template.simple.datekeyword;
203 </sect1>
204 <sect1 id="sec:template:escape">
205 <title>Escape sequences</title>
207 <para id="x_597">Mercurial's templating engine recognises the most commonly
208 used escape sequences in strings. When it sees a backslash
209 (<quote><literal>\</literal></quote>) character, it looks at the
210 following character and substitutes the two characters with a
211 single replacement, as described below.</para>
213 <itemizedlist>
214 <listitem><para id="x_598"><literal>\</literal>:
215 Backslash, <quote><literal>\</literal></quote>, ASCII
216 134.</para>
217 </listitem>
218 <listitem><para id="x_599"><literal>\n</literal>: Newline,
219 ASCII 12.</para>
220 </listitem>
221 <listitem><para id="x_59a"><literal>\r</literal>: Carriage
222 return, ASCII 15.</para>
223 </listitem>
224 <listitem><para id="x_59b"><literal>\t</literal>: Tab, ASCII
225 11.</para>
226 </listitem>
227 <listitem><para id="x_59c"><literal>\v</literal>: Vertical
228 tab, ASCII 13.</para>
229 </listitem>
230 <listitem><para id="x_59d"><literal>{</literal>: Open curly
231 brace, <quote><literal>{</literal></quote>, ASCII
232 173.</para>
233 </listitem>
234 <listitem><para id="x_59e"><literal>}</literal>: Close curly
235 brace, <quote><literal>}</literal></quote>, ASCII
236 175.</para>
237 </listitem></itemizedlist>
239 <para id="x_59f">As indicated above, if you want the expansion of a template
240 to contain a literal <quote><literal>\</literal></quote>,
241 <quote><literal>{</literal></quote>, or
242 <quote><literal>{</literal></quote> character, you must escape
243 it.</para>
245 </sect1>
246 <sect1 id="sec:template:filter">
247 <title>Filtering keywords to change their results</title>
249 <para id="x_5a0">Some of the results of template expansion are not
250 immediately easy to use. Mercurial lets you specify an optional
251 chain of <emphasis>filters</emphasis> to modify the result of
252 expanding a keyword. You have already seen a common filter,
253 <literal role="template-kw-filt-date">isodate</literal>, in
254 action above, to make a date readable.</para>
256 <para id="x_5a1">Below is a list of the most commonly used filters that
257 Mercurial supports. While some filters can be applied to any
258 text, others can only be used in specific circumstances. The
259 name of each filter is followed first by an indication of where
260 it can be used, then a description of its effect.</para>
262 <itemizedlist>
263 <listitem><para id="x_5a2"><literal
264 role="template-filter">addbreaks</literal>: Any text. Add
265 an XHTML <quote><literal>&lt;br/&gt;</literal></quote> tag
266 before the end of every line except the last. For example,
267 <quote><literal>foo\nbar</literal></quote> becomes
268 <quote><literal>foo&lt;br/&gt;\nbar</literal></quote>.</para>
269 </listitem>
270 <listitem><para id="x_5a3"><literal
271 role="template-kw-filt-date">age</literal>: <literal
272 role="template-keyword">date</literal> keyword. Render
273 the age of the date, relative to the current time. Yields a
274 string like <quote><literal>10
275 minutes</literal></quote>.</para>
276 </listitem>
277 <listitem><para id="x_5a4"><literal
278 role="template-filter">basename</literal>: Any text, but
279 most useful for the <literal
280 role="template-keyword">files</literal> keyword and its
281 relatives. Treat the text as a path, and return the
282 basename. For example,
283 <quote><literal>foo/bar/baz</literal></quote> becomes
284 <quote><literal>baz</literal></quote>.</para>
285 </listitem>
286 <listitem><para id="x_5a5"><literal
287 role="template-kw-filt-date">date</literal>: <literal
288 role="template-keyword">date</literal> keyword. Render a
289 date in a similar format to the Unix <literal
290 role="template-keyword">date</literal> command, but with
291 timezone included. Yields a string like <quote><literal>Mon
292 Sep 04 15:13:13 2006 -0700</literal></quote>.</para>
293 </listitem>
294 <listitem><para id="x_5a6"><literal
295 role="template-kw-filt-author">domain</literal>: Any text,
296 but most useful for the <literal
297 role="template-keyword">author</literal> keyword. Finds
298 the first string that looks like an email address, and
299 extract just the domain component. For example,
300 <quote><literal>Bryan O'Sullivan
301 &lt;bos@serpentine.com&gt;</literal></quote> becomes
302 <quote><literal>serpentine.com</literal></quote>.</para>
303 </listitem>
304 <listitem><para id="x_5a7"><literal
305 role="template-kw-filt-author">email</literal>: Any text,
306 but most useful for the <literal
307 role="template-keyword">author</literal> keyword. Extract
308 the first string that looks like an email address. For
309 example, <quote><literal>Bryan O'Sullivan
310 &lt;bos@serpentine.com&gt;</literal></quote> becomes
311 <quote><literal>bos@serpentine.com</literal></quote>.</para>
312 </listitem>
313 <listitem><para id="x_5a8"><literal
314 role="template-filter">escape</literal>: Any text.
315 Replace the special XML/XHTML characters
316 <quote><literal>&amp;</literal></quote>,
317 <quote><literal>&lt;</literal></quote> and
318 <quote><literal>&gt;</literal></quote> with XML
319 entities.</para>
320 </listitem>
321 <listitem><para id="x_5a9"><literal
322 role="template-filter">fill68</literal>: Any text. Wrap
323 the text to fit in 68 columns. This is useful before you
324 pass text through the <literal
325 role="template-filter">tabindent</literal> filter, and
326 still want it to fit in an 80-column fixed-font
327 window.</para>
328 </listitem>
329 <listitem><para id="x_5aa"><literal
330 role="template-filter">fill76</literal>: Any text. Wrap
331 the text to fit in 76 columns.</para>
332 </listitem>
333 <listitem><para id="x_5ab"><literal
334 role="template-filter">firstline</literal>: Any text.
335 Yield the first line of text, without any trailing
336 newlines.</para>
337 </listitem>
338 <listitem><para id="x_5ac"><literal
339 role="template-kw-filt-date">hgdate</literal>: <literal
340 role="template-keyword">date</literal> keyword. Render
341 the date as a pair of readable numbers. Yields a string
342 like <quote><literal>1157407993
343 25200</literal></quote>.</para>
344 </listitem>
345 <listitem><para id="x_5ad"><literal
346 role="template-kw-filt-date">isodate</literal>: <literal
347 role="template-keyword">date</literal> keyword. Render
348 the date as a text string in ISO 8601 format. Yields a
349 string like <quote><literal>2006-09-04 15:13:13
350 -0700</literal></quote>.</para>
351 </listitem>
352 <listitem><para id="x_5ae"><literal
353 role="template-filter">obfuscate</literal>: Any text, but
354 most useful for the <literal
355 role="template-keyword">author</literal> keyword. Yield
356 the input text rendered as a sequence of XML entities. This
357 helps to defeat some particularly stupid screen-scraping
358 email harvesting spambots.</para>
359 </listitem>
360 <listitem><para id="x_5af"><literal
361 role="template-kw-filt-author">person</literal>: Any text,
362 but most useful for the <literal
363 role="template-keyword">author</literal> keyword. Yield
364 the text before an email address. For example,
365 <quote><literal>Bryan O'Sullivan
366 &lt;bos@serpentine.com&gt;</literal></quote> becomes
367 <quote><literal>Bryan O'Sullivan</literal></quote>.</para>
368 </listitem>
369 <listitem><para id="x_5b0"><literal
370 role="template-kw-filt-date">rfc822date</literal>:
371 <literal role="template-keyword">date</literal> keyword.
372 Render a date using the same format used in email headers.
373 Yields a string like <quote><literal>Mon, 04 Sep 2006
374 15:13:13 -0700</literal></quote>.</para>
375 </listitem>
376 <listitem><para id="x_5b1"><literal
377 role="template-kw-filt-node">short</literal>: Changeset
378 hash. Yield the short form of a changeset hash, i.e. a
379 12-character hexadecimal string.</para>
380 </listitem>
381 <listitem><para id="x_5b2"><literal
382 role="template-kw-filt-date">shortdate</literal>: <literal
383 role="template-keyword">date</literal> keyword. Render
384 the year, month, and day of the date. Yields a string like
385 <quote><literal>2006-09-04</literal></quote>.</para>
386 </listitem>
387 <listitem><para id="x_5b3"><literal role="template-filter">strip</literal>:
388 Any text. Strip all leading and trailing whitespace from
389 the string.</para>
390 </listitem>
391 <listitem><para id="x_5b4"><literal
392 role="template-filter">tabindent</literal>: Any text.
393 Yield the text, with every line except the first starting
394 with a tab character.</para>
395 </listitem>
396 <listitem><para id="x_5b5"><literal
397 role="template-filter">urlescape</literal>: Any text.
398 Escape all characters that are considered
399 <quote>special</quote> by URL parsers. For example,
400 <literal>foo bar</literal> becomes
401 <literal>foo%20bar</literal>.</para>
402 </listitem>
403 <listitem><para id="x_5b6"><literal
404 role="template-kw-filt-author">user</literal>: Any text,
405 but most useful for the <literal
406 role="template-keyword">author</literal> keyword. Return
407 the <quote>user</quote> portion of an email address. For
408 example, <quote><literal>Bryan O'Sullivan
409 &lt;bos@serpentine.com&gt;</literal></quote> becomes
410 <quote><literal>bos</literal></quote>.</para>
411 </listitem></itemizedlist>
413 &interaction.template.simple.manyfilters;
415 <note>
416 <para id="x_5b7"> If you try to apply a filter to a piece of data that it
417 cannot process, Mercurial will fail and print a Python
418 exception. For example, trying to run the output of the
419 <literal role="template-keyword">desc</literal> keyword into
420 the <literal role="template-kw-filt-date">isodate</literal>
421 filter is not a good idea.</para>
422 </note>
424 <sect2>
425 <title>Combining filters</title>
427 <para id="x_5b8">It is easy to combine filters to yield output in the form
428 you would like. The following chain of filters tidies up a
429 description, then makes sure that it fits cleanly into 68
430 columns, then indents it by a further 8 characters (at least
431 on Unix-like systems, where a tab is conventionally 8
432 characters wide).</para>
434 &interaction.template.simple.combine;
436 <para id="x_5b9">Note the use of <quote><literal>\t</literal></quote> (a
437 tab character) in the template to force the first line to be
438 indented; this is necessary since <literal
439 role="template-keyword">tabindent</literal> indents all
440 lines <emphasis>except</emphasis> the first.</para>
442 <para id="x_5ba">Keep in mind that the order of filters in a chain is
443 significant. The first filter is applied to the result of the
444 keyword; the second to the result of the first filter; and so
445 on. For example, using <literal>fill68|tabindent</literal>
446 gives very different results from
447 <literal>tabindent|fill68</literal>.</para>
450 </sect2>
451 </sect1>
452 <sect1>
453 <title>From templates to styles</title>
455 <para id="x_5bb">A command line template provides a quick and simple way to
456 format some output. Templates can become verbose, though, and
457 it's useful to be able to give a template a name. A style file
458 is a template with a name, stored in a file.</para>
460 <para id="x_5bc">More than that, using a style file unlocks the power of
461 Mercurial's templating engine in ways that are not possible
462 using the command line <option
463 role="hg-opt-log">--template</option> option.</para>
465 <sect2>
466 <title>The simplest of style files</title>
468 <para id="x_5bd">Our simple style file contains just one line:</para>
470 &interaction.template.simple.rev;
472 <para id="x_5be">This tells Mercurial, <quote>if you're printing a
473 changeset, use the text on the right as the
474 template</quote>.</para>
476 </sect2>
477 <sect2>
478 <title>Style file syntax</title>
480 <para id="x_5bf">The syntax rules for a style file are simple.</para>
482 <itemizedlist>
483 <listitem><para id="x_5c0">The file is processed one line at a
484 time.</para>
485 </listitem>
486 <listitem><para id="x_5c1">Leading and trailing white space are
487 ignored.</para>
488 </listitem>
489 <listitem><para id="x_5c2">Empty lines are skipped.</para>
490 </listitem>
491 <listitem><para id="x_5c3">If a line starts with either of the characters
492 <quote><literal>#</literal></quote> or
493 <quote><literal>;</literal></quote>, the entire line is
494 treated as a comment, and skipped as if empty.</para>
495 </listitem>
496 <listitem><para id="x_5c4">A line starts with a keyword. This must start
497 with an alphabetic character or underscore, and can
498 subsequently contain any alphanumeric character or
499 underscore. (In regexp notation, a keyword must match
500 <literal>[A-Za-z_][A-Za-z0-9_]*</literal>.)</para>
501 </listitem>
502 <listitem><para id="x_5c5">The next element must be an
503 <quote><literal>=</literal></quote> character, which can
504 be preceded or followed by an arbitrary amount of white
505 space.</para>
506 </listitem>
507 <listitem><para id="x_5c6">If the rest of the line starts and ends with
508 matching quote characters (either single or double quote),
509 it is treated as a template body.</para>
510 </listitem>
511 <listitem><para id="x_5c7">If the rest of the line <emphasis>does
512 not</emphasis> start with a quote character, it is
513 treated as the name of a file; the contents of this file
514 will be read and used as a template body.</para>
515 </listitem></itemizedlist>
517 </sect2>
518 </sect1>
519 <sect1>
520 <title>Style files by example</title>
522 <para id="x_5c8">To illustrate how to write a style file, we will construct a
523 few by example. Rather than provide a complete style file and
524 walk through it, we'll mirror the usual process of developing a
525 style file by starting with something very simple, and walking
526 through a series of successively more complete examples.</para>
528 <sect2>
529 <title>Identifying mistakes in style files</title>
531 <para id="x_5c9">If Mercurial encounters a problem in a style file you are
532 working on, it prints a terse error message that, once you
533 figure out what it means, is actually quite useful.</para>
535 &interaction.template.svnstyle.syntax.input;
537 <para id="x_5ca">Notice that <filename>broken.style</filename> attempts to
538 define a <literal>changeset</literal> keyword, but forgets to
539 give any content for it. When instructed to use this style
540 file, Mercurial promptly complains.</para>
542 &interaction.template.svnstyle.syntax.error;
544 <para id="x_5cb">This error message looks intimidating, but it is not too
545 hard to follow.</para>
547 <itemizedlist>
548 <listitem><para id="x_5cc">The first component is simply Mercurial's way
549 of saying <quote>I am giving up</quote>.</para>
550 <programlisting>___abort___: broken.style:1: parse error</programlisting>
551 </listitem>
552 <listitem><para id="x_5cd">Next comes the name of the style file that
553 contains the error.</para>
554 <programlisting>abort: ___broken.style___:1: parse error</programlisting>
555 </listitem>
556 <listitem><para id="x_5ce">Following the file name is the line number
557 where the error was encountered.</para>
558 <programlisting>abort: broken.style:___1___: parse error</programlisting>
559 </listitem>
560 <listitem><para id="x_5cf">Finally, a description of what went
561 wrong.</para>
562 <programlisting>abort: broken.style:1: ___parse error___</programlisting>
563 </listitem>
564 <listitem><para id="x_5d0">The description of the problem is not always
565 clear (as in this case), but even when it is cryptic, it
566 is almost always trivial to visually inspect the offending
567 line in the style file and see what is wrong.</para>
568 </listitem></itemizedlist>
570 </sect2>
571 <sect2>
572 <title>Uniquely identifying a repository</title>
574 <para id="x_5d1">If you would like to be able to identify a Mercurial
575 repository <quote>fairly uniquely</quote> using a short string
576 as an identifier, you can use the first revision in the
577 repository.</para>
579 &interaction.template.svnstyle.id;
581 <para id="x_5d2">This is not guaranteed to be unique, but it is
582 nevertheless useful in many cases.</para>
583 <itemizedlist>
584 <listitem><para id="x_5d3">It will not work in a completely empty
585 repository, because such a repository does not have a
586 revision zero.</para>
587 </listitem>
588 <listitem><para id="x_5d4">Neither will it work in the (extremely rare)
589 case where a repository is a merge of two or more formerly
590 independent repositories, and you still have those
591 repositories around.</para>
592 </listitem></itemizedlist>
593 <para id="x_5d5">Here are some uses to which you could put this
594 identifier:</para>
595 <itemizedlist>
596 <listitem><para id="x_5d6">As a key into a table for a database that
597 manages repositories on a server.</para>
598 </listitem>
599 <listitem><para id="x_5d7">As half of a {<emphasis>repository
600 ID</emphasis>, <emphasis>revision ID</emphasis>} tuple.
601 Save this information away when you run an automated build
602 or other activity, so that you can <quote>replay</quote>
603 the build later if necessary.</para>
604 </listitem></itemizedlist>
606 </sect2>
607 <sect2>
608 <title>Mimicking Subversion's output</title>
610 <para id="x_5d8">Let's try to emulate the default output format used by
611 another revision control tool, Subversion.</para>
613 &interaction.template.svnstyle.short;
615 <para id="x_5d9">Since Subversion's output style is fairly simple, it is
616 easy to copy-and-paste a hunk of its output into a file, and
617 replace the text produced above by Subversion with the
618 template values we'd like to see expanded.</para>
620 &interaction.template.svnstyle.template;
622 <para id="x_5da">There are a few small ways in which this template deviates
623 from the output produced by Subversion.</para>
624 <itemizedlist>
625 <listitem><para id="x_5db">Subversion prints a <quote>readable</quote>
626 date (the <quote><literal>Wed, 27 Sep 2006</literal></quote> in the
627 example output above) in parentheses. Mercurial's
628 templating engine does not provide a way to display a date
629 in this format without also printing the time and time
630 zone.</para>
631 </listitem>
632 <listitem><para id="x_5dc">We emulate Subversion's printing of
633 <quote>separator</quote> lines full of
634 <quote><literal>-</literal></quote> characters by ending
635 the template with such a line. We use the templating
636 engine's <literal role="template-keyword">header</literal>
637 keyword to print a separator line as the first line of
638 output (see below), thus achieving similar output to
639 Subversion.</para>
640 </listitem>
641 <listitem><para id="x_5dd">Subversion's output includes a count in the
642 header of the number of lines in the commit message. We
643 cannot replicate this in Mercurial; the templating engine
644 does not currently provide a filter that counts the number
645 of lines the template generates.</para>
646 </listitem></itemizedlist>
647 <para id="x_5de">It took me no more than a minute or two of work to replace
648 literal text from an example of Subversion's output with some
649 keywords and filters to give the template above. The style
650 file simply refers to the template.</para>
652 &interaction.template.svnstyle.style;
654 <para id="x_5df">We could have included the text of the template file
655 directly in the style file by enclosing it in quotes and
656 replacing the newlines with
657 <quote><literal>\n</literal></quote> sequences, but it would
658 have made the style file too difficult to read. Readability
659 is a good guide when you're trying to decide whether some text
660 belongs in a style file, or in a template file that the style
661 file points to. If the style file will look too big or
662 cluttered if you insert a literal piece of text, drop it into
663 a template instead.</para>
665 </sect2>
666 </sect1>
667 </chapter>
669 <!--
670 local variables:
671 sgml-parent-document: ("00book.xml" "book" "chapter")
672 end:
673 -->