Fix compiler warning due to missing function prototype.
[svn.git] / contrib / client-side / svn2cl / svn2cl.sh
blob01153eade5b991060a4b37f0c0cf58f2b9b56292
1 #!/bin/sh
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
10 # are met:
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
16 # distribution.
17 # 3. The name of the author may not be used to endorse or promote
18 # products derived from this software without specific prior
19 # written permission.
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
34 set -e
35 # report unset variables
36 set -u
38 # svn2cl version
39 VERSION="0.10"
41 # set default parameters
42 PWD=`pwd`
43 STRIPPREFIX="AUTOMATICALLY-DETERMINED"
44 LINELEN=75
45 GROUPBYDAY="no"
46 INCLUDEREV="no"
47 BREAKBEFOREMSG="no"
48 REPARAGRAPH="no"
49 SEPARATEDAYLOGS="no"
50 ACTIONS="no"
51 CHANGELOG=""
52 OUTSTYLE="cl"
53 SVNLOGCMD="svn --verbose --xml log"
54 SVNINFOCMD="svn info"
55 AUTHORSFILE=""
56 IGNORE_MESSAGE_STARTING=""
57 TITLE="ChangeLog"
58 REVISION_LINK="#r"
59 TMPFILES=""
61 # do command line checking
62 prog=`basename $0`
63 while [ $# -gt 0 ]
65 case "$1" in
66 --strip-prefix)
67 STRIPPREFIX="$2"
68 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
70 --strip-prefix=*)
71 STRIPPREFIX=`echo "$1" | sed 's/^--[a-z-]*=//'`
72 shift
74 --linelen)
75 LINELEN="$2";
76 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
78 --linelen=*)
79 LINELEN=`echo "$1" | sed 's/^--[a-z-]*=//'`
80 shift
82 --group-by-day)
83 GROUPBYDAY="yes";
84 shift
86 --separate-daylogs)
87 SEPARATEDAYLOGS="yes"
88 shift
90 -i|--include-rev)
91 INCLUDEREV="yes";
92 shift
94 -a|--include-actions)
95 ACTIONS="yes"
96 shift
98 --break-before-msg|--breaks-before-msg)
99 # FIXME: if next argument is numeric use that as a parameter
100 BREAKBEFOREMSG="yes"
101 shift
103 --break-before-msg=*|--breaks-before-msg=*)
104 BREAKBEFOREMSG=`echo "$1" | sed 's/^--[a-z-]*=//'`
105 shift
107 --reparagraph)
108 REPARAGRAPH="yes"
109 shift
111 --title)
112 TITLE="$2"
113 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
115 --title=*)
116 TITLE=`echo "$1" | sed 's/^--[a-z-]*=//'`
117 shift
119 --revision-link)
120 REVISION_LINK="$2"
121 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
123 --revision-link=*)
124 REVISION_LINK=`echo "$1" | sed 's/^--[a-z-]*=//'`
125 shift
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-]*=//'`
133 shift
135 -f|--file|-o|--output)
136 CHANGELOG="$2"
137 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
139 --file=*|--output=*)
140 CHANGELOG=`echo "$1" | sed 's/^--[a-z-]*=//'`
141 shift
143 --stdout)
144 CHANGELOG="-"
145 shift
147 --authors)
148 AUTHORSFILE="$2"
149 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
151 --authors=*)
152 AUTHORSFILE=`echo "$1" | sed 's/^--[a-z-]*=//'`
153 shift
155 --html)
156 OUTSTYLE="html"
157 shift
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'"
177 shift
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'"
185 shift
187 --stop-on-copy)
188 # add these as simple options
189 SVNLOGCMD="$SVNLOGCMD $1"
190 shift
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"
197 shift
199 -V|--version)
200 echo "$prog $VERSION";
201 echo "Written by Arthur de Jong."
202 echo ""
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."
206 exit 0
208 -h|--help)
209 echo "Usage: $prog [OPTION]... [PATH]..."
210 echo "Generate a ChangeLog from a subversion repository."
211 echo ""
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"
233 echo ""
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)."
238 exit 0
241 echo "$prog: invalid option -- $1"
242 echo "Try '$prog --help' for more information."
243 exit 1
246 arg=`echo "$1" | sed "s/'/'\"'\"'/g"`
247 SVNLOGCMD="$SVNLOGCMD '$arg'"
248 SVNINFOCMD="$SVNINFOCMD '$arg'"
249 shift
251 esac
252 done
254 # find the directory that this script resides in
255 prog="$0"
256 while [ -h "$prog" ]
258 dir=`dirname "$prog"`
259 prog=`ls -ld "$prog" | sed "s/^.*-> \(.*\)/\1/;/^[^/]/s,^,$dir/,"`
260 done
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
269 then
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/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/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)
284 pwd=`pwd`
285 AUTHORSFILE=`echo "$AUTHORSFILE" | sed "/^[^/]/s|^|$pwd/|"`
287 # if no filename was specified, make one up
288 if [ -z "$CHANGELOG" ]
289 then
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" ]
296 then
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-" ]
303 then
304 exec > "$CHANGELOG"
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" \
321 --nowrite \
322 --nomkdir \
323 --nonet \
324 "$XSL" -
326 # clean up temporary files
327 [ -n "$TMPFILES" ] && eval "rm -f $TMPFILES"
329 # we're done (the previous command could return false)
330 exit 0