{"thread":{"id":"59645","subject":"[PATCH v2 00/15] version-gen: complete revamp/rewrite","startedAt":"2023-04-24T16:50:51Z","lastAt":"2023-04-24T16:52:13Z","messageCount":16,"participants":["Felipe Contreras"],"isPatch":true,"patchVersion":2,"patchTotal":15},"messages":[{"id":"475934","messageId":"20230424165041.25180-1-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":null,"subject":"[PATCH v2 00/15] version-gen: complete revamp/rewrite","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:26Z","receivedAt":"2023-04-24T16:50:51Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"The version generation script needs some love, as the last true change was done in 2008.\n\nThis series step by step revamps the whole script ending in only a few lines of code.\n\nThere should be no functional changes.\n\nIt's hard to see the actual changes to this script as 99% of the commits are\njust to bump the default version (which I don't know why it even exists).\n\nFor reference, cleaning the history I came up with these actual changes in case\nanyone is interested:\n\nc48799e560 (Teach GIT-VERSION-GEN about the .git file, 2008-02-20)\n1100ac81a9 (Change GIT-VERSION-GEN to call git commands with \"git\" not \"git-\"., 2006-05-22)\n374dfaa2e3 (Make GIT-VERSION-GEN tolerate missing git describe command again, 2006-01-26)\n5c7d3c9507 (Allow building of RPM from interim snapshot., 2006-01-16)\n181129d24c (For release tarballs, include the proper version, 2006-01-09)\n026351a035 (Make GIT-VERSION-GEN tolerate missing git describe command, 2005-12-30)\n9b88fcef7d (Makefile: use git-describe to mark the git version., 2005-12-27)\n\nCheers.\n\nChanges since v1:\n\nI removed all the controverrsial functional changes (those will come in\na separate series) due to comments by Todd Zullinger.\n\nThe non-functional changes are already plenty, so let's focus on those\nfirst.\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 9a1111af9b..3d30ce74af 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -1,40 +1,18 @@\n #!/bin/sh\n \n-GVF=GIT-VERSION-FILE\n-DEF_VER=v2.40.GIT\n+DEF_VER=2.40.GIT\n \n-LF='\n-'\n-\n-# First see if there is a version file (included in release tarballs),\n-# then try git-describe, then default.\n-if test -f version\n-then\n-\tVN=$(cat version) || VN=\"$DEF_VER\"\n-elif test -d ${GIT_DIR:-.git} -o -f .git &&\n-\tVN=$(git describe --match \"v[0-9]*\" HEAD 2>/dev/null) &&\n-\tcase \"$VN\" in\n-\t*$LF*) (exit 1) ;;\n-\tv[0-9]*)\n-\t\tgit update-index -q --refresh\n-\t\ttest -z \"$(git diff-index --name-only HEAD --)\" ||\n-\t\tVN=\"$VN-dirty\" ;;\n-\tesac\n-then\n-\tVN=$(echo \"$VN\" | sed -e 's/-/./g');\n-else\n-\tVN=\"$DEF_VER\"\n-fi\n-\n-VN=$(expr \"$VN\" : v*'\\(.*\\)')\n-\n-if test -r $GVF\n-then\n-\tVC=$(sed -e 's/^GIT_VERSION = //' <$GVF)\n-else\n-\tVC=unset\n-fi\n-test \"$VN\" = \"$VC\" || {\n-\techo >&2 \"GIT_VERSION = $VN\"\n-\techo \"GIT_VERSION = $VN\" >$GVF\n+get_version () {\n+\ttest -f version && cat version && return\n+\ttest -d \"${GIT_DIR:-.git}\" -o -f .git || return\n+\tgit describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g' -e 's/^v//'\n }\n+\n+VN=$(get_version)\n+\n+: \"${VN:=$DEF_VER}\"\n+\n+NEW=\"GIT_VERSION = $VN\"\n+\n+test -r GIT-VERSION-FILE && test \"$NEW\" = \"$(cat GIT-VERSION-FILE)\" && exit\n+echo \"$NEW\" | tee GIT-VERSION-FILE >&2\n\nFelipe Contreras (15):\n  version-gen: reorganize\n  version-gen: trivial cleanup\n  version-gen: refactor default version\n  version-gen: simplify v prefix removal\n  version-gen: simplify update check\n  version-gen: simplify `git describe` checks\n  version-gen: simplify dirty check\n  version-gen: move describe fix into function\n  version-gen: describe and sed in one go\n  version-gen: refactor describe function\n  version-gen: do v fix only when necessary\n  version-gen: move v fix into sed\n  version-gen: refactor main functionality\n  version-gen: refactor GIT_VERSION string\n  version-gen: get rid of GVF variable\n\n GIT-VERSION-GEN | 50 ++++++++++++++-----------------------------------\n 1 file changed, 14 insertions(+), 36 deletions(-)\n\nRange-diff against v1:\n 1:  18ac0e3784 =  1:  dbe102186a version-gen: reorganize\n 2:  280efc616f =  2:  9a1a46481b version-gen: trivial cleanup\n 3:  af67bdb106 =  3:  04d6741689 version-gen: refactor default version\n 4:  798fd082f3 =  4:  770eeb9abc version-gen: simplify v prefix removal\n 5:  adbad7eab8 =  5:  2234d37305 version-gen: simplify update check\n 6:  2742189cc7 <  -:  ---------- version-gen: remove redundant check\n 7:  414e2efddd =  6:  0784430fe6 version-gen: simplify `git describe` checks\n 8:  04b755dcc1 =  7:  aa0ac9d10c version-gen: simplify dirty check\n 9:  05519e8ece !  8:  51272021d9 version-gen: move describe fix into function\n    @@ GIT-VERSION-GEN: describe () {\n      if test -f version\n      then\n      \tVN=$(cat version)\n    --elif describe\n    --then\n    +-elif test -d \"${GIT_DIR:-.git}\" -o -f .git && describe\n    ++elif test -d \"${GIT_DIR:-.git}\" -o -f .git\n    + then\n     -\tVN=$(echo \"$VN\" | sed -e 's/-/./g')\n    -+else\n     +\tdescribe\n      fi\n      \n10:  f9b0092966 =  9:  06eb36044f version-gen: describe and sed in one go\n11:  2a5167e4f0 ! 10:  4c0785fb5d version-gen: refactor describe function\n    @@ GIT-VERSION-GEN: GVF=GIT-VERSION-FILE\n      }\n      \n      # First see if there is a version file (included in release tarballs),\n    -@@ GIT-VERSION-GEN: if test -f version\n    - then\n    +@@ GIT-VERSION-GEN: then\n      \tVN=$(cat version)\n    - else\n    + elif test -d \"${GIT_DIR:-.git}\" -o -f .git\n    + then\n     -\tdescribe\n     +\tVN=$(describe)\n      fi\n12:  a71fe9229b ! 11:  7bd0e69a1b version-gen: do v fix only when necessary\n    @@ GIT-VERSION-GEN\n      describe () {\n      \tgit describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g'\n     @@ GIT-VERSION-GEN: then\n    - \tVN=$(cat version)\n    - else\n    + elif test -d \"${GIT_DIR:-.git}\" -o -f .git\n    + then\n      \tVN=$(describe)\n     +\tVN=${VN#v}\n      fi\n13:  5462474c52 ! 12:  3834398857 version-gen: move v fix into sed\n    @@ GIT-VERSION-GEN: GVF=GIT-VERSION-FILE\n      \n      # First see if there is a version file (included in release tarballs),\n     @@ GIT-VERSION-GEN: then\n    - \tVN=$(cat version)\n    - else\n    + elif test -d \"${GIT_DIR:-.git}\" -o -f .git\n    + then\n      \tVN=$(describe)\n     -\tVN=${VN#v}\n      fi\n14:  64cb12343a ! 13:  18c2cbaf9c version-gen: refactor main functionality\n    @@ GIT-VERSION-GEN\n     -describe () {\n     +get_version () {\n     +\ttest -f version && cat version && return\n    ++\ttest -d \"${GIT_DIR:-.git}\" -o -f .git || return\n      \tgit describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g' -e 's/^v//'\n      }\n      \n    @@ GIT-VERSION-GEN\n     -if test -f version\n     -then\n     -\tVN=$(cat version)\n    --else\n    +-elif test -d \"${GIT_DIR:-.git}\" -o -f .git\n    +-then\n     -\tVN=$(describe)\n     -fi\n     +VN=$(get_version)\n15:  16b6e38ace <  -:  ---------- version-gen: remove default version\n16:  7bb1206f00 <  -:  ---------- version-gen: refactor GIT_VERSION string\n -:  ---------- > 14:  6c594361df version-gen: refactor GIT_VERSION string\n17:  e0cd32d548 ! 15:  edf380d2fa version-gen: get rid of GVF variable\n    @@ GIT-VERSION-GEN\n      #!/bin/sh\n      \n     -GVF=GIT-VERSION-FILE\n    --\n    - get_version () {\n    - \ttest -f version && cat version && return\n    - \tgit describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g' -e 's/^v//'\n    -@@ GIT-VERSION-GEN: get_version () {\n    + DEF_VER=2.40.GIT\n      \n    - NEW=\"GIT_VERSION = $(get_version)\"\n    + get_version () {\n    +@@ GIT-VERSION-GEN: VN=$(get_version)\n    + \n    + NEW=\"GIT_VERSION = $VN\"\n      \n     -test -r $GVF && test \"$NEW\" = \"$(cat $GVF)\" && exit\n     -echo \"$NEW\" | tee $GVF >&2\n18:  43a59f630a <  -:  ---------- version-gen: generate proper interim versions\n-- \n2.40.0+fc1\n\n"},{"id":"475935","messageId":"20230424165041.25180-5-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 04/15] version-gen: simplify v prefix removal","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:30Z","receivedAt":"2023-04-24T16:50:53Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"There is a much simpler way.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 0d00fa3d9a..c0f6bb242f 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -33,7 +33,7 @@ fi\n \n : \"${VN:=$DEF_VER}\"\n \n-VN=$(expr \"$VN\" : 'v*\\(.*\\)')\n+VN=${VN#v}\n \n if test -r $GVF\n then\n-- \n2.40.0+fc1\n\n"},{"id":"475936","messageId":"20230424165041.25180-2-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 01/15] version-gen: reorganize","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:27Z","receivedAt":"2023-04-24T16:50:54Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Simply move some code into a `describe` function so it's clear what code\nis related to dealing with `git describe`, and what code is the main\nfunctionality.\n\nNo functional changes.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 25 ++++++++++++++++---------\n 1 file changed, 16 insertions(+), 9 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 9a1111af9b..29d634a30b 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -6,20 +6,27 @@ DEF_VER=v2.40.GIT\n LF='\n '\n \n+describe () {\n+\tVN=$(git describe --match \"v[0-9]*\" HEAD 2>/dev/null) || return 1\n+\tcase \"$VN\" in\n+\t*$LF*)\n+\t\treturn 1\n+\t\t;;\n+\tv[0-9]*)\n+\t\tgit update-index -q --refresh\n+\t\ttest -z \"$(git diff-index --name-only HEAD --)\" ||\n+\t\tVN=\"$VN-dirty\"\n+\t\treturn 0\n+\t\t;;\n+\tesac\n+}\n+\n # First see if there is a version file (included in release tarballs),\n # then try git-describe, then default.\n if test -f version\n then\n \tVN=$(cat version) || VN=\"$DEF_VER\"\n-elif test -d ${GIT_DIR:-.git} -o -f .git &&\n-\tVN=$(git describe --match \"v[0-9]*\" HEAD 2>/dev/null) &&\n-\tcase \"$VN\" in\n-\t*$LF*) (exit 1) ;;\n-\tv[0-9]*)\n-\t\tgit update-index -q --refresh\n-\t\ttest -z \"$(git diff-index --name-only HEAD --)\" ||\n-\t\tVN=\"$VN-dirty\" ;;\n-\tesac\n+elif test -d ${GIT_DIR:-.git} -o -f .git && describe\n then\n \tVN=$(echo \"$VN\" | sed -e 's/-/./g');\n else\n-- \n2.40.0+fc1\n\n"},{"id":"475937","messageId":"20230424165041.25180-4-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 03/15] version-gen: refactor default version","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:29Z","receivedAt":"2023-04-24T16:50:57Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It's not clear how `cat version` might fail, but either way if VN is\nempty (or unset), assign the default value.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 6dd7683ee7..0d00fa3d9a 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -25,14 +25,14 @@ describe () {\n # then try `git describe`, then default.\n if test -f version\n then\n-\tVN=$(cat version) || VN=\"$DEF_VER\"\n+\tVN=$(cat version)\n elif test -d \"${GIT_DIR:-.git}\" -o -f .git && describe\n then\n \tVN=$(echo \"$VN\" | sed -e 's/-/./g')\n-else\n-\tVN=\"$DEF_VER\"\n fi\n \n+: \"${VN:=$DEF_VER}\"\n+\n VN=$(expr \"$VN\" : 'v*\\(.*\\)')\n \n if test -r $GVF\n-- \n2.40.0+fc1\n\n"},{"id":"475938","messageId":"20230424165041.25180-3-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 02/15] version-gen: trivial cleanup","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:28Z","receivedAt":"2023-04-24T16:50:58Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We don't use `git-foo` since git 1.6.\n\nHEAD is the default of `git describe`.\n\nAlso, deal with a bunch of shellcheck warnings.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 18 ++++++++----------\n 1 file changed, 8 insertions(+), 10 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 29d634a30b..6dd7683ee7 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -7,7 +7,7 @@ LF='\n '\n \n describe () {\n-\tVN=$(git describe --match \"v[0-9]*\" HEAD 2>/dev/null) || return 1\n+\tVN=$(git describe --match \"v[0-9]*\" 2>/dev/null) || return 1\n \tcase \"$VN\" in\n \t*$LF*)\n \t\treturn 1\n@@ -22,26 +22,24 @@ describe () {\n }\n \n # First see if there is a version file (included in release tarballs),\n-# then try git-describe, then default.\n+# then try `git describe`, then default.\n if test -f version\n then\n \tVN=$(cat version) || VN=\"$DEF_VER\"\n-elif test -d ${GIT_DIR:-.git} -o -f .git && describe\n+elif test -d \"${GIT_DIR:-.git}\" -o -f .git && describe\n then\n-\tVN=$(echo \"$VN\" | sed -e 's/-/./g');\n+\tVN=$(echo \"$VN\" | sed -e 's/-/./g')\n else\n \tVN=\"$DEF_VER\"\n fi\n \n-VN=$(expr \"$VN\" : v*'\\(.*\\)')\n+VN=$(expr \"$VN\" : 'v*\\(.*\\)')\n \n if test -r $GVF\n then\n \tVC=$(sed -e 's/^GIT_VERSION = //' <$GVF)\n else\n-\tVC=unset\n+\tVC='unset'\n fi\n-test \"$VN\" = \"$VC\" || {\n-\techo >&2 \"GIT_VERSION = $VN\"\n-\techo \"GIT_VERSION = $VN\" >$GVF\n-}\n+test \"$VN\" = \"$VC\" && exit\n+echo \"GIT_VERSION = $VN\" | tee $GVF >&2\n-- \n2.40.0+fc1\n\n"},{"id":"475939","messageId":"20230424165041.25180-6-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 05/15] version-gen: simplify update check","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:31Z","receivedAt":"2023-04-24T16:51:00Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We don't need to extract the version when we can compare the whole\ncontents.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 8 +-------\n 1 file changed, 1 insertion(+), 7 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex c0f6bb242f..34f561752b 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -35,11 +35,5 @@ fi\n \n VN=${VN#v}\n \n-if test -r $GVF\n-then\n-\tVC=$(sed -e 's/^GIT_VERSION = //' <$GVF)\n-else\n-\tVC='unset'\n-fi\n-test \"$VN\" = \"$VC\" && exit\n+test -r $GVF && test \"GIT_VERSION = $VN\" = \"$(cat $GVF)\" && exit\n echo \"GIT_VERSION = $VN\" | tee $GVF >&2\n-- \n2.40.0+fc1\n\n"},{"id":"475940","messageId":"20230424165041.25180-7-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 06/15] version-gen: simplify `git describe` checks","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:32Z","receivedAt":"2023-04-24T16:51:01Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"How can `git describe --match 'foo*'` return something that doesn't\ncontain 'foo' and without error?\n\nIt can't, so no need for check for the impossible.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 17 +++--------------\n 1 file changed, 3 insertions(+), 14 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 34f561752b..e99c7b45c0 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -3,22 +3,11 @@\n GVF=GIT-VERSION-FILE\n DEF_VER=v2.40.GIT\n \n-LF='\n-'\n-\n describe () {\n \tVN=$(git describe --match \"v[0-9]*\" 2>/dev/null) || return 1\n-\tcase \"$VN\" in\n-\t*$LF*)\n-\t\treturn 1\n-\t\t;;\n-\tv[0-9]*)\n-\t\tgit update-index -q --refresh\n-\t\ttest -z \"$(git diff-index --name-only HEAD --)\" ||\n-\t\tVN=\"$VN-dirty\"\n-\t\treturn 0\n-\t\t;;\n-\tesac\n+\tgit update-index -q --refresh\n+\ttest -z \"$(git diff-index --name-only HEAD --)\" ||\n+\tVN=\"$VN-dirty\"\n }\n \n # First see if there is a version file (included in release tarballs),\n-- \n2.40.0+fc1\n\n"},{"id":"475941","messageId":"20230424165041.25180-8-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 07/15] version-gen: simplify dirty check","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:33Z","receivedAt":"2023-04-24T16:51:09Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 5 +----\n 1 file changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex e99c7b45c0..8edaf8f335 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -4,10 +4,7 @@ GVF=GIT-VERSION-FILE\n DEF_VER=v2.40.GIT\n \n describe () {\n-\tVN=$(git describe --match \"v[0-9]*\" 2>/dev/null) || return 1\n-\tgit update-index -q --refresh\n-\ttest -z \"$(git diff-index --name-only HEAD --)\" ||\n-\tVN=\"$VN-dirty\"\n+\tVN=$(git describe --match \"v[0-9]*\" --dirty 2>/dev/null) || return 1\n }\n \n # First see if there is a version file (included in release tarballs),\n-- \n2.40.0+fc1\n\n"},{"id":"475942","messageId":"20230424165041.25180-9-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 08/15] version-gen: move describe fix into function","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:34Z","receivedAt":"2023-04-24T16:51:11Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 8edaf8f335..7a7a7fc591 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -5,6 +5,7 @@ DEF_VER=v2.40.GIT\n \n describe () {\n \tVN=$(git describe --match \"v[0-9]*\" --dirty 2>/dev/null) || return 1\n+\tVN=$(echo \"$VN\" | sed -e 's/-/./g')\n }\n \n # First see if there is a version file (included in release tarballs),\n@@ -12,9 +13,9 @@ describe () {\n if test -f version\n then\n \tVN=$(cat version)\n-elif test -d \"${GIT_DIR:-.git}\" -o -f .git && describe\n+elif test -d \"${GIT_DIR:-.git}\" -o -f .git\n then\n-\tVN=$(echo \"$VN\" | sed -e 's/-/./g')\n+\tdescribe\n fi\n \n : \"${VN:=$DEF_VER}\"\n-- \n2.40.0+fc1\n\n"},{"id":"475943","messageId":"20230424165041.25180-10-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 09/15] version-gen: describe and sed in one go","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:35Z","receivedAt":"2023-04-24T16:51:19Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 7a7a7fc591..c5265cf9ad 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -4,8 +4,7 @@ GVF=GIT-VERSION-FILE\n DEF_VER=v2.40.GIT\n \n describe () {\n-\tVN=$(git describe --match \"v[0-9]*\" --dirty 2>/dev/null) || return 1\n-\tVN=$(echo \"$VN\" | sed -e 's/-/./g')\n+\tVN=$(git describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g') || return 1\n }\n \n # First see if there is a version file (included in release tarballs),\n-- \n2.40.0+fc1\n\n"},{"id":"475944","messageId":"20230424165041.25180-11-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 10/15] version-gen: refactor describe function","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:36Z","receivedAt":"2023-04-24T16:51:22Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"No functional changes.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex c5265cf9ad..0eaa813cca 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -4,7 +4,7 @@ GVF=GIT-VERSION-FILE\n DEF_VER=v2.40.GIT\n \n describe () {\n-\tVN=$(git describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g') || return 1\n+\tgit describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g'\n }\n \n # First see if there is a version file (included in release tarballs),\n@@ -14,7 +14,7 @@ then\n \tVN=$(cat version)\n elif test -d \"${GIT_DIR:-.git}\" -o -f .git\n then\n-\tdescribe\n+\tVN=$(describe)\n fi\n \n : \"${VN:=$DEF_VER}\"\n-- \n2.40.0+fc1\n\n"},{"id":"475945","messageId":"20230424165041.25180-12-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 11/15] version-gen: do v fix only when necessary","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:37Z","receivedAt":"2023-04-24T16:51:25Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"There's no point in having a v in the default version only to be\nremoved.\n\nThe only time we need to remove the v is from `git describe`.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 0eaa813cca..40502363dd 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -1,7 +1,7 @@\n #!/bin/sh\n \n GVF=GIT-VERSION-FILE\n-DEF_VER=v2.40.GIT\n+DEF_VER=2.40.GIT\n \n describe () {\n \tgit describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g'\n@@ -15,11 +15,10 @@ then\n elif test -d \"${GIT_DIR:-.git}\" -o -f .git\n then\n \tVN=$(describe)\n+\tVN=${VN#v}\n fi\n \n : \"${VN:=$DEF_VER}\"\n \n-VN=${VN#v}\n-\n test -r $GVF && test \"GIT_VERSION = $VN\" = \"$(cat $GVF)\" && exit\n echo \"GIT_VERSION = $VN\" | tee $GVF >&2\n-- \n2.40.0+fc1\n\n"},{"id":"475946","messageId":"20230424165041.25180-13-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 12/15] version-gen: move v fix into sed","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:38Z","receivedAt":"2023-04-24T16:51:29Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We are already using sed, might as well take advantage of it.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 40502363dd..6bf932c281 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -4,7 +4,7 @@ GVF=GIT-VERSION-FILE\n DEF_VER=2.40.GIT\n \n describe () {\n-\tgit describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g'\n+\tgit describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g' -e 's/^v//'\n }\n \n # First see if there is a version file (included in release tarballs),\n@@ -15,7 +15,6 @@ then\n elif test -d \"${GIT_DIR:-.git}\" -o -f .git\n then\n \tVN=$(describe)\n-\tVN=${VN#v}\n fi\n \n : \"${VN:=$DEF_VER}\"\n-- \n2.40.0+fc1\n\n"},{"id":"475947","messageId":"20230424165041.25180-14-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 13/15] version-gen: refactor main functionality","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:39Z","receivedAt":"2023-04-24T16:51:39Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It's pretty clear that the `version` file overrides `describe`, so do it\nin one function.\n\nThere's no need for the comment as the code is self-describing.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 14 ++++----------\n 1 file changed, 4 insertions(+), 10 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 6bf932c281..5b75cb4976 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -3,19 +3,13 @@\n GVF=GIT-VERSION-FILE\n DEF_VER=2.40.GIT\n \n-describe () {\n+get_version () {\n+\ttest -f version && cat version && return\n+\ttest -d \"${GIT_DIR:-.git}\" -o -f .git || return\n \tgit describe --match \"v[0-9]*\" --dirty 2>/dev/null | sed -e 's/-/./g' -e 's/^v//'\n }\n \n-# First see if there is a version file (included in release tarballs),\n-# then try `git describe`, then default.\n-if test -f version\n-then\n-\tVN=$(cat version)\n-elif test -d \"${GIT_DIR:-.git}\" -o -f .git\n-then\n-\tVN=$(describe)\n-fi\n+VN=$(get_version)\n \n : \"${VN:=$DEF_VER}\"\n \n-- \n2.40.0+fc1\n\n"},{"id":"475948","messageId":"20230424165041.25180-15-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 14/15] version-gen: refactor GIT_VERSION string","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:40Z","receivedAt":"2023-04-24T16:51:43Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 5b75cb4976..a1c50cb06b 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -13,5 +13,7 @@ VN=$(get_version)\n \n : \"${VN:=$DEF_VER}\"\n \n-test -r $GVF && test \"GIT_VERSION = $VN\" = \"$(cat $GVF)\" && exit\n-echo \"GIT_VERSION = $VN\" | tee $GVF >&2\n+NEW=\"GIT_VERSION = $VN\"\n+\n+test -r $GVF && test \"$NEW\" = \"$(cat $GVF)\" && exit\n+echo \"$NEW\" | tee $GVF >&2\n-- \n2.40.0+fc1\n\n"},{"id":"475949","messageId":"20230424165041.25180-16-felipe.contreras@gmail.com","threadId":"59645","inReplyTo":"20230424165041.25180-1-felipe.contreras@gmail.com","subject":"[PATCH v2 15/15] version-gen: get rid of GVF variable","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-24T16:50:41Z","receivedAt":"2023-04-24T16:52:13Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"There's not much point in a variable which is never going to change and\ndoesn't really add any readability.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n GIT-VERSION-GEN | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex a1c50cb06b..3d30ce74af 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -1,6 +1,5 @@\n #!/bin/sh\n \n-GVF=GIT-VERSION-FILE\n DEF_VER=2.40.GIT\n \n get_version () {\n@@ -15,5 +14,5 @@ VN=$(get_version)\n \n NEW=\"GIT_VERSION = $VN\"\n \n-test -r $GVF && test \"$NEW\" = \"$(cat $GVF)\" && exit\n-echo \"$NEW\" | tee $GVF >&2\n+test -r GIT-VERSION-FILE && test \"$NEW\" = \"$(cat GIT-VERSION-FILE)\" && exit\n+echo \"$NEW\" | tee GIT-VERSION-FILE >&2\n-- \n2.40.0+fc1\n\n"}]}