[PATCH 1/3] GIT-VERSION-GEN: make use of git describe --dirty

Subsystems: the rest

STALE3734d

5 messages, 3 authors, 2016-06-15 · open the first message on its own page

[PATCH 1/3] GIT-VERSION-GEN: make use of git describe --dirty

From: Mathias Lafeldt <hidden>
Date: 2016-06-15 22:49:51

Currently, GIT-VERSION-GEN invokes the plumbing commands "git update-index" and
"git diff-index" to determine if the working tree is dirty. It then appends
"-dirty" to the version string returned by "git describe".

However, as of Git v1.6.6, "git describe" can be told to do all that with the
"--dirty" option, saving us the plumbing.

Signed-off-by: Mathias Lafeldt <redacted>
---
 GIT-VERSION-GEN |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index d441d88..73d5cf9 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -12,13 +12,10 @@ if test -f version
 then
 	VN=$(cat version) || VN="$DEF_VER"
 elif test -d .git -o -f .git &&
-	VN=$(git describe --match "v[0-9]*" --abbrev=4 HEAD 2>/dev/null) &&
+	VN=$(git describe --match "v[0-9]*" --abbrev=4 --dirty 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" ;;
+	v[0-9]*) : ;;
 	esac
 then
 	VN=$(echo "$VN" | sed -e 's/-/./g');
-- 
1.7.3.2

Re: [PATCH 1/3] GIT-VERSION-GEN: make use of git describe --dirty

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:51

Mathias Lafeldt wrote:
Currently, GIT-VERSION-GEN invokes the plumbing commands "git update-index" and
"git diff-index" to determine if the working tree is dirty. It then appends
"-dirty" to the version string returned by "git describe".

However, as of Git v1.6.6, "git describe" can be told to do all that with the
"--dirty" option, saving us the plumbing.
This has a minor downside, which is avoiding the nice version numbers when
building Git with git 1.5.6 installed.  What is the upside?

Re: [PATCH 1/3] GIT-VERSION-GEN: make use of git describe --dirty

From: Mathias Lafeldt <hidden>
Date: 2016-06-15 22:49:51

On 10/22/2010 05:11 PM, Jonathan Nieder wrote:
Mathias Lafeldt wrote:
quoted
Currently, GIT-VERSION-GEN invokes the plumbing commands "git update-index" and
"git diff-index" to determine if the working tree is dirty. It then appends
"-dirty" to the version string returned by "git describe".

However, as of Git v1.6.6, "git describe" can be told to do all that with the
"--dirty" option, saving us the plumbing.
This has a minor downside, which is avoiding the nice version numbers when
building Git with git 1.5.6 installed.  What is the upside?
The upside is that the number of executed commands to get the version string
is reduced from three to one.

I understand your point, though it would only be a "problem" once when
doing the upgrade.

If backwards compatibility is more important here, I'd at least add a comment
to GIT-VERSION-GEN. Something like:
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index d441d88..5c226f6 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -16,6 +16,10 @@ elif test -d .git -o -f .git &&
        case "$VN" in
        *$LF*) (exit 1) ;;
        v[0-9]*)
+               # As of Git v1.6.6, we can use "git describe --dirty" to
+               # determine if the working tree is dirty. However, to still
+               # have nice version numbers when building Git with older
+               # versions of git installed, we keep using plumbing.
                git update-index -q --refresh
                test -z "$(git diff-index --name-only HEAD --)" ||
                VN="$VN-dirty" ;;

-Mathias

Re: [PATCH 1/3] GIT-VERSION-GEN: make use of git describe --dirty

From: Mathias Lafeldt <hidden>
Date: 2016-06-15 22:49:54

Mathias Lafeldt wrote:
quoted hunk
On 10/22/2010 05:11 PM, Jonathan Nieder wrote:
quoted
Mathias Lafeldt wrote:
quoted
Currently, GIT-VERSION-GEN invokes the plumbing commands "git update-index" and
"git diff-index" to determine if the working tree is dirty. It then appends
"-dirty" to the version string returned by "git describe".

However, as of Git v1.6.6, "git describe" can be told to do all that with the
"--dirty" option, saving us the plumbing.
This has a minor downside, which is avoiding the nice version numbers when
building Git with git 1.5.6 installed.  What is the upside?
The upside is that the number of executed commands to get the version string
is reduced from three to one.

I understand your point, though it would only be a "problem" once when
doing the upgrade.

If backwards compatibility is more important here, I'd at least add a comment
to GIT-VERSION-GEN. Something like:
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index d441d88..5c226f6 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -16,6 +16,10 @@ elif test -d .git -o -f .git &&
        case "$VN" in
        *$LF*) (exit 1) ;;
        v[0-9]*)
+               # As of Git v1.6.6, we can use "git describe --dirty" to
+               # determine if the working tree is dirty. However, to still
+               # have nice version numbers when building Git with older
+               # versions of git installed, we keep using plumbing.
                git update-index -q --refresh
                test -z "$(git diff-index --name-only HEAD --)" ||
                VN="$VN-dirty" ;;
Any feedback would be welcome.

-Mathias

Re: [PATCH 1/3] GIT-VERSION-GEN: make use of git describe --dirty

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:49:54

Mathias Lafeldt [off-list ref] writes:
Mathias Lafeldt wrote:
quoted
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index d441d88..5c226f6 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -16,6 +16,10 @@ elif test -d .git -o -f .git &&
        case "$VN" in
        *$LF*) (exit 1) ;;
        v[0-9]*)
+               # As of Git v1.6.6, we can use "git describe --dirty" to
+               # determine if the working tree is dirty. However, to still
+               # have nice version numbers when building Git with older
+               # versions of git installed, we keep using plumbing.
                git update-index -q --refresh
                test -z "$(git diff-index --name-only HEAD --)" ||
                VN="$VN-dirty" ;;
Any feedback would be welcome.
I like it, also because people who use GIT-VERSION-GEN from git
repository as inspiration would get to know more modern technique.

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help