# HG changeset patch # Parent c95877008e9f997df652a3ae91c51487f18dfaa0 diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh --- a/sys/conf/newvers.sh +++ b/sys/conf/newvers.sh @@ -87,19 +87,22 @@ v=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`} t=`date` i=`${MAKE:-make} -V KERN_IDENT` -for dir in /bin /usr/bin /usr/local/bin; do - if [ -x "${dir}/svnversion" ] ; then - svnversion=${dir}/svnversion - break - fi - if [ -d "${SYSDIR}/../.git" -a -x "${dir}/git" ] ; then - git_cmd="${dir}/git --git-dir=${SYSDIR}/../.git" - break - fi -done +get_path() { + local name op + op="$1"; shift + name="$1"; shift + for dir in "$@"; do + if [ "$op" "$dir/$name" ]; then + echo "$dir/$name" + return + fi + done +} +bin_path_list="/bin /usr/bin /usr/local/bin" + +svnversion=$(get_path -x svnversion $bin_path_list) if [ -n "$svnversion" ] ; then - echo "$svnversion" svn=`cd ${SYSDIR} && $svnversion` case "$svn" in [0-9]*) svn=" r${svn}" ;; @@ -107,6 +110,15 @@ esac fi +git_cmd=$(get_path -x git $bin_path_list) +if [ -n "$git_cmd" ]; then + git_dir=$(get_path -d .git "${SYSDIR}" "${SYSDIR}/..") + if [ -n "$git_dir" ]; then + git_cmd="${dir}/git --git-dir=$git_dir" + else + unset git_cmd + fi +fi if [ -n "$git_cmd" ] ; then git=`$git_cmd rev-parse --verify --short HEAD 2>/dev/null` svn=`$git_cmd svn find-rev $git 2>/dev/null` @@ -129,10 +141,47 @@ fi fi +hg_cmd=$(get_path -x hg $bin_path_list) +if [ -n "$hg_cmd" ]; then + hg_repo=$(cd ${SYSDIR} && $hg_cmd root 2>/dev/null) + if [ -n "$hg_repo" ]; then + hg_cmd="$hg_cmd --repository ${hg_repo}" + else + unset hg_cmd + fi +fi +if [ -n "$hg_cmd" ] ; then + if [ -n "$($hg_cmd status --modified ${SYSDIR})" ]; then + hg_mod="-dirty" + fi + + if [ -d "${hg_repo}/.hg/patches" ]; then + for I in $($hg_cmd qapplied 2>/dev/null); do + hg_patches="${hg_patches},${I}" + done + fi + + if [ -n "${hg_patches}" ]; then + hg_opt="-rqbase" + else + hg_opt="" + fi + revs=$($hg_cmd parent $hg_opt --template '{node|short}\t{svnrev}\n') + hg_rev=$(echo "$revs" | cut -f 1) + svn_rev=$(echo "$revs" | cut -f 2) + if [ -n "${svn_rev}" ]; then + svn=" r${svn_rev}" + else + svn=" " + fi + + hg="+${hg_rev}${hg_mod}${hg_patches}" +fi + cat << EOF > vers.c $COPYRIGHT -#define SCCSSTR "@(#)${VERSION} #${v}${svn}${git}: ${t}" -#define VERSTR "${VERSION} #${v}${svn}${git}: ${t}\\n ${u}@${h}:${d}\\n" +#define SCCSSTR "@(#)${VERSION} #${v}${svn}${git}${hg}: ${t}" +#define VERSTR "${VERSION} #${v}${svn}${git}${hg}: ${t}\\n ${u}@${h}:${d}\\n" #define RELSTR "${RELEASE}" char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;