# [RFC PATCH] GIT-VERSION-GEN: restrict tags used

6 messages from 2010-05-11 to 2010-05-12. Participants: Tay Ray Chuan, Jonathan Nieder, Junio C Hamano.
Thread: https://gitlist.dev/t/23778

## Tay Ray Chuan, 2010-05-11 17:33

Subject: [RFC PATCH] GIT-VERSION-GEN: restrict tags used
Message-ID: <1273599198-1008-1-git-send-email-rctay89@gmail.com>
URL: https://gitlist.dev/e/1273599198-1008-1-git-send-email-rctay89%40gmail.com

```
Restrict the tags used to generate the version string to those that
begin with "v", since git's tags for git-core (ie. excluding git-gui)
are all of the form "vX.Y...".

This is to avoid using private tags by the user in a clone of the git
code repository, which may break certain machinery (eg. Makefile).

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---

  Ran into this after tagging a topic branch and running make.

  Although a "v.*" match does not guarantee the non-usage of private
  tags, I feel it's an acceptable level of accuracy.

  After this patch, perhaps we could advertise somewhere to git hackers
  that tags beginning with "v" should be avoided.

 GIT-VERSION-GEN |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 59219bd..28b4d56 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -12,7 +12,7 @@ if test -f version
 then
 	VN=$(cat version) || VN="$DEF_VER"
 elif test -d .git -o -f .git &&
-	VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
+	VN=$(git describe --match "v*" --abbrev=4 HEAD 2>/dev/null) &&
 	case "$VN" in
 	*$LF*) (exit 1) ;;
 	v[0-9]*)
--
1.7.1.189.g07419

```

## Jonathan Nieder, 2010-05-11 23:01

Subject: Re: [RFC PATCH] GIT-VERSION-GEN: restrict tags used
Message-ID: <20100511230100.GB31163@progeny.tock>
URL: https://gitlist.dev/e/20100511230100.GB31163%40progeny.tock
In-Reply-To: <1273599198-1008-1-git-send-email-rctay89@gmail.com>

```
Tay Ray Chuan wrote:

> Restrict the tags used to generate the version string to those that
> begin with "v"

I like it.  Thanks!

> since git's tags for git-core (ie. excluding git-gui)
> are all of the form "vX.Y...".

git gui’s too, now.

> This is to avoid using private tags by the user in a clone of the git
> code repository, which may break certain machinery (eg. Makefile).

Not to mention gitk:

  set git_version [join [lrange [split [lindex [exec git version] end] .] 0 2] .]
  if {[package vcompare $git_version "1.6.1"] >= 0} {

This requires ‘git version’ output to have the form

  introducing 1.2.3.otherstuff

or there will be errors at startup time.

>   After this patch, perhaps we could advertise somewhere to git hackers
>   that tags beginning with "v" should be avoided.

Maybe v[0-9]* would make this problem harder to trip.

Jonathan

```

## Jonathan Nieder, 2010-05-11 23:05

Subject: Re: [RFC PATCH] GIT-VERSION-GEN: restrict tags used
Message-ID: <20100511230542.GC31163@progeny.tock>
URL: https://gitlist.dev/e/20100511230542.GC31163%40progeny.tock
In-Reply-To: <20100511230100.GB31163@progeny.tock>

```
Jonathan Nieder wrote:
> Tay Ray Chuan wrote:

>> since git's tags for git-core (ie. excluding git-gui)
>> are all of the form "vX.Y...".
>
> git gui’s too, now.

Aggh --- sent early, there.  Here is what I meant to say.

Shawn, this helps avoid any stray (annotated) tags the user may have
made, following Tay’s example.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index b3f937e..d6a6601 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -13,7 +13,7 @@ tree_search ()
 	for p in $(git rev-list --parents --max-count=1 $head 2>/dev/null)
 	do
 		test $tree = $(git rev-parse $p^{tree} 2>/dev/null) &&
-		vn=$(git describe --abbrev=4 $p 2>/dev/null) &&
+		vn=$(git describe --match=gitgui-[0-9]* --abbrev=4 $p 2>/dev/null) &&
 		case "$vn" in
 		gitgui-[0-9]*) echo $vn; break;;
 		esac
-- 

```

## Tay Ray Chuan, 2010-05-12 03:23

Subject: Re: [RFC PATCH] GIT-VERSION-GEN: restrict tags used
Message-ID: <AANLkTim8SRUEaNWyBF_iRQstu84r9eAaUd0a9KLj6OtR@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTim8SRUEaNWyBF_iRQstu84r9eAaUd0a9KLj6OtR%40mail.gmail.com
In-Reply-To: <20100511230100.GB31163@progeny.tock>

```
On Wed, May 12, 2010 at 7:01 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Tay Ray Chuan wrote:
>> This is to avoid using private tags by the user in a clone of the git
>> code repository, which may break certain machinery (eg. Makefile).
>
> Not to mention gitk:
>
>  set git_version [join [lrange [split [lindex [exec git version] end] .] 0 2] .]
>  if {[package vcompare $git_version "1.6.1"] >= 0} {
>
> This requires ‘git version’ output to have the form
>
>  introducing 1.2.3.otherstuff
>
> or there will be errors at startup time.

Thanks for the heads-up, I'll put that in the patch message.

>>   After this patch, perhaps we could advertise somewhere to git hackers
>>   that tags beginning with "v" should be avoided.
>
> Maybe v[0-9]* would make this problem harder to trip.

Oh, I didn't know character classes were allows. Sounds good.

-- 
Cheers,
Ray Chuan

```

## Tay Ray Chuan, 2010-05-12 03:29

Subject: [PATCH] GIT-VERSION-GEN: restrict tags used
Message-ID: <1273634960-2728-1-git-send-email-rctay89@gmail.com>
URL: https://gitlist.dev/e/1273634960-2728-1-git-send-email-rctay89%40gmail.com
In-Reply-To: <AANLkTim8SRUEaNWyBF_iRQstu84r9eAaUd0a9KLj6OtR@mail.gmail.com>

```
Restrict the tags used to generate the version string to those that
begin with "v", since git's tags for git-core (ie. excluding git-gui)
are all of the form "vX.Y...".

This is to avoid using private tags by the user in a clone of the git
code repository, which may break certain machinery (eg. Makefile, gitk).

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---

  Changes from RFC:

    - used "v[0-9]*" instead of just "v*"
    - mentioned gitk as another piece that may break

 GIT-VERSION-GEN |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 59219bd..e45513d 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -12,7 +12,7 @@ if test -f version
 then
 	VN=$(cat version) || VN="$DEF_VER"
 elif test -d .git -o -f .git &&
-	VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
+	VN=$(git describe --match "v[0-9]*" --abbrev=4 HEAD 2>/dev/null) &&
 	case "$VN" in
 	*$LF*) (exit 1) ;;
 	v[0-9]*)
--
1.7.1.189.g07419

```

## Junio C Hamano, 2010-05-12 05:54

Subject: Re: [PATCH] GIT-VERSION-GEN: restrict tags used
Message-ID: <7vaas58y2t.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vaas58y2t.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1273634960-2728-1-git-send-email-rctay89@gmail.com>

```
Thanks.

```
