[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/02: guix package: '-s' sorts packages by name, then by version.
From: |
Ludovic Courtès |
Subject: |
02/02: guix package: '-s' sorts packages by name, then by version. |
Date: |
Fri, 20 Mar 2015 21:07:39 +0000 |
civodul pushed a commit to branch master
in repository guix.
commit 051edc95f12d3bb55fd67c6f2a3f4478df53a08f
Author: Ludovic Courtès <address@hidden>
Date: Fri Mar 20 22:05:04 2015 +0100
guix package: '-s' sorts packages by name, then by version.
Before that it would sort them by name only, so the order in which two
packages with the same name but a different version would appear was
non-deterministic.
Reported by Tomáš Čech <address@hidden>.
* guix/scripts/package.scm (find-packages-by-description)[version<?]:
New variable.
Change the 2nd argument to 'sort' to use 'string-compare' and resort
to 'version<?' when P1 and P2 have the same name.
---
guix/scripts/package.scm | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 41db191..3cc7ae7 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -240,6 +240,8 @@ DURATION-RELATION with the current time."
(define (find-packages-by-description rx)
"Return the list of packages whose name, synopsis, or description matches
RX."
+ (define version<? (negate version>=?))
+
(sort
(fold-packages (lambda (package result)
(define matches?
@@ -254,8 +256,11 @@ RX."
result))
'())
(lambda (p1 p2)
- (string<? (package-name p1)
- (package-name p2)))))
+ (case (string-compare (package-name p1) (package-name p2)
+ (const '<) (const '=) (const '>))
+ ((=) (version<? (package-version p1) (package-version p2)))
+ ((<) #t)
+ (else #f)))))
(define-syntax-rule (leave-on-EPIPE exp ...)
"Run EXP... in a context when EPIPE errors are caught and lead to 'exit'