Dont assign restore tasks to stateless clients; improve logs
[ladish.git] / svnversion_regenerate.sh
blob8881bd069bb38563c0e7093070b56e2c8ed2a46d
1 #!/bin/sh
3 #set -x
5 if test $# -ne 1 -a $# -ne 2
6 then
7 echo "Usage: "`basename "$0"`" <file> [define_name]"
8 exit 1
9 fi
11 OUTPUT_FILE="${1}"
12 TEMP_FILE="${OUTPUT_FILE}.tmp"
14 if test $# -eq 2
15 then
16 DEFINE=${2}
17 else
18 DEFINE=SVN_VERSION
21 if test -d .svn
22 then
23 SVNVERSION=`svnversion`
24 else
25 if test -d .git
26 then
27 git status >/dev/null # updates dirty state
28 SVNVERSION=`git show | grep '^ *git-svn-id:' | sed 's/.*@\([0-9]*\) .*/\1/'`
29 if test ${SVNVERSION}
30 then
31 test -z "$(git diff-index --name-only HEAD)" || SVNVERSION="${SVNVERSION}M"
32 else
33 SVNVERSION=0+`git rev-parse HEAD`
34 test -z "$(git diff-index --name-only HEAD)" || SVNVERSION="${SVNVERSION}-dirty"
39 if test -z ${SVNVERSION}
40 then
41 SVNVERSION=exported
44 echo "#define ${DEFINE} \"${SVNVERSION}\"" > ${TEMP_FILE}
45 if test ! -f ${OUTPUT_FILE}
46 then
47 echo "Generated ${OUTPUT_FILE}"
48 cp ${TEMP_FILE} ${OUTPUT_FILE}
49 if test $? -ne 0; then exit 1; fi
50 else
51 if ! cmp -s ${OUTPUT_FILE} ${TEMP_FILE}
52 then echo "Regenerated ${OUTPUT_FILE}"
53 cp ${TEMP_FILE} ${OUTPUT_FILE}
54 if test $? -ne 0; then exit 1; fi
58 rm ${TEMP_FILE}
60 exit $?