]> git.0d.be Git - empathy.git/blob - svn2cl.xsl
merge git work
[empathy.git] / svn2cl.xsl
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <!--
4
5    svn2cl.xsl - xslt stylesheet for converting svn log to a normal
6                 changelog
7
8    Usage (replace ++ with two minus signs):
9      svn ++verbose ++xml log | \
10        xsltproc ++stringparam strip-prefix `basename $(pwd)` \
11                 ++stringparam linelen 75 \
12                 ++stringparam groupbyday yes \
13                 ++stringparam include-rev yes \
14                 svn2cl.xsl - > ChangeLog
15
16    This file is based on several implementations of this conversion
17    that I was not completely happy with and some other common
18    xslt constructs found on the web.
19
20    Copyright (C) 2004, 2005 Arthur de Jong.
21
22    Redistribution and use in source and binary forms, with or without
23    modification, are permitted provided that the following conditions
24    are met:
25    1. Redistributions of source code must retain the above copyright
26       notice, this list of conditions and the following disclaimer.
27    2. Redistributions in binary form must reproduce the above copyright
28       notice, this list of conditions and the following disclaimer in
29       the documentation and/or other materials provided with the
30       distribution.
31    3. The name of the author may not be used to endorse or promote
32       products derived from this software without specific prior
33       written permission.
34
35    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
36    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
37    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38    ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
39    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41    GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
42    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
43    IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
44    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
45    IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46
47 -->
48
49 <!DOCTYPE page [
50  <!ENTITY tab "&#9;">
51  <!ENTITY newl "&#13;">
52  <!ENTITY space "&#32;">
53 ]>
54
55 <!--
56    TODO
57    - make external lookups of author names possible
58    - find a place for revision numbers
59    - mark deleted files as such
60    - combine paths
61    - make path formatting nicer
62 -->
63
64 <xsl:stylesheet
65   version="1.0"
66   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
67   xmlns="http://www.w3.org/1999/xhtml">
68
69  <xsl:output
70    method="text"
71    encoding="utf-8"
72    media-type="text/plain"
73    omit-xml-declaration="yes"
74    standalone="yes"
75    indent="no" />
76
77  <xsl:strip-space elements="*" />
78
79  <!-- the prefix of pathnames to strip -->
80  <xsl:param name="strip-prefix" select="'/'" />
81
82  <!-- the length of a line to wrap messages at -->
83  <xsl:param name="linelen" select="75" />
84  
85  <!-- whether entries should be grouped by day -->
86  <xsl:param name="groupbyday" select="'no'" />
87
88  <!-- whether entries should be grouped by day -->
89  <xsl:param name="include-rev" select="'no'" />
90
91  <!-- add newlines at the end of the changelog -->
92  <xsl:template match="log">
93   <xsl:apply-templates/>
94   <xsl:text>&newl;</xsl:text>
95  </xsl:template>
96
97  <!-- format one entry from the log -->
98  <xsl:template match="logentry">
99   <!-- save log entry number -->
100   <xsl:variable name="pos" select="position()"/>
101   <!-- fetch previous entry's date -->
102   <xsl:variable name="prevdate">
103    <xsl:apply-templates select="../logentry[position()=(($pos)-1)]/date"/>
104   </xsl:variable>
105   <!-- fetch previous entry's author -->
106   <xsl:variable name="prevauthor">
107    <xsl:apply-templates select="../logentry[position()=(($pos)-1)]/author"/>
108   </xsl:variable>
109   <!-- fetch this entry's date -->
110   <xsl:variable name="date">
111    <xsl:apply-templates select="date" />
112   </xsl:variable>
113   <!-- fetch this entry's author -->
114   <xsl:variable name="author">
115    <xsl:apply-templates select="author" />
116   </xsl:variable>
117   <!-- check if header is changed -->
118   <xsl:if test="($prevdate!=$date) or ($prevauthor!=$author)">
119    <!-- add newline -->
120    <xsl:if test="not(position()=1)">
121      <xsl:text>&newl;</xsl:text>
122    </xsl:if>
123    <!-- date -->
124    <xsl:apply-templates select="date" />
125    <!-- two spaces -->
126    <xsl:text>&space;&space;</xsl:text>
127    <!-- author's name -->
128    <xsl:apply-templates select="author" />
129    <!-- two newlines -->
130    <xsl:text>&newl;&newl;</xsl:text>
131   </xsl:if>
132   <!-- get paths string -->
133   <xsl:variable name="paths">
134    <xsl:apply-templates select="paths" />
135   </xsl:variable>
136   <!-- get revision number -->
137   <xsl:variable name="rev">
138    <xsl:if test="$include-rev='yes'">
139     <xsl:text>[r</xsl:text>
140     <xsl:value-of select="@revision"/>
141     <xsl:text>]&space;</xsl:text>
142    </xsl:if>
143   </xsl:variable>
144   <!-- first line is indented (other indents are done in wrap template) -->
145   <xsl:text>&tab;*&space;</xsl:text>
146   <!-- print the paths and message nicely wrapped -->
147   <xsl:call-template name="wrap">
148    <xsl:with-param name="txt" select="concat($rev,$paths,normalize-space(msg))" />
149   </xsl:call-template>
150  </xsl:template>
151
152  <!-- format date -->
153  <xsl:template match="date">
154   <xsl:variable name="date" select="normalize-space(.)" />
155   <!-- output date part -->
156   <xsl:value-of select="substring($date,1,10)" />
157   <!-- output time part -->
158   <xsl:if test="$groupbyday!='yes'">
159    <xsl:text>&space;</xsl:text>
160    <xsl:value-of select="substring($date,12,5)" />
161   </xsl:if>
162  </xsl:template>
163
164  <!-- format author -->
165  <xsl:template match="author">
166   <xsl:value-of select="normalize-space(.)" />
167  </xsl:template>
168
169  <!-- present a list of paths names -->
170  <xsl:template match="paths">
171   <xsl:for-each select="path">
172    <xsl:sort select="normalize-space(.)" data-type="text" />
173    <!-- unless we are the first entry, add a comma -->
174    <xsl:if test="not(position()=1)">
175     <xsl:text>,&space;</xsl:text>
176    </xsl:if>
177    <!-- print the path name -->
178    <xsl:apply-templates select="."/>
179   </xsl:for-each>
180   <!-- end the list with a colon -->
181   <xsl:text>:&space;</xsl:text>
182  </xsl:template>
183
184  <!-- transform path to something printable -->
185  <xsl:template match="path">
186   <!-- fetch the pathname -->
187   <xsl:variable name="p1" select="normalize-space(.)" />
188   <!-- strip leading slash -->
189   <xsl:variable name="p2">
190    <xsl:choose>
191     <xsl:when test="starts-with($p1,'/')">
192      <xsl:value-of select="substring($p1,2)" />
193     </xsl:when>
194     <xsl:otherwise>
195      <xsl:value-of select="$p1" />
196     </xsl:otherwise>
197    </xsl:choose>
198   </xsl:variable>
199   <!-- strip trailing slash from strip-prefix -->
200   <xsl:variable name="sp">
201    <xsl:choose>
202     <xsl:when test="substring($strip-prefix,string-length($strip-prefix),1)='/'">
203      <xsl:value-of select="substring($strip-prefix,1,string-length($strip-prefix)-1)" />
204     </xsl:when>
205     <xsl:otherwise>
206      <xsl:value-of select="$strip-prefix" />
207     </xsl:otherwise>
208    </xsl:choose>
209   </xsl:variable>
210   <!-- strip strip-prefix -->
211   <xsl:variable name="p3">
212    <xsl:choose>
213     <xsl:when test="starts-with($p2,$sp)">
214      <xsl:value-of select="substring($p2,1+string-length($sp))" />
215     </xsl:when>
216     <xsl:otherwise>
217      <!-- TODO: do not print strings that do not begin with strip-prefix -->
218      <xsl:value-of select="$p2" />
219     </xsl:otherwise>
220    </xsl:choose>
221   </xsl:variable>
222   <!-- strip another slash -->
223   <xsl:variable name="p4">
224    <xsl:choose>
225     <xsl:when test="starts-with($p3,'/')">
226      <xsl:value-of select="substring($p3,2)" />
227     </xsl:when>
228     <xsl:otherwise>
229      <xsl:value-of select="$p3" />
230     </xsl:otherwise>
231    </xsl:choose>
232   </xsl:variable>
233   <!-- translate empty string to dot -->
234   <xsl:choose>
235    <xsl:when test="$p4 = ''">
236     <xsl:text>.</xsl:text>
237    </xsl:when>
238    <xsl:otherwise>
239     <xsl:value-of select="$p4" />
240    </xsl:otherwise>
241   </xsl:choose>
242  </xsl:template>
243
244  <!-- string-wrapping template -->
245  <xsl:template name="wrap">
246   <xsl:param name="txt" />
247   <xsl:choose>
248    <xsl:when test="(string-length($txt) &lt; (($linelen)-9)) or not(contains($txt,' '))">
249     <!-- this is easy, nothing to do -->
250     <xsl:value-of select="$txt" />
251     <!-- add newline -->
252     <xsl:text>&newl;</xsl:text>
253    </xsl:when>
254    <xsl:otherwise>
255     <!-- find the first line -->
256     <xsl:variable name="tmp" select="substring($txt,1,(($linelen)-10))" />
257     <xsl:variable name="line">
258      <xsl:choose>
259       <xsl:when test="contains($tmp,' ')">
260        <xsl:call-template name="find-line">
261         <xsl:with-param name="txt" select="$tmp" />
262        </xsl:call-template>
263       </xsl:when>
264       <xsl:otherwise>
265        <xsl:value-of select="substring-before($txt,' ')" />
266       </xsl:otherwise>
267      </xsl:choose>
268     </xsl:variable>
269     <!-- print newline and tab -->
270     <xsl:value-of select="$line" />
271     <xsl:text>&newl;&tab;&space;&space;</xsl:text>
272     <!-- wrap the rest of the text -->
273     <xsl:call-template name="wrap">
274      <xsl:with-param name="txt" select="normalize-space(substring($txt,string-length($line)+1))" />
275     </xsl:call-template>
276    </xsl:otherwise>
277   </xsl:choose>
278  </xsl:template>
279
280  <!-- template to trim line to contain space as last char -->
281  <xsl:template name="find-line">
282   <xsl:param name="txt" />
283   <xsl:choose>
284    <xsl:when test="substring($txt,string-length($txt),1) = ' '">
285     <xsl:value-of select="normalize-space($txt)" />
286    </xsl:when>
287    <xsl:otherwise>
288     <xsl:call-template name="find-line">
289      <xsl:with-param name="txt" select="substring($txt,1,string-length($txt)-1)" />
290     </xsl:call-template>
291    </xsl:otherwise>
292   </xsl:choose>
293  </xsl:template>
294
295 </xsl:stylesheet>