From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id EKdlOJWiGWEvKwEAgWs5BA (envelope-from ) for ; Mon, 16 Aug 2021 01:26:13 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id UPb4M5WiGWGEbQAAbx9fmQ (envelope-from ) for ; Sun, 15 Aug 2021 23:26:13 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2D975B546 for ; Mon, 16 Aug 2021 01:26:13 +0200 (CEST) Received: from localhost ([::1]:57452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mFPW8-0008ME-8W for larch@yhetil.org; Sun, 15 Aug 2021 19:26:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mFPVy-0008II-M3 for guix-patches@gnu.org; Sun, 15 Aug 2021 19:26:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36403) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mFPVy-0004xy-G9 for guix-patches@gnu.org; Sun, 15 Aug 2021 19:26:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mFPVy-0001qf-D8 for guix-patches@gnu.org; Sun, 15 Aug 2021 19:26:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50072] [PATCH WIP 2/4] import: Factorize file hashing. Resent-From: Sarah Morgensen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 15 Aug 2021 23:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50072 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50072@debbugs.gnu.org Received: via spool by 50072-submit@debbugs.gnu.org id=B50072.16290699387048 (code B ref 50072); Sun, 15 Aug 2021 23:26:02 +0000 Received: (at 50072) by debbugs.gnu.org; 15 Aug 2021 23:25:38 +0000 Received: from localhost ([127.0.0.1]:47943 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mFPVZ-0001pW-Ic for submit@debbugs.gnu.org; Sun, 15 Aug 2021 19:25:38 -0400 Received: from out2.migadu.com ([188.165.223.204]:47102) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mFPVW-0001pL-Gp for 50072@debbugs.gnu.org; Sun, 15 Aug 2021 19:25:35 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mgsn.dev; s=key1; t=1629069932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7akfLvRyHvBOWqyJCG4HKD+1hne9n2Xo0apkJYmGmzY=; b=KPtZsDwr0kwJOix07b9YzqdBLYRFmDcul3feNT/EMuYAjOAxjTQrAntdUz55xoZ4BscaJD aibBAPHpGhqGo40MH7Ojqzs8n2kt7T+UYXY1/+ZLxWXHkTFmcIr0ZSykFIS22h1wsJBimY sw+7Nb/6p03I60V04zovmDv1OGPV0CM= From: Sarah Morgensen Date: Sun, 15 Aug 2021 16:25:25 -0700 Message-Id: <82bab33f2d4a03c8e83d1825648577fbae3aee7e.1629068119.git.iskarian@mgsn.dev> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Auth-User: iskarian@mgsn.dev 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1629069973; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=7akfLvRyHvBOWqyJCG4HKD+1hne9n2Xo0apkJYmGmzY=; b=Vwvwdfne6bVgUfvID9x2uXPXNrcTxJmrHmhBNXhzzsk8YLbL8o57YDz+0aw/azh7NUoTVX LY7fH0NcnfAxrpeDw14U41PM4pTu5+R6JLdXNHcY9wI5MbK6l2jbWQYB7yNN1nyhv8QehU kHm+0J8M/WJHNy84vu2ptwPQ/i3S4Z5NgVTycoAzI/nQBxh3y4jdxTDTA8R9b4mQmu5+m0 fB6rEn2t4eSnGTuu8sXRbVYQ2QyqIsVLGJYjxz2F5dU3AqnTv7TVszpszYQwgzgzdfAtWX jmNl90sRfc2oRpirQarinmvm0GdngHwr5/UYC6TBjM2U3nwhvHlryqdhfuVo7g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1629069973; a=rsa-sha256; cv=none; b=jeXXLhB2graN6BVfEU9PZafEelB2ebuU5i5fcWo+48WdaJbhjKpgHXg4SLzDVd2OSDQf5M RCrizFo5bqPYuWct2QmyEc5ZUhI3GdW9ujU/93GPvYSbYtLSQVRtx9UgQ5Yp0FFlXlw4YQ qkt6jwIT2mgSXIo0q+qghGoKVr2RroBcD85rIlSUkGGp1kLLejqRwFYfUCCm/JRNbncRh3 q3cBb4cbdna263giM2oDnWRQVQx3aMCm43EwsQkSpFzfo0sgHhUUAQo3EE1v3aD8bFJCUp w0YhcWMbQVz1Vp0Z550LeVFk1GfZ1tsyYbRtS1gRMKWRaSTFLx5wJrq7nsoU0A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=mgsn.dev header.s=key1 header.b=KPtZsDwr; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -0.31 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=mgsn.dev header.s=key1 header.b=KPtZsDwr; dmarc=fail reason="SPF not aligned (relaxed)" header.from=mgsn.dev (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 2D975B546 X-Spam-Score: -0.31 X-Migadu-Scanner: scn1.migadu.com X-TUID: GCHeGENYJ+XR * guix/import/cran.scm (vcs-file?, file-hash): Remove procedures. (description->package): Use 'file-hash*' instead. * guix/import/elpa.scm (vcs-file?, file-hash): Remove procedures. (git-repository->origin, elpa-package->sexp): Use 'file-hash* instead'. * guix/import/go.scm (vcs-file?, file-hash): Remove procedures. (git-checkout-hash): Use 'file-hash*' instead. --- guix/import/cran.scm | 32 +++----------------------------- guix/import/elpa.scm | 28 ++++------------------------ guix/import/go.scm | 26 +++----------------------- 3 files changed, 10 insertions(+), 76 deletions(-) diff --git a/guix/import/cran.scm b/guix/import/cran.scm index f649928c5a..ac24bc117e 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2015, 2016, 2017, 2019, 2020 Ludovic Courtès ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2020 Martin Becze +;;; Copyright © 2021 Sarah Morgensen ;;; ;;; This file is part of GNU Guix. ;;; @@ -34,9 +35,8 @@ #:use-module (web uri) #:use-module (guix memoization) #:use-module (guix http-client) - #:use-module (gcrypt hash) + #:use-module (guix hash) #:use-module (guix store) - #:use-module ((guix serialization) #:select (write-file)) #:use-module (guix base32) #:use-module ((guix download) #:select (download-to-store)) #:use-module (guix import utils) @@ -194,17 +194,6 @@ bioconductor package NAME, or #F if the package is unknown." (bioconductor-packages-list type)) (cut assoc-ref <> "Version"))) -;; XXX taken from (guix scripts hash) -(define (vcs-file? file stat) - (case (stat:type stat) - ((directory) - (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) - ((regular) - ;; Git sub-modules have a '.git' file that is a regular text file. - (string=? (basename file) ".git")) - (else - #f))) - ;; Little helper to download URLs only once. (define download (memoize @@ -437,16 +426,6 @@ reference the pkg-config tool." (define (needs-knitr? meta) (member "knitr" (listify meta "VignetteBuilder"))) -;; XXX adapted from (guix scripts hash) -(define (file-hash file select? recursive?) - ;; Compute the hash of FILE. - (if recursive? - (let-values (((port get-hash) (open-sha256-port))) - (write-file file port #:select? select?) - (force-output port) - (get-hash)) - (call-with-input-file file port-sha256))) - (define (description->package repository meta) "Return the `package' s-expression for an R package published on REPOSITORY from the alist META, which was derived from the R package's DESCRIPTION file." @@ -544,12 +523,7 @@ from the alist META, which was derived from the R package's DESCRIPTION file." (sha256 (base32 ,(bytevector->nix-base32-string - (case repository - ((git) - (file-hash source (negate vcs-file?) #t)) - ((hg) - (file-hash source (negate vcs-file?) #t)) - (else (file-sha256 source)))))))) + (file-hash* source)))))) ,@(if (not (and git? hg? (equal? (string-append "r-" name) (cran-guix-name name)))) diff --git a/guix/import/elpa.scm b/guix/import/elpa.scm index c0dc5acf51..22c937ca5f 100644 --- a/guix/import/elpa.scm +++ b/guix/import/elpa.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2018 Oleg Pykhalov ;;; Copyright © 2020 Martin Becze ;;; Copyright © 2020 Ricardo Wurmus +;;; Copyright © 2021 Sarah Morgensen ;;; ;;; This file is part of GNU Guix. ;;; @@ -36,10 +37,10 @@ #:use-module (guix import utils) #:use-module (guix http-client) #:use-module (guix git) + #:use-module (guix hash) #:use-module ((guix serialization) #:select (write-file)) #:use-module (guix store) #:use-module (guix ui) - #:use-module (gcrypt hash) #:use-module (guix base32) #:use-module (guix upstream) #:use-module (guix packages) @@ -226,27 +227,6 @@ keywords to values." (close-port port) (data->recipe (cons ':name data)))) -;; XXX adapted from (guix scripts hash) -(define (file-hash file select? recursive?) - ;; Compute the hash of FILE. - (if recursive? - (let-values (((port get-hash) (open-sha256-port))) - (write-file file port #:select? select?) - (force-output port) - (get-hash)) - (call-with-input-file file port-sha256))) - -;; XXX taken from (guix scripts hash) -(define (vcs-file? file stat) - (case (stat:type stat) - ((directory) - (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) - ((regular) - ;; Git sub-modules have a '.git' file that is a regular text file. - (string=? (basename file) ".git")) - (else - #f))) - (define (git-repository->origin recipe url) "Fetch origin details from the Git repository at URL for the provided MELPA RECIPE." @@ -268,7 +248,7 @@ RECIPE." (sha256 (base32 ,(bytevector->nix-base32-string - (file-hash directory (negate vcs-file?) #t))))))) + (file-hash* directory))))))) (define* (melpa-recipe->origin recipe) "Fetch origin details from the MELPA recipe and associated repository for @@ -379,7 +359,7 @@ type ''." (sha256 (base32 ,(if tarball - (bytevector->nix-base32-string (file-sha256 tarball)) + (bytevector->nix-base32-string (file-hash* tarball)) "failed to download package"))))))) (build-system emacs-build-system) ,@(maybe-inputs 'propagated-inputs dependencies) diff --git a/guix/import/go.scm b/guix/import/go.scm index 617a0d0e23..c6425667f8 100644 --- a/guix/import/go.scm +++ b/guix/import/go.scm @@ -25,6 +25,7 @@ (define-module (guix import go) #:use-module (guix build-system go) #:use-module (guix git) + #:use-module (guix hash) #:use-module (guix i18n) #:use-module (guix diagnostics) #:use-module (guix import utils) @@ -35,9 +36,7 @@ #:use-module ((guix licenses) #:prefix license:) #:use-module (guix memoization) #:autoload (htmlprag) (html->sxml) ;from Guile-Lib - #:autoload (guix git) (update-cached-checkout) - #:autoload (gcrypt hash) (open-hash-port hash-algorithm sha256) - #:autoload (guix serialization) (write-file) + #:autoload (gcrypt hash) (hash-algorithm sha256) #:autoload (guix base32) (bytevector->nix-base32-string) #:autoload (guix build utils) (mkdir-p) #:use-module (ice-9 match) @@ -494,25 +493,6 @@ source." goproxy (module-meta-repo-root meta-data))) -;; XXX: Copied from (guix scripts hash). -(define (vcs-file? file stat) - (case (stat:type stat) - ((directory) - (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) - ((regular) - ;; Git sub-modules have a '.git' file that is a regular text file. - (string=? (basename file) ".git")) - (else - #f))) - -;; XXX: Adapted from 'file-hash' in (guix scripts hash). -(define* (file-hash file #:optional (algorithm (hash-algorithm sha256))) - ;; Compute the hash of FILE. - (let-values (((port get-hash) (open-hash-port algorithm))) - (write-file file port #:select? (negate vcs-file?)) - (force-output port) - (get-hash))) - (define* (git-checkout-hash url reference algorithm) "Return the ALGORITHM hash of the checkout of URL at REFERENCE, a commit or tag." @@ -531,7 +511,7 @@ tag." (update-cached-checkout url #:ref `(tag-or-commit . ,reference))))) - (file-hash checkout algorithm))) + (file-hash* checkout #:algorithm algorithm))) (define (vcs->origin vcs-type vcs-repo-url version) "Generate the `origin' block of a package depending on what type of source -- 2.31.1