summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-09-21 23:00:07 +0200
committerLudovic Courtès <ludo@gnu.org>2019-09-23 10:38:44 +0200
commitdabdd7d4650da685a9bfe470abbc2ec066ff00b9 (patch)
tree7bbb68903e165c88ddef0c92135256ca8795d7ed
parent192ee02aeb3d2f6d14ea93cfc43b30dd93df80e8 (diff)
pull: Display news titles directly upon 'pull'.
* guix/scripts/pull.scm (display-profile-news): Return true when there's more to display. (display-news-entry-title): New procedure. (display-news-entry): Use it. (display-channel-specific-news): Return true when there's more to display. (display-channel-news-headlines): New procedure. (build-and-install): Call it. When 'display-channel-news-headlines' or 'display-profile-news' returns #t, print a hint to run "pull --news". (display-new/upgraded-packages): Return true when there's more to display.
-rw-r--r--guix/scripts/pull.scm112
1 files changed, 81 insertions, 31 deletions
diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm
index 4a4756dc6e6..a7fd36fffc4 100644
--- a/guix/scripts/pull.scm
+++ b/guix/scripts/pull.scm
@@ -189,7 +189,7 @@ Download and deploy the latest version of Guix.\n"))
189 current-is-newer?) 189 current-is-newer?)
190 "Display what's up in PROFILE--new packages, and all that. If 190 "Display what's up in PROFILE--new packages, and all that. If
191CURRENT-IS-NEWER? is true, assume that the current process represents the 191CURRENT-IS-NEWER? is true, assume that the current process represents the
192newest generation of PROFILE." 192newest generation of PROFILE. Return true when there's more info to display."
193 (match (memv (generation-number profile) 193 (match (memv (generation-number profile)
194 (reverse (profile-generations profile))) 194 (reverse (profile-generations profile)))
195 ((current previous _ ...) 195 ((current previous _ ...)
@@ -212,7 +212,7 @@ newest generation of PROFILE."
212 #:concise? concise? 212 #:concise? concise?
213 #:heading 213 #:heading
214 (G_ "New in this revision:\n"))))) 214 (G_ "New in this revision:\n")))))
215 (_ #t))) 215 (_ #f)))
216 216
217(define (display-channel channel) 217(define (display-channel channel)
218 "Display information about CHANNEL." 218 "Display information about CHANNEL."
@@ -230,33 +230,44 @@ purposes."
230 ;; Assume that the URL matters less than the name. 230 ;; Assume that the URL matters less than the name.
231 (eq? (channel-name channel1) (channel-name channel2))) 231 (eq? (channel-name channel1) (channel-name channel2)))
232 232
233(define (display-news-entry-title entry language port)
234 "Display the title of ENTRY, a news entry, to PORT."
235 (define title
236 (channel-news-entry-title entry))
237
238 (format port " ~a~%"
239 (highlight
240 (string-trim-right
241 (texi->plain-text (or (assoc-ref title language)
242 (assoc-ref title (%default-message-language))
243 ""))))))
244
233(define (display-news-entry entry language port) 245(define (display-news-entry entry language port)
234 "Display ENTRY, a <channel-news-entry>, in LANGUAGE, a language code, to 246 "Display ENTRY, a <channel-news-entry>, in LANGUAGE, a language code, to
235PORT." 247PORT."
236 (let ((title (channel-news-entry-title entry)) 248 (define body
237 (body (channel-news-entry-body entry))) 249 (channel-news-entry-body entry))
238 (format port " ~a~%" 250
239 (highlight 251 (display-news-entry-title entry language port)
252 (format port (G_ " commit ~a~%")
253 (channel-news-entry-commit entry))
254 (newline port)
255 (format port " ~a~%"
256 (indented-string
257 (parameterize ((%text-width (- (%text-width) 4)))
240 (string-trim-right 258 (string-trim-right
241 (texi->plain-text (or (assoc-ref title language) 259 (texi->plain-text (or (assoc-ref body language)
242 (assoc-ref title (%default-message-language)) 260 (assoc-ref body (%default-message-language))
243 ""))))) 261 ""))))
244 (format port (G_ " commit ~a~%") 262 4)))
245 (channel-news-entry-commit entry))
246 (newline port)
247 (format port " ~a~%"
248 (indented-string
249 (parameterize ((%text-width (- (%text-width) 4)))
250 (string-trim-right
251 (texi->plain-text (or (assoc-ref body language)
252 (assoc-ref body (%default-message-language))
253 ""))))
254 4))))
255 263
256(define* (display-channel-specific-news new old 264(define* (display-channel-specific-news new old
257 #:key (port (current-output-port))) 265 #:key (port (current-output-port))
266 concise?)
258 "Display channel news applicable the commits between OLD and NEW, where OLD 267 "Display channel news applicable the commits between OLD and NEW, where OLD
259and NEW are <channel> records with a proper 'commit' field." 268and NEW are <channel> records with a proper 'commit' field. When CONCISE? is
269true, display nothing but the news titles. Return true if there are more news
270to display."
260 (let ((channel new) 271 (let ((channel new)
261 (old (channel-commit old)) 272 (old (channel-commit old))
262 (new (channel-commit new))) 273 (new (channel-commit new)))
@@ -264,13 +275,17 @@ and NEW are <channel> records with a proper 'commit' field."
264 (let ((language (current-message-language))) 275 (let ((language (current-message-language)))
265 (match (channel-news-for-commit channel new old) 276 (match (channel-news-for-commit channel new old)
266 (() ;no news is good news 277 (() ;no news is good news
267 #t) 278 #f)
268 ((entries ...) 279 ((entries ...)
269 (newline port) 280 (newline port)
270 (format port (G_ "News for channel '~a'~%") 281 (format port (G_ "News for channel '~a'~%")
271 (channel-name channel)) 282 (channel-name channel))
272 (for-each (cut display-news-entry <> language port) entries) 283 (for-each (if concise?
273 (newline port))))))) 284 (cut display-news-entry-title <> language port)
285 (cut display-news-entry <> language port))
286 entries)
287 (newline port)
288 #t))))))
274 289
275(define* (display-channel-news profile 290(define* (display-channel-news profile
276 #:optional 291 #:optional
@@ -317,6 +332,35 @@ and NEW are <channel> records with a proper 'commit' field."
317 (and old (list new old))) 332 (and old (list new old)))
318 new-channels))))))) 333 new-channels)))))))
319 334
335(define* (display-channel-news-headlines profile)
336 "Display the titles of news about the channels of PROFILE compared to its
337previous generation. Return true if there are news to display."
338 (define previous
339 (and=> (relative-generation profile -1)
340 (cut generation-file-name profile <>)))
341
342 (when previous
343 (let ((old-channels (profile-channels previous))
344 (new-channels (profile-channels profile)))
345 ;; Find the channels present in both PROFILE and PREVIOUS, and print
346 ;; their news.
347 (and (pair? old-channels) (pair? new-channels)
348 (let ((channels (filter-map (lambda (new)
349 (define old
350 (find (cut channel=? new <>)
351 old-channels))
352
353 (and old (list new old)))
354 new-channels)))
355 (define more?
356 (map (match-lambda
357 ((new old)
358 (display-channel-specific-news new old
359 #:concise? #t)))
360 channels))
361
362 (any ->bool more?))))))
363
320(define (display-news profile) 364(define (display-news profile)
321 ;; Display profile news, with the understanding that this process represents 365 ;; Display profile news, with the understanding that this process represents
322 ;; the newest generation. 366 ;; the newest generation.
@@ -344,7 +388,12 @@ true, display what would be built without actually building it."
344 #:dry-run? dry-run?) 388 #:dry-run? dry-run?)
345 (munless dry-run? 389 (munless dry-run?
346 (return (newline)) 390 (return (newline))
347 (return (display-profile-news profile #:concise? #t)) 391 (return
392 (let ((more? (list (display-profile-news profile #:concise? #t)
393 (display-channel-news-headlines profile))))
394 (when (any ->bool more?)
395 (display-hint
396 (G_ "Run @command{guix pull --news} to read all the news.")))))
348 (if guix-command 397 (if guix-command
349 (let ((new (map (cut string-append <> "/bin/guix") 398 (let ((new (map (cut string-append <> "/bin/guix")
350 (list (user-friendly-profile profile) 399 (list (user-friendly-profile profile)
@@ -544,7 +593,9 @@ it."
544 "Given the two package name/version alists ALIST1 and ALIST2, display the 593 "Given the two package name/version alists ALIST1 and ALIST2, display the
545list of new and upgraded packages going from ALIST1 to ALIST2. When ALIST1 594list of new and upgraded packages going from ALIST1 to ALIST2. When ALIST1
546and ALIST2 differ, display HEADING upfront. When CONCISE? is true, do not 595and ALIST2 differ, display HEADING upfront. When CONCISE? is true, do not
547display long package lists that would fill the user's screen." 596display long package lists that would fill the user's screen.
597
598Return true when there is more package info to display."
548 (define (pretty str column) 599 (define (pretty str column)
549 (indented-string (fill-paragraph str (- (%text-width) 4) 600 (indented-string (fill-paragraph str (- (%text-width) 4)
550 column) 601 column)
@@ -587,10 +638,9 @@ display long package lists that would fill the user's screen."
587 (pretty (list->enumeration (sort upgraded string<?)) 638 (pretty (list->enumeration (sort upgraded string<?))
588 35)))) 639 35))))
589 640
590 (when (and concise? 641 (and concise?
591 (or (> new-count concise/max-item-count) 642 (or (> new-count concise/max-item-count)
592 (> upgraded-count concise/max-item-count))) 643 (> upgraded-count concise/max-item-count)))))
593 (display-hint (G_ "Run @command{guix pull --news} to read all the news.")))))
594 644
595(define (display-profile-content-diff profile gen1 gen2) 645(define (display-profile-content-diff profile gen1 gen2)
596 "Display the changes in PROFILE GEN2 compared to generation GEN1." 646 "Display the changes in PROFILE GEN2 compared to generation GEN1."