From nobody@FreeBSD.org  Tue Aug 10 20:22:07 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id BCE05106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 10 Aug 2010 20:22:07 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id ABE5A8FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 10 Aug 2010 20:22:07 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o7AKM7bG035561
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 10 Aug 2010 20:22:07 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o7AKM7cA035560;
	Tue, 10 Aug 2010 20:22:07 GMT
	(envelope-from nobody)
Message-Id: <201008102022.o7AKM7cA035560@www.freebsd.org>
Date: Tue, 10 Aug 2010 20:22:07 GMT
From: "J. Hellenthal" <jhell@DataIX.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [CFT] [sys/conf/newvers.sh] Cleanup and additions.
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         149510
>Category:       misc
>Synopsis:       [build] [patch] CFT: sys/conf/newvers.sh: Cleanup and additions.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 10 20:30:06 UTC 2010
>Closed-Date:    
>Last-Modified:  Sun Dec 19 22:30:10 UTC 2010
>Originator:     J. Hellenthal
>Release:        stable/8
>Organization:
>Environment:
FreeBSD 8.1-STABLE #0 r211092M 55:65408c40b051 Mon Aug  9 07:03:32 EDT
2010   jhell@ujump.dataix.net:/usr/obj/usr/src/sys/MITHOP
>Description:
Based on the parts of the script with the additions for tracking source
using git(1) I set out to add support for mercurial hg(1) and ended up
cleaning some of the script while making some of those additions.

This works exactly as before but a little more correct and with the
additions to be able to track kernel sources or whole source tree with a
local revision system. Example output follows (uname -v) from my system
being tracked locally with mercurial.

FreeBSD 8.1-STABLE #0 r211092M 55:65408c40b051 Mon Aug  9 07:03:32 EDT
2010   jhell@ujump.dataix.net:/usr/obj/usr/src/sys/MITHOP

Inspiration for making these changes came from mercurial, OpenSolaris
and finally http://wiki.freebsd.org/LocalMercurial

Following is a list of changes that I have made that I believe people
that are involved with the source may find useful.

1 file changed, 55 insertions(+), 35 deletions(-)

This allows a user:
 * That is using csup(1) or cvsup(1) to locally keep track of the whole
source tree or just the kernel part of the tree using svn(1), hg(1) or
git(1).

 * That is using svn(1) to checkout their source tree to use hg(1) or
git(1) to keep track of the whole tree or the kernel part of the tree.
	http://svn.freebsd.org/base/

 * That is using git(1) to checkout their source tree to use hg(1) to
keep track of the whole tree or the kernel part of the tree.
	http://spoerlein.net/gitweb/

This checks for:
 * SCM roots in src/ or src/sys for .svn, .hg, & .git and acts
accordingly if they exist while prioritizing using an SCM root in src/
before it uses src/sys/

 * Then looks for acceptable binaries for svn(1), hg(1) git(1) within
the select paths /usr/local/bin & then /usr/bin. The paths may change
for svn(1) or git(1) & maybe mercurial if it ever becomes part of world.
Currently I have set these to only look in /usr/local/bin.

Cleanups:
 * Instead of using variables that shared the same name as their
counterpart binaries to hold a revision number use more descriptive
names like svnrev gitrev & hgrev for revisions. Use git svnversion & hg
variables for their respective binaries.

 * Adjust the paths that are checked for binaries to be of only
/usr/local/bin and /usr/bin. "/bin" is highly unlikely to hold svn(1),
git(1) or hg(1).

 * Test for a SCM root in the source tree locations before we look for
binaries. If these don't exist there is no need to know where svn or git
are.

 * For git(1) always set work-tree and git-dir so there is no
possibility to end up with a "-dirty" git(1) revision.

 * Remove extraneous "touch version" since the previous if statement
already creates the file if its not found.

 * Inline the test for version file.

>How-To-Repeat:

>Fix:
Attached patch. Should apply cleanly to head and stable/8 but was developed on stable/8 r211092.

Patch attached with submission follows:

Index: sys/conf/newvers.sh
===================================================================
--- sys/conf/newvers.sh	(revision 211140)
+++ sys/conf/newvers.sh	(working copy)
@@ -78,12 +78,8 @@
 "
 
 LC_ALL=C; export LC_ALL
-if [ ! -r version ]
-then
-	echo 0 > version
-fi
+[ ! -r version ] && echo 0 >version
 
-touch version
 v=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`} t=`date`
 i=`${MAKE:-make} -V KERN_IDENT`
 
@@ -95,39 +91,63 @@
 	fi
 	SRCDIR=${SRCDIR%%/sys/*}
 
-	for dir in /bin /usr/bin /usr/local/bin; do
-		if [ -d "${SRCDIR}/sys/.svn" -a -x "${dir}/svnversion" ] ; then
-			svnversion=${dir}/svnversion
-			break
-		fi
-		if [ -d "${SRCDIR}/.git" -a -x "${dir}/git" ] ; then
-			git_cmd="${dir}/git --git-dir=${SRCDIR}/.git"
-			break
+	if [ -d "${SRCDIR}/.svn" -o -d "${SRCDIR}/sys/.svn" ]; then
+		for dir in /usr/local/bin; do
+			if [ -x "${dir}/svn" ]; then
+				svnversion=${dir}/svnversion
+				break
+			fi
+		done
+		if [ -n "$svnversion" ] ; then
+			svnrev=" r`cd ${SRCDIR}/sys && $svnversion`"
 		fi
-	done
+	fi
 
-	if [ -n "$svnversion" ] ; then
-		svn=" r`cd ${SRCDIR}/sys && $svnversion`"
+	if [ -d "${SRCDIR}/.hg" -o -d "${SRCDIR}/sys/.hg" ]; then
+		for dir in /usr/local/bin; do
+			if [ -x "${dir}/hg" ]; then
+				hg=${dir}/hg
+				break
+			fi
+		done
+		if [ -n "$hg" ]; then
+			hgrev=" `cd ${SRCDIR}/sys && $hg tip --template '{rev}:{node|short}'`"
+		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`
-		if [ -n "$svn" ] ; then
-			svn=" r${svn}"
-			git="=${git}"
-		else
-			svn=`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \
-			     sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`
-			if [ -n $svn ] ; then
-				svn=" r${svn}"
-				git="+${git}"
+
+	if [ -d "${SRCDIR}/.git" -o -d "${SRCDIR}/sys/.git" ]; then
+		for dir in /usr/local/bin; do
+			if [ -x "${dir}/git" ]; then
+				if [ -d "${SRCDIR}/.git" ]; then
+					git="${dir}/git --git-dir=${SRCDIR}/.git"
+					git="${git} --work-tree=${SRCDIR}"
+				else
+					git="${dir}/git --git-dir=${SRCDIR}/sys/.git"
+					git="${git} --work-tree=${SRCDIR}/sys"
+				fi
+				break
+			fi
+		done
+
+		if [ -n "$git" ] ; then
+			gitrev="`$git rev-parse --verify --short HEAD 2>/dev/null`"
+			gitsvnrev="`$git svn find-rev $gitrev 2>/dev/null`"
+			if [ -n "${gitsvnrev}" ] ; then
+				svnrev=" r${gitsvnrev}"
+				gitrev="=${gitrev}"
 			else
-				git=" ${git}"
+				gitsvnid="`$git log |fgrep 'git-svn-id:' |head -1 |\
+				sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`"
+				if [ -n "${gitsvnid}" ]; then
+					svnrev=" r${gitsvnid}"
+					gitrev="+${gitrev}"
+				else
+					gitrev=" ${gitrev}"
+				fi
+			fi
+			if [ -n "`$git diff-index --name-only HEAD`" ]; then
+				gitrev="${gitrev}-dirty"
 			fi
-		fi
-		if $git_cmd --work-tree=${SRCDIR} diff-index \
-		    --name-only HEAD | read dummy; then
-			git="${git}-dirty"
 		fi
 	fi
 	;;
@@ -135,8 +155,8 @@
 
 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}${svnrev}${gitrev}${hgrev} ${t}"
+#define VERSTR "${VERSION} #${v}${svnrev}${gitrev}${hgrev} ${t}\\n 	${u}@${h}:${d}\\n"
 #define RELSTR "${RELEASE}"
 
 char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;


>Release-Note:
>Audit-Trail:

From: jhell <jhell@dataix.net>
To: bug-followup@FreeBSD.org, jhell@DataIX.net
Cc:  
Subject: Re: misc/149510: [build] [patch] CFT: sys/conf/newvers.sh: Cleanup
 and additions.
Date: Tue, 10 Aug 2010 21:42:17 -0400

 This is a multi-part message in MIME format.
 --------------050304040402020200040806
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
  Attached is the adjusted patch to relieve the use of head and grep for
 gitsvnid.
 
 -- 
 
  jhell,v
 
 
 
 --------------050304040402020200040806
 Content-Type: text/plain;
  name="newvers.sh.txt"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="newvers.sh.txt"
 
 Index: newvers.sh
 ===================================================================
 --- newvers.sh	(revision 211154)
 +++ newvers.sh	(working copy)
 @@ -78,12 +78,8 @@
  "
  
  LC_ALL=C; export LC_ALL
 -if [ ! -r version ]
 -then
 -	echo 0 > version
 -fi
 +[ ! -r version ] && echo 0 >version
  
 -touch version
  v=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`} t=`date`
  i=`${MAKE:-make} -V KERN_IDENT`
  
 @@ -95,39 +91,63 @@
  	fi
  	SRCDIR=${SRCDIR%%/sys/*}
  
 -	for dir in /bin /usr/bin /usr/local/bin; do
 -		if [ -d "${SRCDIR}/sys/.svn" -a -x "${dir}/svnversion" ] ; then
 -			svnversion=${dir}/svnversion
 -			break
 -		fi
 -		if [ -d "${SRCDIR}/.git" -a -x "${dir}/git" ] ; then
 -			git_cmd="${dir}/git --git-dir=${SRCDIR}/.git"
 -			break
 +	if [ -d "${SRCDIR}/.svn" -o -d "${SRCDIR}/sys/.svn" ]; then
 +		for dir in /usr/local/bin; do
 +			if [ -x "${dir}/svn" ]; then
 +				svnversion=${dir}/svnversion
 +				break
 +			fi
 +		done
 +		if [ -n "$svnversion" ] ; then
 +			svnrev=" r`cd ${SRCDIR}/sys && $svnversion`"
  		fi
 -	done
 +	fi
  
 -	if [ -n "$svnversion" ] ; then
 -		svn=" r`cd ${SRCDIR}/sys && $svnversion`"
 +	if [ -d "${SRCDIR}/.hg" -o -d "${SRCDIR}/sys/.hg" ]; then
 +		for dir in /usr/local/bin; do
 +			if [ -x "${dir}/hg" ]; then
 +				hg=${dir}/hg
 +				break
 +			fi
 +		done
 +		if [ -n "$hg" ]; then
 +			hgrev=" `cd ${SRCDIR}/sys && $hg tip --template '{rev}:{node|short}'`"
 +		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`
 -		if [ -n "$svn" ] ; then
 -			svn=" r${svn}"
 -			git="=${git}"
 -		else
 -			svn=`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \
 -			     sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`
 -			if [ -n $svn ] ; then
 -				svn=" r${svn}"
 -				git="+${git}"
 +
 +	if [ -d "${SRCDIR}/.git" -o -d "${SRCDIR}/sys/.git" ]; then
 +		for dir in /usr/local/bin; do
 +			if [ -x "${dir}/git" ]; then
 +				if [ -d "${SRCDIR}/.git" ]; then
 +					git="${dir}/git --git-dir=${SRCDIR}/.git"
 +					git="${git} --work-tree=${SRCDIR}"
 +				else
 +					git="${dir}/git --git-dir=${SRCDIR}/sys/.git"
 +					git="${git} --work-tree=${SRCDIR}/sys"
 +				fi
 +				break
 +			fi
 +		done
 +
 +		if [ -n "$git" ] ; then
 +			gitrev="`$git rev-parse --verify --short HEAD 2>/dev/null`"
 +			gitsvnrev="`$git svn find-rev $gitrev 2>/dev/null`"
 +			if [ -n "${gitsvnrev}" ] ; then
 +				svnrev=" r${gitsvnrev}"
 +				gitrev="=${gitrev}"
  			else
 -				git=" ${git}"
 +				gitsvnid="`$git log | sed -n '/git-svn-id:/ {
 +				s/.*@\([[:digit:]]\{1,\}\).*/\1/p; q; }'`"
 +				if [ -n "${gitsvnid}" ]; then
 +					svnrev=" r${gitsvnid}"
 +					gitrev="+${gitrev}"
 +				else
 +					gitrev=" ${gitrev}"
 +				fi
 +			fi
 +			if [ -n "`$git diff-index --name-only HEAD`" ]; then
 +				gitrev="${gitrev}-dirty"
  			fi
 -		fi
 -		if $git_cmd --work-tree=${SRCDIR} diff-index \
 -		    --name-only HEAD | read dummy; then
 -			git="${git}-dirty"
  		fi
  	fi
  	;;
 @@ -135,8 +155,8 @@
  
  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}${svnrev}${gitrev}${hgrev} ${t}"
 +#define VERSTR "${VERSION} #${v}${svnrev}${gitrev}${hgrev} ${t}\\n 	${u}@${h}:${d}\\n"
  #define RELSTR "${RELEASE}"
  
  char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;
 
 --------------050304040402020200040806--

From: Anonymous <swell.k@gmail.com>
To: jhell@DataIX.net
Cc: bug-followup@FreeBSD.org
Subject: Re: misc/149510: [build] [patch] CFT: sys/conf/newvers.sh: Cleanup and additions.
Date: Fri, 24 Sep 2010 17:13:59 +0400

 Can you refresh the patch against r213077?

From: jhell <jhell@DataIX.net>
To: Anonymous <swell.k@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: misc/149510: [build] [patch] CFT: sys/conf/newvers.sh: Cleanup
 and additions.
Date: Fri, 24 Sep 2010 13:31:39 -0400

 On 09/24/2010 09:13, Anonymous wrote:
 > Can you refresh the patch against r213077?
 
 Ill do this in about 4 - 5 hours from this email.
 
 -- 
 
  jhell,v

From: jhell <jhell@DataIX.net>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/149510: [build] [patch] CFT: sys/conf/newvers.sh: Cleanup
 and additions.
Date: Fri, 24 Sep 2010 22:22:32 -0400

 This is a multi-part message in MIME format.
 --------------050000080808040400030703
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 
 The following are updated patches to what is already here for current
 and stable/8. Links are respective to where they should be applied.
 
 http://bit.ly/newvers-head-r213132-patch
 1 file changed, 61 insertions(+), 38 deletions(-)
 
 http://bit.ly/newvers-stable8-r213132-patch
 1 file changed, 55 insertions(+), 40 deletions(-)
 
 These are also both attached but linked to just to be sure in case they
 are somehow garbled.
 
 After these two patches are applied both stable/8 and head will be in
 sync with the changes that were made in r213077 & r213078
 
 These were tested locally only with stable/8 and could use verification
 for those using git(1) locally in either /usr/src/.git or
 /usr/src/sys/.git on stable/8 & head.
 
 Included with these changes and attributed to "Anonymous" <- thanks for
 the heads-up, you also have the ability to use LOCALBASE. This could use
 some testing to whether it works or not so I will leave that to others
 for feedback.
 
 
 Regards & Happy Hacking,
 
 -- 
 
  jhell,v
 
 --------------050000080808040400030703
 Content-Type: text/plain;
  name="newvers.sh-head-r213132.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="newvers.sh-head-r213132.patch"
 
 Index: sys/conf/newvers.sh
 ===================================================================
 --- sys/conf/newvers.sh	(revision 213142)
 +++ sys/conf/newvers.sh	(working copy)
 @@ -38,7 +38,10 @@
  fi
  RELEASE="${REVISION}-${BRANCH}"
  VERSION="${TYPE} ${RELEASE}"
 -SYSDIR=$(dirname $0)/..
 +
 +# These are here so we don't have to work in reverse later on.
 +SRCDIR=$(dirname $0)/../..
 +SYSDIR=${SRCDIR}/sys
  
  if [ "X${PARAMFILE}" != "X" ]; then
  	RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
 @@ -78,57 +81,77 @@
  "
  
  LC_ALL=C; export LC_ALL
 -if [ ! -r version ]
 -then
 -	echo 0 > version
 +if [ ! -r version ]; then
 +	echo 0 >version
  fi
  
 -touch version
  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 [ -d "${SYSDIR}/.svn" -a -x "${dir}/svnversion" ] ; then
 -		svnversion=${dir}/svnversion
 -		break
 +if [ -d "${SRCDIR}/.svn" -o -d "${SYSDIR}/.svn" ]; then
 +	for dir in /usr/bin ${LOCALBASE:-/usr/local}/bin; do
 +		if [ -x "${dir}/svn" ]; then
 +			svnversion=${dir}/svnversion
 +			break
 +		fi
 +	done
 +	if [ -n "$svnversion" ] ; then
 +		svnrev=" r`cd ${SYSDIR} && $svnversion`"
  	fi
 -	if [ -d "${SYSDIR}/../.git" -a -x "${dir}/git" ] ; then
 -		git_cmd="${dir}/git --git-dir=${SYSDIR}/../.git"
 -		break
 +fi
 +
 +if [ -d "${SRCDIR}/.hg" -o -d "${SYSDIR}/.hg" ]; then
 +	for dir in /usr/bin ${LOCALBASE:-/usr/local}/bin; do
 +		if [ -x "${dir}/hg" ]; then
 +			hg=${dir}/hg
 +			break
 +		fi
 +	done
 +	if [ -n "$hg" ]; then
 +		hgrev=" `cd ${SYSDIR} && $hg tip --template '{rev}:{node|short}'`"
  	fi
 -done
 +fi
 +
 +if [ -d "${SRCDIR}/.git" -o -d "${SYSDIR}/.git" ]; then
 +	for dir in /usr/bin ${LOCALBASE:-/usr/local}; do
 +		if [ -x "${dir}/git" ]; then
 +			if [ -d "${SRCDIR}/.git" ]; then
 +				git="${dir}/git --git-dir=${SRCDIR}/.git"
 +				git="${git} --work-tree=${SRCDIR}"
 +			else
 +				git="${dir}/git --git-dir=${SYSDIR}/.git"
 +				git="${git} --work-tree=${SYSDIR}"
 +			fi
 +			break
 +		fi
 +	done
  
 -if [ -n "$svnversion" ] ; then
 -    echo "$svnversion"
 -	svn=" r`cd ${SYSDIR} && $svnversion`"
 -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`
 -	if [ -n "$svn" ] ; then
 -		svn=" r${svn}"
 -		git="=${git}"
 -	else
 -		svn=`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \
 -		     sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`
 -		if [ -n $svn ] ; then
 -			svn=" r${svn}"
 -			git="+${git}"
 +	if [ -n "$git" ] ; then
 +		gitrev="`$git rev-parse --verify --short HEAD 2>/dev/null`"
 +		gitsvnrev="`$git svn find-rev $gitrev 2>/dev/null`"
 +		if [ -n "${gitsvnrev}" ] ; then
 +			svnrev=" r${gitsvnrev}"
 +			gitrev=" ${gitrev}"
  		else
 -			git=" ${git}"
 +			gitsvnid="`$git log |sed -n '/git-svn-id:/ {
 +			s/.*@\([[:digit:]]\{1,\}\).*/\1/p; q; }'`"
 +			if [ -n "${gitsvnid}" ]; then
 +				svnrev=" r${gitsvnid}"
 +				gitrev="+${gitrev}"
 +			else
 +				gitrev=" ${gitrev}"
 +			fi
 +		fi
 +		if [ -n "`$git diff-index --name-only HEAD`" ]; then
 +			gitrev="${gitrev}-dirty"
  		fi
 -	fi
 -	if $git_cmd --work-tree=${SYSDIR}/.. diff-index \
 -	    --name-only HEAD | read dummy; then
 -		git="${git}-dirty"
  	fi
  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}${svnrev}${gitrev}${hgrev} ${t}"
 +#define VERSTR "${VERSION} #${v}${svnrev}${gitrev}${hgrev} ${t}\\n 	${u}@${h}:${d}\\n"
  #define RELSTR "${RELEASE}"
  
  char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;
 @@ -139,4 +162,4 @@
  char kern_ident[] = "${i}";
  EOF
  
 -echo `expr ${v} + 1` > version
 +echo $((${v}+1)) >version
 
 --------------050000080808040400030703
 Content-Type: text/plain;
  name="newvers.sh-stable8-r213132.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="newvers.sh-stable8-r213132.patch"
 
 Index: sys/conf/newvers.sh
 ===================================================================
 --- sys/conf/newvers.sh	(revision 213132)
 +++ sys/conf/newvers.sh	(working copy)
 @@ -39,15 +39,18 @@
  RELEASE="${REVISION}-${BRANCH}"
  VERSION="${TYPE} ${RELEASE}"
  
 +# These are here so we don't have to work in reverse later on.
 +SRCDIR=$(dirname $0)/../..
 +SYSDIR=${SRCDIR}/sys
 +
  if [ "X${PARAMFILE}" != "X" ]; then
  	RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
  		${PARAMFILE})
  else
  	RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
 -		$(dirname $0)/../sys/param.h)
 +		${SYSDIR}/sys/param.h)
  fi
  
 -
  b=share/examples/etc/bsd-style-copyright
  year=`date '+%Y'`
  # look for copyright template
 @@ -78,65 +81,77 @@
  "
  
  LC_ALL=C; export LC_ALL
 -if [ ! -r version ]
 -then
 -	echo 0 > version
 +if [ ! -r version ]; then
 +	echo 0 >version
  fi
  
 -touch version
  v=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`} t=`date`
  i=`${MAKE:-make} -V KERN_IDENT`
  
 -case "$d" in
 -*/sys/*)
 -	SRCDIR=${d##*obj}
 -	if [ -n "$MACHINE" ]; then
 -		SRCDIR=${SRCDIR##/$MACHINE}
 +if [ -d "${SRCDIR}/.svn" -o -d "${SYSDIR}/.svn" ]; then
 +	for dir in /usr/bin ${LOCALBASE:-/usr/local}/bin; do
 +		if [ -x "${dir}/svn" ]; then
 +			svnversion=${dir}/svnversion
 +			break
 +		fi
 +	done
 +	if [ -n "$svnversion" ] ; then
 +		svnrev=" r`cd ${SYSDIR} && $svnversion`"
  	fi
 -	SRCDIR=${SRCDIR%%/sys/*}
 +fi
  
 -	for dir in /bin /usr/bin /usr/local/bin; do
 -		if [ -d "${SRCDIR}/sys/.svn" -a -x "${dir}/svnversion" ] ; then
 -			svnversion=${dir}/svnversion
 +if [ -d "${SRCDIR}/.hg" -o -d "${SYSDIR}/.hg" ]; then
 +	for dir in /usr/bin ${LOCALBASE:-/usr/local}/bin; do
 +		if [ -x "${dir}/hg" ]; then
 +			hg=${dir}/hg
  			break
  		fi
 -		if [ -d "${SRCDIR}/.git" -a -x "${dir}/git" ] ; then
 -			git_cmd="${dir}/git --git-dir=${SRCDIR}/.git"
 +	done
 +	if [ -n "$hg" ]; then
 +		hgrev=" `cd ${SYSDIR} && $hg tip --template '{rev}:{node|short}'`"
 +	fi
 +fi
 +
 +if [ -d "${SRCDIR}/.git" -o -d "${SYSDIR}/.git" ]; then
 +	for dir in /usr/bin ${LOCALBASE:-/usr/local}; do
 +		if [ -x "${dir}/git" ]; then
 +			if [ -d "${SRCDIR}/.git" ]; then
 +				git="${dir}/git --git-dir=${SRCDIR}/.git"
 +				git="${git} --work-tree=${SRCDIR}"
 +			else
 +				git="${dir}/git --git-dir=${SYSDIR}/.git"
 +				git="${git} --work-tree=${SYSDIR}"
 +			fi
  			break
  		fi
  	done
  
 -	if [ -n "$svnversion" ] ; then
 -		svn=" r`cd ${SRCDIR}/sys && $svnversion`"
 -	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`
 -		if [ -n "$svn" ] ; then
 -			svn=" r${svn}"
 -			git="=${git}"
 +	if [ -n "$git" ] ; then
 +		gitrev="`$git rev-parse --verify --short HEAD 2>/dev/null`"
 +		gitsvnrev="`$git svn find-rev $gitrev 2>/dev/null`"
 +		if [ -n "${gitsvnrev}" ] ; then
 +			svnrev=" r${gitsvnrev}"
 +			gitrev=" ${gitrev}"
  		else
 -			svn=`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \
 -			     sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`
 -			if [ -n $svn ] ; then
 -				svn=" r${svn}"
 -				git="+${git}"
 +			gitsvnid="`$git log |sed -n '/git-svn-id:/ {
 +			s/.*@\([[:digit:]]\{1,\}\).*/\1/p; q; }'`"
 +			if [ -n "${gitsvnid}" ]; then
 +				svnrev=" r${gitsvnid}"
 +				gitrev="+${gitrev}"
  			else
 -				git=" ${git}"
 +				gitrev=" ${gitrev}"
  			fi
  		fi
 -		if $git_cmd --work-tree=${SRCDIR} diff-index \
 -		    --name-only HEAD | read dummy; then
 -			git="${git}-dirty"
 +		if [ -n "`$git diff-index --name-only HEAD`" ]; then
 +			gitrev="${gitrev}-dirty"
  		fi
  	fi
 -	;;
 -esac
 +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}${svnrev}${gitrev}${hgrev} ${t}"
 +#define VERSTR "${VERSION} #${v}${svnrev}${gitrev}${hgrev} ${t}\\n 	${u}@${h}:${d}\\n"
  #define RELSTR "${RELEASE}"
  
  char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR;
 @@ -147,4 +162,4 @@
  char kern_ident[] = "${i}";
  EOF
  
 -echo `expr ${v} + 1` > version
 +echo $((${v}+1)) >version
 
 --------------050000080808040400030703--

From: jhell <jhell@DataIX.net>
To: bug-followup@FreeBSD.org, jhell@DataIX.net
Cc:  
Subject: Re: misc/149510: [build] [patch] CFT: sys/conf/newvers.sh: Cleanup
 and additions.
Date: Fri, 24 Sep 2010 22:43:22 -0400

 Beware the previous patches that were submitted are concatenated and
 should be separated at the "Index:" line otherwise they will both try to
 apply with one failing.
 
 The patch for head seems to be the first patch and the one for stable/8
 is the second patch.
 
 
 Regards,
 
 -- 
 
  jhell,v

From: Anonymous <swell.k@gmail.com>
To: jhell@DataIX.net
Cc: bug-followup@FreeBSD.org
Subject: Re: misc/149510: [build] [patch] CFT: sys/conf/newvers.sh: Cleanup and additions.
Date: Sun, 26 Sep 2010 11:44:29 +0400

 Typo in git(1) search path: LOCALBASE vs. LOCALBASE/bin.
 
 -	for dir in /usr/bin ${LOCALBASE:-/usr/local}; do
 +	for dir in /usr/bin ${LOCALBASE:-/usr/local}/bin; do
 
 And thanks for including conf/146828.

From: jhell <jhell@DataIX.net>
To: Anonymous <swell.k@gmail.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: misc/149510: [build] [patch] CFT: sys/conf/newvers.sh: Cleanup
 and additions.
Date: Sun, 26 Sep 2010 04:06:18 -0400

 On 09/26/2010 03:44, Anonymous wrote:
 > Typo in git(1) search path: LOCALBASE vs. LOCALBASE/bin.
 > 
 > -	for dir in /usr/bin ${LOCALBASE:-/usr/local}; do
 > +	for dir in /usr/bin ${LOCALBASE:-/usr/local}/bin; do
 > 
 > And thanks for including conf/146828.
 
 Yikes! thank you. Ill just edit the patch and put it back to where it
 was in 20 minutes.
 
 -- 
 
  jhell,v

From: jhell <jhell@DataIX.net>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/149510: [build] [patch] CFT: sys/conf/newvers.sh: Cleanup
 and additions.
Date: Sun, 19 Dec 2010 17:05:18 -0500

 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 
 Any word on when, if, maybe, feedback, etc... can this make it into
 8.2-RELEASE furthermore -> HEAD...
 
 Still running this locally but would love to see this make it into src
 as its just adding support for another SCM and based on the original
 version that worked svn(1) and git(1) into the file.
 
 
 Simplistic as it is, here's the URLs again for the patches.
 http://jhell.googlecode.com/files/newvers.sh-stable8-r213132.patch
 http://jhell.googlecode.com/files/newvers.sh-head-r213132.patch
 
 
 
 Regards,
 
 - -- 
 
  jhell,v
 -----BEGIN PGP SIGNATURE-----
 
 iQEcBAEBAgAGBQJNDoGeAAoJEJBXh4mJ2FR+dsAH/00K7vp7ltBjBjqALXsZlaKt
 IDinWp8XmVqs757qnmk/9sbsSDo1pjuTJFKjYgjoHEgA+MkVNjRKArZ4727WApb3
 ZgRKkdh5FcA1KbV8pJiC7Fk0g/b6EPI7QOCkNHKCzP4uDFrEhqNJ3H11tpzshdMg
 96ZInZYfe07onakUd7gI9/LvZHnRs4LG6M2YIV+VAoE2kMd8C4BxpnLH+l1nT/KG
 ALAGpBTFy7+y04MYREhQOtPPDjEsGG1GWLHG2YXC6rx2dsiXNGsDrl/lXyHjEigX
 mSX+w2lIX+HVvQD0d1ggYID9uBGkuCVPIoltPuh6HBVOSQm7h3yIZ7ALJsLQ90E=
 =Wohc
 -----END PGP SIGNATURE-----
>Unformatted:
