git: a3c92efcaa12 - stable/12 - newvers.sh: add support for gitup(1)

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Tue, 06 Sep 2022 19:32:22 UTC
The branch stable/12 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=a3c92efcaa1252bcff87884a76e7c4a9f2c4afc5

commit a3c92efcaa1252bcff87884a76e7c4a9f2c4afc5
Author:     Michael Osipov <michael.osipov@siemens.com>
AuthorDate: 2021-01-05 10:48:39 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-09-06 19:31:39 +0000

    newvers.sh: add support for gitup(1)
    
    gitup writes a .gituprevision file into the shallow clone directory. Read that
    file and print commit information only.
    
    Submitted by:   Michael Osipov <michael.osipov@siemens.com>
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/449
    
    While here, drop the redundant branch name from the git output and don't
    count commits in shallow clones.
    
    Reported by:    Michael Osipov <michael.osipov@siemens.com>
    MFC after:      2 weeks
    
    PR:             252507
    
    (cherry picked from commit a9fc14fbf445cffd18f34f6a602bdba84bb5a867)
---
 sys/conf/newvers.sh | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh
index 542dae42b567..f8511a3f5912 100644
--- a/sys/conf/newvers.sh
+++ b/sys/conf/newvers.sh
@@ -190,6 +190,10 @@ if findvcs .git; then
 	done
 fi
 
+if findvcs .gituprevision; then
+	gituprevision="${VCSTOP}/.gituprevision"
+fi
+
 if findvcs .hg; then
 	for dir in /usr/bin /usr/local/bin; do
 		if [ -x "${dir}/hg" ] ; then
@@ -217,9 +221,11 @@ fi
 
 if [ -n "$git_cmd" ] ; then
 	git=$($git_cmd rev-parse --verify --short HEAD 2>/dev/null)
-	git_cnt=$($git_cmd rev-list --first-parent --count HEAD 2>/dev/null)
-	if [ -n "$git_cnt" ] ; then
-		git="n${git_cnt}-${git}"
+	if [ "$(git rev-parse --is-shallow-repository)" = false ] ; then
+		git_cnt=$($git_cmd rev-list --first-parent --count HEAD 2>/dev/null)
+		if [ -n "$git_cnt" ] ; then
+			git="n${git_cnt}-${git}"
+		fi
 	fi
 	git_b=$($git_cmd rev-parse --abbrev-ref HEAD)
 	if [ -n "$git_b" -a "$git_b" != "HEAD" ] ; then
@@ -232,6 +238,10 @@ if [ -n "$git_cmd" ] ; then
 	git=" ${git}"
 fi
 
+if [ -n "$gituprevision" ] ; then
+	gitup=" $(awk -F: '{print $2}' $gituprevision)"
+fi
+
 if [ -n "$p4_cmd" ] ; then
 	p4version=`cd ${SYSDIR} && $p4_cmd changes -m1 "./...#have" 2>&1 | \
 		awk '{ print $2 }'`
@@ -278,10 +288,10 @@ done
 shift $((OPTIND - 1))
 
 if [ -z "${include_metadata}" ]; then
-	VERINFO="${VERSION}${svn}${git}${hg}${p4version} ${i}"
+	VERINFO="${VERSION}${svn}${git}${gitup}${hg}${p4version} ${i}"
 	VERSTR="${VERINFO}\\n"
 else
-	VERINFO="${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}"
+	VERINFO="${VERSION} #${v}${svn}${git}${gitup}${hg}${p4version}: ${t}"
 	VERSTR="${VERINFO}\\n    ${u}@${h}:${d}\\n"
 fi