summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorEfraim Flashner <efraim@flashner.co.il>2024-01-09 15:07:37 +0200
committerEfraim Flashner <efraim@flashner.co.il>2024-01-16 14:24:10 +0200
commit8520f00d6989ff5ab22755a97dfcfd0375f6b5ca (patch)
treee280fc941fa9485ccc1231a9b75a9f8179bcd22b /guix
parent5ce1512b0f68cf39cb399623a14302f309c06129 (diff)
import: crate: Simplify find-crate-version.
* guix/import/crate.scm (find-crate-version): Reuse nonyanked-crate-versions, max-crate-version-of-semver. Change-Id: I976a3b5a397f0d6a7d723804a98356544bfc7da3
Diffstat (limited to 'guix')
-rw-r--r--guix/import/crate.scm28
1 files changed, 8 insertions, 20 deletions
diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index d522aecb4f..7a25b2243c 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -322,26 +322,14 @@ look up the development dependencs for the given crate."
;; If no matching non-yanked version has been found and allow-yanked? is #t,
;; also consider yanked packages.
(define (find-crate-version crate range)
- (let* ((semver-range (string->semver-range range))
- (versions
- (sort
- (filter (lambda (entry)
- (and
- (or allow-yanked?
- (not (crate-version-yanked? (second entry))))
- (semver-range-contains? semver-range (first entry))))
- (map (lambda (ver)
- (list (string->semver (crate-version-number ver))
- ver))
- (crate-versions crate)))
- (match-lambda* (((semver ver) ...)
- (match-let (((yanked1 yanked2)
- (map crate-version-yanked? ver)))
- (or (and yanked1 (not yanked2))
- (and (eq? yanked1 yanked2)
- (apply semver<? semver)))))))))
- (and (not (null-list? versions))
- (second (last versions)))))
+ (let ((semver-range (string->semver-range range))
+ (versions (nonyanked-crate-versions crate)))
+ (or (and (not (null-list? versions))
+ (max-crate-version-of-semver semver-range versions))
+ (and allow-yanked?
+ (not (null-list? (crate-versions crate)))
+ (max-crate-version-of-semver semver-range
+ (crate-versions crate))))))
;; If no non-yanked existing package version was found, check the upstream
;; versions. If a non-yanked upsteam version exists, use it instead,