diff mbox series

[bug#57460,10/20] refresh: Allow updating to a specific version (gnome)

Message ID 772d6b613a69ae950b657d94a51019928fdfca5b.1661691694.git.h.goebel@crazy-compilers.com
State New
Headers show
Series Refresh to specific version | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch fail
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Hartmut Goebel Aug. 28, 2022, 1:18 p.m. UTC
* guix/import/gnome.scm(latest-gnome-release): Rename
  to (import-gnome-release), add keyword-argument 'version'. If version is
  given, try to find the respective version
  [find-latest-release]: New function, based on former code.
  [find-version-release]: New function.
---
 guix/import/gnome.scm | 47 ++++++++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 16 deletions(-)

Comments

Ludovic Courtès Sept. 24, 2022, 9:29 a.m. UTC | #1
Hartmut Goebel <h.goebel@crazy-compilers.com> skribis:

> * guix/import/gnome.scm(latest-gnome-release): Rename
>   to (import-gnome-release), add keyword-argument 'version'. If version is
>   given, try to find the respective version
>   [find-latest-release]: New function, based on former code.
>   [find-version-release]: New function.

[...]

> +  (define (find-latest-release releases)
> +    (fold (match-lambda*
> +           (((key . value) result)
> +            (cond ((even-minor-version? key)
> +                   (match result
> +                          (#f
> +                           (cons key value))
> +                          ((newest . _)
> +                           (if (version>? key newest)
> +                               (cons key value)
> +                               result))))

Please reindent ‘match’ as it was.

> +  (define (find-version-release releases version)
> +    (fold (match-lambda*
> +           (((key . value) result)
> +            (if (string=? key version)
> +                (cons key value)
> +                result)))
> +          #f
> +          releases))

I guess we could start at the first match instead of traversing all the
list, no?  How about:

  (define (find-version-release releases version)
    (find (match-lambda
            ((key . value)
             (string=? key version)))
          releases))

?

Otherwise LGTM.
M Sept. 24, 2022, 10:25 a.m. UTC | #2
On 24-09-2022 11:29, Ludovic Courtès wrote:
> Hartmut Goebel <h.goebel@crazy-compilers.com> skribis:
> 
>> * guix/import/gnome.scm(latest-gnome-release): Rename
>>    to (import-gnome-release), add keyword-argument 'version'. If version is
>>    given, try to find the respective version
>>    [find-latest-release]: New function, based on former code.
>>    [find-version-release]: New function.
> 
> [...]
> 
>> +  (define (find-latest-release releases)
>> +    (fold (match-lambda*
>> +           (((key . value) result)
>> +            (cond ((even-minor-version? key)
>> +                   (match result
>> +                          (#f
>> +                           (cons key value))
>> +                          ((newest . _)
>> +                           (if (version>? key newest)
>> +                               (cons key value)
>> +                               result))))
> 
> Please reindent ‘match’ as it was.

"guix style" is IMO not usable here 
(<https://issues.guix.gnu.org/58040>: "guix style" puts closing 
parentheses on the wrong line").

>> +  (define (find-version-release releases version)
>> +    (fold (match-lambda*
>> +           (((key . value) result)
>> +            (if (string=? key version)
>> +                (cons key value)
>> +                result)))
>> +          #f
>> +          releases))
> 
> I guess we could start at the first match instead of traversing all the
> list, no?  How about:
> 
>    (define (find-version-release releases version)
>      (find (match-lambda
>              ((key . value)
>               (string=? key version)))
>            releases))
> 
> ?

(1) according to "guix style", this should be

(define (find-version-release releases version)
   (find (match-lambda
           ((key . value) (string=? key version))) releases))


(2)  Isn't this an inline definition of 'assoc' (except for replacing 
equal? by string=?)?

(use-modules (srfi srfi-1)) ; the third argument is only documented in 
SRFI-1 Asosciation Lists
(define (find-version-release releases version)
   (assoc version releases string=?)

Some code duplication can be avoided here.

Greetings,
Maxime.
Ludovic Courtès Sept. 24, 2022, 4:31 p.m. UTC | #3
Maxime Devos <maximedevos@telenet.be> skribis:

> "guix style" is IMO not usable here
> (<https://issues.guix.gnu.org/58040>: "guix style" puts closing
> parentheses on the wrong line").

‘guix style’ has shortcomings, which is why I didn’t mention it.
Initially it had a much narrower scope though.  :-)

Ludo’.
diff mbox series

Patch

diff --git a/guix/import/gnome.scm b/guix/import/gnome.scm
index 3562e17e0f..496c253969 100644
--- a/guix/import/gnome.scm
+++ b/guix/import/gnome.scm
@@ -1,5 +1,6 @@ 
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2017, 2019, 2021 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022 Hartmut Goebel <h.goebel@crazy-compilers.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -54,7 +55,7 @@  source for metadata."
                                             name "/" relative-url))))
                         '("tar.lz" "tar.xz" "tar.bz2" "tar.gz")))))))
 
-(define (latest-gnome-release package)
+(define* (import-gnome-release package #:key (version #f))
   "Return the latest release of PACKAGE, a GNOME package, or #f if it could
 not be determined."
   (define %not-dot
@@ -72,6 +73,31 @@  not be determined."
     ;; Some packages like "NetworkManager" have camel-case names.
     (package-upstream-name package))
 
+  (define (find-latest-release releases)
+    (fold (match-lambda*
+           (((key . value) result)
+            (cond ((even-minor-version? key)
+                   (match result
+                          (#f
+                           (cons key value))
+                          ((newest . _)
+                           (if (version>? key newest)
+                               (cons key value)
+                               result))))
+                  (else
+                   result))))
+          #f
+          releases))
+
+  (define (find-version-release releases version)
+    (fold (match-lambda*
+           (((key . value) result)
+            (if (string=? key version)
+                (cons key value)
+                result)))
+          #f
+          releases))
+
   (guard (c ((http-get-error? c)
              (if (= 404 (http-get-error-code c))
                  #f
@@ -92,20 +118,9 @@  not be determined."
       (match json
         (#(4 releases _ ...)
          (let* ((releases (assoc-ref releases upstream-name))
-                (latest   (fold (match-lambda*
-                                  (((key . value) result)
-                                   (cond ((even-minor-version? key)
-                                          (match result
-                                            (#f
-                                             (cons key value))
-                                            ((newest . _)
-                                             (if (version>? key newest)
-                                                 (cons key value)
-                                                 result))))
-                                         (else
-                                          result))))
-                                #f
-                                releases)))
+                (latest (if version
+                            (find-version-release releases version)
+                            (find-latest-release releases))))
            (and latest
                 (jsonish->upstream-source upstream-name latest))))))))
 
@@ -114,4 +129,4 @@  not be determined."
    (name 'gnome)
    (description "Updater for GNOME packages")
    (pred (url-prefix-predicate "mirror://gnome/"))
-   (import latest-gnome-release)))
+   (import import-gnome-release)))