From: Marius Bakke <marius@gnu.org>
To: 50377@debbugs.gnu.org
Subject: [bug#50377] [PATCH 2/2] transformations: 'git describe' style commit IDs are used as version.
Date: Sat, 4 Sep 2021 20:10:35 +0200 [thread overview]
Message-ID: <20210904181035.24161-2-marius@gnu.org> (raw)
In-Reply-To: <20210904181035.24161-1-marius@gnu.org>
* guix/transformations.scm (transform-package-source-commit): Look for
'git describe' style IDs and use it as the version if applicable.
* tests/transformations.scm
("options->transformation, with-commit, 'git describe' style version"): New
test.
---
guix/transformations.scm | 34 +++++++++++++++++++++++++---------
tests/transformations.scm | 19 +++++++++++++++++++
2 files changed, 44 insertions(+), 9 deletions(-)
diff --git a/guix/transformations.scm b/guix/transformations.scm
index 5122baa403..e91bce3808 100644
--- a/guix/transformations.scm
+++ b/guix/transformations.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2021 Marius Bakke <marius@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -278,15 +279,30 @@ strings like \"guile-next=cabba9e\" meaning that packages are built using
(define (replace old url commit)
(package
(inherit old)
- (version (if (and (> (string-length commit) 1)
- (string-prefix? "v" commit)
- (char-set-contains? char-set:digit
- (string-ref commit 1)))
- (string-drop commit 1) ;looks like a tag like "v1.0"
- (string-append "git."
- (if (< (string-length commit) 7)
- commit
- (string-take commit 7)))))
+ (version (cond ((and (> (string-length commit) 8)
+ (string-contains commit "-g")
+ (match (string-split commit #\-)
+ ((components ... g+id)
+ (char-set-every (cut char-set-contains?
+ char-set:hex-digit <>)
+ (string->char-set
+ (string-drop g+id 1))))
+ (_ #f)))
+ ;; This looks like a 'git describe' style ID. Drop
+ ;; the 'v' prefix if applicable.
+ (if (string-prefix? "v" commit)
+ (string-drop commit 1)
+ commit))
+ ((and (> (string-length commit) 1)
+ (string-prefix? "v" commit)
+ (char-set-contains? char-set:digit
+ (string-ref commit 1)))
+ (string-drop commit 1)) ;looks like a tag like "v1.0"
+ (else
+ (string-append "git."
+ (if (< (string-length commit) 7)
+ commit
+ (string-take commit 7))))))
(source (git-checkout (url url) (commit commit)
(recursive? #t)))))
diff --git a/tests/transformations.scm b/tests/transformations.scm
index 3417c994ec..44fccffcce 100644
--- a/tests/transformations.scm
+++ b/tests/transformations.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016, 2017, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2021 Marius Bakke <marius@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -235,6 +236,24 @@
(string=? (package-name dep2) "chbouib")
(package-source dep2))))))))
+(test-equal "options->transformation, with-commit, 'git describe' style version"
+ "1.0-gcabba9e2"
+ (let* ((p (dummy-package "guix.scm"
+ (inputs `(("foo" ,grep)
+ ("bar" ,(dummy-package "chbouib"
+ (source (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://example.org")
+ (commit "cabba9e")))
+ (sha256 #f)))))))))
+ (t (options->transformation '((with-commit . "chbouib=v1.0-gcabba9e2")))))
+ (let ((new (t p)))
+ (and (not (eq? new p))
+ (match (package-inputs new)
+ ((("foo" dep1) ("bar" dep2))
+ (package-version dep2)))))))
+
(test-equal "options->transformation, with-git-url"
(let ((source (git-checkout (url "https://example.org")
(recursive? #t))))
--
2.31.1
next prev parent reply other threads:[~2021-09-04 18:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-04 18:08 [bug#50377] [PATCH 0/2] Support 'git describe' style commit IDs in transformations Marius Bakke
2021-09-04 18:10 ` [bug#50377] [PATCH 1/2] git: 'resolve-reference' handles 'git describe'-style commit IDs Marius Bakke
2021-09-04 18:10 ` Marius Bakke [this message]
2021-09-05 22:52 ` [bug#50377] [PATCH v2 " Marius Bakke
2021-09-06 10:38 ` [bug#50377] [PATCH v3 0/2] Support 'git describe' style commit IDs in transformations Marius Bakke
2021-09-06 10:38 ` [bug#50377] [PATCH v3 1/2] git: 'resolve-reference' handles 'git describe'-style commit IDs Marius Bakke
2021-09-06 21:02 ` [bug#50377] [PATCH 0/2] Support 'git describe' style commit IDs in transformations Ludovic Courtès
2021-09-06 10:38 ` [bug#50377] [PATCH v3 2/2] transformations: 'git describe' style commit IDs are used as version Marius Bakke
2021-09-06 21:04 ` [bug#50377] [PATCH 0/2] Support 'git describe' style commit IDs in transformations Ludovic Courtès
2021-09-08 16:08 ` bug#50377: " Marius Bakke
2021-09-06 11:52 ` [bug#50377] [PATCH v3 " Xinglu Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210904181035.24161-2-marius@gnu.org \
--to=marius@gnu.org \
--cc=50377@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).