]> git.plutz.net Git - busy/blob - pages/Subversion.sh
upgraded to fit new shcgi revision, slightly better input validation, switched to...
[busy] / pages / Subversion.sh
1 #!/bin/sh
2
3 # Copyright 2014 Paul Hänsch
4 #
5 # This file is part of Busy
6
7 # Busy is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # Busy is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Busy. If not, see <http://www.gnu.org/licenses/>. 
19
20 url="$(echo "${_GET[i]}" |sed -rn '1{s:\t: :g;s:\r::g;s:\\:\\\\:g;s:/+:/:g;p}')"
21 rev="$(echo "${_GET[r]}" |sed -rn '1{/^[0-9]+$/p}')"
22 url="${url:-/}"
23
24 baseuri=$(sed -rn 's:^svnRepo=(.*)$:\1:p' project.meta)
25 lastrev=$(svn info "$baseuri" |sed -rn 's;^Revision: *([0-9]+);\1;p')
26 [ -z "$rev" ] && rev="$lastrev"
27
28 svn_path(){
29   tmp="${url%/*}" 
30   until [ "$tmp" = "${tmp#/}" ]; do
31     echo "<a href='?p=Subversion&amp;i=$tmp/&amp;r=$rev'>${tmp##*/}/</a> "
32     tmp="${tmp%/*}"
33   done \
34   | tac
35   echo "${url##*/}"
36 }
37
38 svn_revisions(){
39   for i in {1.."$lastrev"}; do
40     echo "<a href='?p=Subversion&amp;i=$url&amp;r=$i'>$i</a>"
41   done
42 }
43
44 svn_changelog(){
45   svn log "${baseuri}/${url}" \
46   | sed -rn '2,${s:^-+$:</div>:g;
47                  s:^r([0-9]+) \| ([a-zA-Z0-9]+) \| ([0-9: -]+) .+$:<div class="changelog"><h2>Revision \1 by \2<br>at \3</h2>:g;p}'
48 }
49
50 svn_showurl(){
51   if [ "${url%/}" != "$url" ]; then
52     # we are showing a directory
53     svn propget svn:externals -r "$rev" "${baseuri}/${url}" \
54     | sed -rn "s;^([^ ]+) (.+)$;<span class='extern'>\2/</span> [external include from <a href='\1'>\1</a>]<br>;p"
55
56     svn ls -r "$rev" "${baseuri}/${url}" \
57     | sed -r "s:^.*$:<a href='?p=Subversion\&amp;i=$url&\&amp;r=$rev'>&</a><br>:g"
58   else
59     # we are showing a file
60     if [ "$url" = "${url#*.}" ] && \
61        lang=txt \
62     || lang="$(source-highlight --lang-list |grep -o "^${url##*.} ")"
63     lang="${lang:-sh}"
64     lang="${lang% }"
65     svn cat -r "$rev" "${baseuri}/${url}" \
66     | source-highlight -s "$lang"
67   fi
68 }
69
70 case "$1" in
71   title)
72     echo "Code"
73   ;;
74   css)
75     cat ${_EXEC}/templates/Subversion.css
76   ;;
77   body)
78     #. ${_EXEC}/templates/text_subversion.sh
79     . ${_EXEC}/templates/Subversion.page
80   ;;
81 esac
82