[Openvpn-devel] git-version.py: use tag as branch name

Message ID 20221216090717.1082-1-lstipakov@gmail.com
State Superseded
Headers show
Series [Openvpn-devel] git-version.py: use tag as branch name | expand

Commit Message

Lev Stipakov Dec. 16, 2022, 9:07 a.m. UTC
From: Lev Stipakov <lev@openvpn.net>

Git magic to get branch name

  git rev-parse --symbolic-full-name HEAD

doesn't work when we're on tag, which is the case when
we build releases. In this case, use tag name as branch name
with another git magic:

  git describe --tags

This fixes https://github.com/OpenVPN/openvpn/issues/199.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
---
 build/msvc/msvc-generate/git-version.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Marc Becker Dec. 16, 2022, 10:19 a.m. UTC | #1
Hi,

> From: Lev Stipakov <lev@openvpn.net>
> 
> Git magic to get branch name
> 
>   git rev-parse --symbolic-full-name HEAD
> 
> doesn't work when we're on tag, which is the case when
> we build releases. In this case, use tag name as branch name
> with another git magic:
> 
>   git describe --tags
> 
> This fixes https://github.com/OpenVPN/openvpn/issues/199.
> 
> Signed-off-by: Lev Stipakov <lev@openvpn.net>
> ---


For me, reason for "rev-parse" failing is detached HEAD (not clear from commit message).
Likely, builder creates checkout for commit-ID without local branches.

For stability purposes, I'd throw in an "--exact-match" to increase "none" fallback conditions,
so things like "v2.6_beta1-22-g73cab722/g73c…" will not end up in the version string.


Kind Regards,
Marc Becker
Frank Lichtenheld Dec. 16, 2022, 10:54 a.m. UTC | #2
On Fri, Dec 16, 2022 at 11:07:17AM +0200, Lev Stipakov wrote:
> From: Lev Stipakov <lev@openvpn.net>
> 
> Git magic to get branch name
> 
>   git rev-parse --symbolic-full-name HEAD
> 
> doesn't work when we're on tag, which is the case when
> we build releases. In this case, use tag name as branch name
> with another git magic:
> 
>   git describe --tags
> 
> This fixes https://github.com/OpenVPN/openvpn/issues/199.

NAK.

I would propose to invert the logic:

Do "git describe --exact-match" first.

That matches only annotated tags that point to this commit.
So it will actually use the tag consistently independent of
whether you have the commit checked out with detached HEAD
or via the release branch.

And then fall back to the previous mechanism if that doesn't
match.

Regards,

Patch

diff --git a/build/msvc/msvc-generate/git-version.py b/build/msvc/msvc-generate/git-version.py
index 814dc86a..513f489a 100644
--- a/build/msvc/msvc-generate/git-version.py
+++ b/build/msvc/msvc-generate/git-version.py
@@ -30,9 +30,16 @@  def get_branch_commit_id():
     if not commit_id:
         raise
     l = os.popen("git rev-parse --symbolic-full-name HEAD").read().split("/")[2:]
-    if not l:
-        l = ["none\n"]
-    branch = "/" .join(l)[:-1]
+    if l:
+        branch = "/" .join(l)[:-1]
+    else:
+        # are we on tag?
+        l = os.popen("git describe --tags").read()
+        if l:
+            branch = l[:-1]
+        else:
+            branch = "none"
+
     return branch, commit_id
 
 def main():