Author: glebius
Date: Fri Nov 18 00:13:30 2016
New Revision: 308789
URL: https://svnweb.freebsd.org/changeset/base/308789

Log:
  If FreeBSD source tree is a subproject of a bigger project, then .git or
  .hg may reside above FreeBSD sources root.  Provide function findvcs()
  that will climb up and seek for presence of a VCS directory.
  
  Reviewed by:  imp (earlier version of the patch)

Modified:
  head/sys/conf/newvers.sh

Modified: head/sys/conf/newvers.sh
==============================================================================
--- head/sys/conf/newvers.sh    Thu Nov 17 23:16:56 2016        (r308788)
+++ head/sys/conf/newvers.sh    Fri Nov 18 00:13:30 2016        (r308789)
@@ -39,6 +39,28 @@ fi
 RELEASE="${REVISION}-${BRANCH}"
 VERSION="${TYPE} ${RELEASE}"
 
+#
+# findvcs dir
+#      Looks up directory dir at world root and up the filesystem
+#
+findvcs()
+{
+       local savedir
+
+       savedir=$(pwd)
+       cd ${SYSDIR}/..
+       while [ $(pwd) != "/" ]; do
+               if [ -d "./$1" ]; then
+                       VCSDIR=$(pwd)"/$1"
+                       cd ${savedir}
+                       return 0
+               fi
+               cd ..
+       done
+       cd ${savedir}
+       return 1
+}
+
 if [ -z "${SYSDIR}" ]; then
     SYSDIR=$(dirname $0)/..
 fi
@@ -142,19 +164,20 @@ for dir in /usr/bin /usr/local/bin; do
                p4_cmd=${dir}/p4
        fi
 done
-if [ -d "${SYSDIR}/../.git" ] ; then
+
+if findvcs .git; then
        for dir in /usr/bin /usr/local/bin; do
                if [ -x "${dir}/git" ] ; then
-                       git_cmd="${dir}/git --git-dir=${SYSDIR}/../.git"
+                       git_cmd="${dir}/git --git-dir=${VCSDIR}"
                        break
                fi
        done
 fi
 
-if [ -d "${SYSDIR}/../.hg" ] ; then
+if findvcs .hg; then
        for dir in /usr/bin /usr/local/bin; do
                if [ -x "${dir}/hg" ] ; then
-                       hg_cmd="${dir}/hg -R ${SYSDIR}/.."
+                       hg_cmd="${dir}/hg -R ${VCSDIR}"
                        break
                fi
        done
@@ -193,7 +216,7 @@ if [ -n "$git_cmd" ] ; then
        if [ -n "$git_b" ] ; then
                git="${git}(${git_b})"
        fi
-       if $git_cmd --work-tree=${SYSDIR}/.. diff-index \
+       if $git_cmd --work-tree=${VCSDIR}/.. diff-index \
            --name-only HEAD | read dummy; then
                git="${git}-dirty"
        fi
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to