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)
This commit is contained in:
Gleb Smirnoff 2016-11-18 00:13:30 +00:00
parent 9952941dd9
commit 5e680acd76
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=308789

View File

@ -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