#!/bin/bash
# $Id$
+# $URL$
COMMAND=$(basename $0)
-
usage () {
- echo "Usage: $COMMAND keywords -- directories"
+ echo "Usage: $COMMAND keywords -- files or directories"
exit 1
}
usage
fi
-here=$(pwd -P)
-
-for dir in $dirs; do
-
- cd $here
- cd $dir
-
- echo "xxxxxxxxxxxxxxxxxxxx Working in $(pwd)"
-
- for keyword in $keywords ; do
-
- echo -n "xxxxxxxxxx Gathering files under subversion containing the keyword $keyword "
- files=$(grep -l '$'"$keyword" $(svn list -R))
- echo Done
-
- for file in $files ; do
-
- echo -n "$dir/$file "
-
- if [ ! -f $file ] ; then
+function run_keyword_on_file () {
+ file=$1; shift
+ echo -n "$file "
+ if [ ! -f $file ] ; then
echo "NOT FOUND - skipped"
continue
- fi
-
- current_keywords=$(svn propget svn:keywords $file)
- has_keyword=$(echo $current_keywords | grep $keyword)
-
- if [ -z "$has_keyword" ] ; then
+ fi
+ current_keywords=$(svn propget svn:keywords $file)
+ has_keyword=$(echo $current_keywords | grep $keyword)
+ if [ -z "$has_keyword" ] ; then
echo "+$keyword"
svn propset svn:keywords "$current_keywords $keyword" $file
- else
+ else
echo "="
- fi
+ fi
+}
+
+# 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)
+ echo $(ls -1 $svnfiles | wc -l) files found
+
+ for keyword in $keywords ; do
+
+ files=$(grep -l '$'"$keyword" $svnfiles)
+ nbfiles=$(ls -1 $files | wc -l)
+ echo Found $nbfiles with \$$keyword
+
+ for file in $files ; do
+ run_keywords_on_file $file
+ done
+ done
+ else
+ for keyword in $keywords ; do
+ run_keyword_on_file $dir
+ done
+ fi
done
+}
- 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"
+ sed -i -e 's,$'"$keyword"'.*\$,\$'"$keyword"'$,' "$@"
+ done
+}
+
+function run_normalize () {
+ for dir in $dirs; do
+ cd $here
+ if [ -d $dir ] ; then
+ cd $dir
+ echo "xxxxxxxxxxxxxxxxxxxx Normalizing keywords $keywords in $dir(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
+}
-done
+here=$(pwd -P)
+
+case $0 in
+ *keywords*)
+ run_keywords ;;
+ *normalize*)
+ run_normalize ;;
+ *)
+ echo Unsupported command $0 ;;
+esac