aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorAlex Kost <alezost@gmail.com>2014-10-10 17:56:59 +0400
committerAlex Kost <alezost@gmail.com>2014-10-12 08:45:38 +0400
commit3ccde087528cc04ef5275224ca6123b68e075e3c (patch)
treeca85be418f6ddf37102dd0e47b7c6c1e9bfd52bf /guix
parentc0c018f1805d8410ffb1bc2abb1295ebbe55c38b (diff)
downloadgnu-guix-3ccde087528cc04ef5275224ca6123b68e075e3c.tar
gnu-guix-3ccde087528cc04ef5275224ca6123b68e075e3c.tar.gz
profiles: Add 'relative-generation'.
* guix/profiles.scm: (relative-generation): New procedure. (previous-generation-number): Use it.
Diffstat (limited to 'guix')
-rw-r--r--guix/profiles.scm27
1 files changed, 20 insertions, 7 deletions
diff --git a/guix/profiles.scm b/guix/profiles.scm
index 793af2463f..2742ba8933 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -80,6 +80,7 @@
generation-number
generation-numbers
profile-generations
+ relative-generation
previous-generation-number
generation-time
generation-file-name))
@@ -503,16 +504,28 @@ former profiles were found."
'()
generations)))
-(define (previous-generation-number profile number)
+(define* (relative-generation profile shift #:optional
+ (current (generation-number profile)))
+ "Return PROFILE's generation shifted from the CURRENT generation by SHIFT.
+SHIFT is a positive or negative number.
+Return #f if there is no such generation."
+ (let* ((abs-shift (abs shift))
+ (numbers (profile-generations profile))
+ (from-current (memq current
+ (if (negative? shift)
+ (reverse numbers)
+ numbers))))
+ (and from-current
+ (< abs-shift (length from-current))
+ (list-ref from-current abs-shift))))
+
+(define* (previous-generation-number profile #:optional
+ (number (generation-number profile)))
"Return the number of the generation before generation NUMBER of
PROFILE, or 0 if none exists. It could be NUMBER - 1, but it's not the
case when generations have been deleted (there are \"holes\")."
- (fold (lambda (candidate highest)
- (if (and (< candidate number) (> candidate highest))
- candidate
- highest))
- 0
- (generation-numbers profile)))
+ (or (relative-generation profile -1 number)
+ 0))
(define (generation-file-name profile generation)
"Return the file name for PROFILE's GENERATION."