* [PATCH v2 00/15] version-gen: complete revamp/rewrite
@ 2023-04-24 16:50 Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 01/15] version-gen: reorganize Felipe Contreras
` (14 more replies)
0 siblings, 15 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
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.
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
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
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 01/15] version-gen: reorganize
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 02/15] version-gen: trivial cleanup Felipe Contreras
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
Simply move some code into a `describe` function so it's clear what code
is related to dealing with `git describe`, and what code is the main
functionality.
No functional changes.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 9a1111af9b..29d634a30b 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -6,20 +6,27 @@ DEF_VER=v2.40.GIT
LF='
'
+describe () {
+ VN=$(git describe --match "v[0-9]*" HEAD 2>/dev/null) || return 1
+ case "$VN" in
+ *$LF*)
+ return 1
+ ;;
+ v[0-9]*)
+ git update-index -q --refresh
+ test -z "$(git diff-index --name-only HEAD --)" ||
+ VN="$VN-dirty"
+ return 0
+ ;;
+ esac
+}
+
# 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
+elif test -d ${GIT_DIR:-.git} -o -f .git && describe
then
VN=$(echo "$VN" | sed -e 's/-/./g');
else
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 02/15] version-gen: trivial cleanup
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 01/15] version-gen: reorganize Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 03/15] version-gen: refactor default version Felipe Contreras
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
We don't use `git-foo` since git 1.6.
HEAD is the default of `git describe`.
Also, deal with a bunch of shellcheck warnings.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 29d634a30b..6dd7683ee7 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -7,7 +7,7 @@ LF='
'
describe () {
- VN=$(git describe --match "v[0-9]*" HEAD 2>/dev/null) || return 1
+ VN=$(git describe --match "v[0-9]*" 2>/dev/null) || return 1
case "$VN" in
*$LF*)
return 1
@@ -22,26 +22,24 @@ describe () {
}
# First see if there is a version file (included in release tarballs),
-# then try git-describe, then default.
+# 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 && describe
+elif test -d "${GIT_DIR:-.git}" -o -f .git && describe
then
- VN=$(echo "$VN" | sed -e 's/-/./g');
+ VN=$(echo "$VN" | sed -e 's/-/./g')
else
VN="$DEF_VER"
fi
-VN=$(expr "$VN" : v*'\(.*\)')
+VN=$(expr "$VN" : 'v*\(.*\)')
if test -r $GVF
then
VC=$(sed -e 's/^GIT_VERSION = //' <$GVF)
else
- VC=unset
+ VC='unset'
fi
-test "$VN" = "$VC" || {
- echo >&2 "GIT_VERSION = $VN"
- echo "GIT_VERSION = $VN" >$GVF
-}
+test "$VN" = "$VC" && exit
+echo "GIT_VERSION = $VN" | tee $GVF >&2
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 03/15] version-gen: refactor default version
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 01/15] version-gen: reorganize Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 02/15] version-gen: trivial cleanup Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 04/15] version-gen: simplify v prefix removal Felipe Contreras
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
It's not clear how `cat version` might fail, but either way if VN is
empty (or unset), assign the default value.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 6dd7683ee7..0d00fa3d9a 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -25,14 +25,14 @@ describe () {
# then try `git describe`, then default.
if test -f version
then
- VN=$(cat version) || VN="$DEF_VER"
+ VN=$(cat version)
elif test -d "${GIT_DIR:-.git}" -o -f .git && describe
then
VN=$(echo "$VN" | sed -e 's/-/./g')
-else
- VN="$DEF_VER"
fi
+: "${VN:=$DEF_VER}"
+
VN=$(expr "$VN" : 'v*\(.*\)')
if test -r $GVF
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 04/15] version-gen: simplify v prefix removal
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (2 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 03/15] version-gen: refactor default version Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 05/15] version-gen: simplify update check Felipe Contreras
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
There is a much simpler way.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 0d00fa3d9a..c0f6bb242f 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -33,7 +33,7 @@ fi
: "${VN:=$DEF_VER}"
-VN=$(expr "$VN" : 'v*\(.*\)')
+VN=${VN#v}
if test -r $GVF
then
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 05/15] version-gen: simplify update check
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (3 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 04/15] version-gen: simplify v prefix removal Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 06/15] version-gen: simplify `git describe` checks Felipe Contreras
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
We don't need to extract the version when we can compare the whole
contents.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index c0f6bb242f..34f561752b 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -35,11 +35,5 @@ fi
VN=${VN#v}
-if test -r $GVF
-then
- VC=$(sed -e 's/^GIT_VERSION = //' <$GVF)
-else
- VC='unset'
-fi
-test "$VN" = "$VC" && exit
+test -r $GVF && test "GIT_VERSION = $VN" = "$(cat $GVF)" && exit
echo "GIT_VERSION = $VN" | tee $GVF >&2
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 06/15] version-gen: simplify `git describe` checks
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (4 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 05/15] version-gen: simplify update check Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 07/15] version-gen: simplify dirty check Felipe Contreras
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
How can `git describe --match 'foo*'` return something that doesn't
contain 'foo' and without error?
It can't, so no need for check for the impossible.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 34f561752b..e99c7b45c0 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -3,22 +3,11 @@
GVF=GIT-VERSION-FILE
DEF_VER=v2.40.GIT
-LF='
-'
-
describe () {
VN=$(git describe --match "v[0-9]*" 2>/dev/null) || return 1
- case "$VN" in
- *$LF*)
- return 1
- ;;
- v[0-9]*)
- git update-index -q --refresh
- test -z "$(git diff-index --name-only HEAD --)" ||
- VN="$VN-dirty"
- return 0
- ;;
- esac
+ git update-index -q --refresh
+ test -z "$(git diff-index --name-only HEAD --)" ||
+ VN="$VN-dirty"
}
# First see if there is a version file (included in release tarballs),
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 07/15] version-gen: simplify dirty check
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (5 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 06/15] version-gen: simplify `git describe` checks Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 08/15] version-gen: move describe fix into function Felipe Contreras
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index e99c7b45c0..8edaf8f335 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -4,10 +4,7 @@ GVF=GIT-VERSION-FILE
DEF_VER=v2.40.GIT
describe () {
- VN=$(git describe --match "v[0-9]*" 2>/dev/null) || return 1
- git update-index -q --refresh
- test -z "$(git diff-index --name-only HEAD --)" ||
- VN="$VN-dirty"
+ VN=$(git describe --match "v[0-9]*" --dirty 2>/dev/null) || return 1
}
# First see if there is a version file (included in release tarballs),
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 08/15] version-gen: move describe fix into function
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (6 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 07/15] version-gen: simplify dirty check Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 09/15] version-gen: describe and sed in one go Felipe Contreras
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 8edaf8f335..7a7a7fc591 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -5,6 +5,7 @@ DEF_VER=v2.40.GIT
describe () {
VN=$(git describe --match "v[0-9]*" --dirty 2>/dev/null) || return 1
+ VN=$(echo "$VN" | sed -e 's/-/./g')
}
# First see if there is a version file (included in release tarballs),
@@ -12,9 +13,9 @@ describe () {
if test -f version
then
VN=$(cat version)
-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')
+ describe
fi
: "${VN:=$DEF_VER}"
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 09/15] version-gen: describe and sed in one go
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (7 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 08/15] version-gen: move describe fix into function Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 10/15] version-gen: refactor describe function Felipe Contreras
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 7a7a7fc591..c5265cf9ad 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -4,8 +4,7 @@ GVF=GIT-VERSION-FILE
DEF_VER=v2.40.GIT
describe () {
- VN=$(git describe --match "v[0-9]*" --dirty 2>/dev/null) || return 1
- VN=$(echo "$VN" | sed -e 's/-/./g')
+ VN=$(git describe --match "v[0-9]*" --dirty 2>/dev/null | sed -e 's/-/./g') || return 1
}
# First see if there is a version file (included in release tarballs),
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 10/15] version-gen: refactor describe function
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (8 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 09/15] version-gen: describe and sed in one go Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 11/15] version-gen: do v fix only when necessary Felipe Contreras
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
No functional changes.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index c5265cf9ad..0eaa813cca 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -4,7 +4,7 @@ GVF=GIT-VERSION-FILE
DEF_VER=v2.40.GIT
describe () {
- VN=$(git describe --match "v[0-9]*" --dirty 2>/dev/null | sed -e 's/-/./g') || return 1
+ git describe --match "v[0-9]*" --dirty 2>/dev/null | sed -e 's/-/./g'
}
# First see if there is a version file (included in release tarballs),
@@ -14,7 +14,7 @@ then
VN=$(cat version)
elif test -d "${GIT_DIR:-.git}" -o -f .git
then
- describe
+ VN=$(describe)
fi
: "${VN:=$DEF_VER}"
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 11/15] version-gen: do v fix only when necessary
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (9 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 10/15] version-gen: refactor describe function Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 12/15] version-gen: move v fix into sed Felipe Contreras
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
There's no point in having a v in the default version only to be
removed.
The only time we need to remove the v is from `git describe`.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 0eaa813cca..40502363dd 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,7 +1,7 @@
#!/bin/sh
GVF=GIT-VERSION-FILE
-DEF_VER=v2.40.GIT
+DEF_VER=2.40.GIT
describe () {
git describe --match "v[0-9]*" --dirty 2>/dev/null | sed -e 's/-/./g'
@@ -15,11 +15,10 @@ then
elif test -d "${GIT_DIR:-.git}" -o -f .git
then
VN=$(describe)
+ VN=${VN#v}
fi
: "${VN:=$DEF_VER}"
-VN=${VN#v}
-
test -r $GVF && test "GIT_VERSION = $VN" = "$(cat $GVF)" && exit
echo "GIT_VERSION = $VN" | tee $GVF >&2
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 12/15] version-gen: move v fix into sed
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (10 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 11/15] version-gen: do v fix only when necessary Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 13/15] version-gen: refactor main functionality Felipe Contreras
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
We are already using sed, might as well take advantage of it.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 40502363dd..6bf932c281 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -4,7 +4,7 @@ GVF=GIT-VERSION-FILE
DEF_VER=2.40.GIT
describe () {
- git describe --match "v[0-9]*" --dirty 2>/dev/null | sed -e 's/-/./g'
+ git describe --match "v[0-9]*" --dirty 2>/dev/null | sed -e 's/-/./g' -e 's/^v//'
}
# First see if there is a version file (included in release tarballs),
@@ -15,7 +15,6 @@ then
elif test -d "${GIT_DIR:-.git}" -o -f .git
then
VN=$(describe)
- VN=${VN#v}
fi
: "${VN:=$DEF_VER}"
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 13/15] version-gen: refactor main functionality
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (11 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 12/15] version-gen: move v fix into sed Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 14/15] version-gen: refactor GIT_VERSION string Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 15/15] version-gen: get rid of GVF variable Felipe Contreras
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
It's pretty clear that the `version` file overrides `describe`, so do it
in one function.
There's no need for the comment as the code is self-describing.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 6bf932c281..5b75cb4976 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -3,19 +3,13 @@
GVF=GIT-VERSION-FILE
DEF_VER=2.40.GIT
-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//'
}
-# 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)
-elif test -d "${GIT_DIR:-.git}" -o -f .git
-then
- VN=$(describe)
-fi
+VN=$(get_version)
: "${VN:=$DEF_VER}"
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 14/15] version-gen: refactor GIT_VERSION string
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (12 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 13/15] version-gen: refactor main functionality Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 15/15] version-gen: get rid of GVF variable Felipe Contreras
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 5b75cb4976..a1c50cb06b 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -13,5 +13,7 @@ VN=$(get_version)
: "${VN:=$DEF_VER}"
-test -r $GVF && test "GIT_VERSION = $VN" = "$(cat $GVF)" && exit
-echo "GIT_VERSION = $VN" | tee $GVF >&2
+NEW="GIT_VERSION = $VN"
+
+test -r $GVF && test "$NEW" = "$(cat $GVF)" && exit
+echo "$NEW" | tee $GVF >&2
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 15/15] version-gen: get rid of GVF variable
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
` (13 preceding siblings ...)
2023-04-24 16:50 ` [PATCH v2 14/15] version-gen: refactor GIT_VERSION string Felipe Contreras
@ 2023-04-24 16:50 ` Felipe Contreras
14 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2023-04-24 16:50 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano, Todd Zullinger, Felipe Contreras
There's not much point in a variable which is never going to change and
doesn't really add any readability.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
GIT-VERSION-GEN | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index a1c50cb06b..3d30ce74af 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,6 +1,5 @@
#!/bin/sh
-GVF=GIT-VERSION-FILE
DEF_VER=2.40.GIT
get_version () {
@@ -15,5 +14,5 @@ VN=$(get_version)
NEW="GIT_VERSION = $VN"
-test -r $GVF && test "$NEW" = "$(cat $GVF)" && exit
-echo "$NEW" | tee $GVF >&2
+test -r GIT-VERSION-FILE && test "$NEW" = "$(cat GIT-VERSION-FILE)" && exit
+echo "$NEW" | tee GIT-VERSION-FILE >&2
--
2.40.0+fc1
^ permalink raw reply related [flat|nested] 16+ messages in thread
end of thread, other threads:[~2023-04-24 16:52 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-24 16:50 [PATCH v2 00/15] version-gen: complete revamp/rewrite Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 01/15] version-gen: reorganize Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 02/15] version-gen: trivial cleanup Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 03/15] version-gen: refactor default version Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 04/15] version-gen: simplify v prefix removal Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 05/15] version-gen: simplify update check Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 06/15] version-gen: simplify `git describe` checks Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 07/15] version-gen: simplify dirty check Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 08/15] version-gen: move describe fix into function Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 09/15] version-gen: describe and sed in one go Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 10/15] version-gen: refactor describe function Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 11/15] version-gen: do v fix only when necessary Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 12/15] version-gen: move v fix into sed Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 13/15] version-gen: refactor main functionality Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 14/15] version-gen: refactor GIT_VERSION string Felipe Contreras
2023-04-24 16:50 ` [PATCH v2 15/15] version-gen: get rid of GVF variable Felipe Contreras
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).