Wednesday 23 May 2007

Fun late last night, script to add subversion ign...

Fun late last night, script to add subversion ignores
 (incrementally and using wildcards for dotted extensions).
Script should be run on clean repository after build e.g. by a automated buildbot.
Note the bash propadd function. Would be nice if subversion provided that.

#!/bin/bash

# e.g. propadd svn:ignore . "*.a"
# e.g. (multiline) propadd svn:ignore . "*.a
# *.o"
propadd () {
  PROP=$1
  FILE=$2
  ADDVAL=$3
  OLDVAL=`svn propget $PROP $FILE`
  NEWVAL="$OLDVAL
$ADDVAL"
  echo svn propset $PROP \""$NEWVAL"\" $FILE
  svn propset $PROP "$NEWVAL" $FILE
}

#####
# get plain list of files
svn status -u |grep ^? |sed "s/\?  *//" >svn_ignore_files.log

##### Anything with a dotted extension insert wildcard * in place of rest of file name
# sort | uniq to rm duplicates for wildcards
IGNORES=`cat svn_ignore_files.log |sed "s/\([^\/][^\/]*\)\.\([^\.\/]*\)$/\*\.\2/" |sed s/^/BBB/ |sort |uniq`

### for or echo in shell expand <dir>/*.ext to full list of matches
### so add BBB
### meh

##### for each dir/file call propadd svn:ignore
# watch out $fNAME can have wildcard
for f in $IGNORES ; do
    #echo "f=$f" ;
    fNAME=${f##*\/}
    fNAME=${fNAME##BBB}
    fPATH=${f%%"$fNAME"}
    fPATH=${fPATH##BBB}
    if [[ "$fPATH" == "" ]] ; then fPATH=.; fi
    #echo fNAME=$fNAME fPATH=$fPATH
    #ls $fPATH/$fNAME
    propadd svn:ignore $fPATH "$fNAME"
done

#####
echo "Now commit ignores: 'svn ci -m\"updated svn:ignore values\"'"
echo "Or remove unwanted ignores 'svn revert [-R] <dir>'"
echo "'svn status' will show

No comments: