+# figures what files need to have the svn:keywords set, and adds it when missing
+function run_keywords () {
+ for dir in $dirs; do
+ cd $here
+ if [ -d $dir ] ; then
+ cd $dir
+ echo "xxxxxxxxxxxxxxxxxxxx Fixing keywords props in $(pwd)"
+ echo -n "xxxxxxxxxx Gathering files under subversion "
+ svnfiles=$(svn list -R | grep -v '/$')
+
+ # handle this, as otherwise grep hangs on stdin
+ if [ -z "$svnfiles" ] ; then
+ echo "xxxxx Nothing applicable in $dir - skipping"
+ continue
+ fi
+
+ echo $(ls -1 $svnfiles | wc -l) files found
+
+ for keyword in $keywords ; do
+
+ files=$(grep -l '$'"$keyword" $svnfiles)
+ if [ -z "$files" ] ; then
+ echo "xxxxx No file found with \$$keyword"
+ continue
+ fi
+ nbfiles=$(ls -1 $files | wc -l)
+ echo "xxxxx Found" $nbfiles "with \$$keyword"
+
+ for file in $files ; do
+ run_keyword_on_file $keyword $file
+ done
+ done
+ else
+ for keyword in $keywords ; do
+ grep '$'"$keyword" $dir > /dev/null && run_keyword_on_file $keyword $dir
+ done
+ fi
+ done
+}
+
+# removes expansion of the specified keywords for diff
+# useful when comparing with another codebase
+function run_normalize_on_files () {
+ for keyword in $keywords ; do
+ echo "Deflating \$$keyword on $# files"
+ for file in "$@" ; do
+ sed -e 's,$'"$keyword"'.*\$,\$'"$keyword"'$,' $file > $file.new
+ mv $file.new $file
+ done
+ done
+}
+
+function run_normalize () {
+ for dir in $dirs; do
+ cd $here
+ if [ -d $dir ] ; then
+ cd $dir
+ echo "xxxxxxxxxxxxxxxxxxxx Normalizing keywords $keywords in $(pwd) "
+ echo -n "xxxxxxxxxx Gathering actual files under subversion "
+ svnfiles=$(svn list -R)
+
+ files=""
+ for scan in $svnfiles; do
+ if [ -d $scan ] ; then continue
+ elif [ -L $scan ] ; then continue
+ else files="$files $scan"
+ fi
+ done
+ echo $(ls -1 $files |wc -l) files found
+ run_normalize_on_files $files
+ echo Done
+ else
+ run_normalize_on_files $dir
+ fi
+ done
+}
+
+here=$(pwd -P)
+
+case $0 in
+ *keywords*)
+ run_keywords ;;
+ *normalize*)
+ run_normalize ;;
+ *)
+ echo Unsupported command $0 ;;
+esac