From patchwork Sat Sep 21 21:12:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 15428 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 12F0D17400; Sat, 21 Sep 2019 22:13:48 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id B1C4E173FB for ; Sat, 21 Sep 2019 22:13:47 +0100 (BST) Received: from localhost ([::1]:43758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iBmhP-0003Pz-0E for patchwork@mira.cbaines.net; Sat, 21 Sep 2019 17:13:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41456) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iBmgq-00035l-Vl for guix-patches@gnu.org; Sat, 21 Sep 2019 17:13:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iBmgo-00061c-K4 for guix-patches@gnu.org; Sat, 21 Sep 2019 17:13:12 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:52666) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iBmgo-00061L-Cj for guix-patches@gnu.org; Sat, 21 Sep 2019 17:13:10 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iBmgo-0000P9-3t for guix-patches@gnu.org; Sat, 21 Sep 2019 17:13:10 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#37413] [PATCH v2 09/11] pull: Display news titles directly upon 'pull'. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 21 Sep 2019 21:13:10 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37413 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 37413@debbugs.gnu.org Received: via spool by 37413-submit@debbugs.gnu.org id=B37413.15691003821469 (code B ref 37413); Sat, 21 Sep 2019 21:13:10 +0000 Received: (at 37413) by debbugs.gnu.org; 21 Sep 2019 21:13:02 +0000 Received: from localhost ([127.0.0.1]:33241 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iBmgf-0000NO-F3 for submit@debbugs.gnu.org; Sat, 21 Sep 2019 17:13:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:32830) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iBmgb-0000LZ-H2 for 37413@debbugs.gnu.org; Sat, 21 Sep 2019 17:12:58 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:49546) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iBmgW-0005iC-Du; Sat, 21 Sep 2019 17:12:52 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=53014 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1iBmgV-00065A-TX; Sat, 21 Sep 2019 17:12:52 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sat, 21 Sep 2019 23:12:26 +0200 Message-Id: <20190921211228.13096-10-ludo@gnu.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190921211228.13096-1-ludo@gnu.org> References: <87sgow0w7w.fsf@gnu.org> <20190921211228.13096-1-ludo@gnu.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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. --- guix/scripts/pull.scm | 112 ++++++++++++++++++++++++++++++------------ 1 file changed, 81 insertions(+), 31 deletions(-) diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm index 4a4756dc6e..a7fd36fffc 100644 --- a/guix/scripts/pull.scm +++ b/guix/scripts/pull.scm @@ -189,7 +189,7 @@ Download and deploy the latest version of Guix.\n")) current-is-newer?) "Display what's up in PROFILE--new packages, and all that. If 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) (reverse (profile-generations profile))) ((current previous _ ...) @@ -212,7 +212,7 @@ newest generation of PROFILE." #:concise? concise? #:heading (G_ "New in this revision:\n"))))) - (_ #t))) + (_ #f))) (define (display-channel channel) "Display information about CHANNEL." @@ -230,33 +230,44 @@ purposes." ;; Assume that the URL matters less than the name. (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) "Display ENTRY, a , in LANGUAGE, a language code, to PORT." - (let ((title (channel-news-entry-title entry)) - (body (channel-news-entry-body entry))) - (format port " ~a~%" - (highlight + (define body + (channel-news-entry-body entry)) + + (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 - (texi->plain-text (or (assoc-ref title language) - (assoc-ref title (%default-message-language)) - ""))))) - (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 - (texi->plain-text (or (assoc-ref body language) - (assoc-ref body (%default-message-language)) - "")))) - 4)))) + (texi->plain-text (or (assoc-ref body language) + (assoc-ref body (%default-message-language)) + "")))) + 4))) (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 -and NEW are records with a proper 'commit' field." +and NEW are 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) (old (channel-commit old)) (new (channel-commit new))) @@ -264,13 +275,17 @@ and NEW are records with a proper 'commit' field." (let ((language (current-message-language))) (match (channel-news-for-commit channel new old) (() ;no news is good news - #t) + #f) ((entries ...) (newline port) (format port (G_ "News for channel '~a'~%") (channel-name channel)) - (for-each (cut display-news-entry <> language port) entries) - (newline port))))))) + (for-each (if concise? + (cut display-news-entry-title <> language port) + (cut display-news-entry <> language port)) + entries) + (newline port) + #t)))))) (define* (display-channel-news profile #:optional @@ -317,6 +332,35 @@ and NEW are records with a proper 'commit' field." (and old (list new old))) 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) ;; Display profile news, with the understanding that this process represents ;; the newest generation. @@ -344,7 +388,12 @@ true, display what would be built without actually building it." #:dry-run? dry-run?) (munless dry-run? (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 (let ((new (map (cut string-append <> "/bin/guix") (list (user-friendly-profile profile) @@ -544,7 +593,9 @@ it." "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 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) (indented-string (fill-paragraph str (- (%text-width) 4) column) @@ -587,10 +638,9 @@ display long package lists that would fill the user's screen." (pretty (list->enumeration (sort upgraded string new-count concise/max-item-count) - (> upgraded-count concise/max-item-count))) - (display-hint (G_ "Run @command{guix pull --news} to read all the news."))))) + (and concise? + (or (> new-count concise/max-item-count) + (> upgraded-count concise/max-item-count))))) (define (display-profile-content-diff profile gen1 gen2) "Display the changes in PROFILE GEN2 compared to generation GEN1."