Am 05.05.2010 21:15, schrieb Stefan Sperling: > On Wed, May 05, 2010 at 07:03:44PM +0200, Jörg Steffens wrote: >> +function stat_details() >> +{ >> + # attention: stat uses other variables as find, eg. %u<->%U >> + local path=${1:-.} >> + stat -c "mode=%a user=%U(%u) group=%G(%g)" "$path" > > This isn't portable, e.g. on OpenBSD you get: > > stat: unknown option -- c > usage: stat [-FLnq] [-f format | -l | -r | -s | -x] [-t timefmt] [file ...] > > Is there a more portable way to get at this information? > > In general it's quite hard to write shell scripts that run everywhere. > Maybe just keep the original find-based code, but filter some errors?
IMHO it is a cleaner approach to only work on files that are part of the svn checkout instead of calling "svn" for all files in the directory (and filter for errors). But of course, both approaches are doable. I replaced "stat -c" by "find -maxdepth 0". If this would work also with BSD, I would appreciate if my patch gets included.
Index: contrib/client-side/asvn =================================================================== --- contrib/client-side/asvn (Revision 941610) +++ contrib/client-side/asvn (Arbeitskopie) @@ -61,6 +61,24 @@ rm -f $TMPFILE $TMPFILE1 $TMPFILE2 } +function stat_details() +{ + local path=${1:-.} + # stat -c: can not be used, because it does not work on BSD + find "$path" -maxdepth 0 -printf "mode=%m user=%u(%U) group=%g(%G)\n" +} + +function svn_list() +{ + [ $# -eq 0 ] && local path="`pwd`" + # grep -v "^?": exclude all files that do not belong to subversion + # cut -c 42-: svn status lists different information. The filename starts at column 42 + # improvement: use "svn status --xml" and parse the xml output + svn status -v --ignore-externals $path "$@" | grep -v "^?" | cut -c 42- +} + + + function basedirname() { refname="$1" @@ -320,10 +338,12 @@ # Find all the directories and files cp /dev/null $TMPFILE - eval "find $PCWD $SKIPSVN -o \( \( -type d ! -name .svn \) -o -type f \) $PRINTDETAILS" | while read info + # uses svn_list instead of version based on find, + # because the find version produces warnings for all files + # that are not part of the repository (eg. backup files) + svn_list $PCWD | while read device do - device=`expr "$info" : "file='\(.*\)' mode"` - info=`expr "$info" : "file='.*' \(mode.*\)"` + info=`stat_details "$device"` if [ "$PCWD" = "$device" ] then