guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

09/18: import: git: Allow updating to a specific version.


From: guix-commits
Subject: 09/18: import: git: Allow updating to a specific version.
Date: Mon, 26 Dec 2022 11:41:43 -0500 (EST)

htgoebel pushed a commit to branch master
in repository guix.

commit 6da60453e25f3941202ab51f74821c9ed7299bca
Author: Hartmut Goebel <h.goebel@crazy-compilers.com>
AuthorDate: Thu Jun 30 11:05:13 2022 +0200

    import: git: Allow updating to a specific version.
    
    * guix/import/git.scm
      (latest-tag): Add #:version argument. If version is given, try to
      find the respective version tag.
      (latest-git-tag-version): Add #:version argument and pass it on to
      called functions.
      (latest-releease) Rename to 'import-release', add #:version argument
      and pass it on to called functions.
---
 guix/import/git.scm | 39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/guix/import/git.scm b/guix/import/git.scm
index bb5ba4d97e..c15943bd7c 100644
--- a/guix/import/git.scm
+++ b/guix/import/git.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
 ;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
+;;; Copyright © 2022 Hartmut Goebel <h.goebel@crazy-compilers.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -146,9 +147,11 @@ version corresponding to the tag, and the cdr is the name 
of the tag."
                            tags)
                entry<?))
 
-(define* (latest-tag url #:key prefix suffix delim pre-releases?)
+(define* (latest-tag url
+                     #:key prefix suffix delim pre-releases? (version #f))
   "Return the latest version and corresponding tag available from the Git
-repository at URL."
+repository at URL. Optionally include a VERSION string to fetch a specific
+version."
   (define (pre-release? tag)
     (any (cut regexp-exec <> tag)
          %pre-release-rx))
@@ -169,13 +172,22 @@ repository at URL."
      ((null? versions->tags)
       (git-no-valid-tags-error))
      (else
-      (match (last versions->tags)
-        ((version . tag)
-         (values version tag)))))))
-
-(define (latest-git-tag-version package)
+      (let ((versions (if version
+                          (filter (match-lambda
+                                   ((candidate-version . tag)
+                                    (string=? version candidate-version)))
+                                  versions->tags)
+                          versions->tags)))
+        (if (null? versions)
+            (values #f #f)
+            (match (last versions)
+              ((version . tag)
+               (values version tag)))))))))
+
+(define* (latest-git-tag-version package #:key (version #f))
   "Given a PACKAGE, return the latest version of it and the corresponding git
-tag, or #false and #false if the latest version could not be determined."
+tag, or #false and #false if the latest version could not be determined.
+Optionally include a VERSION string to fetch a specific version."
   (guard (c ((or (git-no-tags-error? c) (git-no-valid-tags-error? c))
              (warning (or (package-field-location package 'source)
                           (package-location package))
@@ -193,6 +205,7 @@ tag, or #false and #false if the latest version could not 
be determined."
            (url (git-reference-url (origin-uri source)))
            (property (cute assq-ref (package-properties package) <>)))
       (latest-tag url
+                  #:version version
                   #:prefix (property 'release-tag-prefix)
                   #:suffix (property 'release-tag-suffix)
                   #:delim (property 'release-tag-version-delimiter)
@@ -206,12 +219,14 @@ tag, or #false and #false if the latest version could not 
be determined."
           (git-reference? (origin-uri origin))))
     (_ #f)))
 
-(define (latest-git-release package)
-  "Return an <upstream-source> for the latest release of PACKAGE."
+(define* (import-git-release package #:key (version #f))
+  "Return an <upstream-source> for the latest release of PACKAGE.
+Optionally include a VERSION string to fetch a specific version."
   (let* ((name (package-name package))
          (old-version (package-version package))
          (old-reference (origin-uri (package-source package)))
-         (new-version new-version-tag (latest-git-tag-version package)))
+         (new-version new-version-tag
+                      (latest-git-tag-version package #:version version)))
     (and new-version new-version-tag
          (upstream-source
           (package name)
@@ -226,4 +241,4 @@ tag, or #false and #false if the latest version could not 
be determined."
    (name 'generic-git)
    (description "Updater for packages hosted on Git repositories")
    (pred git-package?)
-   (import latest-git-release)))
+   (import import-git-release)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]