guix-commits
[Top][All Lists]
Advanced

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

01/05: packages: Allow package lookups with version prefixes.


From: Ludovic Courtès
Subject: 01/05: packages: Allow package lookups with version prefixes.
Date: Sat, 18 Apr 2015 21:19:08 +0000

civodul pushed a commit to branch master
in repository guix.

commit 724311a26b5205dd5721439389ab70aab4082371
Author: Ludovic Courtès <address@hidden>
Date:   Sat Apr 18 22:30:07 2015 +0200

    packages: Allow package lookups with version prefixes.
    
    * gnu/packages.scm (find-packages-by-name): Sort MATCHING according to
      'version>?'.  Use 'string-prefix?' instead of 'string=?' to compare
      against VERSION.
    * doc/guix.texi (Invoking guix package): Add example and explanation.
---
 doc/guix.texi    |    5 ++++-
 gnu/packages.scm |   12 ++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index ad57236..69d6599 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -962,7 +962,10 @@ Install the specified @var{package}s.
 
 Each @var{package} may specify either a simple package name, such as
 @code{guile}, or a package name followed by a hyphen and version number,
-such as @code{guile-1.8.8}.  If no version number is specified, the
+such as @code{guile-1.8.8} or simply @code{guile-1.8} (in the latter
+case, the newest version prefixed by @code{1.8} is selected.)
+
+If no version number is specified, the
 newest available version will be selected.  In addition, @var{package}
 may contain a colon, followed by the name of one of the outputs of the
 package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
diff --git a/gnu/packages.scm b/gnu/packages.scm
index 6ef0fb6..9eb4877 100644
--- a/gnu/packages.scm
+++ b/gnu/packages.scm
@@ -211,14 +211,18 @@ same package twice."
   (let ((packages (delay
                     (fold-packages (lambda (p r)
                                      (vhash-cons (package-name p) p r))
-                                   vlist-null))))
+                                   vlist-null)))
+        (version>? (lambda (p1 p2)
+                     (version>? (package-version p1) (package-version p2)))))
     (lambda* (name #:optional version)
       "Return the list of packages with the given NAME.  If VERSION is not #f,
-then only return packages whose version is equal to VERSION."
-      (let ((matching (vhash-fold* cons '() name (force packages))))
+then only return packages whose version is prefixed by VERSION, sorted in
+decreasing version order."
+      (let ((matching (sort (vhash-fold* cons '() name (force packages))
+                            version>?)))
         (if version
             (filter (lambda (package)
-                      (string=? (package-version package) version))
+                      (string-prefix? version (package-version package)))
                     matching)
             matching)))))
 



reply via email to

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