Glen Barber <[email protected]> wrote
  in <[email protected]>:

gj> Author: gjb
gj> Date: Thu Aug  8 15:59:00 2013
gj> New Revision: 254094
gj> URL: http://svnweb.freebsd.org/changeset/base/254094
gj>
gj> Log:
gj>   When newvers.sh is run, it is possible that the svnversion
gj>   (or svnliteversion) in the current lookup path is not what
gj>   was used to check out the tree.  If an incompatible version
gj>   is used, the svn revision number is not reported in uname(1).
gj>
gj>   Run ${svnversion} on newvers.sh itself when evaluating if the
gj>   svn(1) in use is compatible with the tree.  Fallback to an
gj>   empty ${svnversion} if necessary.
gj>
gj>   With this change, svnliteversion from base is only used
gj>   if no compatible svnversion is found, so with this change,
gj>   the version of svn(1) from the ports tree is evaluated first.
gj>
gj>   Requested by:     many
gj>   MFC after:        3 days
gj>   X-MFC-To: stable/9, releng/9.2 only
gj>
gj> Modified:
gj>   head/sys/conf/newvers.sh
gj>
gj> Modified: head/sys/conf/newvers.sh
gj> 
==============================================================================
gj> --- head/sys/conf/newvers.sh        Thu Aug  8 11:53:47 2013        
(r254093)
gj> +++ head/sys/conf/newvers.sh        Thu Aug  8 15:59:00 2013        
(r254094)
gj> @@ -88,19 +88,31 @@ v=`cat version` u=${USER:-root} d=`pwd`
gj>  i=`${MAKE:-make} -V KERN_IDENT`
gj>  compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep 'version')
gj>
gj> -if [ -x /usr/bin/svnliteversion ] ; then
gj> -   svnversion=/usr/bin/svnliteversion
gj> -fi
gj> -
gj>  for dir in /usr/bin /usr/local/bin; do
gj>     if [ ! -z "${svnversion}" ] ; then
gj>             break
gj>     fi
gj>     if [ -x "${dir}/svnversion" ] && [ -z ${svnversion} ] ; then
gj> -           svnversion=${dir}/svnversion
gj> -           break
gj> +           # Run svnversion from ${dir} on this script; if return code
gj> +           # is not zero, the checkout might not be compatible with the
gj> +           # svnversion being used.
gj> +           ${dir}/svnversion $(basename ${0}) >/dev/null 2>&1
gj> +           if [ $? -eq 0 ]; then
gj> +                   svnversion=${dir}/svnversion
gj> +                   break
gj> +           fi
gj>     fi
gj>  done
gj> +
gj> +if [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then
gj> +   /usr/bin/svnversion $(basename ${0}) >/dev/null 2>&1
gj> +   if [ $? -eq 0 ]; then
gj> +           svnversion=/usr/bin/svnliteversion
gj> +   else
gj> +           svnversion=
gj> +   fi
gj> +fi
gj> +

 I think this logic is unnecessarily complex.  svnversion does not
 need to run twice, at least.

 How about the attached patch?

-- Hiroki
Index: sys/conf/newvers.sh
===================================================================
--- sys/conf/newvers.sh	(revision 254095)
+++ sys/conf/newvers.sh	(working copy)
@@ -88,31 +88,20 @@
 i=`${MAKE:-make} -V KERN_IDENT`
 compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep 'version')

-for dir in /usr/bin /usr/local/bin; do
-	if [ ! -z "${svnversion}" ] ; then
-		break
+for bin in $svnversion /usr/bin/svnversion /usr/local/bin/svnversion \
+    /usr/bin/svnliteversion; do
+	if svn=$("$bin" ${SYSDIR} 2>/dev/null); then
+		case "$svn" in
+		[0-9]*)	svn=" r${svn}"; break ;;
+		esac
+	else
+		# If return code is not zero, the binary is not found or
+		# the checkout might not be compatible with the svnversion
+		# being used.
+		unset svn
 	fi
-	if [ -x "${dir}/svnversion" ] && [ -z ${svnversion} ] ; then
-		# Run svnversion from ${dir} on this script; if return code
-		# is not zero, the checkout might not be compatible with the
-		# svnversion being used.
-		${dir}/svnversion $(basename ${0}) >/dev/null 2>&1
-		if [ $? -eq 0 ]; then
-			svnversion=${dir}/svnversion
-			break
-		fi
-	fi
 done

-if [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then
-	/usr/bin/svnversion $(basename ${0}) >/dev/null 2>&1
-	if [ $? -eq 0 ]; then
-		svnversion=/usr/bin/svnliteversion
-	else
-		svnversion=
-	fi
-fi
-
 for dir in /usr/bin /usr/local/bin; do
 	if [ -x "${dir}/p4" ] && [ -z ${p4_cmd} ] ; then
 		p4_cmd=${dir}/p4
@@ -127,14 +116,6 @@
 	done
 fi

-if [ -n "$svnversion" ] ; then
-	svn=`cd ${SYSDIR} && $svnversion 2>/dev/null`
-	case "$svn" in
-	[0-9]*)	svn=" r${svn}" ;;
-	*)	unset svn ;;
-	esac
-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`

Attachment: pgpoRUwQj1lLb.pgp
Description: PGP signature

Reply via email to