3 # svn2cl.sh - front end shell script for svn2cl.xsl, calls xsltproc
4 # with the correct parameters
6 # Copyright (C) 2005, 2006, 2007, 2008 Arthur de Jong.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in
15 # the documentation and/or other materials provided with the
17 # 3. The name of the author may not be used to endorse or promote
18 # products derived from this software without specific prior
21 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 # exit on any failures
35 # report unset variables
41 # set default parameters
43 STRIPPREFIX
="AUTOMATICALLY-DETERMINED"
53 SVNLOGCMD
="svn --verbose --xml log"
56 IGNORE_MESSAGE_STARTING
=""
61 # do command line checking
68 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
71 STRIPPREFIX
=`echo "$1" | sed 's/^--[a-z-]*=//'`
76 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
79 LINELEN
=`echo "$1" | sed 's/^--[a-z-]*=//'`
98 --break-before-msg|
--breaks-before-msg)
99 # FIXME: if next argument is numeric use that as a parameter
103 --break-before-msg=*|
--breaks-before-msg=*)
104 BREAKBEFOREMSG
=`echo "$1" | sed 's/^--[a-z-]*=//'`
113 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
116 TITLE
=`echo "$1" | sed 's/^--[a-z-]*=//'`
121 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
124 REVISION_LINK
=`echo "$1" | sed 's/^--[a-z-]*=//'`
127 --ignore-message-starting)
128 IGNORE_MESSAGE_STARTING
="$2"
129 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
131 --ignore-message-starting=*)
132 IGNORE_MESSAGE_STARTING
=`echo "$1" | sed 's/^--[a-z-]*=//'`
135 -f|
--file|
-o|
--output)
137 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
140 CHANGELOG
=`echo "$1" | sed 's/^--[a-z-]*=//'`
149 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
152 AUTHORSFILE
=`echo "$1" | sed 's/^--[a-z-]*=//'`
159 -r|
--revision|
--targets|
--limit)
160 # add these as extra options to the command (with argument)
161 arg
=`echo "$2" | sed "s/'/'\"'\"'/g"`
162 SVNLOGCMD
="$SVNLOGCMD $1 '$arg'"
163 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
165 --username|
--password|
--config-dir)
166 # add these as extra options to the command (with argument)
167 arg
=`echo "$2" | sed "s/'/'\"'\"'/g"`
168 SVNLOGCMD
="$SVNLOGCMD $1 '$arg'"
169 # also add to svn info command
170 SVNINFOCMD
="$SVNINFOCMD $1 '$arg'"
171 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
173 --revision=*|
--targets=*|
--limit=*)
174 # these are single argument versions of the above
175 arg
=`echo "$1" | sed "s/'/'\"'\"'/g"`
176 SVNLOGCMD
="$SVNLOGCMD '$arg'"
179 --username=*|
--password=*|
--config-dir=*)
180 # these are single argument versions of the above
181 arg
=`echo "$1" | sed "s/'/'\"'\"'/g"`
182 SVNLOGCMD
="$SVNLOGCMD '$arg'"
183 # also add to svn info command
184 SVNINFOCMD
="$SVNINFOCMD '$arg'"
188 # add these as simple options
189 SVNLOGCMD
="$SVNLOGCMD $1"
192 --no-auth-cache|
--non-interactive)
193 # add these as simple options
194 SVNLOGCMD
="$SVNLOGCMD $1"
195 # also add to svn info command
196 SVNINFOCMD
="$SVNINFOCMD $1"
200 echo "$prog $VERSION";
201 echo "Written by Arthur de Jong."
203 echo "Copyright (C) 2005, 2006, 2007 Arthur de Jong."
204 echo "This is free software; see the source for copying conditions. There is NO"
205 echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
209 echo "Usage: $prog [OPTION]... [PATH]..."
210 echo "Generate a ChangeLog from a subversion repository."
212 echo " --strip-prefix=NAME prefix to strip from all entries, defaults"
213 echo " path inside the repository"
214 echo " --linelen=NUM maximum length of an output line"
215 echo " --group-by-day group changelog entries by day"
216 echo " --separate-daylogs put a blank line between grouped by day entries"
217 echo " -i, --include-rev include revision numbers"
218 echo " -a, --include-actions add [ADD], [DEL] and [CPY] tags to files"
219 echo " --break-before-msg[=NUM] add a line break (or multiple breaks)"
220 echo " between the paths and the log message"
221 echo " --reparagraph rewrap lines inside a paragraph"
222 echo " --title=NAME title used in html file"
223 echo " --revision-link=NAME link revision numbers in html output"
224 echo " --ignore-message-starting=STRING"
225 echo " ignore messages starting with the string"
226 echo " -o, --output=FILE output to FILE instead of ChangeLog"
227 echo " -f, --file=FILE alias for -o, --output"
228 echo " --stdout output to stdout instead of ChangeLog"
229 echo " --authors=FILE file to read for authors"
230 echo " --html output as html instead of plain text"
231 echo " -h, --help display this help and exit"
232 echo " -V, --version output version information and exit"
234 echo "PATH arguments and the following options are passed to the svn log"
235 echo "command: -r, --revision, --targets --stop-on-copy, --username,"
236 echo "--password, --no-auth-cache, --non-interactive, --config-dir and"
237 echo "--limit (see 'svn help log' for more information)."
241 echo "$prog: invalid option -- $1"
242 echo "Try '$prog --help' for more information."
246 arg
=`echo "$1" | sed "s/'/'\"'\"'/g"`
247 SVNLOGCMD
="$SVNLOGCMD '$arg'"
248 SVNINFOCMD
="$SVNINFOCMD '$arg'"
254 # find the directory that this script resides in
258 dir
=`dirname "$prog"`
259 prog
=`ls -ld "$prog" | sed "s/^.*-> \(.*\)/\1/;/^[^/]/s,^,$dir/,"`
261 dir
=`dirname "$prog"`
262 dir
=`cd "$dir" && pwd`
263 XSL
="$dir/svn2${OUTSTYLE}.xsl"
265 # check if the authors file is formatted as a legacy
266 # colon separated file
267 if [ -n "$AUTHORSFILE" ] && \
268 egrep '^(#.*|[a-zA-Z0-9].*:)' "$AUTHORSFILE" > /dev
/null
2>/dev
/null
270 # create a temporary file
271 tmpfile
=`mktemp -t svn2cl.XXXXXX 2> /dev/null || tempfile -s .svn2cl 2> /dev/null || echo "$AUTHORSFILE.$$.xml"`
272 arg
=`echo "$tmpfile" | sed "s/'/'\"'\"'/g"`
273 TMPFILES
="$TMPFILES '$arg'"
274 # generate an authors.xml file on the fly
275 echo '<authors>' > "$tmpfile"
276 sed -n 's/&/\&/g;s/</\</g;s/>/\>/g;s|^\([a-zA-Z0-9][^:]*\):\(.*\)$| <author uid="\1">\2</author>|p' \
277 < "$AUTHORSFILE" >> "$tmpfile"
278 echo '</authors>' >> "$tmpfile"
279 AUTHORSFILE
="$tmpfile"
282 # find the absolute path of the authors file
283 # (otherwise xsltproc will find the file relative to svn2cl.xsl)
285 AUTHORSFILE
=`echo "$AUTHORSFILE" | sed "/^[^/]/s|^|$pwd/|"`
287 # if no filename was specified, make one up
288 if [ -z "$CHANGELOG" ]
290 CHANGELOG
="ChangeLog"
291 [ "$OUTSTYLE" != "cl" ] && CHANGELOG
="$CHANGELOG.$OUTSTYLE"
294 # try to determin a prefix to strip from all paths
295 if [ "$STRIPPREFIX" = "AUTOMATICALLY-DETERMINED" ]
297 STRIPPREFIX
=`LANG=C eval "$SVNINFOCMD" 2> /dev/null | awk '/^URL:/{url=$2} /^Repository Root:/{root=$3} END{if(root){print substr(url,length(root)+2)}else{gsub("^.*/","",url);print url}}'`
298 STRIPPREFIX
=`echo "$STRIPPREFIX" | sed 's/%20/ /g'`
301 # redirect stdout to the changelog file if needed
302 if [ "x$CHANGELOG" != "x-" ]
307 # actually run the command we need
308 eval "$SVNLOGCMD" | \
309 xsltproc
--stringparam strip-prefix
"$STRIPPREFIX" \
310 --stringparam linelen
"$LINELEN" \
311 --stringparam groupbyday
"$GROUPBYDAY" \
312 --stringparam separate-daylogs
"$SEPARATEDAYLOGS" \
313 --stringparam include-rev
"$INCLUDEREV" \
314 --stringparam include-actions
"$ACTIONS" \
315 --stringparam breakbeforemsg
"$BREAKBEFOREMSG" \
316 --stringparam reparagraph
"$REPARAGRAPH" \
317 --stringparam authorsfile
"$AUTHORSFILE" \
318 --stringparam title
"$TITLE" \
319 --stringparam revision-link
"$REVISION_LINK" \
320 --stringparam ignore-message-starting
"$IGNORE_MESSAGE_STARTING" \
326 # clean up temporary files
327 [ -n "$TMPFILES" ] && eval "rm -f $TMPFILES"
329 # we're done (the previous command could return false)