diff mbox

[v2,00/15] version-gen: complete revamp/rewrite

Message ID 20230424165041.25180-1-felipe.contreras@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Felipe Contreras April 24, 2023, 4:50 p.m. UTC
The version generation script needs some love, as the last true change was done in 2008.

This series step by step revamps the whole script ending in only a few lines of code.

There should be no functional changes.

It's hard to see the actual changes to this script as 99% of the commits are
just to bump the default version (which I don't know why it even exists).

For reference, cleaning the history I came up with these actual changes in case
anyone is interested:

c48799e560 (Teach GIT-VERSION-GEN about the .git file, 2008-02-20)
1100ac81a9 (Change GIT-VERSION-GEN to call git commands with "git" not "git-"., 2006-05-22)
374dfaa2e3 (Make GIT-VERSION-GEN tolerate missing git describe command again, 2006-01-26)
5c7d3c9507 (Allow building of RPM from interim snapshot., 2006-01-16)
181129d24c (For release tarballs, include the proper version, 2006-01-09)
026351a035 (Make GIT-VERSION-GEN tolerate missing git describe command, 2005-12-30)
9b88fcef7d (Makefile: use git-describe to mark the git version., 2005-12-27)

Cheers.

Changes since v1:

I removed all the controverrsial functional changes (those will come in
a separate series) due to comments by Todd Zullinger.

The non-functional changes are already plenty, so let's focus on those
first.


Felipe Contreras (15):
  version-gen: reorganize
  version-gen: trivial cleanup
  version-gen: refactor default version
  version-gen: simplify v prefix removal
  version-gen: simplify update check
  version-gen: simplify `git describe` checks
  version-gen: simplify dirty check
  version-gen: move describe fix into function
  version-gen: describe and sed in one go
  version-gen: refactor describe function
  version-gen: do v fix only when necessary
  version-gen: move v fix into sed
  version-gen: refactor main functionality
  version-gen: refactor GIT_VERSION string
  version-gen: get rid of GVF variable

 GIT-VERSION-GEN | 50 ++++++++++++++-----------------------------------
 1 file changed, 14 insertions(+), 36 deletions(-)

Range-diff against v1:
 1:  18ac0e3784 =  1:  dbe102186a version-gen: reorganize
 2:  280efc616f =  2:  9a1a46481b version-gen: trivial cleanup
 3:  af67bdb106 =  3:  04d6741689 version-gen: refactor default version
 4:  798fd082f3 =  4:  770eeb9abc version-gen: simplify v prefix removal
 5:  adbad7eab8 =  5:  2234d37305 version-gen: simplify update check
 6:  2742189cc7 <  -:  ---------- version-gen: remove redundant check
 7:  414e2efddd =  6:  0784430fe6 version-gen: simplify `git describe` checks
 8:  04b755dcc1 =  7:  aa0ac9d10c version-gen: simplify dirty check
 9:  05519e8ece !  8:  51272021d9 version-gen: move describe fix into function
    @@ GIT-VERSION-GEN: describe () {
      if test -f version
      then
      	VN=$(cat version)
    --elif describe
    --then
    +-elif test -d "${GIT_DIR:-.git}" -o -f .git && describe
    ++elif test -d "${GIT_DIR:-.git}" -o -f .git
    + then
     -	VN=$(echo "$VN" | sed -e 's/-/./g')
    -+else
     +	describe
      fi
      
10:  f9b0092966 =  9:  06eb36044f version-gen: describe and sed in one go
11:  2a5167e4f0 ! 10:  4c0785fb5d version-gen: refactor describe function
    @@ GIT-VERSION-GEN: GVF=GIT-VERSION-FILE
      }
      
      # First see if there is a version file (included in release tarballs),
    -@@ GIT-VERSION-GEN: if test -f version
    - then
    +@@ GIT-VERSION-GEN: then
      	VN=$(cat version)
    - else
    + elif test -d "${GIT_DIR:-.git}" -o -f .git
    + then
     -	describe
     +	VN=$(describe)
      fi
12:  a71fe9229b ! 11:  7bd0e69a1b version-gen: do v fix only when necessary
    @@ GIT-VERSION-GEN
      describe () {
      	git describe --match "v[0-9]*" --dirty 2>/dev/null | sed -e 's/-/./g'
     @@ GIT-VERSION-GEN: then
    - 	VN=$(cat version)
    - else
    + elif test -d "${GIT_DIR:-.git}" -o -f .git
    + then
      	VN=$(describe)
     +	VN=${VN#v}
      fi
13:  5462474c52 ! 12:  3834398857 version-gen: move v fix into sed
    @@ GIT-VERSION-GEN: GVF=GIT-VERSION-FILE
      
      # First see if there is a version file (included in release tarballs),
     @@ GIT-VERSION-GEN: then
    - 	VN=$(cat version)
    - else
    + elif test -d "${GIT_DIR:-.git}" -o -f .git
    + then
      	VN=$(describe)
     -	VN=${VN#v}
      fi
14:  64cb12343a ! 13:  18c2cbaf9c version-gen: refactor main functionality
    @@ GIT-VERSION-GEN
     -describe () {
     +get_version () {
     +	test -f version && cat version && return
    ++	test -d "${GIT_DIR:-.git}" -o -f .git || return
      	git describe --match "v[0-9]*" --dirty 2>/dev/null | sed -e 's/-/./g' -e 's/^v//'
      }
      
    @@ GIT-VERSION-GEN
     -if test -f version
     -then
     -	VN=$(cat version)
    --else
    +-elif test -d "${GIT_DIR:-.git}" -o -f .git
    +-then
     -	VN=$(describe)
     -fi
     +VN=$(get_version)
15:  16b6e38ace <  -:  ---------- version-gen: remove default version
16:  7bb1206f00 <  -:  ---------- version-gen: refactor GIT_VERSION string
 -:  ---------- > 14:  6c594361df version-gen: refactor GIT_VERSION string
17:  e0cd32d548 ! 15:  edf380d2fa version-gen: get rid of GVF variable
    @@ GIT-VERSION-GEN
      #!/bin/sh
      
     -GVF=GIT-VERSION-FILE
    --
    - get_version () {
    - 	test -f version && cat version && return
    - 	git describe --match "v[0-9]*" --dirty 2>/dev/null | sed -e 's/-/./g' -e 's/^v//'
    -@@ GIT-VERSION-GEN: get_version () {
    + DEF_VER=2.40.GIT
      
    - NEW="GIT_VERSION = $(get_version)"
    + get_version () {
    +@@ GIT-VERSION-GEN: VN=$(get_version)
    + 
    + NEW="GIT_VERSION = $VN"
      
     -test -r $GVF && test "$NEW" = "$(cat $GVF)" && exit
     -echo "$NEW" | tee $GVF >&2
18:  43a59f630a <  -:  ---------- version-gen: generate proper interim versions
diff mbox

Patch

diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 9a1111af9b..3d30ce74af 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,40 +1,18 @@ 
 #!/bin/sh
 
-GVF=GIT-VERSION-FILE
-DEF_VER=v2.40.GIT
+DEF_VER=2.40.GIT
 
-LF='
-'
-
-# First see if there is a version file (included in release tarballs),
-# then try git-describe, then default.
-if test -f version
-then
-	VN=$(cat version) || VN="$DEF_VER"
-elif test -d ${GIT_DIR:-.git} -o -f .git &&
-	VN=$(git describe --match "v[0-9]*" HEAD 2>/dev/null) &&
-	case "$VN" in
-	*$LF*) (exit 1) ;;
-	v[0-9]*)
-		git update-index -q --refresh
-		test -z "$(git diff-index --name-only HEAD --)" ||
-		VN="$VN-dirty" ;;
-	esac
-then
-	VN=$(echo "$VN" | sed -e 's/-/./g');
-else
-	VN="$DEF_VER"
-fi
-
-VN=$(expr "$VN" : v*'\(.*\)')
-
-if test -r $GVF
-then
-	VC=$(sed -e 's/^GIT_VERSION = //' <$GVF)
-else
-	VC=unset
-fi
-test "$VN" = "$VC" || {
-	echo >&2 "GIT_VERSION = $VN"
-	echo "GIT_VERSION = $VN" >$GVF
+get_version () {
+	test -f version && cat version && return
+	test -d "${GIT_DIR:-.git}" -o -f .git || return
+	git describe --match "v[0-9]*" --dirty 2>/dev/null | sed -e 's/-/./g' -e 's/^v//'
 }
+
+VN=$(get_version)
+
+: "${VN:=$DEF_VER}"
+
+NEW="GIT_VERSION = $VN"
+
+test -r GIT-VERSION-FILE && test "$NEW" = "$(cat GIT-VERSION-FILE)" && exit
+echo "$NEW" | tee GIT-VERSION-FILE >&2