From patchwork Sat Jan 16 18:34:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 26426 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 20D2327BC13; Sat, 16 Jan 2021 18:35:29 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id A7B1927BC13 for ; Sat, 16 Jan 2021 18:35:28 +0000 (GMT) Received: from localhost ([::1]:40566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0qPz-0004ab-1V for patchwork@mira.cbaines.net; Sat, 16 Jan 2021 13:35:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0qPf-0004II-Be for guix-patches@gnu.org; Sat, 16 Jan 2021 13:35:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:60730) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l0qPf-0006Nx-4I for guix-patches@gnu.org; Sat, 16 Jan 2021 13:35:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l0qPe-0002X4-W7 for guix-patches@gnu.org; Sat, 16 Jan 2021 13:35:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45919] [PATCH 4/8] channels: Factorize 'manifest-entry-channel' and channel serialization. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 16 Jan 2021 18:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45919 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 45919@debbugs.gnu.org Received: via spool by 45919-submit@debbugs.gnu.org id=B45919.16108220719641 (code B ref 45919); Sat, 16 Jan 2021 18:35:02 +0000 Received: (at 45919) by debbugs.gnu.org; 16 Jan 2021 18:34:31 +0000 Received: from localhost ([127.0.0.1]:44032 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l0qP8-0002VJ-OC for submit@debbugs.gnu.org; Sat, 16 Jan 2021 13:34:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57926) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l0qP4-0002UG-Su for 45919@debbugs.gnu.org; Sat, 16 Jan 2021 13:34:27 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:57161) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0qOz-0006BX-MX; Sat, 16 Jan 2021 13:34:21 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=36420 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l0qOz-0000li-4X; Sat, 16 Jan 2021 13:34:21 -0500 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sat, 16 Jan 2021 19:34:05 +0100 Message-Id: <20210116183409.31229-4-ludo@gnu.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210116183409.31229-1-ludo@gnu.org> References: <20210116183409.31229-1-ludo@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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/channels.scm (sexp->channel, manifest-entry-channel): New procedures. (profile-channels): Replace lambda by 'manifest-entry-channel'. (channel-instance->sexp): New procedure. (channel-instances->manifest)[instance->entry]: Use 'channel-instance->sexp' instead of inline code. --- guix/channels.scm | 106 +++++++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 43 deletions(-) diff --git a/guix/channels.scm b/guix/channels.scm index 0c84eed477..65a0d849ec 100644 --- a/guix/channels.scm +++ b/guix/channels.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2018 Ricardo Wurmus ;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen ;;; @@ -802,13 +802,35 @@ derivation." (derivation-input-derivation input)))) (derivation-inputs drv)))) +(define (channel-instance->sexp instance) + "Return an sexp representation of INSTANCE, a channel instance." + (let* ((commit (channel-instance-commit instance)) + (channel (channel-instance-channel instance)) + (intro (channel-introduction channel))) + `(repository + (version 0) + (url ,(channel-url channel)) + (branch ,(channel-branch channel)) + (commit ,commit) + ,@(if intro + `((introduction + (channel-introduction + (version 0) + (commit + ,(channel-introduction-first-signed-commit + intro)) + (signer + ,(openpgp-format-fingerprint + (channel-introduction-first-commit-signer + intro)))))) + '())))) + (define (channel-instances->manifest instances) "Return a profile manifest with entries for all of INSTANCES, a list of channel instances." (define (instance->entry instance drv) - (let* ((commit (channel-instance-commit instance)) - (channel (channel-instance-channel instance)) - (intro (channel-introduction channel))) + (let ((commit (channel-instance-commit instance)) + (channel (channel-instance-channel instance))) (manifest-entry (name (symbol->string (channel-name channel))) (version (string-take commit 7)) @@ -819,23 +841,7 @@ channel instances." drv) drv)) (properties - `((source (repository - (version 0) - (url ,(channel-url channel)) - (branch ,(channel-branch channel)) - (commit ,commit) - ,@(if intro - `((introduction - (channel-introduction - (version 0) - (commit - ,(channel-introduction-first-signed-commit - intro)) - (signer - ,(openpgp-format-fingerprint - (channel-introduction-first-commit-signer - intro)))))) - '())))))))) + `((source ,(channel-instance->sexp instance))))))) (mlet* %store-monad ((derivations (channel-instance-derivations instances)) (entries -> (map instance->entry instances derivations))) @@ -900,31 +906,45 @@ to 'latest-channel-instances'." validate-pull))) (channel-instances->derivation instances))) +(define* (sexp->channel sexp #:optional (name 'channel)) + "Read SEXP, a provenance sexp as created by 'channel-instance->sexp', +and return a channel called NAME. Return #f if the sexp does not have the +expected structure." + (match sexp + (('repository ('version 0) + ('url url) + ('branch branch) + ('commit commit) + rest ...) + (channel (name name) + (url url) + (commit commit) + (introduction + (match (assq 'introduction rest) + (#f #f) + (('introduction intro) + (sexp->channel-introduction intro)))))) + + (_ #f))) + +(define (manifest-entry-channel entry) + "Return the channel ENTRY corresponds to, or #f if that information is +missing or unreadable. ENTRY must be an entry created by +'channel-instances->manifest', with the 'source' property." + (let ((name (string->symbol (manifest-entry-name entry)))) + (match (assq-ref (manifest-entry-properties entry) 'source) + ((sexp) + (sexp->channel sexp name)) + (_ + ;; No channel information for this manifest entry. + ;; XXX: Pre-0.15.0 Guix did not provide that information, + ;; but there's not much we can do in that case. + #f)))) + (define (profile-channels profile) "Return the list of channels corresponding to entries in PROFILE. If PROFILE is not a profile created by 'guix pull', return the empty list." - (filter-map (lambda (entry) - (match (assq 'source (manifest-entry-properties entry)) - (('source ('repository ('version 0) - ('url url) - ('branch branch) - ('commit commit) - rest ...)) - (channel (name (string->symbol - (manifest-entry-name entry))) - (url url) - (commit commit) - (introduction - (match (assq 'introduction rest) - (#f #f) - (('introduction intro) - (sexp->channel-introduction intro)))))) - - ;; No channel information for this manifest entry. - ;; XXX: Pre-0.15.0 Guix did not provide that information, - ;; but there's not much we can do in that case. - (_ #f))) - + (filter-map manifest-entry-channel ;; Show most recently installed packages last. (reverse (manifest-entries (profile-manifest profile)))))