profiles: Extract a procedure for getting relative generation numbers.
* guix/profiles.scm (relative-generation-spec->number): New procedure. * guix/scripts/package.scm (switch-generation-action): Use it. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
3382bfe9ea
commit
9008debc54
|
@ -5,6 +5,7 @@
|
||||||
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
|
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
|
||||||
;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
|
;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
|
||||||
;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
|
;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
|
||||||
|
;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -97,6 +98,7 @@
|
||||||
generation-number
|
generation-number
|
||||||
generation-numbers
|
generation-numbers
|
||||||
profile-generations
|
profile-generations
|
||||||
|
relative-generation-spec->number
|
||||||
relative-generation
|
relative-generation
|
||||||
previous-generation-number
|
previous-generation-number
|
||||||
generation-time
|
generation-time
|
||||||
|
@ -1039,6 +1041,23 @@ former profiles were found."
|
||||||
'()
|
'()
|
||||||
generations)))
|
generations)))
|
||||||
|
|
||||||
|
(define (relative-generation-spec->number profile spec)
|
||||||
|
"Return PROFILE's generation specified by SPEC, which is a string. The SPEC
|
||||||
|
may be a N, -N, or +N, where N is a number. If the spec is N, then the number
|
||||||
|
returned is N. If it is -N, then the number returned is the profile's current
|
||||||
|
generation number minus N. If it is +N, then the number returned is the
|
||||||
|
profile's current generation number plus N. Return #f if there is no such
|
||||||
|
generation."
|
||||||
|
(let ((number (string->number spec)))
|
||||||
|
(and number
|
||||||
|
(case (string-ref spec 0)
|
||||||
|
((#\+ #\-)
|
||||||
|
(relative-generation profile number))
|
||||||
|
(else (if (memv number (profile-generations profile))
|
||||||
|
number
|
||||||
|
#f))))))
|
||||||
|
|
||||||
|
|
||||||
(define* (relative-generation profile shift #:optional
|
(define* (relative-generation profile shift #:optional
|
||||||
(current (generation-number profile)))
|
(current (generation-number profile)))
|
||||||
"Return PROFILE's generation shifted from the CURRENT generation by SHIFT.
|
"Return PROFILE's generation shifted from the CURRENT generation by SHIFT.
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
;;; Copyright © 2014, 2016 Alex Kost <alezost@gmail.com>
|
;;; Copyright © 2014, 2016 Alex Kost <alezost@gmail.com>
|
||||||
;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
|
;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
|
||||||
;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
|
;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
|
||||||
|
;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -782,12 +783,7 @@ processed, #f otherwise."
|
||||||
#:key dry-run?)
|
#:key dry-run?)
|
||||||
"Switch PROFILE to the generation specified by SPEC."
|
"Switch PROFILE to the generation specified by SPEC."
|
||||||
(unless dry-run?
|
(unless dry-run?
|
||||||
(let* ((number (string->number spec))
|
(let ((number (relative-generation-spec->number profile spec)))
|
||||||
(number (and number
|
|
||||||
(case (string-ref spec 0)
|
|
||||||
((#\+ #\-)
|
|
||||||
(relative-generation profile number))
|
|
||||||
(else number)))))
|
|
||||||
(if number
|
(if number
|
||||||
(switch-to-generation* profile number)
|
(switch-to-generation* profile number)
|
||||||
(leave (_ "cannot switch to generation '~a'~%") spec)))))
|
(leave (_ "cannot switch to generation '~a'~%") spec)))))
|
||||||
|
|
Loading…
Reference in New Issue