annotate es/template.tex @ 501:b05e35d641e4

Copying the files from en to es and taking intro chapter
author Igor TAmara <igor@tamarapatino.org>
date Fri, 07 Nov 2008 21:42:57 -0500
parents 04c08ad7e92e
children 012631b248de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
501
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
1 \chapter{Customising the output of Mercurial}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
2 \label{chap:template}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
3
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
4 Mercurial provides a powerful mechanism to let you control how it
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
5 displays information. The mechanism is based on templates. You can
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
6 use templates to generate specific output for a single command, or to
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
7 customise the entire appearance of the built-in web interface.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
8
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
9 \section{Using precanned output styles}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
10 \label{sec:style}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
11
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
12 Packaged with Mercurial are some output styles that you can use
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
13 immediately. A style is simply a precanned template that someone
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
14 wrote and installed somewhere that Mercurial can find.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
15
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
16 Before we take a look at Mercurial's bundled styles, let's review its
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
17 normal output.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
18
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
19 \interaction{template.simple.normal}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
20
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
21 This is somewhat informative, but it takes up a lot of space---five
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
22 lines of output per changeset. The \texttt{compact} style reduces
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
23 this to three lines, presented in a sparse manner.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
24
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
25 \interaction{template.simple.compact}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
26
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
27 The \texttt{changelog} style hints at the expressive power of
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
28 Mercurial's templating engine. This style attempts to follow the GNU
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
29 Project's changelog guidelines\cite{web:changelog}.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
30
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
31 \interaction{template.simple.changelog}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
32
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
33 You will not be shocked to learn that Mercurial's default output style
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
34 is named \texttt{default}.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
35
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
36 \subsection{Setting a default style}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
37
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
38 You can modify the output style that Mercurial will use for every
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
39 command by editing your \hgrc\ file, naming the style you would
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
40 prefer to use.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
41
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
42 \begin{codesample2}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
43 [ui]
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
44 style = compact
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
45 \end{codesample2}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
46
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
47 If you write a style of your own, you can use it by either providing
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
48 the path to your style file, or copying your style file into a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
49 location where Mercurial can find it (typically the \texttt{templates}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
50 subdirectory of your Mercurial install directory).
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
51
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
52 \section{Commands that support styles and templates}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
53
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
54 All of Mercurial's ``\texttt{log}-like'' commands let you use styles
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
55 and templates: \hgcmd{incoming}, \hgcmd{log}, \hgcmd{outgoing}, and
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
56 \hgcmd{tip}.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
57
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
58 As I write this manual, these are so far the only commands that
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
59 support styles and templates. Since these are the most important
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
60 commands that need customisable output, there has been little pressure
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
61 from the Mercurial user community to add style and template support to
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
62 other commands.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
63
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
64 \section{The basics of templating}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
65
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
66 At its simplest, a Mercurial template is a piece of text. Some of the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
67 text never changes, while other parts are \emph{expanded}, or replaced
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
68 with new text, when necessary.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
69
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
70 Before we continue, let's look again at a simple example of
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
71 Mercurial's normal output.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
72
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
73 \interaction{template.simple.normal}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
74
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
75 Now, let's run the same command, but using a template to change its
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
76 output.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
77
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
78 \interaction{template.simple.simplest}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
79
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
80 The example above illustrates the simplest possible template; it's
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
81 just a piece of static text, printed once for each changeset. The
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
82 \hgopt{log}{--template} option to the \hgcmd{log} command tells
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
83 Mercurial to use the given text as the template when printing each
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
84 changeset.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
85
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
86 Notice that the template string above ends with the text
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
87 ``\Verb+\n+''. This is an \emph{escape sequence}, telling Mercurial
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
88 to print a newline at the end of each template item. If you omit this
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
89 newline, Mercurial will run each piece of output together. See
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
90 section~\ref{sec:template:escape} for more details of escape sequences.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
91
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
92 A template that prints a fixed string of text all the time isn't very
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
93 useful; let's try something a bit more complex.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
94
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
95 \interaction{template.simple.simplesub}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
96
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
97 As you can see, the string ``\Verb+{desc}+'' in the template has been
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
98 replaced in the output with the description of each changeset. Every
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
99 time Mercurial finds text enclosed in curly braces (``\texttt{\{}''
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
100 and ``\texttt{\}}''), it will try to replace the braces and text with
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
101 the expansion of whatever is inside. To print a literal curly brace,
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
102 you must escape it, as described in section~\ref{sec:template:escape}.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
103
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
104 \section{Common template keywords}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
105 \label{sec:template:keyword}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
106
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
107 You can start writing simple templates immediately using the keywords
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
108 below.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
109
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
110 \begin{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
111 \item[\tplkword{author}] String. The unmodified author of the changeset.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
112 \item[\tplkword{branches}] String. The name of the branch on which
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
113 the changeset was committed. Will be empty if the branch name was
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
114 \texttt{default}.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
115 \item[\tplkword{date}] Date information. The date when the changeset
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
116 was committed. This is \emph{not} human-readable; you must pass it
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
117 through a filter that will render it appropriately. See
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
118 section~\ref{sec:template:filter} for more information on filters.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
119 The date is expressed as a pair of numbers. The first number is a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
120 Unix UTC timestamp (seconds since January 1, 1970); the second is
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
121 the offset of the committer's timezone from UTC, in seconds.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
122 \item[\tplkword{desc}] String. The text of the changeset description.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
123 \item[\tplkword{files}] List of strings. All files modified, added, or
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
124 removed by this changeset.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
125 \item[\tplkword{file\_adds}] List of strings. Files added by this
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
126 changeset.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
127 \item[\tplkword{file\_dels}] List of strings. Files removed by this
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
128 changeset.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
129 \item[\tplkword{node}] String. The changeset identification hash, as a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
130 40-character hexadecimal string.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
131 \item[\tplkword{parents}] List of strings. The parents of the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
132 changeset.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
133 \item[\tplkword{rev}] Integer. The repository-local changeset revision
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
134 number.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
135 \item[\tplkword{tags}] List of strings. Any tags associated with the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
136 changeset.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
137 \end{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
138
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
139 A few simple experiments will show us what to expect when we use these
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
140 keywords; you can see the results in
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
141 figure~\ref{fig:template:keywords}.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
142
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
143 \begin{figure}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
144 \interaction{template.simple.keywords}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
145 \caption{Template keywords in use}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
146 \label{fig:template:keywords}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
147 \end{figure}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
148
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
149 As we noted above, the date keyword does not produce human-readable
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
150 output, so we must treat it specially. This involves using a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
151 \emph{filter}, about which more in section~\ref{sec:template:filter}.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
152
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
153 \interaction{template.simple.datekeyword}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
154
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
155 \section{Escape sequences}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
156 \label{sec:template:escape}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
157
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
158 Mercurial's templating engine recognises the most commonly used escape
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
159 sequences in strings. When it sees a backslash (``\Verb+\+'')
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
160 character, it looks at the following character and substitutes the two
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
161 characters with a single replacement, as described below.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
162
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
163 \begin{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
164 \item[\Verb+\textbackslash\textbackslash+] Backslash, ``\Verb+\+'',
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
165 ASCII~134.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
166 \item[\Verb+\textbackslash n+] Newline, ASCII~12.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
167 \item[\Verb+\textbackslash r+] Carriage return, ASCII~15.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
168 \item[\Verb+\textbackslash t+] Tab, ASCII~11.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
169 \item[\Verb+\textbackslash v+] Vertical tab, ASCII~13.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
170 \item[\Verb+\textbackslash \{+] Open curly brace, ``\Verb+{+'', ASCII~173.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
171 \item[\Verb+\textbackslash \}+] Close curly brace, ``\Verb+}+'', ASCII~175.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
172 \end{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
173
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
174 As indicated above, if you want the expansion of a template to contain
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
175 a literal ``\Verb+\+'', ``\Verb+{+'', or ``\Verb+{+'' character, you
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
176 must escape it.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
177
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
178 \section{Filtering keywords to change their results}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
179 \label{sec:template:filter}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
180
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
181 Some of the results of template expansion are not immediately easy to
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
182 use. Mercurial lets you specify an optional chain of \emph{filters}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
183 to modify the result of expanding a keyword. You have already seen a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
184 common filter, \tplkwfilt{date}{isodate}, in action above, to make a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
185 date readable.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
186
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
187 Below is a list of the most commonly used filters that Mercurial
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
188 supports. While some filters can be applied to any text, others can
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
189 only be used in specific circumstances. The name of each filter is
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
190 followed first by an indication of where it can be used, then a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
191 description of its effect.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
192
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
193 \begin{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
194 \item[\tplfilter{addbreaks}] Any text. Add an XHTML ``\Verb+<br/>+''
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
195 tag before the end of every line except the last. For example,
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
196 ``\Verb+foo\nbar+'' becomes ``\Verb+foo<br/>\nbar+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
197 \item[\tplkwfilt{date}{age}] \tplkword{date} keyword. Render the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
198 age of the date, relative to the current time. Yields a string like
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
199 ``\Verb+10 minutes+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
200 \item[\tplfilter{basename}] Any text, but most useful for the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
201 \tplkword{files} keyword and its relatives. Treat the text as a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
202 path, and return the basename. For example, ``\Verb+foo/bar/baz+''
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
203 becomes ``\Verb+baz+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
204 \item[\tplkwfilt{date}{date}] \tplkword{date} keyword. Render a date
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
205 in a similar format to the Unix \tplkword{date} command, but with
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
206 timezone included. Yields a string like
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
207 ``\Verb+Mon Sep 04 15:13:13 2006 -0700+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
208 \item[\tplkwfilt{author}{domain}] Any text, but most useful for the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
209 \tplkword{author} keyword. Finds the first string that looks like
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
210 an email address, and extract just the domain component. For
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
211 example, ``\Verb+Bryan O'Sullivan <bos@serpentine.com>+'' becomes
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
212 ``\Verb+serpentine.com+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
213 \item[\tplkwfilt{author}{email}] Any text, but most useful for the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
214 \tplkword{author} keyword. Extract the first string that looks like
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
215 an email address. For example,
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
216 ``\Verb+Bryan O'Sullivan <bos@serpentine.com>+'' becomes
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
217 ``\Verb+bos@serpentine.com+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
218 \item[\tplfilter{escape}] Any text. Replace the special XML/XHTML
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
219 characters ``\Verb+&+'', ``\Verb+<+'' and ``\Verb+>+'' with
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
220 XML entities.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
221 \item[\tplfilter{fill68}] Any text. Wrap the text to fit in 68
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
222 columns. This is useful before you pass text through the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
223 \tplfilter{tabindent} filter, and still want it to fit in an
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
224 80-column fixed-font window.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
225 \item[\tplfilter{fill76}] Any text. Wrap the text to fit in 76
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
226 columns.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
227 \item[\tplfilter{firstline}] Any text. Yield the first line of text,
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
228 without any trailing newlines.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
229 \item[\tplkwfilt{date}{hgdate}] \tplkword{date} keyword. Render the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
230 date as a pair of readable numbers. Yields a string like
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
231 ``\Verb+1157407993 25200+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
232 \item[\tplkwfilt{date}{isodate}] \tplkword{date} keyword. Render the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
233 date as a text string in ISO~8601 format. Yields a string like
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
234 ``\Verb+2006-09-04 15:13:13 -0700+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
235 \item[\tplfilter{obfuscate}] Any text, but most useful for the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
236 \tplkword{author} keyword. Yield the input text rendered as a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
237 sequence of XML entities. This helps to defeat some particularly
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
238 stupid screen-scraping email harvesting spambots.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
239 \item[\tplkwfilt{author}{person}] Any text, but most useful for the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
240 \tplkword{author} keyword. Yield the text before an email address.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
241 For example, ``\Verb+Bryan O'Sullivan <bos@serpentine.com>+''
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
242 becomes ``\Verb+Bryan O'Sullivan+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
243 \item[\tplkwfilt{date}{rfc822date}] \tplkword{date} keyword. Render a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
244 date using the same format used in email headers. Yields a string
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
245 like ``\Verb+Mon, 04 Sep 2006 15:13:13 -0700+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
246 \item[\tplkwfilt{node}{short}] Changeset hash. Yield the short form
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
247 of a changeset hash, i.e.~a 12-byte hexadecimal string.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
248 \item[\tplkwfilt{date}{shortdate}] \tplkword{date} keyword. Render
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
249 the year, month, and day of the date. Yields a string like
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
250 ``\Verb+2006-09-04+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
251 \item[\tplfilter{strip}] Any text. Strip all leading and trailing
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
252 whitespace from the string.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
253 \item[\tplfilter{tabindent}] Any text. Yield the text, with every line
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
254 except the first starting with a tab character.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
255 \item[\tplfilter{urlescape}] Any text. Escape all characters that are
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
256 considered ``special'' by URL parsers. For example, \Verb+foo bar+
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
257 becomes \Verb+foo%20bar+.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
258 \item[\tplkwfilt{author}{user}] Any text, but most useful for the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
259 \tplkword{author} keyword. Return the ``user'' portion of an email
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
260 address. For example,
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
261 ``\Verb+Bryan O'Sullivan <bos@serpentine.com>+'' becomes
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
262 ``\Verb+bos+''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
263 \end{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
264
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
265 \begin{figure}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
266 \interaction{template.simple.manyfilters}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
267 \caption{Template filters in action}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
268 \label{fig:template:filters}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
269 \end{figure}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
270
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
271 \begin{note}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
272 If you try to apply a filter to a piece of data that it cannot
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
273 process, Mercurial will fail and print a Python exception. For
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
274 example, trying to run the output of the \tplkword{desc} keyword
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
275 into the \tplkwfilt{date}{isodate} filter is not a good idea.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
276 \end{note}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
277
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
278 \subsection{Combining filters}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
279
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
280 It is easy to combine filters to yield output in the form you would
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
281 like. The following chain of filters tidies up a description, then
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
282 makes sure that it fits cleanly into 68 columns, then indents it by a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
283 further 8~characters (at least on Unix-like systems, where a tab is
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
284 conventionally 8~characters wide).
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
285
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
286 \interaction{template.simple.combine}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
287
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
288 Note the use of ``\Verb+\t+'' (a tab character) in the template to
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
289 force the first line to be indented; this is necessary since
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
290 \tplkword{tabindent} indents all lines \emph{except} the first.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
291
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
292 Keep in mind that the order of filters in a chain is significant. The
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
293 first filter is applied to the result of the keyword; the second to
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
294 the result of the first filter; and so on. For example, using
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
295 \Verb+fill68|tabindent+ gives very different results from
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
296 \Verb+tabindent|fill68+.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
297
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
298
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
299 \section{From templates to styles}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
300
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
301 A command line template provides a quick and simple way to format some
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
302 output. Templates can become verbose, though, and it's useful to be
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
303 able to give a template a name. A style file is a template with a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
304 name, stored in a file.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
305
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
306 More than that, using a style file unlocks the power of Mercurial's
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
307 templating engine in ways that are not possible using the command line
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
308 \hgopt{log}{--template} option.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
309
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
310 \subsection{The simplest of style files}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
311
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
312 Our simple style file contains just one line:
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
313
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
314 \interaction{template.simple.rev}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
315
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
316 This tells Mercurial, ``if you're printing a changeset, use the text
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
317 on the right as the template''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
318
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
319 \subsection{Style file syntax}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
320
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
321 The syntax rules for a style file are simple.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
322
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
323 \begin{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
324 \item The file is processed one line at a time.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
325
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
326 \item Leading and trailing white space are ignored.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
327
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
328 \item Empty lines are skipped.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
329
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
330 \item If a line starts with either of the characters ``\texttt{\#}'' or
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
331 ``\texttt{;}'', the entire line is treated as a comment, and skipped
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
332 as if empty.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
333
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
334 \item A line starts with a keyword. This must start with an
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
335 alphabetic character or underscore, and can subsequently contain any
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
336 alphanumeric character or underscore. (In regexp notation, a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
337 keyword must match \Verb+[A-Za-z_][A-Za-z0-9_]*+.)
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
338
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
339 \item The next element must be an ``\texttt{=}'' character, which can
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
340 be preceded or followed by an arbitrary amount of white space.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
341
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
342 \item If the rest of the line starts and ends with matching quote
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
343 characters (either single or double quote), it is treated as a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
344 template body.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
345
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
346 \item If the rest of the line \emph{does not} start with a quote
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
347 character, it is treated as the name of a file; the contents of this
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
348 file will be read and used as a template body.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
349 \end{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
350
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
351 \section{Style files by example}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
352
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
353 To illustrate how to write a style file, we will construct a few by
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
354 example. Rather than provide a complete style file and walk through
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
355 it, we'll mirror the usual process of developing a style file by
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
356 starting with something very simple, and walking through a series of
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
357 successively more complete examples.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
358
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
359 \subsection{Identifying mistakes in style files}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
360
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
361 If Mercurial encounters a problem in a style file you are working on,
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
362 it prints a terse error message that, once you figure out what it
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
363 means, is actually quite useful.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
364
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
365 \interaction{template.svnstyle.syntax.input}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
366
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
367 Notice that \filename{broken.style} attempts to define a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
368 \texttt{changeset} keyword, but forgets to give any content for it.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
369 When instructed to use this style file, Mercurial promptly complains.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
370
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
371 \interaction{template.svnstyle.syntax.error}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
372
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
373 This error message looks intimidating, but it is not too hard to
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
374 follow.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
375
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
376 \begin{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
377 \item The first component is simply Mercurial's way of saying ``I am
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
378 giving up''.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
379 \begin{codesample4}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
380 \textbf{abort:} broken.style:1: parse error
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
381 \end{codesample4}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
382
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
383 \item Next comes the name of the style file that contains the error.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
384 \begin{codesample4}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
385 abort: \textbf{broken.style}:1: parse error
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
386 \end{codesample4}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
387
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
388 \item Following the file name is the line number where the error was
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
389 encountered.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
390 \begin{codesample4}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
391 abort: broken.style:\textbf{1}: parse error
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
392 \end{codesample4}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
393
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
394 \item Finally, a description of what went wrong.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
395 \begin{codesample4}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
396 abort: broken.style:1: \textbf{parse error}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
397 \end{codesample4}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
398 The description of the problem is not always clear (as in this
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
399 case), but even when it is cryptic, it is almost always trivial to
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
400 visually inspect the offending line in the style file and see what
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
401 is wrong.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
402 \end{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
403
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
404 \subsection{Uniquely identifying a repository}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
405
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
406 If you would like to be able to identify a Mercurial repository
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
407 ``fairly uniquely'' using a short string as an identifier, you can
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
408 use the first revision in the repository.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
409 \interaction{template.svnstyle.id}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
410 This is not guaranteed to be unique, but it is nevertheless useful in
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
411 many cases.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
412 \begin{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
413 \item It will not work in a completely empty repository, because such
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
414 a repository does not have a revision~zero.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
415 \item Neither will it work in the (extremely rare) case where a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
416 repository is a merge of two or more formerly independent
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
417 repositories, and you still have those repositories around.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
418 \end{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
419 Here are some uses to which you could put this identifier:
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
420 \begin{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
421 \item As a key into a table for a database that manages repositories
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
422 on a server.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
423 \item As half of a \{\emph{repository~ID}, \emph{revision~ID}\} tuple.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
424 Save this information away when you run an automated build or other
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
425 activity, so that you can ``replay'' the build later if necessary.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
426 \end{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
427
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
428 \subsection{Mimicking Subversion's output}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
429
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
430 Let's try to emulate the default output format used by another
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
431 revision control tool, Subversion.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
432 \interaction{template.svnstyle.short}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
433
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
434 Since Subversion's output style is fairly simple, it is easy to
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
435 copy-and-paste a hunk of its output into a file, and replace the text
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
436 produced above by Subversion with the template values we'd like to see
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
437 expanded.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
438 \interaction{template.svnstyle.template}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
439
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
440 There are a few small ways in which this template deviates from the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
441 output produced by Subversion.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
442 \begin{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
443 \item Subversion prints a ``readable'' date (the ``\texttt{Wed, 27 Sep
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
444 2006}'' in the example output above) in parentheses. Mercurial's
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
445 templating engine does not provide a way to display a date in this
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
446 format without also printing the time and time zone.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
447 \item We emulate Subversion's printing of ``separator'' lines full of
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
448 ``\texttt{-}'' characters by ending the template with such a line.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
449 We use the templating engine's \tplkword{header} keyword to print a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
450 separator line as the first line of output (see below), thus
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
451 achieving similar output to Subversion.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
452 \item Subversion's output includes a count in the header of the number
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
453 of lines in the commit message. We cannot replicate this in
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
454 Mercurial; the templating engine does not currently provide a filter
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
455 that counts the number of items it is passed.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
456 \end{itemize}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
457 It took me no more than a minute or two of work to replace literal
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
458 text from an example of Subversion's output with some keywords and
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
459 filters to give the template above. The style file simply refers to
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
460 the template.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
461 \interaction{template.svnstyle.style}
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
462
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
463 We could have included the text of the template file directly in the
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
464 style file by enclosing it in quotes and replacing the newlines with
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
465 ``\verb!\n!'' sequences, but it would have made the style file too
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
466 difficult to read. Readability is a good guide when you're trying to
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
467 decide whether some text belongs in a style file, or in a template
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
468 file that the style file points to. If the style file will look too
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
469 big or cluttered if you insert a literal piece of text, drop it into a
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
470 template instead.
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
471
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
472 %%% Local Variables:
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
473 %%% mode: latex
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
474 %%% TeX-master: "00book"
b05e35d641e4 Copying the files from en to es and taking intro chapter
Igor TAmara <igor@tamarapatino.org>
parents: 432
diff changeset
475 %%% End: