misc/162866: extract revision from hg.

KOIE Hidetaka koie at suri.co.jp
Fri Nov 25 05:30:11 UTC 2011


>Number:         162866
>Category:       misc
>Synopsis:       extract revision from hg.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 25 05:30:10 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     KOIE Hidetaka
>Release:        10.0-CURRENT
>Organization:
Surigiken
>Environment:
FreeBSD guriandgura 10.0-CURRENT FreeBSD 10.0-CURRENT #0 r227876+c95877008e9f,hgver,npowerd,zfs_cv_init: Thu Nov 24 21:41:32 JST 2011     koie at guriandgura:/usr/obj/usr/src/sys/GURIANDGURA  amd64
>Description:
I'm using hgsubversion that is a subversion client on mercurial(hg).
This patch is to extract hg-revision, svn-revision, and applied MQ patches.

This patch includes some minor bugfixs:
- echo "$svnversion" is removed. (it is a debug code?)
- hg/git are not used when svnversion command exists and /usr/src is not managed by subvresion.

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

# 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;


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list