diff mbox

[1/2] profiles: manifest-lookup-package: Optionally match version prefix.

Message ID 20160922202827.22039-1-rekado@elephly.net
State New
Headers show

Commit Message

Ricardo Wurmus Sept. 22, 2016, 8:28 p.m. UTC
* guix/profiles.scm (manifest-lookup-package): Optionally filter store
item matches by version prefix.
---
 guix/profiles.scm | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

Comments

Ludovic Courtès Sept. 26, 2016, 10:41 a.m. UTC | #1
Ricardo Wurmus <rekado@elephly.net> skribis:

> * guix/profiles.scm (manifest-lookup-package): Optionally filter store
> item matches by version prefix.

[...]

> -(define (manifest-lookup-package manifest name)
> +(define* (manifest-lookup-package manifest name #:optional version)
>    "Return as a monadic value the first package or store path referenced by
> -MANIFEST that named NAME, or #f if not found."
> +MANIFEST that is named NAME and optionally has the given VERSION prefix, or #f
> +if not found."

This should be phrased to mention that VERSION can be #f.

> +              (let-values (((pkg-name pkg-version)

Rather ‘name*’ and ‘version*’, but no abbreviations.

> +                            (package-name->name+version
> +                             (store-path-package-name item))))
> +                (and (equal? name pkg-name)

‘string=?’

OK with these changes, thanks!

Ludo’.
diff mbox

Patch

diff --git a/guix/profiles.scm b/guix/profiles.scm
index 4a2ba1c..78deeb7 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -472,21 +472,30 @@  replace it."
                 (cons (gexp-input thing output) deps)))
               (manifest-entries manifest)))
 
-(define (manifest-lookup-package manifest name)
+(define* (manifest-lookup-package manifest name #:optional version)
   "Return as a monadic value the first package or store path referenced by
-MANIFEST that named NAME, or #f if not found."
+MANIFEST that is named NAME and optionally has the given VERSION prefix, or #f
+if not found."
   ;; Return as a monadic value the package or store path referenced by the
   ;; manifest ENTRY, or #f if not referenced.
   (define (entry-lookup-package entry)
     (define (find-among-inputs inputs)
       (find (lambda (input)
               (and (package? input)
-                   (equal? name (package-name input))))
+                   (equal? name (package-name input))
+                   (if version
+                       (string-prefix? version (package-version input))
+                       #t)))
             inputs))
     (define (find-among-store-items items)
       (find (lambda (item)
-              (equal? name (package-name->name+version
-                            (store-path-package-name item))))
+              (let-values (((pkg-name pkg-version)
+                            (package-name->name+version
+                             (store-path-package-name item))))
+                (and (equal? name pkg-name)
+                     (if version
+                         (string-prefix? version pkg-version)
+                         #t))))
             items))
 
     ;; TODO: Factorize.