Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / scripts / setlocalversion
index d6a866e..bd6dca8 100755 (executable)
 #
 
 usage() {
-       echo "Usage: $0 [--scm-only] [srctree]" >&2
+       echo "Usage: $0 [--save-scmversion] [srctree]" >&2
        exit 1
 }
 
 scm_only=false
 srctree=.
-if test "$1" = "--scm-only"; then
+if test "$1" = "--save-scmversion"; then
        scm_only=true
        shift
 fi
@@ -30,11 +30,12 @@ fi
 
 scm_version()
 {
-       local short=false
+       local short
+       short=false
 
        cd "$srctree"
        if test -e .scmversion; then
-               cat "$_"
+               cat .scmversion
                return
        fi
        if test "$1" = "--short"; then
@@ -42,7 +43,7 @@ scm_version()
        fi
 
        # Check for git and a git repo.
-       if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+       if test -d .git && 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.
@@ -74,8 +75,7 @@ scm_version()
                [ -w . ] && git update-index --refresh --unmerged > /dev/null
 
                # Check for uncommitted changes
-               if git diff-index --name-only HEAD | grep -v "^scripts/package" \
-                   | read dummy; then
+               if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
                        printf '%s' -dirty
                fi
 
@@ -84,13 +84,17 @@ scm_version()
        fi
 
        # Check for mercurial and a mercurial repo.
-       if hgid=`hg id 2>/dev/null`; then
-               tag=`printf '%s' "$hgid" | cut -d' ' -f2`
-
-               # Do we have an untagged version?
-               if [ -z "$tag" -o "$tag" = tip ]; then
-                       id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
+       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?
@@ -131,12 +135,15 @@ collect_files()
 }
 
 if $scm_only; then
-       scm_version
+       if test ! -e .scmversion; then
+               res=$(scm_version)
+               echo "$res" >.scmversion
+       fi
        exit
 fi
 
 if test -e include/config/auto.conf; then
-       source "$_"
+       . include/config/auto.conf
 else
        echo "Error: kernelrelease not valid - run 'make prepare' to update it"
        exit 1
@@ -156,8 +163,10 @@ if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
        # full scm version string
        res="$res$(scm_version)"
 else
-       # apped a plus sign if the repository is not in a clean tagged
-       # state and  LOCALVERSION= is not specified
+       # 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:++}"