lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y9bloPVG++Vk2Exz@bergen.fjasle.eu>
Date:   Sun, 29 Jan 2023 22:31:12 +0100
From:   Nicolas Schier <nicolas@...sle.eu>
To:     Masahiro Yamada <masahiroy@...nel.org>
Cc:     linux-kbuild@...r.kernel.org, linux-kernel@...r.kernel.org,
        Rasmus Villemoes <rasmus.villemoes@...vas.dk>
Subject: Re: [PATCH 3/7] setlocalversion: make indentation shallower

On Sun 22 Jan 2023 23:14:23 GMT, Masahiro Yamada wrote:
> Return earlier if we are not in the correct git repository. This makes
> the code more readable.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@...nel.org>
> ---
> 
>  scripts/setlocalversion | 79 +++++++++++++++++++++--------------------
>  1 file changed, 41 insertions(+), 38 deletions(-)
> 
> diff --git a/scripts/setlocalversion b/scripts/setlocalversion
> index 5cdf409204aa..b8e1018d611e 100755
> --- a/scripts/setlocalversion
> +++ b/scripts/setlocalversion
> @@ -34,46 +34,49 @@ scm_version()
>  		short=true
>  	fi
>  
> -	# Check for git and a git repo.
> -	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 only the short version is requested, don't bother
> -			# running further git commands
> -			if $short; then
> -				echo "+"
> -				return
> -			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", $(NF-1))}'
> -			fi
> -
> -			# Add -g and exactly 12 hex chars.
> -			printf '%s%s' -g "$(echo $head | cut -c1-12)"
> -		fi
> +	if test -n "$(git rev-parse --show-cdup 2>/dev/null)"; then
> +		return
> +	fi
> +
> +	if ! head=$(git rev-parse --verify HEAD 2>/dev/null); then
> +		return
> +	fi
> +
> +	# 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
>  
> -		# 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
> +		# If only the short version is requested, don't bother
> +		# running further git commands
> +		if $short; then
> +			echo "+"
> +			return
>  		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", $(NF-1))}'
> +		fi
> +
> +		# Add -g and exactly 12 hex chars.
> +		printf '%s%s' -g "$(echo $head | cut -c1-12)"
> +	fi
> +
> +	# 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
>  }
>  
> -- 
> 2.34.1

Reviewed-by: Nicolas Schier <nicolas@...sle.eu>

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ