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.
This commit is contained in:
Ludovic Courtès 2019-09-21 23:00:07 +02:00
parent 192ee02aeb
commit dabdd7d465
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -189,7 +189,7 @@ (define* (display-profile-news profile #:key concise?
current-is-newer?) current-is-newer?)
"Display what's up in PROFILE--new packages, and all that. If "Display what's up in PROFILE--new packages, and all that. If
CURRENT-IS-NEWER? is true, assume that the current process represents the CURRENT-IS-NEWER? is true, assume that the current process represents the
newest generation of PROFILE." newest generation of PROFILE. Return true when there's more info to display."
(match (memv (generation-number profile) (match (memv (generation-number profile)
(reverse (profile-generations profile))) (reverse (profile-generations profile)))
((current previous _ ...) ((current previous _ ...)
@ -212,7 +212,7 @@ (define* (display-profile-news profile #:key concise?
#:concise? concise? #:concise? concise?
#:heading #:heading
(G_ "New in this revision:\n"))))) (G_ "New in this revision:\n")))))
(_ #t))) (_ #f)))
(define (display-channel channel) (define (display-channel channel)
"Display information about CHANNEL." "Display information about CHANNEL."
@ -230,33 +230,44 @@ (define (channel=? channel1 channel2)
;; Assume that the URL matters less than the name. ;; Assume that the URL matters less than the name.
(eq? (channel-name channel1) (channel-name channel2))) (eq? (channel-name channel1) (channel-name channel2)))
(define (display-news-entry-title entry language port)
"Display the title of ENTRY, a news entry, to PORT."
(define title
(channel-news-entry-title entry))
(format port " ~a~%"
(highlight
(string-trim-right
(texi->plain-text (or (assoc-ref title language)
(assoc-ref title (%default-message-language))
""))))))
(define (display-news-entry entry language port) (define (display-news-entry entry language port)
"Display ENTRY, a <channel-news-entry>, in LANGUAGE, a language code, to "Display ENTRY, a <channel-news-entry>, in LANGUAGE, a language code, to
PORT." PORT."
(let ((title (channel-news-entry-title entry)) (define body
(body (channel-news-entry-body entry))) (channel-news-entry-body entry))
(format port " ~a~%"
(highlight (display-news-entry-title entry language port)
(format port (G_ " commit ~a~%")
(channel-news-entry-commit entry))
(newline port)
(format port " ~a~%"
(indented-string
(parameterize ((%text-width (- (%text-width) 4)))
(string-trim-right (string-trim-right
(texi->plain-text (or (assoc-ref title language) (texi->plain-text (or (assoc-ref body language)
(assoc-ref title (%default-message-language)) (assoc-ref body (%default-message-language))
""))))) ""))))
(format port (G_ " commit ~a~%") 4)))
(channel-news-entry-commit entry))
(newline port)
(format port " ~a~%"
(indented-string
(parameterize ((%text-width (- (%text-width) 4)))
(string-trim-right
(texi->plain-text (or (assoc-ref body language)
(assoc-ref body (%default-message-language))
""))))
4))))
(define* (display-channel-specific-news new old (define* (display-channel-specific-news new old
#:key (port (current-output-port))) #:key (port (current-output-port))
concise?)
"Display channel news applicable the commits between OLD and NEW, where OLD "Display channel news applicable the commits between OLD and NEW, where OLD
and NEW are <channel> records with a proper 'commit' field." and NEW are <channel> records with a proper 'commit' field. When CONCISE? is
true, display nothing but the news titles. Return true if there are more news
to display."
(let ((channel new) (let ((channel new)
(old (channel-commit old)) (old (channel-commit old))
(new (channel-commit new))) (new (channel-commit new)))
@ -264,13 +275,17 @@ (define* (display-channel-specific-news new old
(let ((language (current-message-language))) (let ((language (current-message-language)))
(match (channel-news-for-commit channel new old) (match (channel-news-for-commit channel new old)
(() ;no news is good news (() ;no news is good news
#t) #f)
((entries ...) ((entries ...)
(newline port) (newline port)
(format port (G_ "News for channel '~a'~%") (format port (G_ "News for channel '~a'~%")
(channel-name channel)) (channel-name channel))
(for-each (cut display-news-entry <> language port) entries) (for-each (if concise?
(newline port))))))) (cut display-news-entry-title <> language port)
(cut display-news-entry <> language port))
entries)
(newline port)
#t))))))
(define* (display-channel-news profile (define* (display-channel-news profile
#:optional #:optional
@ -317,6 +332,35 @@ (define old
(and old (list new old))) (and old (list new old)))
new-channels))))))) new-channels)))))))
(define* (display-channel-news-headlines profile)
"Display the titles of news about the channels of PROFILE compared to its
previous generation. Return true if there are news to display."
(define previous
(and=> (relative-generation profile -1)
(cut generation-file-name profile <>)))
(when previous
(let ((old-channels (profile-channels previous))
(new-channels (profile-channels profile)))
;; Find the channels present in both PROFILE and PREVIOUS, and print
;; their news.
(and (pair? old-channels) (pair? new-channels)
(let ((channels (filter-map (lambda (new)
(define old
(find (cut channel=? new <>)
old-channels))
(and old (list new old)))
new-channels)))
(define more?
(map (match-lambda
((new old)
(display-channel-specific-news new old
#:concise? #t)))
channels))
(any ->bool more?))))))
(define (display-news profile) (define (display-news profile)
;; Display profile news, with the understanding that this process represents ;; Display profile news, with the understanding that this process represents
;; the newest generation. ;; the newest generation.
@ -344,7 +388,12 @@ (define guix-command
#:dry-run? dry-run?) #:dry-run? dry-run?)
(munless dry-run? (munless dry-run?
(return (newline)) (return (newline))
(return (display-profile-news profile #:concise? #t)) (return
(let ((more? (list (display-profile-news profile #:concise? #t)
(display-channel-news-headlines profile))))
(when (any ->bool more?)
(display-hint
(G_ "Run @command{guix pull --news} to read all the news.")))))
(if guix-command (if guix-command
(let ((new (map (cut string-append <> "/bin/guix") (let ((new (map (cut string-append <> "/bin/guix")
(list (user-friendly-profile profile) (list (user-friendly-profile profile)
@ -544,7 +593,9 @@ (define* (display-new/upgraded-packages alist1 alist2
"Given the two package name/version alists ALIST1 and ALIST2, display the "Given the two package name/version alists ALIST1 and ALIST2, display the
list of new and upgraded packages going from ALIST1 to ALIST2. When ALIST1 list of new and upgraded packages going from ALIST1 to ALIST2. When ALIST1
and ALIST2 differ, display HEADING upfront. When CONCISE? is true, do not and ALIST2 differ, display HEADING upfront. When CONCISE? is true, do not
display long package lists that would fill the user's screen." display long package lists that would fill the user's screen.
Return true when there is more package info to display."
(define (pretty str column) (define (pretty str column)
(indented-string (fill-paragraph str (- (%text-width) 4) (indented-string (fill-paragraph str (- (%text-width) 4)
column) column)
@ -587,10 +638,9 @@ (define upgraded-count (length upgraded))
(pretty (list->enumeration (sort upgraded string<?)) (pretty (list->enumeration (sort upgraded string<?))
35)))) 35))))
(when (and concise? (and concise?
(or (> new-count concise/max-item-count) (or (> new-count concise/max-item-count)
(> upgraded-count concise/max-item-count))) (> upgraded-count concise/max-item-count)))))
(display-hint (G_ "Run @command{guix pull --news} to read all the news.")))))
(define (display-profile-content-diff profile gen1 gen2) (define (display-profile-content-diff profile gen1 gen2)
"Display the changes in PROFILE GEN2 compared to generation GEN1." "Display the changes in PROFILE GEN2 compared to generation GEN1."