git: 18052912af5d - main - Uses/cargo: Fix invalid WRKSRC for crates fetched from GitLab with tag

From: Tobias Kortkamp <tobik_at_FreeBSD.org>
Date: Sat, 08 Oct 2022 12:23:48 UTC
The branch main has been updated by tobik:

URL: https://cgit.FreeBSD.org/ports/commit/?id=18052912af5ddbea5d2008e750c568dda0d97b43

commit 18052912af5ddbea5d2008e750c568dda0d97b43
Author:     Tobias Kortkamp <tobik@FreeBSD.org>
AuthorDate: 2022-10-08 12:21:19 +0000
Commit:     Tobias Kortkamp <tobik@FreeBSD.org>
CommitDate: 2022-10-08 12:21:19 +0000

    Uses/cargo: Fix invalid WRKSRC for crates fetched from GitLab with tag
    
    When using tags the archive fetched from GitLab has the
    corresponding commit hash appended to the directory root too.
    
    snui@git+https://gitlab.com/snakedye/snui.git?tag=v0.1.4\#83873f1e148a9c84471c10f166c9a945a44d3e64
    
    would result in
    
    WRKSRC_crate_snui=      ${WRKDIR}/snui-v0.1.4
    
    but it must be
    
    WRKSRC_crate_snui=      ${WRKDIR}/snui-v0.1.4-83873f1e148a9c84471c10f166c9a945a44d3e64
    
    PR:             266724
    Reported by:    jbeich
---
 Mk/Scripts/cargo-crates-git-common.awk | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/Mk/Scripts/cargo-crates-git-common.awk b/Mk/Scripts/cargo-crates-git-common.awk
index c1c5dcc7ce6e..f4023bb4f880 100644
--- a/Mk/Scripts/cargo-crates-git-common.awk
+++ b/Mk/Scripts/cargo-crates-git-common.awk
@@ -38,7 +38,7 @@ function commit_from_git_url(url) {
 	}
 }
 
-function split_git_url(info, git_url,		url, path, account, project, commit, i, dir_ver, host) {
+function split_git_url(info, git_url,		url, path, account, project, commit, i, dir_ver, host, tag, fragment) {
 	delete info
 	split_url(url, git_url)
 	url["scheme"] = tolower(url["scheme"])
@@ -80,6 +80,8 @@ function split_git_url(info, git_url,		url, path, account, project, commit, i, d
 			project = path[i]
 			sub(/\.[gG][iI][tT]$/, "", project)
 			commit = commit_from_git_url(url)
+			fragment = url["fragment"]
+			tag = url["query", "tag"]
 
 			host = url["host"]
 			delete url
@@ -93,7 +95,12 @@ function split_git_url(info, git_url,		url, path, account, project, commit, i, d
 			gsub(/\//, "-", account)
 			info["filename"] = sprintf("%s-%s-%s_GL0.tar.gz", account, project, commit)
 
-			info["dir"] = sprintf("%s-%s", project, commit)
+			# c.f. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=266724
+			if (tag) {
+				info["dir"] = sprintf("%s-%s-%s", project, tag, fragment)
+			} else {
+				info["dir"] = sprintf("%s-%s", project, commit)
+			}
 
 			return 1
 		}