[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/06: profiles: Extract a procedure for getting relative generation num
From: |
Ludovic Courtès |
Subject: |
02/06: profiles: Extract a procedure for getting relative generation numbers. |
Date: |
Sun, 6 Nov 2016 17:13:57 +0000 (UTC) |
civodul pushed a commit to branch master
in repository guix.
commit 9008debc54aaa4d65444d5cef85df83455d48d7b
Author: Chris Marusich <address@hidden>
Date: Tue Nov 1 22:48:11 2016 -0700
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 <address@hidden>
---
guix/profiles.scm | 19 +++++++++++++++++++
guix/scripts/package.scm | 8 ++------
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/guix/profiles.scm b/guix/profiles.scm
index 96f8b65..33a5f50 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -5,6 +5,7 @@
;;; Copyright © 2015 Mark H Weaver <address@hidden>
;;; Copyright © 2015 Sou Bunnbu <address@hidden>
;;; Copyright © 2016 Ricardo Wurmus <address@hidden>
+;;; Copyright © 2016 Chris Marusich <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -97,6 +98,7 @@
generation-number
generation-numbers
profile-generations
+ relative-generation-spec->number
relative-generation
previous-generation-number
generation-time
@@ -1039,6 +1041,23 @@ former profiles were found."
'()
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
(current (generation-number profile)))
"Return PROFILE's generation shifted from the CURRENT generation by SHIFT.
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 70ed0a7..96a22f6 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -5,6 +5,7 @@
;;; Copyright © 2014, 2016 Alex Kost <address@hidden>
;;; Copyright © 2016 Roel Janssen <address@hidden>
;;; Copyright © 2016 Benz Schenk <address@hidden>
+;;; Copyright © 2016 Chris Marusich <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -782,12 +783,7 @@ processed, #f otherwise."
#:key dry-run?)
"Switch PROFILE to the generation specified by SPEC."
(unless dry-run?
- (let* ((number (string->number spec))
- (number (and number
- (case (string-ref spec 0)
- ((#\+ #\-)
- (relative-generation profile number))
- (else number)))))
+ (let ((number (relative-generation-spec->number profile spec)))
(if number
(switch-to-generation* profile number)
(leave (_ "cannot switch to generation '~a'~%") spec)))))
- branch master updated (f4dc22b -> 8074b33), Ludovic Courtès, 2016/11/06
- 01/06: system: Avoid using device paths in <menu-entry> device field., Ludovic Courtès, 2016/11/06
- 03/06: system: Rename previous-grub-entries to profile-grub-entries., Ludovic Courtès, 2016/11/06
- 04/06: system: Optionally limit the entries returned by profile-grub-entries., Ludovic Courtès, 2016/11/06
- 05/06: install: Extract procedure: install-grub-config., Ludovic Courtès, 2016/11/06
- 02/06: profiles: Extract a procedure for getting relative generation numbers.,
Ludovic Courtès <=
- 06/06: system: Add 'guix system' actions: switch-generation and roll-back., Ludovic Courtès, 2016/11/06