Fix make-array transforms.
[sbcl.git] / generate-version.sh
index 10dcc5b..7d2ef6f 100755 (executable)
@@ -2,30 +2,21 @@
 # Not a shell script, but something intended to be sourced from shell scripts
 git_available_p() {
     # Check that (1) we have git (2) this is a git tree.
-    if (which git >/dev/null 2>/dev/null && git describe >/dev/null 2>/dev/null)
+    if ( which git >/dev/null 2>/dev/null && git describe >/dev/null 2>/dev/null )
     then
-        # Check that some of the newer git versions we use are supported.
-        if [ "0" != "$(git rev-list HEAD --not HEAD --count 2> /dev/null)" ]
-        then
-            echo "Too old a git installation."
-            echo
-            echo "Your git doesn't support --count option with git rev-list,"
-            echo "which SBCL build requires. Git 1.7.2 or later should work."
-            exit 1
-        else
-            true
-        fi
+        echo "ok"
     else
-        false
+        echo ""
     fi
 }
 
 generate_version() {
-    if ([ -f version.lisp-expr ] && ! git_available_p)
+    AVAILABLE=`git_available_p`
+    if [ -f version.lisp-expr -a -z "$AVAILABLE" ]
     then
         # Relase tarball, leave version.lisp-expr alone.
         return
-    elif ! git_available_p
+    elif [ -z "$AVAILABLE" ]
     then
         echo "Can't run 'git describe' and version.lisp-expr is missing." >&2
         echo "To fix this, either install git or create a fake version.lisp-expr file." >&2
@@ -34,18 +25,34 @@ generate_version() {
         exit 1
     fi
     # Build it.
-    version_head=$(git rev-parse HEAD)
+    version_head=`git rev-parse HEAD`
+    if grep -q "ref: refs/heads/.*" .git/HEAD > /dev/null 2>&1
+    then
+        version_branchname=`cut -d / -f 3- < .git/HEAD`
+    else
+        # Detached head.
+        version_branchname="HEAD"
+    fi
     if [ -z "$SBCL_BUILDING_RELEASE_FROM" ]
     then
-        version_root="origin/master"
+        if [ "`git rev-list HEAD --not origin/master`" = '' ]
+        then
+            # If origin/master contains all the commits on current
+            # branch, use current head as the root instead.
+            version_root="$version_branchname"
+        else
+            version_root="origin/master"
+        fi
     else
         version_root="$SBCL_BUILDING_RELEASE_FROM"
     fi
-    version_base=$(git rev-parse "$version_root")
+    version_base=`git rev-parse "$version_root"`
     version_tag=`git describe --tags --match="sbcl*" --abbrev=0 $version_base`
     version_release=`echo $version_tag | sed -e 's/sbcl[_-]//' | sed -e 's/_/\./g'`
-    version_n_root=`git rev-list $version_base --not $version_tag --count`
-    version_n_branch=`git rev-list HEAD --not $version_base --count`
+    # Using wc -l instead of --count argument to rev-list because
+    # pre-1.7.2 Gits are still common out in the wilderness.
+    version_n_root=`git rev-list $version_base --not $version_tag | wc -l`
+    version_n_branch=`git rev-list HEAD --not $version_base | wc -l`
     if [ -z "$NO_GIT_HASH_IN_VERSION" ]
     then
         version_hash="-`git rev-parse --short $version_head`"
@@ -78,7 +85,6 @@ EOF
     else
         echo "base=$version_base"
         echo "head=$version_head"
-        version_branchname=`git describe --contains --all HEAD`
         printf "\"%s.%s.%s.%s%s%s\"\n" \
             $version_release $version_n_root \
             $version_branchname $version_n_branch \