#!/bin/bash # # svnchache.sh - redirecting read-only svn to a (faster) cache repository # Copyright (C) 2007 Clifford Wolf # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. if [ "$*" = "sync" ]; then while read from to; do echo "Syncing $to.." svnsync sync $to done < <( grep -h '^[^#]' /etc/svncache $HOME/.svncache 2> /dev/null; ) exit 0 fi declare -a newargs found_url=0 error=0 sedscript=`mktemp` greplist=`mktemp` while read from to; do echo "s,^$from\(/\|$\),$to\1,;" >> "$sedscript" echo "^$to" >> "$greplist" done < <( grep -h '^[^#]' /etc/svncache $HOME/.svncache 2> /dev/null; ) translate_arg() { translated_arg="$1" url="$( LC_ALL=C svn info "$1" 2> /dev/null | grep '^URL: ' | cut -f2- -d' '; )" if [ -n "$url" ]; then found_url=1 newurl="$( echo "$url" | sed -f "$sedscript"; )" if echo "$newurl" | grep -qf "$greplist"; then translated_arg="$newurl" else echo "Can not translate: $url" >&2 error=1 fi fi } if [ $# != 0 -a "${1##-*}" != "" ]; then newargs=("$1") shift for arg in "$@"; do translate_arg "$arg" newargs=("${newargs[@]}" "$translated_arg") done if [ $found_url = 0 ]; then translate_arg "." newargs=("${newargs[@]}" "$translated_arg") fi fi rm -f "$sedscript" rm -f "$greplist" if [ $found_url = 0 -o $error = 1 ]; then { echo echo "Usage Example: $0 log -v -r300:600" echo echo "Example /etc/svnchache or ~/.svncache entry:" echo "http://svn.clifford.at/tools file:///data/svncache/clifford-tools" echo echo "Caches can be created and kept in sync with 'svnsync'." echo echo "The command '$0 sync' calls 'svnsync sync' for all caches."; echo }>&2 exit 1 fi exec svn "${newargs[@]}"