3 # svn2cl.sh - front end shell script for svn2cl.xsl, calls xsltproc
4 # with the correct parameters
6 # Copyright (C) 2005, 2006, 2007 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"
52 SVNLOGCMD
="svn --verbose --xml log"
55 IGNORE_MESSAGE_STARTING
=""
60 # do command line checking
67 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
70 STRIPPREFIX
=`echo "$1" | sed 's/^--[a-z-]*=//'`
75 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
78 LINELEN
=`echo "$1" | sed 's/^--[a-z-]*=//'`
93 --break-before-msg|
--breaks-before-msg)
94 # FIXME: if next argument is numeric use that as a parameter
98 --break-before-msg=*|
--breaks-before-msg=*)
99 BREAKBEFOREMSG
=`echo "$1" | sed 's/^--[a-z-]*=//'`
108 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
111 TITLE
=`echo "$1" | sed 's/^--[a-z-]*=//'`
116 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
119 REVISION_LINK
=`echo "$1" | sed 's/^--[a-z-]*=//'`
122 --ignore-message-starting)
123 IGNORE_MESSAGE_STARTING
="$2"
124 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
126 --ignore-message-starting=*)
127 IGNORE_MESSAGE_STARTING
=`echo "$1" | sed 's/^--[a-z-]*=//'`
130 -f|
--file|
-o|
--output)
132 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
135 CHANGELOG
=`echo "$1" | sed 's/^--[a-z-]*=//'`
144 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
147 AUTHORSFILE
=`echo "$1" | sed 's/^--[a-z-]*=//'`
154 -r|
--revision|
--targets|
--limit)
155 # add these as extra options to the command (with argument)
156 arg
=`echo "$2" | sed "s/'/'\"'\"'/g"`
157 SVNLOGCMD
="$SVNLOGCMD $1 '$arg'"
158 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
160 --username|
--password|
--config-dir)
161 # add these as extra options to the command (with argument)
162 arg
=`echo "$2" | sed "s/'/'\"'\"'/g"`
163 SVNLOGCMD
="$SVNLOGCMD $1 '$arg'"
164 # also add to svn info command
165 SVNINFOCMD
="$SVNINFOCMD $1 '$arg'"
166 shift 2 ||
{ echo "$prog: option requires an argument -- $1";exit 1; }
168 --revision=*|
--targets=*|
--limit=*)
169 # these are single argument versions of the above
170 arg
=`echo "$1" | sed "s/'/'\"'\"'/g"`
171 SVNLOGCMD
="$SVNLOGCMD '$arg'"
174 --username=*|
--password=*|
--config-dir=*)
175 # these are single argument versions of the above
176 arg
=`echo "$1" | sed "s/'/'\"'\"'/g"`
177 SVNLOGCMD
="$SVNLOGCMD '$arg'"
178 # also add to svn info command
179 SVNINFOCMD
="$SVNINFOCMD '$arg'"
183 # add these as simple options
184 SVNLOGCMD
="$SVNLOGCMD $1"
187 --no-auth-cache|
--non-interactive)
188 # add these as simple options
189 SVNLOGCMD
="$SVNLOGCMD $1"
190 # also add to svn info command
191 SVNINFOCMD
="$SVNINFOCMD $1"
195 echo "$prog $VERSION";
196 echo "Written by Arthur de Jong."
198 echo "Copyright (C) 2005, 2006, 2007 Arthur de Jong."
199 echo "This is free software; see the source for copying conditions. There is NO"
200 echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
204 echo "Usage: $prog [OPTION]... [PATH]..."
205 echo "Generate a ChangeLog from a subversion repository."
207 echo " --strip-prefix=NAME prefix to strip from all entries, defaults"
208 echo " path inside the repository"
209 echo " --linelen=NUM maximum length of an output line"
210 echo " --group-by-day group changelog entries by day"
211 echo " --separate-daylogs put a blank line between grouped by day entries"
212 echo " -i, --include-rev include revision numbers"
213 echo " --break-before-msg[=NUM] add a line break (or multiple breaks)"
214 echo " between the paths and the log message"
215 echo " --reparagraph rewrap lines inside a paragraph"
216 echo " --title=NAME title used in html file"
217 echo " --revision-link=NAME link revision numbers in html output"
218 echo " --ignore-message-starting=STRING"
219 echo " ignore messages starting with the string"
220 echo " -o, --output=FILE output to FILE instead of ChangeLog"
221 echo " -f, --file=FILE alias for -o, --output"
222 echo " --stdout output to stdout instead of ChangeLog"
223 echo " --authors=FILE file to read for authors"
224 echo " --html output as html instead of plain text"
225 echo " -h, --help display this help and exit"
226 echo " -V, --version output version information and exit"
228 echo "PATH arguments and the following options are passed to the svn log"
229 echo "command: -r, --revision, --targets --stop-on-copy, --username,"
230 echo "--password, --no-auth-cache, --non-interactive, --config-dir and"
231 echo "--limit (see \`svn help log' for more information)."
235 echo "$prog: invalid option -- $1"
236 echo "Try \`$prog --help' for more information."
240 arg
=`echo "$1" | sed "s/'/'\"'\"'/g"`
241 SVNLOGCMD
="$SVNLOGCMD '$arg'"
242 SVNINFOCMD
="$SVNINFOCMD '$arg'"
248 # find the directory that this script resides in
252 dir
=`dirname "$prog"`
253 prog
=`ls -ld "$prog" | sed "s/^.*-> \(.*\)/\1/;/^[^/]/s,^,$dir/,"`
255 dir
=`dirname "$prog"`
256 dir
=`cd "$dir" && pwd`
257 XSL
="$dir/svn2${OUTSTYLE}.xsl"
259 # check if the authors file is formatted as a legacy
260 # colon separated file
261 if [ -n "$AUTHORSFILE" ] && \
262 egrep '^(#.*|[a-zA-Z0-9].*:)' "$AUTHORSFILE" > /dev
/null
2>/dev
/null
264 # create a temporary file
265 tmpfile
=`mktemp -t svn2cl.XXXXXX 2> /dev/null || tempfile -s .svn2cl 2> /dev/null || echo "$AUTHORSFILE.$$.xml"`
266 arg
=`echo "$tmpfile" | sed "s/'/'\"'\"'/g"`
267 TMPFILES
="$TMPFILES '$arg'"
268 # generate an authors.xml file on the fly
269 echo '<authors>' > "$tmpfile"
270 sed -n 's/&/\&/g;s/</\</g;s/>/\>/g;s|^\([a-zA-Z0-9][^:]*\):\(.*\)$| <author uid="\1">\2</author>|p' \
271 < "$AUTHORSFILE" >> "$tmpfile"
272 echo '</authors>' >> "$tmpfile"
273 AUTHORSFILE
="$tmpfile"
276 # find the absolute path of the authors file
277 # (otherwise xsltproc will find the file relative to svn2cl.xsl)
279 AUTHORSFILE
=`echo "$AUTHORSFILE" | sed "/^[^/]/s|^|$pwd/|"`
281 # if no filename was specified, make one up
282 if [ -z "$CHANGELOG" ]
284 CHANGELOG
="ChangeLog"
285 [ "$OUTSTYLE" != "cl" ] && CHANGELOG
="$CHANGELOG.$OUTSTYLE"
288 # try to determin a prefix to strip from all paths
289 if [ "$STRIPPREFIX" = "AUTOMATICALLY-DETERMINED" ]
291 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}}'`
292 STRIPPREFIX
=`echo "$STRIPPREFIX" | sed 's/%20/ /g'`
295 # redirect stdout to the changelog file if needed
296 if [ "x$CHANGELOG" != "x-" ]
301 # actually run the command we need
302 eval "$SVNLOGCMD" | \
303 xsltproc
--stringparam strip-prefix
"$STRIPPREFIX" \
304 --stringparam linelen
"$LINELEN" \
305 --stringparam groupbyday
"$GROUPBYDAY" \
306 --stringparam separate-daylogs
"$SEPARATEDAYLOGS" \
307 --stringparam include-rev
"$INCLUDEREV" \
308 --stringparam breakbeforemsg
"$BREAKBEFOREMSG" \
309 --stringparam reparagraph
"$REPARAGRAPH" \
310 --stringparam authorsfile
"$AUTHORSFILE" \
311 --stringparam title
"$TITLE" \
312 --stringparam revision-link
"$REVISION_LINK" \
313 --stringparam ignore-message-starting
"$IGNORE_MESSAGE_STARTING" \
319 # clean up temporary files
320 [ -n "$TMPFILES" ] && eval "rm -f $TMPFILES"
322 # we're done (the previous command could return false)