Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / contrib / client-side / svn2cl / svn2cl.sh
blob928b10264f9f6f178e1e0c8c845759f41efa9374
1 #!/bin/sh
3 # svn2cl.sh - front end shell script for svn2cl.xsl, calls xsltproc
4 # with the correct parameters
5 #
6 # Copyright (C) 2005, 2006, 2007 Arthur de Jong.
7 #
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.9"
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 CHANGELOG=""
51 OUTSTYLE="cl"
52 SVNLOGCMD="svn --verbose --xml log"
53 SVNINFOCMD="svn info"
54 AUTHORSFILE=""
55 IGNORE_MESSAGE_STARTING=""
56 TITLE="ChangeLog"
57 REVISION_LINK="#r"
58 TMPFILES=""
60 # do command line checking
61 prog=`basename $0`
62 while [ $# -gt 0 ]
64 case "$1" in
65 --strip-prefix)
66 STRIPPREFIX="$2"
67 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
69 --strip-prefix=*)
70 STRIPPREFIX=`echo "$1" | sed 's/^--[a-z-]*=//'`
71 shift
73 --linelen)
74 LINELEN="$2";
75 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
77 --linelen=*)
78 LINELEN=`echo "$1" | sed 's/^--[a-z-]*=//'`
79 shift
81 --group-by-day)
82 GROUPBYDAY="yes";
83 shift
85 --separate-daylogs)
86 SEPARATEDAYLOGS="yes"
87 shift
89 -i|--include-rev)
90 INCLUDEREV="yes";
91 shift
93 --break-before-msg|--breaks-before-msg)
94 # FIXME: if next argument is numeric use that as a parameter
95 BREAKBEFOREMSG="yes"
96 shift
98 --break-before-msg=*|--breaks-before-msg=*)
99 BREAKBEFOREMSG=`echo "$1" | sed 's/^--[a-z-]*=//'`
100 shift
102 --reparagraph)
103 REPARAGRAPH="yes"
104 shift
106 --title)
107 TITLE="$2"
108 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
110 --title=*)
111 TITLE=`echo "$1" | sed 's/^--[a-z-]*=//'`
112 shift
114 --revision-link)
115 REVISION_LINK="$2"
116 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
118 --revision-link=*)
119 REVISION_LINK=`echo "$1" | sed 's/^--[a-z-]*=//'`
120 shift
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-]*=//'`
128 shift
130 -f|--file|-o|--output)
131 CHANGELOG="$2"
132 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
134 --file=*|--output=*)
135 CHANGELOG=`echo "$1" | sed 's/^--[a-z-]*=//'`
136 shift
138 --stdout)
139 CHANGELOG="-"
140 shift
142 --authors)
143 AUTHORSFILE="$2"
144 shift 2 || { echo "$prog: option requires an argument -- $1";exit 1; }
146 --authors=*)
147 AUTHORSFILE=`echo "$1" | sed 's/^--[a-z-]*=//'`
148 shift
150 --html)
151 OUTSTYLE="html"
152 shift
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'"
172 shift
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'"
180 shift
182 --stop-on-copy)
183 # add these as simple options
184 SVNLOGCMD="$SVNLOGCMD $1"
185 shift
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"
192 shift
194 -V|--version)
195 echo "$prog $VERSION";
196 echo "Written by Arthur de Jong."
197 echo ""
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."
201 exit 0
203 -h|--help)
204 echo "Usage: $prog [OPTION]... [PATH]..."
205 echo "Generate a ChangeLog from a subversion repository."
206 echo ""
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"
227 echo ""
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)."
232 exit 0
235 echo "$prog: invalid option -- $1"
236 echo "Try \`$prog --help' for more information."
237 exit 1
240 arg=`echo "$1" | sed "s/'/'\"'\"'/g"`
241 SVNLOGCMD="$SVNLOGCMD '$arg'"
242 SVNINFOCMD="$SVNINFOCMD '$arg'"
243 shift
245 esac
246 done
248 # find the directory that this script resides in
249 prog="$0"
250 while [ -h "$prog" ]
252 dir=`dirname "$prog"`
253 prog=`ls -ld "$prog" | sed "s/^.*-> \(.*\)/\1/;/^[^/]/s,^,$dir/,"`
254 done
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
263 then
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/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/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)
278 pwd=`pwd`
279 AUTHORSFILE=`echo "$AUTHORSFILE" | sed "/^[^/]/s|^|$pwd/|"`
281 # if no filename was specified, make one up
282 if [ -z "$CHANGELOG" ]
283 then
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" ]
290 then
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-" ]
297 then
298 exec > "$CHANGELOG"
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" \
314 --nowrite \
315 --nomkdir \
316 --nonet \
317 "$XSL" -
319 # clean up temporary files
320 [ -n "$TMPFILES" ] && eval "rm -f $TMPFILES"
322 # we're done (the previous command could return false)
323 exit 0