turn off py2 builds, that worked all right with all the tags
[infrastructure.git] / scripts / svn-keywords.sh
index 740a2a3..caa4cb9 100755 (executable)
 #!/bin/bash
-# $Id$
 
 COMMAND=$(basename $0)
 
-
 usage () {
 
-   echo "Usage: $COMMAND keywords"
+   echo "Usage: $COMMAND keywords -- files or directories"
    exit 1
 
 }
 
 [[ -z "$@" ]] && usage
-keywords="$@"
 
-for keyword in $keywords ; do
+mode=keywords
 
-  echo -n "Gathering files under subversion containing the keyword $keyword "
-  files=$(grep -l '$'"$keyword" $(svn list -R))
-  echo Done
+while [[ "$@" ]] ; do
 
-  for file in $files ; do
+  case "$1" in
+    --)
+      mode=dirs ; shift ;;
+    *)
+      case $mode in
+       keywords)
+         keywords="$keywords $1" ; shift ;;
+       dirs)
+         dirs="$dirs $1" ; shift ;;
+       *)
+         usage ;;
+      esac
+      ;;
+  esac
+done
+  
+if [ "$mode" == keywords -o -z "$dirs" -o -z "$keywords" ] ; then
+  usage
+fi
 
+function run_keyword_on_file () {
+    keyword=$1; shift
+    file=$1; shift
     echo -n "$file "
-
     if [ ! -f $file ] ; then
-      echo "NOT FOUND - skipped"
-      continue
+       echo "NOT FOUND - skipped"
+       continue
     fi
-    
     current_keywords=$(svn propget svn:keywords $file)
     has_keyword=$(echo $current_keywords | grep $keyword)
-
-# dbg
-#    echo ck=$current_keywords -- hk=$has_keyword
-#    continue
-
-    if [ -z $has_keyword ] ; then
-      echo "+$keyword"
-      svn propset svn:keywords "$current_keywords $keyword" $file
+    if [ -z "$has_keyword" ] ; then
+       echo "+$keyword"
+       svn propset svn:keywords "$current_keywords $keyword" $file
     else
-      echo "="
+       echo "="
     fi
-  done
+}    
 
-done
+# 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