Follow upstream changes -- Bytestring updates
[git-darcs-import.git] / tools / cgi / xslt / annotate.xslt
blob0a623af0379e2abb044fcc76f75801a981df35c7
1 <?xml version="1.0" encoding="utf-8"?>
3 <!--
4 template for converting darcs' `annotate` output from XML to XHTML. This
5 template expects the following external variables:
7 cgi-program - path to the CGI executable, to place in links
8 sort-by - field to sort by
9 stylesheet - path to the CSS stylesheet
11 -->
12 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
13 <xsl:strip-space elements="*"/>
15 <xsl:include href="common.xslt"/>
17 <xsl:template match="path">
18 <h1 class="target">
19 annotations for <span class="path"><a href="{$cgi-program}">projects</a></span> / <span class="path"><xsl:apply-templates/></span>
20 </h1>
21 </xsl:template>
23 <!-- patch annotate tags -->
24 <xsl:template match="/darcs/patch">
25 <xsl:call-template name="show-patch-info">
26 <xsl:with-param name="patch" select="."/>
27 <xsl:with-param name="show-comment" select="true()"/>
28 <xsl:with-param name="show-author" select="true()"/>
29 <xsl:with-param name="show-date" select="true()"/>
30 </xsl:call-template>
31 </xsl:template>
33 <xsl:template match="summary">
34 <xsl:variable name="hash" select="../patch/@hash"/>
36 <table>
37 <tr class="annotate">
38 <th>file</th>
39 <th>change</th>
40 <th></th>
41 <th></th>
42 </tr>
44 <xsl:apply-templates/>
45 </table>
47 <form action="{$command}" method="get">
48 <p>
49 <input type="submit" name="c" value="diff"/>
50 <input type="hidden" name="p" value="{$hash}"/>
51 </p>
52 </form>
53 </xsl:template>
55 <xsl:template match="modify_file">
56 <xsl:variable name="file" select="text()"/>
57 <xsl:variable name="hash" select="/darcs/patch/@hash" />
59 <tr class="modified-file">
60 <td><xsl:value-of select="$file"/></td>
62 <td class="line-count">
63 <xsl:for-each select="added_lines">
64 +<xsl:value-of select="@num"/>/
65 </xsl:for-each>
66 <xsl:for-each select="removed_lines">-<xsl:value-of select="@num"/>
67 </xsl:for-each>
68 lines
69 </td>
71 <td><a href="{$command}{$file}?c=annotate&amp;p={$hash}">annotate</a></td>
72 <td><a href="{$command}{$file}?c=patches">patches</a></td>
73 </tr>
74 </xsl:template>
76 <xsl:template match="add_file">
77 <xsl:variable name="file" select="text()"/>
78 <xsl:variable name="hash" select="/darcs/patch/@hash" />
80 <tr class="add-remove-file">
81 <td><xsl:value-of select="$file"/></td>
82 <td>added file</td>
83 <td><a href="{$command}{$file}?c=annotate&amp;p={$hash}">annotate</a></td>
84 <td><a href="{$command}{$file}?c=patches">patches</a></td>
85 </tr>
86 </xsl:template>
88 <xsl:template match="move">
89 <xsl:variable name="file" select="@to"/>
90 <xsl:variable name="old-file" select="@from"/>
91 <xsl:variable name="hash" select="/darcs/patch/@hash" />
93 <tr class="add-remove-file">
94 <td><xsl:value-of select="$file"/></td>
95 <td>moved from <xsl:value-of select="$old-file"/></td>
96 <td><a href="{$command}{$file}?c=annotate&amp;p={$hash}">annotate</a></td>
97 <td><a href="{$command}{$file}?c=patches">patches</a></td>
98 </tr>
99 </xsl:template>
101 <xsl:template match="remove_file">
102 <xsl:variable name="file" select="text()"/>
103 <xsl:variable name="hash" select="/darcs/patch/@hash" />
105 <tr class="add-remove-file">
106 <td><xsl:value-of select="$file"/></td>
107 <td>removed file</td>
108 <td><a href="{$command}{$file}?c=annotate&amp;p={$hash}">annotate</a></td>
109 <td><a href="{$command}{$file}?c=patches">patches</a></td>
110 </tr>
111 </xsl:template>
113 <xsl:template match="add_directory">
114 <xsl:variable name="dir" select="text()"/>
115 <xsl:variable name="hash" select="/darcs/patch/@hash" />
117 <tr class="add-remove-file">
118 <td><xsl:value-of select="$dir"/></td>
119 <td>added directory</td>
120 <td><a href="{$command}{$dir}/?c=annotate&amp;p={$hash}">annotate</a></td>
121 <td><a href="{$command}{$dir}/?c=patches">patches</a></td>
122 </tr>
123 </xsl:template>
125 <xsl:template match="remove_directory">
126 <xsl:variable name="dir" select="text()"/>
127 <xsl:variable name="hash" select="/darcs/patch/@hash" />
129 <tr class="add-remove-file">
130 <td><xsl:value-of select="$dir"/></td>
131 <td>removed directory</td>
132 <td><a href="{$command}{$dir}/?c=annotate&amp;p={$hash}">annotate</a></td>
133 <td><a href="{$command}{$dir}/?c=patches">patches</a></td>
134 </tr>
135 </xsl:template>
137 <!-- directory annotate templates -->
138 <xsl:template match="/darcs/directory">
139 <xsl:call-template name="show-patch-info">
140 <xsl:with-param name="patch" select="modified/patch"/>
141 </xsl:call-template>
143 <table>
144 <tr class="annotate">
145 <th>file</th>
146 <th>change</th>
147 <th></th>
148 <th></th>
149 </tr>
151 <xsl:apply-templates/>
152 </table>
153 </xsl:template>
155 <xsl:template match="directory/modified/modified_how">
156 <xsl:variable name="hash" select="../patch/@hash" />
157 <xsl:variable name="how" select="substring(text(), 0, 10)"/>
158 <xsl:variable name="target" select="/darcs/@target"/>
160 <!--
161 annotating a directory outputs the directory itself as well as
162 any contents. this ugly code checks if the matching element is
163 the original directory so that the 'annotate' and 'patch' links
164 don't append the directory twice.
166 <xsl:variable name="last" select="//darcs/path/directory[last()]"/>
167 <xsl:variable name="name" select="../../@name"/>
168 <xsl:variable name="dir">
169 <xsl:choose>
170 <xsl:when test="$last = $name"></xsl:when>
171 <xsl:otherwise><xsl:value-of select="$name"/>/</xsl:otherwise>
172 </xsl:choose>
173 </xsl:variable>
175 <tr class="add-remove-file">
176 <td><xsl:value-of select="$name"/></td>
177 <td>
178 <xsl:choose>
179 <xsl:when test="$how = 'Dir added'">added directory</xsl:when>
180 <xsl:when test="$how = 'Dir moved'">moved directory</xsl:when>
181 <xsl:when test="$how = 'Dir remov'">removed directory</xsl:when>
182 </xsl:choose>
183 </td>
184 <td>
185 <a href="{$command}{$dir}?c=annotate&amp;p={$hash}">annotate</a>
186 </td>
187 <td><a href="{$command}{$dir}?c=patches">patches</a></td>
188 </tr>
189 </xsl:template>
191 <xsl:template match="directory/file/modified/modified_how">
192 <xsl:variable name="file" select="../../@name"/>
193 <xsl:variable name="hash" select="../patch/@hash" />
194 <xsl:variable name="how" select="substring(text(), 0, 11)"/>
196 <tr class="add-remove-file">
197 <td><xsl:value-of select="$file"/></td>
198 <td>
199 <xsl:choose>
200 <xsl:when test="$how = 'File added'">added file</xsl:when>
201 <xsl:when test="$how = 'File moved'">moved file</xsl:when>
202 <xsl:when test="$how = 'File remov'">removed file</xsl:when>
203 </xsl:choose>
204 </td>
205 <td><a href="{$command}{$file}?c=annotate&amp;p={$hash}">annotate</a></td>
206 <td><a href="{$command}{$file}?c=patches">patches</a></td>
207 </tr>
208 </xsl:template>
210 <!-- file annotate templates -->
211 <xsl:template match="/darcs/file">
212 <xsl:variable name="modified_how" select="modified/modified_how/text()"/>
214 <xsl:call-template name="show-patch-info">
215 <xsl:with-param name="patch" select="modified/patch"/>
216 </xsl:call-template>
218 <!-- don't display table of changes when file's contents are modified -->
219 <xsl:if test="$modified_how != 'File modified'">
220 <xsl:variable name="file" select="@name"/>
221 <xsl:variable name="how" select="substring($modified_how, 0, 11)"/>
223 <xsl:variable name="annotate-href">
224 <xsl:call-template name="make-annotate-href">
225 <xsl:with-param name="hash" select="modified/patch/@hash"/>
226 </xsl:call-template>
227 </xsl:variable>
229 <table>
230 <tr class="annotate">
231 <th>file</th>
232 <th>change</th>
233 <th></th>
234 <th></th>
235 </tr>
237 <tr class="add-remove-file">
238 <td><xsl:value-of select="$file"/></td>
239 <td>
240 <xsl:choose>
241 <xsl:when test="$how = 'File added'">added file</xsl:when>
242 <xsl:when test="$how = 'File moved'">moved file</xsl:when>
243 <xsl:when test="$how = 'File remov'">removed file</xsl:when>
244 </xsl:choose>
245 </td>
246 <td><a href="{$annotate-href}">annotate</a></td>
247 <td><a href="{$command}?c=patches">patches</a></td>
248 </tr>
249 </table>
250 </xsl:if>
252 <!-- the empty <p/> element is a Konqueror bug workaround -->
253 <pre xml:space="preserve"><p/>
254 <xsl:apply-templates/>
255 </pre>
256 </xsl:template>
258 <xsl:template match="added_line">
259 <xsl:variable name="annotate-href">
260 <xsl:call-template name="make-annotate-href">
261 <xsl:with-param name="hash" select="preceding::modified/patch/@hash"/>
262 </xsl:call-template>
263 </xsl:variable>
265 <xsl:variable name="annotate-name" select="preceding::modified/patch/name"/>
266 <xsl:variable name="author" select="preceding::modified/patch/@author"/>
268 <a class="added-line" href="{$annotate-href}" title="added with '{$annotate-name}' by '{$author}'">
269 <pre><xsl:value-of select="text()"/></pre>
270 </a>
271 <xsl:call-template name="check-removed-by"/>
272 </xsl:template>
274 <xsl:template match="normal_line">
275 <xsl:variable name="annotate-href">
276 <xsl:call-template name="make-annotate-href">
277 <xsl:with-param name="hash" select="*/patch/@hash"/>
278 </xsl:call-template>
279 </xsl:variable>
281 <xsl:variable name="annotate-name" select="*/patch/name"/>
282 <xsl:variable name="author" select="*/patch/@author"/>
284 <a class="normal-line" href="{$annotate-href}" title="last changed with '{$annotate-name}' by '{$author}'">
285 <pre><xsl:value-of select="text()"/></pre>
286 </a>
287 <xsl:call-template name="check-removed-by"/>
288 </xsl:template>
290 <xsl:template match="removed_line">
291 <xsl:variable name="annotate-href">
292 <xsl:call-template name="make-annotate-href">
293 <xsl:with-param name="hash" select="*/patch/@hash"/>
294 </xsl:call-template>
295 </xsl:variable>
297 <xsl:variable name="annotate-name" select="*/patch/name"/>
298 <xsl:variable name="author" select="*/patch/@author"/>
300 <!-- don't display removed lines when a file is removed -->
301 <xsl:if test="../modified/modified_how/text() != 'File removed'">
303 <a class="removed-line" href="{$annotate-href}" title="removed with '{$annotate-name}' by '{$author}'">
304 <pre><xsl:value-of select="text()"/></pre>
305 </a>
306 <xsl:call-template name="check-removed-by"/>
307 </xsl:if>
308 </xsl:template>
310 <xsl:template name="check-removed-by">
311 <xsl:variable name="hash" select="removed_by/patch/@hash"/>
313 <xsl:variable name="annotate-href">
314 <xsl:call-template name="make-annotate-href">
315 <xsl:with-param name="hash" select="$hash"/>
316 </xsl:call-template>
317 </xsl:variable>
319 <xsl:choose>
320 <xsl:when test="$hash != ''">
321 <a class="removed-by" href="{$annotate-href}">-</a>
322 </xsl:when>
323 </xsl:choose>
325 <!-- put a newline after the hyperlink -->
326 <xsl:text xml:space="preserve">
327 </xsl:text>
328 </xsl:template>
330 <xsl:template name="show-patch-info">
331 <xsl:param name="patch"/>
332 <xsl:param name="show-comment"/>
333 <xsl:param name="show-author"/>
334 <xsl:param name="show-date"/>
336 <xsl:variable name="hash" select="$patch/@hash"/>
337 <xsl:variable name="name" select="$patch/name"/>
338 <xsl:variable name="author" select="$patch/@author"/>
339 <xsl:variable name="local_date" select="$patch/@local_date"/>
341 <h2 class="patch">
342 patch "<span class="path">
343 <a href="{$cgi-program}/{$repo}/?c=annotate&amp;p={$hash}">
344 <xsl:value-of select="$name"/>
345 </a>
346 </span>"
347 </h2>
349 <xsl:if test="$show-comment">
350 <xsl:if test="$patch/comment">
351 <h2 class="patch">
352 comment "<span class="comment">
353 <xsl:value-of select="$patch/comment"/>
354 </span>"
355 </h2>
356 </xsl:if>
357 </xsl:if>
359 <xsl:if test="$show-author">
360 <h2 class="author">
361 by <span class="author">
362 <xsl:value-of select="$patch/@author"/>
363 </span>
365 <xsl:if test="$show-date">
366 on <span class="local_date">
367 <xsl:value-of select="$patch/@local_date"/>
368 </span>
369 </xsl:if>
370 </h2>
371 </xsl:if>
373 </xsl:template>
375 <xsl:template name="make-annotate-href" xml:space="default">
376 <xsl:param name="hash"/>
378 <xsl:variable name="created-as" select="/darcs/*/created_as"/>
379 <xsl:variable name="creator-hash" select="$created-as/patch/@hash"/>
380 <xsl:variable name="original-name" select="$created-as/@original_name"/>
382 <xsl:value-of select="$command"/>?c=annotate&amp;p=<xsl:value-of select="$hash"/>&amp;ch=<xsl:value-of select="$creator-hash"/>&amp;o=<xsl:value-of select="$original-name"/>
383 </xsl:template>
385 <!-- ignore <name>, <comment> and <modified_how> children -->
386 <xsl:template match="name"/>
387 <xsl:template match="comment"/>
388 <xsl:template match="author"/>
389 <xsl:template match="modified_how"/>
390 </xsl:stylesheet>