ui: Refactor the package-strings helper in show-manifest-transaction.

* guix/ui.scm (show-manifest-transaction)[package-strings]: Add an
OLD-VERSIONS keyword parameter.  Absorb the code path previously found in the
upgrade-string.  Remove upgrade-string.
(show-manifest-transaction): Adjust to the above changes.
This commit is contained in:
Maxim Cournoyer 2020-09-02 11:52:16 -04:00
parent 71e746cc63
commit 7d3eb5e6b7
No known key found for this signature in database
GPG key ID: 1260E46482E63562

View file

@ -15,6 +15,7 @@
;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr> ;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2019 Simon Tournier <zimon.toutoune@gmail.com> ;;; Copyright © 2019 Simon Tournier <zimon.toutoune@gmail.com>
;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net> ;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -1238,31 +1239,24 @@ (define (string-pad-right* str len)
(define* (show-manifest-transaction store manifest transaction (define* (show-manifest-transaction store manifest transaction
#:key dry-run?) #:key dry-run?)
"Display what will/would be installed/removed from MANIFEST by TRANSACTION." "Display what will/would be installed/removed from MANIFEST by TRANSACTION."
(define (package-strings names versions outputs) (define* (package-strings names versions outputs #:key old-versions)
(tabulate (zip (map (lambda (name output)
(if (string=? output "out")
name
(string-append name ":" output)))
names outputs)
versions)
#:initial-indent 3))
(define ;an arrow that can be represented on stderr
(right-arrow (current-error-port)))
(define (upgrade-string names old-version new-version outputs)
(tabulate (zip (map (lambda (name output) (tabulate (zip (map (lambda (name output)
(if (string=? output "out") (if (string=? output "out")
name name
(string-append name ":" output))) (string-append name ":" output)))
names outputs) names outputs)
(if old-versions
(map (lambda (old new) (map (lambda (old new)
(if (string=? old new) (if (string=? old new)
(G_ "(dependencies or package changed)") (G_ "(dependencies or package changed)")
(string-append old " " " " new))) (string-append old " " " " new)))
old-version new-version)) old-versions versions)
versions))
#:initial-indent 3)) #:initial-indent 3))
(define ;an arrow that can be represented on stderr
(right-arrow (current-error-port)))
(let-values (((remove install upgrade downgrade) (let-values (((remove install upgrade downgrade)
(manifest-transaction-effects manifest transaction))) (manifest-transaction-effects manifest transaction)))
(match remove (match remove
@ -1285,8 +1279,8 @@ (define (upgrade-string names old-version new-version outputs)
(((($ <manifest-entry> name old-version) (((($ <manifest-entry> name old-version)
. ($ <manifest-entry> _ new-version output item)) ..1) . ($ <manifest-entry> _ new-version output item)) ..1)
(let ((len (length name)) (let ((len (length name))
(downgrade (upgrade-string name old-version new-version (downgrade (package-strings name new-version output
output))) #:old-versions old-version)))
(if dry-run? (if dry-run?
(format (current-error-port) (format (current-error-port)
(N_ "The following package would be downgraded:~%~{~a~%~}~%" (N_ "The following package would be downgraded:~%~{~a~%~}~%"
@ -1303,9 +1297,8 @@ (define (upgrade-string names old-version new-version outputs)
(((($ <manifest-entry> name old-version) (((($ <manifest-entry> name old-version)
. ($ <manifest-entry> _ new-version output item)) ..1) . ($ <manifest-entry> _ new-version output item)) ..1)
(let ((len (length name)) (let ((len (length name))
(upgrade (upgrade-string name (upgrade (package-strings name new-version output
old-version new-version #:old-versions old-version)))
output)))
(if dry-run? (if dry-run?
(format (current-error-port) (format (current-error-port)
(N_ "The following package would be upgraded:~%~{~a~%~}~%" (N_ "The following package would be upgraded:~%~{~a~%~}~%"