mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] setlocalversion: update to Linux 5.16
@ 2022-02-07 13:47 Masahiro Yamada
  2022-02-08  8:15 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Masahiro Yamada @ 2022-02-07 13:47 UTC (permalink / raw)
  To: barebox; +Cc: Masahiro Yamada

It has been a long time since this script was updated.

Now resync it with Linux 5.16.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/setlocalversion | 103 +++++++++++++++-------------------------
 1 file changed, 39 insertions(+), 64 deletions(-)

diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index cce4706cc..6b54e46a0 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -1,8 +1,14 @@
 #!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
 #
 # This scripts adds local version information from the version
 # control systems git, mercurial (hg) and subversion (svn).
 #
+# If something goes wrong, send a mail the kernel build mailinglist
+# (see MAINTAINERS) and CC Nico Schottelius
+# <nico-linuxsetlocalversion -at- schottelius.org>.
+#
+#
 
 usage() {
 	echo "Usage: $0 [--save-scmversion] [srctree]" >&2
@@ -38,11 +44,12 @@ scm_version()
 	fi
 
 	# Check for git and a git repo.
-	if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+	if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
+	   head=$(git rev-parse --verify HEAD 2>/dev/null); then
 
 		# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
 		# it, because this version is defined in the top level Makefile.
-		if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
+		if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
 
 			# If only the short version is requested, don't bother
 			# running further git commands
@@ -52,69 +59,36 @@ scm_version()
 			fi
 			# If we are past a tagged commit (like
 			# "v2.6.30-rc5-302-g72357d5"), we pretty print it.
-			if atag="`git describe 2>/dev/null`"; then
-				echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
-
-			# If we don't have a tag at all we print -g{commitish}.
-			else
-				printf '%s%s' -g $head
+			if atag="$(git describe 2>/dev/null)"; then
+				echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}'
 			fi
-		fi
 
-		# Is this git on svn?
-		if git config --get svn-remote.svn.url >/dev/null; then
-			printf -- '-svn%s' "`git svn find-rev $head`"
+			# Add -g and exactly 12 hex chars.
+			printf '%s%s' -g "$(echo $head | cut -c1-12)"
 		fi
 
-		# Update index only on r/w media
-		[ -w . ] && git update-index --refresh --unmerged > /dev/null
-
-		# Check for uncommitted changes
-		if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
+		# Check for uncommitted changes.
+		# This script must avoid any write attempt to the source tree,
+		# which might be read-only.
+		# You cannot use 'git describe --dirty' because it tries to
+		# create .git/index.lock .
+		# First, with git-status, but --no-optional-locks is only
+		# supported in git >= 2.14, so fall back to git-diff-index if
+		# it fails. Note that git-diff-index does not refresh the
+		# index, so it may give misleading results. See
+		# git-update-index(1), git-diff-index(1), and git-status(1).
+		if {
+			git --no-optional-locks status -uno --porcelain 2>/dev/null ||
+			git diff-index --name-only HEAD
+		} | read dummy; then
 			printf '%s' -dirty
 		fi
-
-		# All done with git
-		return
-	fi
-
-	# Check for mercurial and a mercurial repo.
-	if test -d .hg && hgid=`hg id 2>/dev/null`; then
-		# Do we have an tagged version?  If so, latesttagdistance == 1
-		if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then
-			id=`hg log -r . --template '{latesttag}'`
-			printf '%s%s' -hg "$id"
-		else
-			tag=`printf '%s' "$hgid" | cut -d' ' -f2`
-			if [ -z "$tag" -o "$tag" = tip ]; then
-				id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
-				printf '%s%s' -hg "$id"
-			fi
-		fi
-
-		# Are there uncommitted changes?
-		# These are represented by + after the changeset id.
-		case "$hgid" in
-			*+|*+\ *) printf '%s' -dirty ;;
-		esac
-
-		# All done with mercurial
-		return
-	fi
-
-	# Check for svn and a svn repo.
-	if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
-		rev=`echo $rev | awk '{print $NF}'`
-		printf -- '-svn%s' "$rev"
-
-		# All done with svn
-		return
 	fi
 }
 
 collect_files()
 {
-	local file res
+	local file res=
 
 	for file; do
 		case "$file" in
@@ -140,7 +114,7 @@ fi
 if test -e include/config/auto.conf; then
 	. include/config/auto.conf
 else
-	echo "Error: kernelrelease not valid - run 'make prepare' to update it"
+	echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
 	exit 1
 fi
 
@@ -157,15 +131,16 @@ res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"
 if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
 	# full scm version string
 	res="$res$(scm_version)"
-else
-	# append a plus sign if the repository is not in a clean
-	# annotated or signed tagged state (as git describe only
-	# looks at signed or annotated tags - git tag -a/-s) and
-	# LOCALVERSION= is not specified
-	if test "${LOCALVERSION+set}" != "set"; then
-		scm=$(scm_version --short)
-		res="$res${scm:++}"
-	fi
+elif [ "${LOCALVERSION+set}" != "set" ]; then
+	# If the variable LOCALVERSION is not set, append a plus
+	# sign if the repository is not in a clean annotated or
+	# signed tagged state (as git describe only looks at signed
+	# or annotated tags - git tag -a/-s).
+	#
+	# If the variable LOCALVERSION is set (including being set
+	# to an empty string), we don't want to append a plus sign.
+	scm=$(scm_version --short)
+	res="$res${scm:++}"
 fi
 
 echo "$res"
-- 
2.32.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] setlocalversion: update to Linux 5.16
  2022-02-07 13:47 [PATCH] setlocalversion: update to Linux 5.16 Masahiro Yamada
@ 2022-02-08  8:15 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-02-08  8:15 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: barebox

On Mon, Feb 07, 2022 at 10:47:07PM +0900, Masahiro Yamada wrote:
> It has been a long time since this script was updated.
> 
> Now resync it with Linux 5.16.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  scripts/setlocalversion | 103 +++++++++++++++-------------------------
>  1 file changed, 39 insertions(+), 64 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/scripts/setlocalversion b/scripts/setlocalversion
> index cce4706cc..6b54e46a0 100755
> --- a/scripts/setlocalversion
> +++ b/scripts/setlocalversion
> @@ -1,8 +1,14 @@
>  #!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0
>  #
>  # This scripts adds local version information from the version
>  # control systems git, mercurial (hg) and subversion (svn).
>  #
> +# If something goes wrong, send a mail the kernel build mailinglist
> +# (see MAINTAINERS) and CC Nico Schottelius
> +# <nico-linuxsetlocalversion -at- schottelius.org>.
> +#
> +#
>  
>  usage() {
>  	echo "Usage: $0 [--save-scmversion] [srctree]" >&2
> @@ -38,11 +44,12 @@ scm_version()
>  	fi
>  
>  	# Check for git and a git repo.
> -	if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
> +	if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
> +	   head=$(git rev-parse --verify HEAD 2>/dev/null); then
>  
>  		# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
>  		# it, because this version is defined in the top level Makefile.
> -		if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
> +		if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
>  
>  			# If only the short version is requested, don't bother
>  			# running further git commands
> @@ -52,69 +59,36 @@ scm_version()
>  			fi
>  			# If we are past a tagged commit (like
>  			# "v2.6.30-rc5-302-g72357d5"), we pretty print it.
> -			if atag="`git describe 2>/dev/null`"; then
> -				echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
> -
> -			# If we don't have a tag at all we print -g{commitish}.
> -			else
> -				printf '%s%s' -g $head
> +			if atag="$(git describe 2>/dev/null)"; then
> +				echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}'
>  			fi
> -		fi
>  
> -		# Is this git on svn?
> -		if git config --get svn-remote.svn.url >/dev/null; then
> -			printf -- '-svn%s' "`git svn find-rev $head`"
> +			# Add -g and exactly 12 hex chars.
> +			printf '%s%s' -g "$(echo $head | cut -c1-12)"
>  		fi
>  
> -		# Update index only on r/w media
> -		[ -w . ] && git update-index --refresh --unmerged > /dev/null
> -
> -		# Check for uncommitted changes
> -		if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
> +		# Check for uncommitted changes.
> +		# This script must avoid any write attempt to the source tree,
> +		# which might be read-only.
> +		# You cannot use 'git describe --dirty' because it tries to
> +		# create .git/index.lock .
> +		# First, with git-status, but --no-optional-locks is only
> +		# supported in git >= 2.14, so fall back to git-diff-index if
> +		# it fails. Note that git-diff-index does not refresh the
> +		# index, so it may give misleading results. See
> +		# git-update-index(1), git-diff-index(1), and git-status(1).
> +		if {
> +			git --no-optional-locks status -uno --porcelain 2>/dev/null ||
> +			git diff-index --name-only HEAD
> +		} | read dummy; then
>  			printf '%s' -dirty
>  		fi
> -
> -		# All done with git
> -		return
> -	fi
> -
> -	# Check for mercurial and a mercurial repo.
> -	if test -d .hg && hgid=`hg id 2>/dev/null`; then
> -		# Do we have an tagged version?  If so, latesttagdistance == 1
> -		if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then
> -			id=`hg log -r . --template '{latesttag}'`
> -			printf '%s%s' -hg "$id"
> -		else
> -			tag=`printf '%s' "$hgid" | cut -d' ' -f2`
> -			if [ -z "$tag" -o "$tag" = tip ]; then
> -				id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
> -				printf '%s%s' -hg "$id"
> -			fi
> -		fi
> -
> -		# Are there uncommitted changes?
> -		# These are represented by + after the changeset id.
> -		case "$hgid" in
> -			*+|*+\ *) printf '%s' -dirty ;;
> -		esac
> -
> -		# All done with mercurial
> -		return
> -	fi
> -
> -	# Check for svn and a svn repo.
> -	if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
> -		rev=`echo $rev | awk '{print $NF}'`
> -		printf -- '-svn%s' "$rev"
> -
> -		# All done with svn
> -		return
>  	fi
>  }
>  
>  collect_files()
>  {
> -	local file res
> +	local file res=
>  
>  	for file; do
>  		case "$file" in
> @@ -140,7 +114,7 @@ fi
>  if test -e include/config/auto.conf; then
>  	. include/config/auto.conf
>  else
> -	echo "Error: kernelrelease not valid - run 'make prepare' to update it"
> +	echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
>  	exit 1
>  fi
>  
> @@ -157,15 +131,16 @@ res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"
>  if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
>  	# full scm version string
>  	res="$res$(scm_version)"
> -else
> -	# append a plus sign if the repository is not in a clean
> -	# annotated or signed tagged state (as git describe only
> -	# looks at signed or annotated tags - git tag -a/-s) and
> -	# LOCALVERSION= is not specified
> -	if test "${LOCALVERSION+set}" != "set"; then
> -		scm=$(scm_version --short)
> -		res="$res${scm:++}"
> -	fi
> +elif [ "${LOCALVERSION+set}" != "set" ]; then
> +	# If the variable LOCALVERSION is not set, append a plus
> +	# sign if the repository is not in a clean annotated or
> +	# signed tagged state (as git describe only looks at signed
> +	# or annotated tags - git tag -a/-s).
> +	#
> +	# If the variable LOCALVERSION is set (including being set
> +	# to an empty string), we don't want to append a plus sign.
> +	scm=$(scm_version --short)
> +	res="$res${scm:++}"
>  fi
>  
>  echo "$res"
> -- 
> 2.32.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-08  8:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-07 13:47 [PATCH] setlocalversion: update to Linux 5.16 Masahiro Yamada
2022-02-08  8:15 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox