]> git.ipfire.org Git - thirdparty/u-boot.git/blobdiff - scripts/setlocalversion
Merge branch 'master-fdt' of https://source.denx.de/u-boot/custodians/u-boot-sh
[thirdparty/u-boot.git] / scripts / setlocalversion
index 8564bedd1a7cf31c9b3d3f71b5c328de690bf182..4a63143706705a574957b626baa8ff4d3a050260 100755 (executable)
@@ -1,4 +1,5 @@
 #!/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).
@@ -44,11 +45,11 @@ scm_version()
 
        # Check for git and a git repo.
        if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
-          head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+          head=$(git rev-parse --verify --short 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
@@ -58,7 +59,7 @@ 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
+                       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}.
@@ -69,11 +70,19 @@ scm_version()
 
                # Is this git on svn?
                if git config --get svn-remote.svn.url >/dev/null; then
-                       printf -- '-svn%s' "`git svn find-rev $head`"
+                       printf -- '-svn%s' "$(git svn find-rev $head)"
                fi
 
-               # Check for uncommitted changes
-               if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
+               # Check for uncommitted changes.
+               # 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
+               } | grep -qvE '^(.. )?scripts/package'; then
                        printf '%s' -dirty
                fi
 
@@ -82,15 +91,15 @@ scm_version()
        fi
 
        # Check for mercurial and a mercurial repo.
-       if test -d .hg && hgid=`hg id 2>/dev/null`; then
+       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}'`
+               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`
+                       tag=$(printf '%s' "$hgid" | cut -d' ' -f2)
                        if [ -z "$tag" -o "$tag" = tip ]; then
-                               id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
+                               id=$(printf '%s' "$hgid" | sed 's/[+ ].*//')
                                printf '%s%s' -hg "$id"
                        fi
                fi
@@ -106,8 +115,8 @@ scm_version()
        fi
 
        # Check for svn and a svn repo.
-       if rev=`LANG= LC_ALL= LC_MESSAGES=C svn info 2>/dev/null | grep '^Last Changed Rev'`; then
-               rev=`echo $rev | awk '{print $NF}'`
+       if rev=$(LANG= LC_ALL= LC_MESSAGES=C svn info 2>/dev/null | grep '^Last Changed Rev'); then
+               rev=$(echo $rev | awk '{print $NF}')
                printf -- '-svn%s' "$rev"
 
                # All done with svn
@@ -117,7 +126,7 @@ scm_version()
 
 collect_files()
 {
-       local file res
+       local file res=
 
        for file; do
                case "$file" in
@@ -142,12 +151,13 @@ fi
 
 if test -e include/config/auto.conf; then
        # We are interested only in CONFIG_LOCALVERSION and
-        # CONFIG_LOCALVERSION_AUTO, so extract these in a safe
-        # way (i.e. w/o sourcing auto.conf)
-       CONFIG_LOCALVERSION=`cat include/config/auto.conf | awk -F '=' '/^CONFIG_LOCALVERSION=/ {print $2}'`
-       CONFIG_LOCALVERSION_AUTO=`cat include/config/auto.conf | awk -F '=' '/^CONFIG_LOCALVERSION_AUTO=/ {print $2}'`
+       # CONFIG_LOCALVERSION_AUTO, so extract these in a safe
+       # way (i.e. w/o sourcing auto.conf)
+       # xargs echo removes quotes
+       CONFIG_LOCALVERSION=`cat include/config/auto.conf | awk -F '=' '/^CONFIG_LOCALVERSION=/ {print $2}' | xargs echo`
+       CONFIG_LOCALVERSION_AUTO=`cat include/config/auto.conf | awk -F '=' '/^CONFIG_LOCALVERSION_AUTO=/ {print $2}' | xargs echo`
 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