summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-05-20 15:55:37 +0200
committerLudovic Courtès <ludo@gnu.org>2020-05-25 00:00:28 +0200
commit9b049de84ed101e2c0a5d071e76f424b3bc46bd9 (patch)
treeb71844f74fc05c615a9d002f0048662e4e50ad28
parentc098c11be8eb9e0c12be42640721e3cb21c37628 (diff)
channels: 'latest-channel-instances' doesn't leak internal state.
* guix/channels.scm (latest-channel-instances): Remove 'previous-channels' argument. Introduce 'loop' and use it.
-rw-r--r--guix/channels.scm69
1 files changed, 34 insertions, 35 deletions
diff --git a/guix/channels.scm b/guix/channels.scm
index f0174de7674..e0a7a84f55d 100644
--- a/guix/channels.scm
+++ b/guix/channels.scm
@@ -231,10 +231,9 @@ result is unspecified."
231 #:select? (negate dot-git?)))) 231 #:select? (negate dot-git?))))
232 (channel-instance channel commit checkout)))) 232 (channel-instance channel commit checkout))))
233 233
234(define* (latest-channel-instances store channels #:optional (previous-channels '())) 234(define* (latest-channel-instances store channels)
235 "Return a list of channel instances corresponding to the latest checkouts of 235 "Return a list of channel instances corresponding to the latest checkouts of
236CHANNELS and the channels on which they depend. PREVIOUS-CHANNELS is a list 236CHANNELS and the channels on which they depend."
237of previously processed channels."
238 ;; Only process channels that are unique, or that are more specific than a 237 ;; Only process channels that are unique, or that are more specific than a
239 ;; previous channel specification. 238 ;; previous channel specification.
240 (define (ignore? channel others) 239 (define (ignore? channel others)
@@ -245,38 +244,38 @@ of previously processed channels."
245 (not (or (channel-commit a) 244 (not (or (channel-commit a)
246 (channel-commit b)))))))) 245 (channel-commit b))))))))
247 246
248 ;; Accumulate a list of instances. A list of processed channels is also 247 (let loop ((channels channels)
249 ;; accumulated to decide on duplicate channel specifications. 248 (previous-channels '()))
250 (define-values (resulting-channels instances) 249 ;; Accumulate a list of instances. A list of processed channels is also
251 (fold2 (lambda (channel previous-channels instances) 250 ;; accumulated to decide on duplicate channel specifications.
252 (if (ignore? channel previous-channels) 251 (define-values (resulting-channels instances)
253 (values previous-channels instances) 252 (fold2 (lambda (channel previous-channels instances)
254 (begin 253 (if (ignore? channel previous-channels)
255 (format (current-error-port) 254 (values previous-channels instances)
256 (G_ "Updating channel '~a' from Git repository at '~a'...~%") 255 (begin
257 (channel-name channel) 256 (format (current-error-port)
258 (channel-url channel)) 257 (G_ "Updating channel '~a' from Git repository at '~a'...~%")
259 (let ((instance (latest-channel-instance store channel))) 258 (channel-name channel)
260 (let-values (((new-instances new-channels) 259 (channel-url channel))
261 (latest-channel-instances 260 (let ((instance (latest-channel-instance store channel)))
262 store 261 (let-values (((new-instances new-channels)
263 (channel-instance-dependencies instance) 262 (loop (channel-instance-dependencies instance)
264 previous-channels))) 263 previous-channels)))
265 (values (append (cons channel new-channels) 264 (values (append (cons channel new-channels)
266 previous-channels) 265 previous-channels)
267 (append (cons instance new-instances) 266 (append (cons instance new-instances)
268 instances))))))) 267 instances)))))))
269 previous-channels 268 previous-channels
270 '() ;instances 269 '() ;instances
271 channels)) 270 channels))
272 271
273 (let ((instance-name (compose channel-name channel-instance-channel))) 272 (let ((instance-name (compose channel-name channel-instance-channel)))
274 ;; Remove all earlier channel specifications if they are followed by a 273 ;; Remove all earlier channel specifications if they are followed by a
275 ;; more specific one. 274 ;; more specific one.
276 (values (delete-duplicates instances 275 (values (delete-duplicates instances
277 (lambda (a b) 276 (lambda (a b)
278 (eq? (instance-name a) (instance-name b)))) 277 (eq? (instance-name a) (instance-name b))))
279 resulting-channels))) 278 resulting-channels))))
280 279
281(define* (checkout->channel-instance checkout 280(define* (checkout->channel-instance checkout
282 #:key commit 281 #:key commit