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