misc/149510: [CFT] [sys/conf/newvers.sh] Cleanup and additions.
J. Hellenthal
jhell at DataIX.net
Tue Aug 10 20:30:07 UTC 2010
>Number: 149510
>Category: misc
>Synopsis: [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:
>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 at 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 at 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:
>Unformatted:
More information about the freebsd-bugs
mailing list