threads / patch / 34922

v2, 2 partsversion-gen: cleanup

Subject: [PATCH v2 1/2] version-gen: cleanup

## tl;dr

7 messages between Sep 13, 2013 and Sep 14, 2013. Diffs are folded; open one to read it.

replies: 6people: 2as markdown or json

Felipe Contreras· Sep 13, 2013, 01:17 UTC · lore

[PATCH v2 0/2] version-gen: fixes and cleanups

Felipe Contreras (2):
  version-gen: cleanup
  version-gen: avoid messing the version
 GIT-VERSION-GEN | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)
-- 
1.8.4-338-gefd7fa6
Felipe Contreras· Sep 13, 2013, 01:17 UTC · re: Felipe Contreras · lore
No functional changes.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 GIT-VERSION-GEN | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)
Show changes to GIT-VERSION-GEN +20 −16
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 06026ea..e96538d 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -6,22 +6,29 @@ DEF_VER=v1.8.4
 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]*" --abbrev=7 HEAD 2>/dev/null) &&
+describe () {
+	VN=$(git describe --match "v[0-9]*" --abbrev=7 HEAD 2>/dev/null) || return 1
 	case "$VN" in
-	*$LF*) (exit 1) ;;
+	*$LF*)
+		return 1
+		;;
 	v[0-9]*)
 		git update-index -q --refresh
 		test -z "$(git diff-index --name-only HEAD --)" ||
-		VN="$VN-dirty" ;;
+		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 && describe
 then
-	VN=$(echo "$VN" | sed -e 's/-/./g');
+	VN=$(echo "$VN" | sed -e 's/-/./g')
 else
 	VN="$DEF_VER"
 fi
@@ -34,9 +41,6 @@ then
 else
 	VC=unset
 fi
-test "$VN" = "$VC" || {
-	echo >&2 "GIT_VERSION = $VN"
-	echo "GIT_VERSION = $VN" >$GVF
-}
-
-
+test "$VN" = "$VC" && exit
+echo >&2 "GIT_VERSION = $VN"
+echo "GIT_VERSION = $VN" >$GVF
-- 
1.8.4-338-gefd7fa6
Junio C Hamano· Sep 13, 2013, 06:10 UTC · re: Felipe Contreras · lore

Re: [PATCH v2 1/2] version-gen: cleanup

Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 22 quoted lines
> +describe () {
> +	VN=$(git describe --match "v[0-9]*" --abbrev=7 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 && describe
>  then

Makes sense; using a helper function makes the primary logic easier to read.

Show 9 quoted lines
> -test "$VN" = "$VC" || {
> -	echo >&2 "GIT_VERSION = $VN"
> -	echo "GIT_VERSION = $VN" >$GVF
> -}
> -
> -
> +test "$VN" = "$VC" && exit
> +echo >&2 "GIT_VERSION = $VN"
> +echo "GIT_VERSION = $VN" >$GVF

The point of this part is "if the version file is already up to date, do not rewrite it only to smudge the mtime to confuse make", so it would be much easier to read to write it like so:

	if test "$VN" != "$VC"
        then
		... two echoes ...
	fi

compared to "exiting in the middle" which is harder to follow, especially if we consider that we may have to grow the remaining two lines in the future.

Felipe Contreras· Sep 13, 2013, 12:16 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/2] version-gen: cleanup

On Fri, Sep 13, 2013 at 1:10 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 50 quoted lines
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> +describe () {
>> +     VN=$(git describe --match "v[0-9]*" --abbrev=7 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 && describe
>>  then
>
> Makes sense; using a helper function makes the primary logic easier
> to read.
>
>> -test "$VN" = "$VC" || {
>> -     echo >&2 "GIT_VERSION = $VN"
>> -     echo "GIT_VERSION = $VN" >$GVF
>> -}
>> -
>> -
>> +test "$VN" = "$VC" && exit
>> +echo >&2 "GIT_VERSION = $VN"
>> +echo "GIT_VERSION = $VN" >$GVF
>
> The point of this part is "if the version file is already up to
> date, do not rewrite it only to smudge the mtime to confuse make",
> so it would be much easier to read to write it like so:
>
>         if test "$VN" != "$VC"
>         then
>                 ... two echoes ...
>         fi
>
> compared to "exiting in the middle" which is harder to follow,
> especially if we consider that we may have to grow the remaining two
> lines in the future.

No, it's much easier to follow, the code clearly says "if the version is up to date, there's nothing else to do".

-- 
Felipe Contreras
Felipe Contreras· Sep 13, 2013, 01:17 UTC · re: Felipe Contreras · lore

[PATCH v2 2/2] version-gen: avoid messing the version

If the version is 'v1.8.4-rc1' that is the version, and there's no need to change it to anything else, like 'v1.8.4.rc1'.

If RedHat, or somebody else, needs a specific version, they can use the 'version' file, like everybody else.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 GIT-VERSION-GEN | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
Show changes to GIT-VERSION-GEN +1 −3
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index e96538d..b3de2db 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -26,10 +26,8 @@ describe () {
 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')
-else
 	VN="$DEF_VER"
 fi
 
-- 
1.8.4-338-gefd7fa6
Junio C Hamano· Sep 13, 2013, 18:16 UTC · re: Felipe Contreras · lore

Re: [PATCH v2 2/2] version-gen: avoid messing the version

Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 8 quoted lines
> If the version is 'v1.8.4-rc1' that is the version, and there's no need
> to change it to anything else, like 'v1.8.4.rc1'.
>
> If RedHat, or somebody else, needs a specific version, they can use the
> 'version' file, like everybody else.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
I already explained to you why this is a bad change.

When we say "we try to avoid regressions", we really mean it. Before coming up with a change to pay Paul by robbing Peter, we must make an honest effort to see if there is a way to pay Paul without robbing anybody.

This change forces existing users who depend on how dashes are mangled into dots to change their tooling.

We do occasionally make deliberate regressions that force existing users to change the way they work, but only when there is no other way, and when the benefit of the change far outweighs the cost of such an adjustment, and with careful planning to ease the pain of transition. The updates to "git add" and "git push" planned for 2.0 fall into that category.

There has to be a benefit that far outweighs the inconvenience this patch imposes on existing users, but I do not see there is any. "If somebody needs a specific version, they can use the 'version' file" does not justify it at all; it equally applies to those who want to use a version name with a dash.

Besides, the patch does not even do what it claims to do; if the version is "v1.8.4-rc1", what you get out of the updated code is "1.8.4-rc1", still losing the leading "v".

I'd be more receptive if the patch were like this instead, though.
Show changes to GIT-VERSION-GEN +9 −2
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index b444c18..c6d78ec 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -3,12 +3,16 @@
 GVF=GIT-VERSION-FILE
 DEF_VER=v1.8.4.GIT
 
+READ_RAW_VERSION=
 LF='
 '
 
 # First see if there is a version file (included in release tarballs),
 # then try git-describe, then default.
-if test -f version
+if test -f raw-version && VN=$(cat raw-version)
+then
+	READ_RAW_VERSION=yes
+elif test -f version
 then
 	VN=$(cat version) || VN="$DEF_VER"
 elif test -d ${GIT_DIR:-.git} -o -f .git &&
@@ -26,7 +30,10 @@ else
 	VN="$DEF_VER"
 fi
 
-VN=$(expr "$VN" : v*'\(.*\)')
+if test -z "$READ_RAW_VERSION"
+then
+	VN=$(expr "$VN" : v*'\(.*\)')
+fi
 
 if test -r $GVF
 then
Felipe Contreras· Sep 14, 2013, 05:59 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 2/2] version-gen: avoid messing the version

On Fri, Sep 13, 2013 at 1:16 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> If the version is 'v1.8.4-rc1' that is the version, and there's no need
>> to change it to anything else, like 'v1.8.4.rc1'.
>>
>> If RedHat, or somebody else, needs a specific version, they can use the
>> 'version' file, like everybody else.
>>
>> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
>> ---
>
> I already explained to you why this is a bad change.
No, you did not.
All you did is throw a non sequitur argument which I already exposed as such.
> When we say "we try to avoid regressions", we really mean it.
Maybe by "regressions" you mean progress.
> Before coming up with a change to pay Paul by robbing Peter, we must
> make an honest effort to see if there is a way to pay Paul without
> robbing anybody.

There is, because Peter, the RedHat maintainer, can do exactly the same that Alice does; use the 'version' file.

In fact, Peter, cannot possibly use Git's version because of this:

% rpmdev-vercmp git-1.8.4 git-1.8.4.rc1 git-1.8.4 < git-1.8.4.rc1 % rpmdev-vercmp git-1.8.4 git-1.8.4-rc1 git-1.8.4 < git-1.8.4-rc1 % rpmdev-vercmp git-1.8.4 git-1.8.4~rc1 git-1.8.4 > git-1.8.4~rc1

Fedora's guideline[1] is to use a format like git-1.8.4-1.rc1, then the final release would be git-1.8.4-2, in other words, the '.rc1' is mostly informative, but that has nothing to do with Git's internal version (git-1.8.4.rc1).

openSUSE's guideline[1] prefers to use git-1.8.4~rc1.

Either way, none of them could possibly use git-1.8.4.rc1, because that's greater than git-1.8.4.

> This change forces existing users who depend on how dashes are
> mangled into dots to change their tooling.
No, it does not.

You just say that, and you assume because you said it, it must be true; it's not.

First of all, nor RedHat, nor any other RPM-based distribution needs this any more, because as a simple search demonstrates, they don't use release candidates any more.

http://www.rpmfind.net/linux/rpm2html/search.php?query=git&submit=Search+...
Essentially, Peter is a figment of your imagination.

The closest thing to Peter 1) doesn't use release candidates, and 2) if he did, he wouldn't use a version like git-1.8.4.rc1.

Show 16 quoted lines
> We do occasionally make deliberate regressions that force existing
> users to change the way they work, but only when there is no other
> way, and when the benefit of the change far outweighs the cost of
> such an adjustment, and with careful planning to ease the pain of
> transition.  The updates to "git add" and "git push" planned for 2.0
> fall into that category.
>
> There has to be a benefit that far outweighs the inconvenience this
> patch imposes on existing users, but I do not see there is any.  "If
> somebody needs a specific version, they can use the 'version' file"
> does not justify it at all; it equally applies to those who want to
> use a version name with a dash.
>
> Besides, the patch does not even do what it claims to do; if the
> version is "v1.8.4-rc1", what you get out of the updated code is
> "1.8.4-rc1", still losing the leading "v".
Wrong.

% git tag -m '' v1.8.5-rc1 % ./GIT-VERSION-GEN GIT_VERSION = 1.8.5-rc1-dirty

[1] https://fedoraproject.org/wiki/Packaging:NamingGuidelines#NonNumericRelease [2] http://en.opensuse.org/openSUSE:Package_naming_guidelines

-- 
Felipe Contreras

← back to recent threads