]> git.plutz.net Git - busy/blobdiff - templates/Git.page
porting busy to confetti framework
[busy] / templates / Git.page
diff --git a/templates/Git.page b/templates/Git.page
new file mode 100755 (executable)
index 0000000..236f767
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/zsh
+url="$(sed -rn 's:\+: :g;s:%:\\x:g;s:^(.*&)?i=([^&]+)(&.*)?$:\2:p' <<<"${QUERY_STRING}")"
+url="$(echo -e "${url}" |sed -rn '1{s:\t: :g;s:\r::g;s:\\:\\\\:g;p}')"
+rev="$(sed -rn 's:\+: :g;s:%:\\x:g;s:^(.*&)?r=([0-9a-fA-F]+)(&.*)?$:\2:p' <<<"${QUERY_STRING}")"
+
+baseuri=$(sed -rn 's:^gitRepo=(.*)$:\1:p' project.meta)
+[ -z "$rev" ] && rev="HEAD"
+
+cat <<SVNEND
+  <div id="LEFT">
+    <h1>Path:</h1>
+    <a href='?p=Subversion&amp;i=/&amp;r=$rev'>[root]</a> 
+    $(tmp=$url
+    until [ -z "$tmp" -o "$tmp" = // ]; do
+      echo "<a href='?p=Git&amp;i=$tmp&amp;r=$rev'>/$(basename "$tmp")</a> "
+      tmp=$(dirname "$tmp")/
+    done |tac)
+    <hr><!----------------------------------------------->
+    <h1>Tags:</h1>
+    $(for i in {1.."$lastrev"}; do
+      echo "<a href='?p=Git&amp;i=$url&amp;r=$i'>$i</a>"
+    done)
+
+    <h1>Branches:</h1>
+    $(for i in {1.."$lastrev"}; do
+      echo "<a href='?p=Git&amp;i=$url&amp;r=$i'>$i</a>"
+    done)
+  </div>
+
+  <div id="RIGHT">
+    <h1>Changelog:</h1><hr>
+    $(svn log $(egrep -q '^(.*/|)$' <<<"$url" && echo '') "${baseuri}/${url}" |\
+      sed -rn '2,${s:^-+$:</div>:g;
+      s:^r([0-9]+) \| ([a-zA-Z0-9]+) \| ([0-9: -]+) .+$:<div class="changelog"><h2>Revision \1 by \2<br>at \3</h2>:g;p}')
+  </div>
+
+  <div id="MAIN">
+  <div class='wikitext'><h1>$(basename "$url"), Revision "$rev":</h1>
+  $(if (egrep -q '^(.*/|)$' <<<"$url"); then #are we showing a directory
+    svn ls -r "$rev" "${baseuri}/${url}" |sed -r "s:^.*$:<a href='?p=Subversion\&amp;i=$url/&\&amp;r=$rev'>&</a><br>:g"
+    echo '</div>'
+  else #or are we showing a file
+    lang=$(source-highlight --lang-list |cut -d\  -f1 |grep -x "$(sed 's:.*\.::g' <<<"$url")" || echo sh)
+    grep -q '\.' <<<"$url" || lang=txt
+    svn cat -r "$rev" "${baseuri}/${url}" |source-highlight -s "$lang"
+  fi)
+  </div></div>
+SVNEND