turn off f24 build
[infrastructure.git] / scripts / svn-keywords.sh
index 036e7fa..caa4cb9 100755 (executable)
@@ -1,12 +1,10 @@
 #!/bin/bash
-# $Id$
 
 COMMAND=$(basename $0)
 
-
 usage () {
 
-   echo "Usage: $COMMAND keywords -- directories"
+   echo "Usage: $COMMAND keywords -- files or directories"
    exit 1
 
 }
@@ -37,41 +35,108 @@ if [ "$mode" == keywords -o -z "$dirs" -o -z "$keywords" ] ; then
   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 () {
+    keyword=$1; shift
+    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 | 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
+}
 
-  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
+}
 
-done
+here=$(pwd -P)
+
+case $0 in
+    *keywords*)
+       run_keywords ;;
+    *normalize*)
+       run_normalize ;;
+    *)
+       echo Unsupported command $0 ;;
+esac