Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Jan 2012 11:02:25 -0800
From:      David Wolfskill <david@catwhisker.org>
To:        Oliver Pinter <pinter@tresorium.hu>
Cc:        current@freebsd.org
Subject:   Re: [RFC] fix git detection code in newvers.sh when svn installed
Message-ID:  <20120106190225.GR1733@albert.catwhisker.org>
In-Reply-To: <201201061850.33863.pinter@tresorium.hu>
References:  <201201061850.33863.pinter@tresorium.hu>

next in thread | previous in thread | raw e-mail | index | archive | help

--7ff5AkW+g6+eEohN
Content-Type: multipart/mixed; boundary="SENi13OXelf/Rv8V"
Content-Disposition: inline


--SENi13OXelf/Rv8V
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

[-stable@ removed, as there's no need to cross-post this.  dhw]

On Fri, Jan 06, 2012 at 06:50:33PM +0100, Oliver Pinter wrote:
> Hi All!
>=20
> When svn installed and the source stored in git, then now the version=20
> detection failed. The attached patch fixed this situation.
> ...

Caveat: I don't use git.

Given that folks will use various combinations of VCSen to maintain
their source trees, rather than hacking/munging newvers.sh whenever
the behavior of a certain subset of VCSen changes, why not change
newvers.sh to source the site-specific code in question?

We (the FreeBSD project) could provide some sample files, but folks
who want to do something different would have an easy way to do
that without hacking newvers.sh.

E.g., the attached.  I would normally make the file being sourced a
symlink to a selected file.  Note: Yes, some of the examples are absurd.
The point is to illustrate the idea.

I've been using this code in head, stable/9, and stable/8 since late
November; I track eack of those daily (both on a build machine and on my
laptop).

Peace,
david
--=20
David H. Wolfskill				david@catwhisker.org
Depriving a girl or boy of an opportunity for education is evil.

See http://www.catwhisker.org/~david/publickey.gpg for my public key.

--SENi13OXelf/Rv8V
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="newvers.sh.patch"
Content-Transfer-Encoding: quoted-printable

diff -Nru conf/get_version_from_jot.sh conf/get_version_from_jot.sh
--- conf/get_version_from_jot.sh	1969-12-31 16:00:00.000000000 -0800
+++ conf/get_version_from_jot.sh	2011-11-20 08:29:19.000000000 -0800
@@ -0,0 +1,4 @@
+# Sample get_version_from_vcs.sh as a silly example
+get_version_from_vcs() {
+	jot -r 1 $( date +%s )
+}
diff -Nru conf/get_version_from_null.sh conf/get_version_from_null.sh
--- conf/get_version_from_null.sh	1969-12-31 16:00:00.000000000 -0800
+++ conf/get_version_from_null.sh	2011-11-19 11:24:51.000000000 -0800
@@ -0,0 +1,4 @@
+# Sample get_version_from_vcs.sh as a silly example
+get_version_from_vcs() {
+	echo ""
+}
diff -Nru conf/get_version_from_svn.sh conf/get_version_from_svn.sh
--- conf/get_version_from_svn.sh	1969-12-31 16:00:00.000000000 -0800
+++ conf/get_version_from_svn.sh	2011-11-29 13:32:25.000000000 -0800
@@ -0,0 +1,17 @@
+# Sample get_version_from_vcs.sh for use with SVN
+get_version_from_vcs() {
+	for dir in /bin /usr/bin /usr/local/bin; do
+		if [ -x "${dir}/svnversion" ] ; then
+			svnversion=3D${dir}/svnversion
+			break
+		fi
+	done
+	if [ -n "$svnversion" ] ; then
+		svn=3D`cd ${SYSDIR} && $svnversion`
+		case "$svn" in
+		[0-9]*) svn=3D"r${svn}" ;;
+		*)	unset svn ;;
+		esac
+	fi
+	echo "$svn"
+}
diff -Nru conf/get_version_from_vcs.sh conf/get_version_from_vcs.sh
--- conf/get_version_from_vcs.sh	1969-12-31 16:00:00.000000000 -0800
+++ conf/get_version_from_vcs.sh	2011-11-20 08:29:45.000000000 -0800
@@ -0,0 +1,5 @@
+# dhw's get_version_from_vcs.sh for use with SVN to get GRN for entire /us=
r/src
+# I know where I keep svnversion, so I don't need to look for it.
+get_version_from_vcs() {
+	/usr/local/bin/svnversion /usr/src/
+}
diff -Nru conf/newvers.sh conf/newvers.sh
--- conf/newvers.sh	2012-01-06 10:40:08.000000000 -0800
+++ conf/newvers.sh	2012-01-06 10:47:58.000000000 -0800
@@ -87,51 +87,25 @@
 v=3D`cat version` u=3D${USER:-root} d=3D`pwd` h=3D${HOSTNAME:-`hostname`} =
t=3D`date`
 i=3D`${MAKE:-make} -V KERN_IDENT`
=20
-for dir in /bin /usr/bin /usr/local/bin; do
-	if [ -x "${dir}/svnversion" ] ; then
-		svnversion=3D${dir}/svnversion
-		break
-	fi
-	if [ -d "${SYSDIR}/../.git" -a -x "${dir}/git" ] ; then
-		git_cmd=3D"${dir}/git --git-dir=3D${SYSDIR}/../.git"
-		break
-	fi
-done
-
-if [ -n "$svnversion" ] ; then
-	svn=3D`cd ${SYSDIR} && $svnversion`
-	case "$svn" in
-	[0-9]*)	svn=3D" r${svn}" ;;
-	*)	unset svn ;;
-	esac
+if [ -r ${SYSDIR}/conf/get_version_from_vcs.sh ] ; then
+	. ${SYSDIR}/conf/get_version_from_vcs.sh
+else
+	# Fallback function to get a "version ID" if we can't find
+	# a replacement function.
+	get_version_from_vcs() {
+		date +%s
+	}
 fi
+version_from_vcs=3D`get_version_from_vcs`
=20
-if [ -n "$git_cmd" ] ; then
-	git=3D`$git_cmd rev-parse --verify --short HEAD 2>/dev/null`
-	svn=3D`$git_cmd svn find-rev $git 2>/dev/null`
-	if [ -n "$svn" ] ; then
-		svn=3D" r${svn}"
-		git=3D"=3D${git}"
-	else
-		svn=3D`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \
-		     sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`
-		if [ -n $svn ] ; then
-			svn=3D" r${svn}"
-			git=3D"+${git}"
-		else
-			git=3D" ${git}"
-		fi
-	fi
-	if $git_cmd --work-tree=3D${SYSDIR}/.. diff-index \
-	    --name-only HEAD | read dummy; then
-		git=3D"${git}-dirty"
-	fi
+if [ -n "$version_from_vcs" ]; then
+	version_from_vcs=3D" $version_from_vcs"
 fi
=20
 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}${version_from_vcs}: ${t}"
+#define VERSTR "${VERSION} #${v}${version_from_vcs}: ${t}\\n    ${u}@${h}:=
${d}\\n"
 #define RELSTR "${RELEASE}"
=20
 char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] =3D SCCSSTR;

--SENi13OXelf/Rv8V--

--7ff5AkW+g6+eEohN
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (FreeBSD)

iEYEARECAAYFAk8HRUAACgkQmprOCmdXAD1eYwCbBpS6Tl639jyeBOORwCwYOSFQ
epMAnjnihv7VgT5lfzwH8zAjixlZDzcJ
=vEhQ
-----END PGP SIGNATURE-----

--7ff5AkW+g6+eEohN--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120106190225.GR1733>